Skip to content

Commit 2d21233

Browse files
committed
ASTDemangler: Implement unresolved DependentMemberType
The debug mangling emits these when the type parameter only conforms to one protocol having an associated type with this name.
1 parent 8df0d8e commit 2d21233

File tree

6 files changed

+132
-1
lines changed

6 files changed

+132
-1
lines changed

include/swift/AST/ASTDemangler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class ASTBuilder {
9090

9191
Type createGenericTypeParameterType(unsigned depth, unsigned index);
9292

93+
Type createDependentMemberType(StringRef member, Type base);
94+
9395
Type createDependentMemberType(StringRef member, Type base,
9496
ProtocolDecl *protocol);
9597

include/swift/Demangling/TypeDecoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ class TypeDecoder {
464464
auto member = Node->getChild(1)->getText();
465465
auto assocTypeChild = Node->getChild(1);
466466
if (assocTypeChild->getNumChildren() < 1)
467-
return BuiltType();
467+
return Builder.createDependentMemberType(member, base);
468468

469469
auto protocol = decodeMangledProtocolType(assocTypeChild->getChild(0));
470470
if (!protocol)

include/swift/Reflection/TypeRefBuilder.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ class TypeRefBuilder {
300300
return GenericTypeParameterTypeRef::create(*this, depth, index);
301301
}
302302

303+
const DependentMemberTypeRef *
304+
createDependentMemberType(const std::string &member,
305+
const TypeRef *base) {
306+
// Should not have unresolved dependent member types here.
307+
return nullptr;
308+
}
309+
303310
const DependentMemberTypeRef *
304311
createDependentMemberType(const std::string &member,
305312
const TypeRef *base,

lib/AST/ASTDemangler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ Type ASTBuilder::createGenericTypeParameterType(unsigned depth,
329329
return GenericTypeParamType::get(depth, index, Ctx);
330330
}
331331

332+
Type ASTBuilder::createDependentMemberType(StringRef member,
333+
Type base) {
334+
if (!base->isTypeParameter())
335+
return Type();
336+
337+
return DependentMemberType::get(base, Ctx.getIdentifier(member));
338+
}
339+
332340
Type ASTBuilder::createDependentMemberType(StringRef member,
333341
Type base,
334342
ProtocolDecl *protocol) {

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,11 @@ class DecodedMetadataBuilder {
11641164
/*proposedWitnesses=*/nullptr).Value;
11651165
}
11661166

1167+
BuiltType createDependentMemberType(StringRef name, BuiltType base) const {
1168+
// Should not have unresolved dependent member types here.
1169+
return BuiltType();
1170+
}
1171+
11671172
BuiltType createDependentMemberType(StringRef name, BuiltType base,
11681173
BuiltProtocolDecl protocol) const {
11691174
#if SWIFT_OBJC_INTEROP

test/TypeDecoder/generics.swift

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift -emit-executable %s -g -o %t/generics -emit-module
4+
// RUN: sed -ne '/\/\/ *DEMANGLE: /s/\/\/ *DEMANGLE: *//p' < %s > %t/input
5+
// RUN: %lldb-moduleimport-test %t/generics -type-from-mangled=%t/input | %FileCheck %s
6+
7+
func blackHole(_: Any...) {}
8+
9+
protocol First {
10+
associatedtype Assoc : First
11+
}
12+
13+
protocol Second {
14+
associatedtype Assoc : Second
15+
}
16+
17+
struct OuterFirst<A : First, B : First> {
18+
struct Inner<C : First, D : First> {
19+
func method(a: A, b: B, c: C, d: D) {
20+
do {
21+
let fn: (A, A.Assoc, A.Assoc.Assoc) -> () = { _, _, _ in }
22+
}
23+
do {
24+
let fn: (B, B.Assoc, B.Assoc.Assoc) -> () = { _, _, _ in }
25+
}
26+
do {
27+
let fn: (C, C.Assoc, C.Assoc.Assoc) -> () = { _, _, _ in }
28+
}
29+
do {
30+
let fn: (D, D.Assoc, D.Assoc.Assoc) -> () = { _, _, _ in }
31+
}
32+
}
33+
}
34+
}
35+
36+
struct OuterBoth<A : First & Second, B : First & Second> {
37+
struct Inner<C : First & Second, D : First & Second> {
38+
func method(a: A, b: B, c: C, d: D) {
39+
do {
40+
let fn: (A, A.Assoc, A.Assoc.Assoc) -> () = { _, _, _ in }
41+
}
42+
do {
43+
let fn: (B, B.Assoc, B.Assoc.Assoc) -> () = { _, _, _ in }
44+
}
45+
do {
46+
let fn: (C, C.Assoc, C.Assoc.Assoc) -> () = { _, _, _ in }
47+
}
48+
do {
49+
let fn: (D, D.Assoc, D.Assoc.Assoc) -> () = { _, _, _ in }
50+
}
51+
}
52+
}
53+
}
54+
55+
// DEMANGLE: $sxD
56+
// DEMANGLE: $s5AssocQzD
57+
// DEMANGLE: $s5Assoc_AAQZD
58+
59+
// CHECK: τ_0_0
60+
// CHECK: τ_0_0.Assoc
61+
// CHECK: τ_0_0.Assoc.Assoc
62+
63+
// DEMANGLE: $sq_D
64+
// DEMANGLE: $s5AssocQy_D
65+
// DEMANGLE: $s5Assoc_AAQY_D
66+
67+
// CHECK: τ_0_1
68+
// CHECK: τ_0_1.Assoc
69+
// CHECK: τ_0_1.Assoc.Assoc
70+
71+
// DEMANGLE: $sqd__D
72+
// DEMANGLE: $s5AssocQyd__D
73+
// DEMANGLE: $s5Assoc_AAQYd__D
74+
75+
// CHECK: τ_1_0
76+
// CHECK: τ_1_0.Assoc
77+
// CHECK: τ_1_0.Assoc.Assoc
78+
79+
// DEMANGLE: $sqd_0_D
80+
// DEMANGLE: $s5AssocQyd_0_D
81+
// DEMANGLE: $s5Assoc_AAQYd_0_D
82+
83+
// CHECK: τ_1_1
84+
// CHECK: τ_1_1.Assoc
85+
// CHECK: τ_1_1.Assoc.Assoc
86+
87+
// DEMANGLE: $s5Assoc8generics5FirstPQzD
88+
// DEMANGLE: $s5Assoc8generics5FirstP_AaDQZD
89+
90+
// CHECK: τ_0_0.Assoc
91+
// CHECK: τ_0_0.Assoc.Assoc
92+
93+
// DEMANGLE: $s5Assoc8generics5FirstPQy_D
94+
// DEMANGLE: $s5Assoc8generics5FirstP_AaDQY_D
95+
96+
// CHECK: τ_0_1.Assoc
97+
// CHECK: τ_0_1.Assoc.Assoc
98+
99+
// DEMANGLE: $s5Assoc8generics5FirstPQyd__D
100+
// DEMANGLE: $s5Assoc8generics5FirstP_AaDQYd__D
101+
102+
// CHECK: τ_1_0.Assoc
103+
// CHECK: τ_1_0.Assoc.Assoc
104+
105+
// DEMANGLE: $s5Assoc8generics5FirstPQyd_0_D
106+
// DEMANGLE: $s5Assoc8generics5FirstP_AaDQYd_0_D
107+
108+
// CHECK: τ_1_1.Assoc
109+
// CHECK: τ_1_1.Assoc.Assoc

0 commit comments

Comments
 (0)