Skip to content

Commit 4c6a22a

Browse files
committed
[lldb] Factor out iteration over runtime types from GetChildCompilerTypeAtIndex()
This patch introduces a new class SwiftRuntimeTypeVisitor that exists to unify iteration over runtime type information. The visitor callback has closure parameters that can be called to make additional expensive queries on a child. TODO: This is not the final evolution step. - We probably should remove the "depth" parameter entirely and implement the access path computation for GetIndexOfChildMemberWithName at a different layer. - We could cache the results for the last execution context. Relanding with an off-by-one error fixed in GetExistentialSyntheticChildren that was caught by ASAN!
1 parent 784a8a8 commit 4c6a22a

File tree

12 files changed

+815
-646
lines changed

12 files changed

+815
-646
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ struct SuperClassType;
6767
using ThreadSafeReflectionContext = LockGuarded<ReflectionContextInterface>;
6868

6969
class SwiftLanguageRuntime : public LanguageRuntime {
70+
friend class SwiftRuntimeTypeVisitor;
71+
7072
protected:
7173
SwiftLanguageRuntime(Process &process);
7274

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

+771-632
Large diffs are not rendered by default.

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

-4
Original file line numberDiff line numberDiff line change
@@ -8623,10 +8623,6 @@ std::string SwiftASTContext::GetSwiftName(const clang::Decl *clang_decl,
86238623
return {};
86248624
}
86258625

8626-
CompilerType SwiftASTContext::GetBuiltinRawPointerType() {
8627-
return GetTypeFromMangledTypename(ConstString("$sBpD"));
8628-
}
8629-
86308626
CompilerType
86318627
SwiftASTContext::ConvertClangTypeToSwiftType(CompilerType clang_type) {
86328628
auto ts = GetTypeSystemSwiftTypeRef();

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

-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ class SwiftASTContext : public TypeSystemSwift {
412412
std::string GetSwiftName(const clang::Decl *clang_decl,
413413
TypeSystemClang &clang_typesystem) override;
414414

415-
CompilerType GetBuiltinRawPointerType() override;
416415
CompilerType GetBuiltinIntType();
417416

418417
/// Attempts to convert a Clang type into a Swift type.

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

+8
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ bool TypeSystemSwift::IsScalarType(opaque_compiler_type_t type) {
9898
return (GetTypeInfo(type, nullptr) & eTypeIsScalar) != 0;
9999
}
100100

101+
CompilerType TypeSystemSwift::GetBuiltinRawPointerType() {
102+
return GetTypeFromMangledTypename(ConstString("$sBpD"));
103+
}
104+
105+
CompilerType TypeSystemSwift::GetBuiltinUnknownObjectType() {
106+
return GetTypeFromMangledTypename(ConstString("$sBOD"));
107+
}
108+
101109
bool TypeSystemSwift::ShouldTreatScalarValueAsAddress(
102110
opaque_compiler_type_t type) {
103111
return Flags(GetTypeInfo(type, nullptr))

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ class TypeSystemSwift : public TypeSystem {
197197
virtual std::string GetSwiftName(const clang::Decl *clang_decl,
198198
TypeSystemClang &clang_typesystem) = 0;
199199

200-
virtual CompilerType GetBuiltinRawPointerType() = 0;
200+
CompilerType GetBuiltinRawPointerType();
201+
CompilerType GetBuiltinUnknownObjectType();
201202

202203
/// Attempts to convert a Clang type into a Swift type.
203204
/// For example, int is converted to Int32.

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

-5
Original file line numberDiff line numberDiff line change
@@ -1445,11 +1445,6 @@ TypeSystemSwiftTypeRef::GetSwiftName(const clang::Decl *clang_decl,
14451445
return {};
14461446
}
14471447

1448-
CompilerType TypeSystemSwiftTypeRef::GetBuiltinRawPointerType() {
1449-
return GetTypeFromMangledTypename(ConstString("$sBpD"));
1450-
}
1451-
1452-
14531448
static bool IsImportedType(swift::Demangle::NodePointer node) {
14541449
if (!node)
14551450
return false;

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

-2
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
412412
std::string GetSwiftName(const clang::Decl *clang_decl,
413413
TypeSystemClang &clang_typesystem) override;
414414

415-
CompilerType GetBuiltinRawPointerType() override;
416-
417415
/// Wrap \p node as \p Global(TypeMangling(node)), remangle the type
418416
/// and create a CompilerType from it.
419417
CompilerType RemangleAsType(swift::Demangle::Demangler &dem,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
3+
include Makefile.rules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
class TestSwiftObjCBaseClassMemberLookup(TestBase):
7+
NO_DEBUG_INFO_TESTCASE = True
8+
@skipUnlessDarwin
9+
@swiftTest
10+
def test(self):
11+
"""Test accessing a static member from a member function"""
12+
self.build()
13+
lldbutil.run_to_source_breakpoint(
14+
self, 'break here', lldb.SBFileSpec('main.swift')
15+
)
16+
17+
p = self.frame().FindVariable("p").GetStaticValue()
18+
self.assertEqual(p.GetNumChildren(), 1)
19+
self.assertEqual(p.GetChildAtIndex(0).GetSummary(), '"hello"')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Foundation
2+
3+
func foo(p: NSCopying) {
4+
print("break here")
5+
}
6+
7+
let s : NSString = "hello"
8+
foo(p: s)
9+

lldb/test/API/lang/swift/variables/protocol/TestSwiftProtocolTypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_swift_protocol_types(self):
7272
self.expect("expression --dynamic-type no-dynamic-values"
7373
" --raw-output --show-types -- loc3dCB",
7474
substrs=['PointUtils & Swift.AnyObject) $R',
75-
'(Builtin.RawPointer) object = 0x',
75+
'(Builtin.UnknownObject) object = 0x',
7676
'(Builtin.RawPointer) wtable = 0x'])
7777

7878
self.expect("expression -- loc3dCB",

0 commit comments

Comments
 (0)