@@ -818,7 +818,7 @@ const void *RequirementSource::getOpaqueStorage1() const {
818818 return storage.type ;
819819
820820 case StorageKind::AssociatedTypeDecl:
821- return storage.assocType ;
821+ return storage.dependentMember ;
822822 }
823823
824824 llvm_unreachable (" Unhandled StorageKind in switch." );
@@ -918,11 +918,16 @@ bool RequirementSource::isSelfDerivedSource(GenericSignatureBuilder &builder,
918918// / the nested type. This limited operation makes sure that it does not
919919// / create any new potential archetypes along the way, so it should only be
920920// / used in cases where we're reconstructing something that we know exists.
921- static Type replaceSelfWithType (Type selfType, Type depTy) {
921+ static Type replaceSelfWithType (llvm::DenseMap<Type, Type> &cache,
922+ Type selfType, Type depTy) {
922923 if (auto depMemTy = depTy->getAs <DependentMemberType>()) {
923- Type baseType = replaceSelfWithType (selfType, depMemTy->getBase ());
924+ Type baseType = replaceSelfWithType (cache, selfType, depMemTy->getBase ());
924925 assert (depMemTy->getAssocType () && " Missing associated type" );
925- return DependentMemberType::get (baseType, depMemTy->getAssocType ());
926+ auto &known = cache[baseType];
927+ if (!known) {
928+ known = DependentMemberType::get (baseType, depMemTy->getAssocType ());
929+ }
930+ return known;
926931 }
927932
928933 assert (depTy->is <GenericTypeParamType>() && " missing Self?" );
@@ -1366,8 +1371,8 @@ RequirementSource::visitPotentialArchetypesAlongPath(
13661371
13671372 if (visitor (parentType, this )) return nullptr ;
13681373
1369- return replaceSelfWithType (parentType ,
1370- getAssociatedType ()-> getDeclaredInterfaceType ());
1374+ return replaceSelfWithType (ReplacedSelfCache ,
1375+ parentType, getDependentMember ());
13711376 }
13721377
13731378 case RequirementSource::NestedTypeNameMatch:
@@ -1402,7 +1407,8 @@ RequirementSource::visitPotentialArchetypesAlongPath(
14021407
14031408 if (visitor (parentType, this )) return nullptr ;
14041409
1405- return replaceSelfWithType (parentType, getStoredType ());
1410+ return replaceSelfWithType (ReplacedSelfCache,
1411+ parentType, getStoredType ());
14061412 }
14071413 }
14081414 llvm_unreachable (" unhandled kind" );
@@ -1436,7 +1442,7 @@ ProtocolDecl *RequirementSource::getProtocolDecl() const {
14361442 return getProtocolConformance ().getRequirement ();
14371443
14381444 case StorageKind::AssociatedTypeDecl:
1439- return storage.assocType ->getProtocol ();
1445+ return storage.dependentMember -> getAssocType () ->getProtocol ();
14401446 }
14411447
14421448 llvm_unreachable (" Unhandled StorageKind in switch." );
@@ -1607,8 +1613,9 @@ void RequirementSource::print(llvm::raw_ostream &out,
16071613 }
16081614
16091615 case StorageKind::AssociatedTypeDecl:
1610- out << " (" << storage.assocType ->getProtocol ()->getName ()
1611- << " ::" << storage.assocType ->getName () << " )" ;
1616+ auto assocType = storage.dependentMember ->getAssocType ();
1617+ out << " (" << assocType->getProtocol ()->getName ()
1618+ << " ::" << assocType->getName () << " )" ;
16121619 break ;
16131620 }
16141621
@@ -2935,7 +2942,7 @@ Type GenericSignatureBuilder::PotentialArchetype::getDependentType(
29352942
29362943 // If we've resolved to an associated type, use it.
29372944 if (auto assocType = getResolvedType ())
2938- return DependentMemberType::get (parentType, assocType );
2945+ return getResolvedDependentMemberType (parentType);
29392946
29402947 return DependentMemberType::get (parentType, getNestedName ());
29412948 }
0 commit comments