@@ -2981,6 +2981,21 @@ void ASTMangler::appendGenericSignatureParts(
2981
2981
appendOperator (" r" , StringRef (OpStorage.data (), OpStorage.size ()));
2982
2982
}
2983
2983
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
+
2984
2999
// If the base type is known to have a single protocol conformance
2985
3000
// in the current generic context, then we don't need to disambiguate the
2986
3001
// associated type name by protocol.
@@ -2990,7 +3005,7 @@ ASTMangler::dropProtocolFromAssociatedType(DependentMemberType *dmt,
2990
3005
auto baseTy = dmt->getBase ();
2991
3006
bool unambiguous =
2992
3007
(!dmt->getAssocType () ||
2993
- sig->getRequiredProtocols (baseTy). size () <= 1 );
3008
+ associatedTypeRefIsUnambiguous ( sig->getRequiredProtocols (baseTy)) );
2994
3009
2995
3010
if (auto *baseDMT = baseTy->getAs <DependentMemberType>())
2996
3011
baseTy = dropProtocolFromAssociatedType (baseDMT, sig);
@@ -3026,7 +3041,8 @@ void ASTMangler::appendAssociatedTypeName(DependentMemberType *dmt,
3026
3041
// in the current generic context, then we don't need to disambiguate the
3027
3042
// associated type name by protocol.
3028
3043
if (!OptimizeProtocolNames || !sig ||
3029
- sig->getRequiredProtocols (dmt->getBase ()).size () > 1 ) {
3044
+ !associatedTypeRefIsUnambiguous (
3045
+ sig->getRequiredProtocols (dmt->getBase ()))) {
3030
3046
appendAnyGenericType (assocTy->getProtocol ());
3031
3047
}
3032
3048
return ;
0 commit comments