@@ -986,7 +986,6 @@ class AssociatedTypeInference {
986986
987987 // / Infer associated type witnesses for the given associated type.
988988 InferredAssociatedTypesByWitnesses inferTypeWitnessesViaAssociatedType (
989- const llvm::SetVector<AssociatedTypeDecl *> &allUnresolved,
990989 AssociatedTypeDecl *assocType);
991990
992991 // / Infer associated type witnesses for all relevant value requirements.
@@ -1790,8 +1789,7 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
17901789 if (assocTypes.count (assocType) == 0 )
17911790 continue ;
17921791
1793- auto reqInferred = inferTypeWitnessesViaAssociatedType (assocTypes,
1794- assocType);
1792+ auto reqInferred = inferTypeWitnessesViaAssociatedType (assocType);
17951793 if (!reqInferred.empty ())
17961794 result.push_back ({req, std::move (reqInferred)});
17971795
@@ -1853,6 +1851,19 @@ static Type mapErrorTypeToOriginal(Type type) {
18531851 return type;
18541852}
18551853
1854+ // / Desugar protocol type aliases, since they can cause request cycles in
1855+ // / type resolution if printed in a module interface and parsed back in.
1856+ static Type getWithoutProtocolTypeAliases (Type type) {
1857+ return type.transformRec ([](TypeBase *t) -> llvm::Optional<Type> {
1858+ if (auto *aliasTy = dyn_cast<TypeAliasType>(t)) {
1859+ if (aliasTy->getDecl ()->getDeclContext ()->getExtendedProtocolDecl ())
1860+ return getWithoutProtocolTypeAliases (aliasTy->getSinglyDesugaredType ());
1861+ }
1862+
1863+ return llvm::None;
1864+ });
1865+ }
1866+
18561867// / Produce the type when matching a witness.
18571868// /
18581869// / If the witness is a member of the type itself or a superclass, we
@@ -1886,6 +1897,9 @@ static Type getWitnessTypeForMatching(NormalProtocolConformance *conformance,
18861897 conformance->getDeclContext ()->mapTypeIntoContext (conformance->getType ());
18871898 TypeSubstitutionMap substitutions = model->getMemberSubstitutions (witness);
18881899 Type type = witness->getInterfaceType ()->getReferenceStorageReferent ();
1900+
1901+ type = getWithoutProtocolTypeAliases (type);
1902+
18891903 LLVM_DEBUG (llvm::dbgs () << " Witness interface type is " << type << " \n " ;);
18901904
18911905 if (substitutions.empty ())
@@ -1998,7 +2012,6 @@ static Type removeSelfParam(ValueDecl *value, Type type) {
19982012
19992013InferredAssociatedTypesByWitnesses
20002014AssociatedTypeInference::inferTypeWitnessesViaAssociatedType (
2001- const llvm::SetVector<AssociatedTypeDecl *> &allUnresolved,
20022015 AssociatedTypeDecl *assocType) {
20032016 InferredAssociatedTypesByWitnesses result;
20042017
0 commit comments