Skip to content

Commit 6743226

Browse files
Merge pull request #3437 from adrian-prantl/breakpointperf
Add a test to ensure that no SwiftASTContext is initialized for setti…
2 parents 9dddb46 + 69ca168 commit 6743226

File tree

7 files changed

+56
-1
lines changed

7 files changed

+56
-1
lines changed

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,13 +1335,18 @@ SwiftASTContext *TypeSystemSwiftTypeRef::GetSwiftASTContext() const {
13351335
return m_swift_ast_context;
13361336
}
13371337

1338+
SwiftASTContext *TypeSystemSwiftTypeRef::GetSwiftASTContextOrNull() const {
1339+
return m_swift_ast_context;
1340+
}
1341+
13381342
void TypeSystemSwiftTypeRef::SetTriple(const llvm::Triple triple) {
13391343
if (auto *swift_ast_context = GetSwiftASTContext())
13401344
swift_ast_context->SetTriple(triple);
13411345
}
13421346

13431347
void TypeSystemSwiftTypeRef::ClearModuleDependentCaches() {
1344-
if (auto *swift_ast_context = GetSwiftASTContext())
1348+
// There is no need to notify a not-yet created SwiftASTContext to reset.
1349+
if (auto *swift_ast_context = GetSwiftASTContextOrNull())
13451350
swift_ast_context->ClearModuleDependentCaches();
13461351
}
13471352
const char *TypeSystemSwiftTypeRef::AsMangledName(opaque_compiler_type_t type) {

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
5757
~TypeSystemSwiftTypeRef();
5858
TypeSystemSwiftTypeRef(Module &module);
5959
TypeSystemSwiftTypeRef(SwiftASTContextForExpressions &swift_ast_context);
60+
/// Get the corresponding SwiftASTContext, and create one if necessary.
6061
SwiftASTContext *GetSwiftASTContext() const override;
62+
/// Return SwiftASTContext, iff one has already been created.
63+
SwiftASTContext *GetSwiftASTContextOrNull() const;
6164
TypeSystemSwiftTypeRef &GetTypeSystemSwiftTypeRef() override { return *this; }
6265
void SetTriple(const llvm::Triple triple) override;
6366
void ClearModuleDependentCaches() override;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SWIFT_SOURCES := main.swift
2+
include Makefile.rules
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import unittest2
6+
7+
class TestSwiftReflectionLoading(lldbtest.TestBase):
8+
mydir = lldbtest.TestBase.compute_mydir(__file__)
9+
10+
@swiftTest
11+
def test(self):
12+
"""Test that no SwiftASTContext is initialized just to stop at a breakpoint"""
13+
self.build()
14+
15+
log = self.getBuildArtifact("types.log")
16+
self.runCmd('log enable lldb types -f "%s"' % log)
17+
18+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
19+
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))
20+
21+
# Scan through the types log.
22+
logfile = open(log, "r")
23+
found_typeref = 0
24+
found_astctx = 0
25+
for line in logfile:
26+
if 'TypeSystemSwiftTypeRef("a.out")::TypeSystemSwiftTypeRef()' in line:
27+
found_typeref += 1
28+
if 'SwiftASTContext' in line:
29+
found_astctx += 1
30+
self.assertEqual(found_typeref, 1)
31+
self.assertEqual(found_astctx, 0)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
class C {
3+
func f() {
4+
{
5+
print("hello from a complicated context") // Set breakpoint here
6+
}()
7+
}
8+
}
9+
10+
let c = C()
11+
c.f()

lldb/test/API/lang/swift/clangimporter/rewrite_clang_paths/TestSwiftRewriteClangPaths.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def dotest(self, remap):
8787
self.expect("fr var foo", comment, substrs=["x", "23"])
8888
self.expect("fr var bar", comment, substrs=["y", "42"])
8989
self.assertTrue(os.path.isdir(mod_cache), "module cache exists")
90+
else:
91+
self.expect("p foo", error=True)
9092

9193
# Scan through the types log.
9294
errs = 0

lldb/test/API/lang/swift/parseable_interfaces/shared/TestSwiftInterfaceNoDebugInfo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_prebuilt_cache_location(self):
5959
lldbutil.run_to_source_breakpoint(
6060
self, "break here", lldb.SBFileSpec("main.swift"),
6161
exe_name=self.getBuildArtifact("main"))
62+
self.expect("expr 1")
6263

6364
# Check the prebuilt cache path in the log output
6465
prefix = 'Using prebuilt Swift module cache path: '

0 commit comments

Comments
 (0)