Skip to content

Commit a0e7cce

Browse files
committed
ASTDemangler: Use associated type declarations instead of identifiers as keys
1 parent 2f6b45d commit a0e7cce

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

lib/AST/ASTDemangler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,8 @@ Type ASTBuilder::createExistentialMetatypeType(
767767
Type ASTBuilder::createConstrainedExistentialType(
768768
Type base, ArrayRef<BuiltRequirement> constraints,
769769
ArrayRef<BuiltInverseRequirement> inverseRequirements) {
770-
llvm::SmallDenseMap<Identifier, Type> primaryAssociatedTypes;
771-
llvm::SmallDenseSet<Identifier> claimed;
770+
llvm::SmallDenseMap<AssociatedTypeDecl *, Type> primaryAssociatedTypes;
771+
llvm::SmallDenseSet<AssociatedTypeDecl *> claimed;
772772

773773
for (const auto &req : constraints) {
774774
switch (req.getKind()) {
@@ -782,7 +782,7 @@ Type ASTBuilder::createConstrainedExistentialType(
782782
if (auto *memberTy = req.getFirstType()->getAs<DependentMemberType>()) {
783783
if (memberTy->getBase()->is<GenericTypeParamType>()) {
784784
// This is the only case we understand so far.
785-
primaryAssociatedTypes[memberTy->getName()] = req.getSecondType();
785+
primaryAssociatedTypes[memberTy->getAssocType()] = req.getSecondType();
786786
continue;
787787
}
788788
}
@@ -799,7 +799,7 @@ Type ASTBuilder::createConstrainedExistentialType(
799799

800800
llvm::SmallVector<Type, 4> args;
801801
for (auto *assocTy : proto->getPrimaryAssociatedTypes()) {
802-
auto found = primaryAssociatedTypes.find(assocTy->getName());
802+
auto found = primaryAssociatedTypes.find(assocTy);
803803
if (found == primaryAssociatedTypes.end())
804804
return protoTy;
805805
args.push_back(found->second);

test/DebugInfo/parameterized_existential_composition.swift

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ public protocol P<A, B> {
88
associatedtype B
99
}
1010

11+
public protocol P1<A> {
12+
associatedtype A
13+
}
14+
1115
public protocol Q<C> {
1216
associatedtype C
1317
}
@@ -34,16 +38,29 @@ public func foo(_ a: (any P<Int, Float> & Q<String> & R).Type) {}
3438
public func foo(_ a: (any P<Int, Float> & Q<String> & R & C<Bool>).Type) {}
3539
public func foo(_ a: (any P<Int, Float> & Q<String> & R & AnyObject).Type) {}
3640

37-
public func foo(_ a: (any P & R).Type) {}
38-
public func foo(_ a: (any P & Q<String>).Type) {}
39-
public func foo(_ a: (any P & Q<String> & R).Type) {}
40-
public func foo(_ a: (any P & Q<String> & R & C<Bool>).Type) {}
41-
public func foo(_ a: (any P & Q<String> & R & AnyObject).Type) {}
41+
public func foo(_ a: (any P & P1).Type) {}
42+
public func foo(_ a: (any P & P1<String>).Type) {}
43+
public func foo(_ a: (any P & P1<String> & R).Type) {}
44+
public func foo(_ a: (any P & P1<String> & R & C<Bool>).Type) {}
45+
public func foo(_ a: (any P & P1<String> & R & AnyObject).Type) {}
46+
47+
public func foo(_ a: (any P<Int, Float> & P1).Type) {}
48+
public func foo(_ a: (any P<Int, Float> & P1 & R).Type) {}
49+
public func foo(_ a: (any P<Int, Float> & P1 & R & C<Bool>).Type) {}
50+
public func foo(_ a: (any P<Int, Float> & P1 & R & AnyObject).Type) {}
51+
52+
public protocol Q2<C>: Q {}
53+
54+
public protocol Q3<C>: Q {
55+
associatedtype C
56+
}
4257

43-
public func foo(_ a: (any P<Int, Float> & Q).Type) {}
44-
public func foo(_ a: (any P<Int, Float> & Q & R).Type) {}
45-
public func foo(_ a: (any P<Int, Float> & Q & R & C<Bool>).Type) {}
46-
public func foo(_ a: (any P<Int, Float> & Q & R & AnyObject).Type) {}
58+
public func foo(_ a: (any Q2<Int> & R).Type) {}
59+
public func foo(_ a: (any Q3<Int> & R).Type) {}
60+
public func foo(_ a: (any Q2 & Q3).Type) {}
61+
public func foo(_ a: (any Q2 & Q3<Int>).Type) {}
62+
public func foo2(_ a: (any Q2<Int> & Q3).Type) {}
63+
public func foo3(_ a: (any Q2<Int> & Q3<Int>).Type) {}
4764

4865
public struct Foo<each T, U> {
4966
public var a1: (repeat any P<each T, U> & R)

0 commit comments

Comments
 (0)