Skip to content

Commit fce9339

Browse files
committed
ASTDemangler: Implement types in generic local context
If we nest a type inside a local context inside a generic type, we have to look through the local context(s) to find the outer generic type when stripping off generic arguments. We don't support nominal types inside generic local context right now, but this can happen with type aliases.
1 parent 81aad59 commit fce9339

File tree

7 files changed

+158
-97
lines changed

7 files changed

+158
-97
lines changed

include/swift/Demangling/TypeDecoder.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@
2828
namespace swift {
2929
namespace Demangle {
3030

31-
/// Strip generic arguments from the "spine" of a context node, producing a
32-
/// bare context to be used in (e.g.) forming nominal type descriptors.
33-
NodePointer stripGenericArgsFromContextNode(NodePointer node,
34-
NodeFactory &factory);
35-
3631
/// Describe a function parameter, parameterized on the type
3732
/// representation.
3833
template <typename BuiltType>
@@ -611,8 +606,7 @@ class TypeDecoder {
611606
parent = decodeMangledType(parentContext);
612607
// Remove any generic arguments from the context node, producing a
613608
// node that references the nominal type declaration.
614-
declNode =
615-
stripGenericArgsFromContextNode(node, Builder.getNodeFactory());
609+
declNode = Demangle::getUnspecialized(node, Builder.getNodeFactory());
616610
break;
617611
}
618612
}

lib/Demangling/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ add_swift_host_library(swiftDemangling
99
OldRemangler.cpp
1010
Punycode.cpp
1111
Remangler.cpp
12-
TypeDecoder.cpp
1312
C_COMPILE_FLAGS
1413
-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1)
1514

lib/Demangling/TypeDecoder.cpp

Lines changed: 0 additions & 85 deletions
This file was deleted.

stdlib/public/Reflection/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ set(swiftReflection_SOURCES
99
"${SWIFT_SOURCE_DIR}/lib/Demangling/NodePrinter.cpp"
1010
"${SWIFT_SOURCE_DIR}/lib/Demangling/ManglingUtils.cpp"
1111
"${SWIFT_SOURCE_DIR}/lib/Demangling/Punycode.cpp"
12-
"${SWIFT_SOURCE_DIR}/lib/Demangling/Remangler.cpp"
13-
"${SWIFT_SOURCE_DIR}/lib/Demangling/TypeDecoder.cpp")
12+
"${SWIFT_SOURCE_DIR}/lib/Demangling/Remangler.cpp")
1413

1514
# When we're building with assertions, include the demangle node dumper to aid
1615
# in debugging.

stdlib/public/runtime/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ set(swift_runtime_objc_sources
2626
ObjCRuntimeGetImageNameFromClass.mm
2727
"${SWIFT_SOURCE_DIR}/lib/Demangling/OldRemangler.cpp"
2828
"${SWIFT_SOURCE_DIR}/lib/Demangling/Remangler.cpp"
29-
"${SWIFT_SOURCE_DIR}/lib/Demangling/TypeDecoder.cpp"
3029
)
3130

