@@ -986,7 +986,6 @@ class AssociatedTypeInference {
986
986
987
987
// / Infer associated type witnesses for the given associated type.
988
988
InferredAssociatedTypesByWitnesses inferTypeWitnessesViaAssociatedType (
989
- const llvm::SetVector<AssociatedTypeDecl *> &allUnresolved,
990
989
AssociatedTypeDecl *assocType);
991
990
992
991
// / Infer associated type witnesses for all relevant value requirements.
@@ -1790,8 +1789,7 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
1790
1789
if (assocTypes.count (assocType) == 0 )
1791
1790
continue ;
1792
1791
1793
- auto reqInferred = inferTypeWitnessesViaAssociatedType (assocTypes,
1794
- assocType);
1792
+ auto reqInferred = inferTypeWitnessesViaAssociatedType (assocType);
1795
1793
if (!reqInferred.empty ())
1796
1794
result.push_back ({req, std::move (reqInferred)});
1797
1795
@@ -1853,6 +1851,19 @@ static Type mapErrorTypeToOriginal(Type type) {
1853
1851
return type;
1854
1852
}
1855
1853
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
+
1856
1867
// / Produce the type when matching a witness.
1857
1868
// /
1858
1869
// / If the witness is a member of the type itself or a superclass, we
@@ -1886,6 +1897,9 @@ static Type getWitnessTypeForMatching(NormalProtocolConformance *conformance,
1886
1897
conformance->getDeclContext ()->mapTypeIntoContext (conformance->getType ());
1887
1898
TypeSubstitutionMap substitutions = model->getMemberSubstitutions (witness);
1888
1899
Type type = witness->getInterfaceType ()->getReferenceStorageReferent ();
1900
+
1901
+ type = getWithoutProtocolTypeAliases (type);
1902
+
1889
1903
LLVM_DEBUG (llvm::dbgs () << " Witness interface type is " << type << " \n " ;);
1890
1904
1891
1905
if (substitutions.empty ())
@@ -1998,7 +2012,6 @@ static Type removeSelfParam(ValueDecl *value, Type type) {
1998
2012
1999
2013
InferredAssociatedTypesByWitnesses
2000
2014
AssociatedTypeInference::inferTypeWitnessesViaAssociatedType (
2001
- const llvm::SetVector<AssociatedTypeDecl *> &allUnresolved,
2002
2015
AssociatedTypeDecl *assocType) {
2003
2016
InferredAssociatedTypesByWitnesses result;
2004
2017
0 commit comments