@@ -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 ;
0 commit comments