Skip to content

Commit 1ff370b

Browse files
authored
Merge pull request #59869 from DougGregor/marker-protocol-assoc-type-mangling
2 parents 198b974 + e937510 commit 1ff370b

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,6 +2981,21 @@ void ASTMangler::appendGenericSignatureParts(
29812981
appendOperator("r", StringRef(OpStorage.data(), OpStorage.size()));
29822982
}
29832983

2984+
/// Determine whether an associated type reference into the given set of
2985+
/// protocols is unambiguous.
2986+
static bool associatedTypeRefIsUnambiguous(ArrayRef<ProtocolDecl *> protocols) {
2987+
unsigned numProtocols = 0;
2988+
for (auto proto : protocols) {
2989+
// Skip marker protocols, which cannot have associated types.
2990+
if (proto->isMarkerProtocol())
2991+
continue;
2992+
2993+
++numProtocols;
2994+
}
2995+
2996+
return numProtocols <= 1;
2997+
}
2998+
29842999
// If the base type is known to have a single protocol conformance
29853000
// in the current generic context, then we don't need to disambiguate the
29863001
// associated type name by protocol.
@@ -2990,7 +3005,7 @@ ASTMangler::dropProtocolFromAssociatedType(DependentMemberType *dmt,
29903005
auto baseTy = dmt->getBase();
29913006
bool unambiguous =
29923007
(!dmt->getAssocType() ||
2993-
sig->getRequiredProtocols(baseTy).size() <= 1);
3008+
associatedTypeRefIsUnambiguous(sig->getRequiredProtocols(baseTy)));
29943009

29953010
if (auto *baseDMT = baseTy->getAs<DependentMemberType>())
29963011
baseTy = dropProtocolFromAssociatedType(baseDMT, sig);
@@ -3026,7 +3041,8 @@ void ASTMangler::appendAssociatedTypeName(DependentMemberType *dmt,
30263041
// in the current generic context, then we don't need to disambiguate the
30273042
// associated type name by protocol.
30283043
if (!OptimizeProtocolNames || !sig ||
3029-
sig->getRequiredProtocols(dmt->getBase()).size() > 1) {
3044+
!associatedTypeRefIsUnambiguous(
3045+
sig->getRequiredProtocols(dmt->getBase()))) {
30303046
appendAnyGenericType(assocTy->getProtocol());
30313047
}
30323048
return;

test/IRGen/marker_protocol.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@ struct Foo: SelfConstrainedProtocol {
7878
Foo(x: 123)
7979
}
8080
}
81+
82+
protocol P2 {
83+
associatedtype Foo
84+
}
85+
86+
// CHECK: define{{.*}}$s15marker_protocol3fooyy3FooQz_xtAA1PRzAA2P2RzlF
87+
func foo<T: P & P2>(_: T.Foo, _: T) { }

0 commit comments

Comments
 (0)