@@ -2979,6 +2979,21 @@ void ASTMangler::appendGenericSignatureParts(
2979
2979
appendOperator (" r" , StringRef (OpStorage.data (), OpStorage.size ()));
2980
2980
}
2981
2981
2982
+ // / Determine whether an associated type reference into the given set of
2983
+ // / protocols is unambiguous.
2984
+ static bool associatedTypeRefIsUnambiguous (ArrayRef<ProtocolDecl *> protocols) {
2985
+ unsigned numProtocols = 0 ;
2986
+ for (auto proto : protocols) {
2987
+ // Skip marker protocols, which cannot have associated types.
2988
+ if (proto->isMarkerProtocol ())
2989
+ continue ;
2990
+
2991
+ ++numProtocols;
2992
+ }
2993
+
2994
+ return numProtocols <= 1 ;
2995
+ }
2996
+
2982
2997
// If the base type is known to have a single protocol conformance
2983
2998
// in the current generic context, then we don't need to disambiguate the
2984
2999
// associated type name by protocol.
@@ -2988,7 +3003,7 @@ ASTMangler::dropProtocolFromAssociatedType(DependentMemberType *dmt,
2988
3003
auto baseTy = dmt->getBase ();
2989
3004
bool unambiguous =
2990
3005
(!dmt->getAssocType () ||
2991
- sig->getRequiredProtocols (baseTy). size () <= 1 );
3006
+ associatedTypeRefIsUnambiguous ( sig->getRequiredProtocols (baseTy)) );
2992
3007
2993
3008
if (auto *baseDMT = baseTy->getAs <DependentMemberType>())
2994
3009
baseTy = dropProtocolFromAssociatedType (baseDMT, sig);
@@ -3024,7 +3039,8 @@ void ASTMangler::appendAssociatedTypeName(DependentMemberType *dmt,
3024
3039
// in the current generic context, then we don't need to disambiguate the
3025
3040
// associated type name by protocol.
3026
3041
if (!OptimizeProtocolNames || !sig ||
3027
- sig->getRequiredProtocols (dmt->getBase ()).size () > 1 ) {
3042
+ !associatedTypeRefIsUnambiguous (
3043
+ sig->getRequiredProtocols (dmt->getBase ()))) {
3028
3044
appendAnyGenericType (assocTy->getProtocol ());
3029
3045
}
3030
3046
return ;
0 commit comments