@@ -818,7 +818,7 @@ const void *RequirementSource::getOpaqueStorage1() const {
818
818
return storage.type ;
819
819
820
820
case StorageKind::AssociatedTypeDecl:
821
- return storage.assocType ;
821
+ return storage.dependentMember ;
822
822
}
823
823
824
824
llvm_unreachable (" Unhandled StorageKind in switch." );
@@ -918,11 +918,16 @@ bool RequirementSource::isSelfDerivedSource(GenericSignatureBuilder &builder,
918
918
// / the nested type. This limited operation makes sure that it does not
919
919
// / create any new potential archetypes along the way, so it should only be
920
920
// / 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) {
922
923
if (auto depMemTy = depTy->getAs <DependentMemberType>()) {
923
- Type baseType = replaceSelfWithType (selfType, depMemTy->getBase ());
924
+ Type baseType = replaceSelfWithType (cache, selfType, depMemTy->getBase ());
924
925
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;
926
931
}
927
932
928
933
assert (depTy->is <GenericTypeParamType>() && " missing Self?" );
@@ -1366,8 +1371,8 @@ RequirementSource::visitPotentialArchetypesAlongPath(
1366
1371
1367
1372
if (visitor (parentType, this )) return nullptr ;
1368
1373
1369
- return replaceSelfWithType (parentType ,
1370
- getAssociatedType ()-> getDeclaredInterfaceType ());
1374
+ return replaceSelfWithType (ReplacedSelfCache ,
1375
+ parentType, getDependentMember ());
1371
1376
}
1372
1377
1373
1378
case RequirementSource::NestedTypeNameMatch:
@@ -1402,7 +1407,8 @@ RequirementSource::visitPotentialArchetypesAlongPath(
1402
1407
1403
1408
if (visitor (parentType, this )) return nullptr ;
1404
1409
1405
- return replaceSelfWithType (parentType, getStoredType ());
1410
+ return replaceSelfWithType (ReplacedSelfCache,
1411
+ parentType, getStoredType ());
1406
1412
}
1407
1413
}
1408
1414
llvm_unreachable (" unhandled kind" );
@@ -1436,7 +1442,7 @@ ProtocolDecl *RequirementSource::getProtocolDecl() const {
1436
1442
return getProtocolConformance ().getRequirement ();
1437
1443
1438
1444
case StorageKind::AssociatedTypeDecl:
1439
- return storage.assocType ->getProtocol ();
1445
+ return storage.dependentMember -> getAssocType () ->getProtocol ();
1440
1446
}
1441
1447
1442
1448
llvm_unreachable (" Unhandled StorageKind in switch." );
@@ -1607,8 +1613,9 @@ void RequirementSource::print(llvm::raw_ostream &out,
1607
1613
}
1608
1614
1609
1615
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 () << " )" ;
1612
1619
break ;
1613
1620
}
1614
1621
@@ -2935,7 +2942,7 @@ Type GenericSignatureBuilder::PotentialArchetype::getDependentType(
2935
2942
2936
2943
// If we've resolved to an associated type, use it.
2937
2944
if (auto assocType = getResolvedType ())
2938
- return DependentMemberType::get (parentType, assocType );
2945
+ return getResolvedDependentMemberType (parentType);
2939
2946
2940
2947
return DependentMemberType::get (parentType, getNestedName ());
2941
2948
}
0 commit comments