Skip to content

Commit 1a10c81

Browse files
committed
[lldb] Change LLDBTypeInfoProvider to a local (per-module) TypeSystemSwift
The decision of using a scratch context in TIP was made because reading types from a Process' reflection metadata can return types outside of the current lldb_private::Module. That'd be a huge problem for SwiftASTContext because it would pollute the context with ASTs from outside the Module, but TypeSystemSwiftTypeRef only deals in type names, which makes it immune to these risks. This change allows TypeAlias lookups to be made locally, which can dramatically speed up type resolution. In a real-world benchmark of printing self in a large Swift/ObjC application the time spent in FindTypes() goes from 50% to it not even showing up on the profile. rdar://145884579
1 parent 6f817b2 commit 1a10c81

File tree

8 files changed

+128
-97
lines changed

8 files changed

+128
-97
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp

Lines changed: 81 additions & 93 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
typedef enum { someValue } TDEnum;
2+
3+
typedef struct {
4+
TDEnum e;
5+
} TDStruct;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFTFLAGS_EXTRAS = -I$(SRCDIR) -Xcc -I$(SRCDIR)
3+
4+
include Makefile.rules
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
class TestSwiftDWARFImporterC(lldbtest.TestBase):
7+
8+
@swiftTest
9+
def test(self):
10+
self.build()
11+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
12+
self, 'break here', lldb.SBFileSpec('main.swift'))
13+
s = self.frame().FindVariable("s", lldb.eDynamicDontRunTarget)
14+
s_e = s.GetChildAtIndex(0)
15+
self.expect("log enable lldb types -v")
16+
lldbutil.check_variable(self, s_e, value="someValue")
17+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import CTypes
2+
3+
func f() {
4+
var s = TDStruct(e: someValue)
5+
print("break here")
6+
}
7+
8+
f()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module CTypes {
2+
header "CTypes.h"
3+
export *
4+
}

lldb/test/API/lang/swift/late_swift_dylib_clangdeps/TestSwiftLateSwiftDylibClangDeps.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ def test(self):
2323
lldb.SBFileSpec('dylib.swift'), 5)
2424
threads = lldbutil.continue_to_breakpoint(process, bkpt)
2525

26-
self.expect("v x", substrs=['42'])
26+
self.expect("v fromClang", substrs=['42'])
2727
self.expect("frame select 1")
28-
self.expect("v fromClang", substrs=['23'])
28+
# Note that in earlier versions the lookup was a global one and
29+
# thus re-evaluating the variable after adding dylib would
30+
# have produced a different result. Currently these lookups
31+
# are per-module so this expectedly still fails.
32+
self.expect("v fromClang",
33+
substrs=["missing debug info", "FromClang"])
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ClangMod
22

33
@_silgen_name("f") public func f() {
4-
let x = FromClang(x: 42)
5-
print(x) // line 5
4+
let fromClang = FromClang(x: 42)
5+
print(fromClang) // line 5
66
}

0 commit comments

Comments
 (0)