Skip to content

Commit c0570d5

Browse files
committed
ASTMangler: Check isValidTypeParameter() to work around broken generalized existential mangling
1 parent 75d25c6 commit c0570d5

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,9 +3164,13 @@ void ASTMangler::appendGenericSignatureParts(
31643164

31653165
/// Determine whether an associated type reference into the given set of
31663166
/// protocols is unambiguous.
3167-
static bool associatedTypeRefIsUnambiguous(ArrayRef<ProtocolDecl *> protocols) {
3167+
static bool associatedTypeRefIsUnambiguous(GenericSignature sig, Type t) {
3168+
// FIXME: This should be an assertion.
3169+
if (!sig->isValidTypeParameter(t))
3170+
return false;
3171+
31683172
unsigned numProtocols = 0;
3169-
for (auto proto : protocols) {
3173+
for (auto proto : sig->getRequiredProtocols(t)) {
31703174
// Skip marker protocols, which cannot have associated types.
31713175
if (proto->isMarkerProtocol())
31723176
continue;
@@ -3186,7 +3190,7 @@ ASTMangler::dropProtocolFromAssociatedType(DependentMemberType *dmt,
31863190
auto baseTy = dmt->getBase();
31873191
bool unambiguous =
31883192
(!dmt->getAssocType() ||
3189-
associatedTypeRefIsUnambiguous(sig->getRequiredProtocols(baseTy)));
3193+
associatedTypeRefIsUnambiguous(sig, baseTy));
31903194

31913195
if (auto *baseDMT = baseTy->getAs<DependentMemberType>())
31923196
baseTy = dropProtocolFromAssociatedType(baseDMT, sig);
@@ -3223,7 +3227,7 @@ void ASTMangler::appendAssociatedTypeName(DependentMemberType *dmt,
32233227
// associated type name by protocol.
32243228
if (!OptimizeProtocolNames || !sig ||
32253229
!associatedTypeRefIsUnambiguous(
3226-
sig->getRequiredProtocols(dmt->getBase()))) {
3230+
sig, dmt->getBase())) {
32273231
appendAnyGenericType(assocTy->getProtocol());
32283232
}
32293233
return;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-swift-emit-silgen -module-name parameterized -disable-availability-checking %s -enable-experimental-feature VariadicGenerics | %FileCheck %s
2+
3+
protocol P<A> {
4+
associatedtype A
5+
}
6+
7+
// The mangling for generalized existentials is buggy; we decide whether to
8+
// qualify the primary associated type requirement with a protocol or not
9+
// by looking at the first generic parameter of the outer generic context.
10+
11+
struct S1 {
12+
// CHECK-LABEL: sil hidden [ossa] @$s13parameterized2S1V1fAA1P_pSi1AAaEPRts_XPyF : $@convention(method) (S1) -> @out any P<Int> {
13+
func f() -> any P<Int> {}
14+
}
15+
16+
struct S2<T> {
17+
// CHECK-LABEL: sil hidden [ossa] @$s13parameterized2S2V1fAA1P_pSi1ARts_XPyF : $@convention(method) <T> (S2<T>) -> @out any P<Int> {
18+
func f() -> any P<Int> {}
19+
}
20+
21+
struct S3<each T> {
22+
// CHECK-LABEL: sil hidden [ossa] @$s13parameterized2S3V1fAA1P_pSi1AAaEPRts_XPyF : $@convention(method) <each T> (S3<repeat each T>) -> @out any P<Int> {
23+
func f() -> any P<Int> {}
24+
}

0 commit comments

Comments
 (0)