3231
set(swift_runtime_sources

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ _findExtendedTypeContextDescriptor(const ExtensionContextDescriptor *extension,
246246
return nullptr;
247247
node = node->getChild(0);
248248
}
249-
node = stripGenericArgsFromContextNode(node, demangler);
249+
node = Demangle::getUnspecialized(node, demangler);
250250

251251
return _findNominalTypeDescriptor(node, demangler);
252252
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift -emit-executable %s -g -o %t/generic_local_types -emit-module
4+
// RUN: sed -ne '/\/\/ *DEMANGLE: /s/\/\/ *DEMANGLE: *//p' < %s > %t/input
5+
// RUN: %lldb-moduleimport-test %t/generic_local_types -type-from-mangled=%t/input | %FileCheck %s
6+
7+
func blackHole(_: Any...) {}
8+
9+
class Generic<T> {
10+
// Initializer -> closure
11+
var x1: Int = {
12+
typealias Alias1 = Int
13+
let a: Alias1 = 0
14+
return a
15+
}()
16+
17+
// Implicit getter
18+
var x2: Int {
19+
typealias Alias2 = Int
20+
let a: Alias2 = 0
21+
return a
22+
}
23+
24+
// Observers
25+
var x3: Int = 0 {
26+
didSet {
27+
typealias Alias3 = Int
28+
let a: Alias3 = 0
29+
blackHole(a)
30+
}
31+
willSet {
32+
typealias Alias4 = Int
33+
let a: Alias4 = 0
34+
blackHole(a)
35+
}
36+
}
37+
38+
// Getter and setter
39+
var x4: Int {
40+
get {
41+
typealias Alias5 = Int
42+
let a: Alias5 = 0
43+
return a
44+
}
45+
set {
46+
typealias Alias6 = Int
47+
let a: Alias6 = 0
48+
blackHole(a)
49+
}
50+
}
51+
52+
// Read and modify
53+
var x5: Int {
54+
_read {
55+
typealias Alias7 = Int
56+
let a: Alias7 = 0
57+
yield a
58+
}
59+
_modify {
60+
typealias Alias8 = Int
61+
var a: Alias8 = 0
62+
yield &a
63+
}
64+
}
65+
66+
// Subscript implicit getter
67+
subscript(x x: Int) -> Int {
68+
typealias Alias9 = Int
69+
let a: Alias9 = 0
70+
return a
71+
}
72+
73+
// Subscript getter and setter
74+
subscript(y y: Int) -> Int {
75+
get {
76+
typealias Alias10 = Int
77+
let a: Alias10 = 0
78+
return a
79+
}
80+
set {
81+
typealias Alias11 = Int
82+
let a: Alias11 = 0
83+
blackHole(a)
84+
}
85+
}
86+
87+
// Function -> default argument -> closure
88+
func method(_: Int = {
89+
typealias Alias12 = Int
90+
let a: Alias12 = 0
91+
return a
92+
}()) {
93+
// Function
94+
typealias Alias13 = Int
95+
let a: Alias13 = 0
96+
97+
blackHole(a)
98+
99+
// Function -> function
100+
func nested() {
101+
typealias Alias = Int
102+
let a: Alias = 0
103+
104+
blackHole(a)
105+
}
106+
}
107+
108+
// Constructor
109+
init() {
110+
typealias Alias14 = Int
111+
let a: Alias14 = 0
112+
113+
blackHole(a)
114+
}
115+
116+
// Destructor
117+
deinit {
118+
typealias Alias15 = Int
119+
let a: Alias15 = 0
120+
121+
blackHole(a)
122+
}
123+
}
124+
125+
// DEMANGLE: $s19generic_local_types7GenericC2x1SivpfiSiyXEfU_6Alias1L_ayx_GD
126+
// DEMANGLE: $s19generic_local_types7GenericC2x2Sivg6Alias2L_ayx__GD
127+
// DEMANGLE: $s19generic_local_types7GenericC2x3SivW6Alias3L_ayx__GD
128+
// DEMANGLE: $s19generic_local_types7GenericC2x3Sivw6Alias4L_ayx__GD
129+
// DEMANGLE: $s19generic_local_types7GenericC2x4Sivg6Alias5L_ayx__GD
130+
// DEMANGLE: $s19generic_local_types7GenericC2x4Sivs6Alias6L_ayx__GD
131+
// DEMANGLE: $s19generic_local_types7GenericC2x5Sivr6Alias7L_ayx__GD
132+
// DEMANGLE: $s19generic_local_types7GenericC2x5SivM6Alias8L_ayx__GD
133+
// DEMANGLE: $s19generic_local_types7GenericC1xS2i_tcig6Alias9L_ayx__GD
134+
// DEMANGLE: $s19generic_local_types7GenericC1yS2i_tcig7Alias10L_ayx__GD
135+
// DEMANGLE: $s19generic_local_types7GenericC1yS2i_tcis7Alias11L_ayx__GD
136+
// DEMANGLE: $s19generic_local_types7GenericC6methodyySiFfA_SiycfU_7Alias12L_ayx__GD
137+
// DEMANGLE: $s19generic_local_types7GenericC6methodyySiF7Alias13L_ayx__GD
138+
// DEMANGLE: $s19generic_local_types7GenericCACyxGycfc7Alias14L_ayx__GD
139+
// DEMANGLE: $s19generic_local_types7GenericCfd7Alias15L_ayx__GD
140+
141+
// CHECK: Alias1
142+
// CHECK: Alias2
143+
// CHECK: Alias3
144+
// CHECK: Alias4
145+
// CHECK: Alias5
146+
// CHECK: Alias6
147+
// CHECK: Alias7
148+
// CHECK: Alias8
149+
// CHECK: Alias9
150+
// CHECK: Alias10
151+
// CHECK: Alias11
152+
// CHECK: Alias12
153+
// CHECK: Alias13
154+
// CHECK: Alias14
155+
// CHECK: Alias15

0 commit comments

Comments
 (0)