@@ -1550,6 +1550,14 @@ unsigned GenericSignatureBuilder::PotentialArchetype::getNestingDepth() const {
1550
1550
return Depth;
1551
1551
}
1552
1552
1553
+ void EquivalenceClass::addMember (PotentialArchetype *pa) {
1554
+ members.push_back (pa);
1555
+ if (members.back ()->getNestingDepth () < members.front ()->getNestingDepth ()) {
1556
+ MutableArrayRef<PotentialArchetype *> mutMembers = members;
1557
+ std::swap (mutMembers.front (), mutMembers.back ());
1558
+ }
1559
+ }
1560
+
1553
1561
bool EquivalenceClass::recordConformanceConstraint (
1554
1562
PotentialArchetype *pa,
1555
1563
ProtocolDecl *proto,
@@ -2759,6 +2767,8 @@ PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(
2759
2767
proto, getDependentType (/* genericParams=*/ {}),
2760
2768
ProtocolConformanceRef (proto));
2761
2769
type = type.subst (subMap, SubstFlags::UseErrorType);
2770
+ if (!type)
2771
+ type = ErrorType::get (proto->getASTContext ());
2762
2772
} else {
2763
2773
// Substitute in the superclass type.
2764
2774
auto superclass = getEquivalenceClassIfPresent ()->superclass ;
@@ -3095,21 +3105,19 @@ ResolveResult GenericSignatureBuilder::maybeResolveEquivalenceClass(
3095
3105
}
3096
3106
}
3097
3107
3098
- // Retrieve the anchor of the base equivalence class, and use that to
3099
- // find the nested potential archetype corresponding to this dependent
3100
- // type.
3101
- auto baseAnchorPA =
3102
- baseEquivClass->members .front ()->getArchetypeAnchor (*this );
3108
+ // Retrieve the "smallest" type in the equivalence class, by depth, and
3109
+ // use that to find a nested potential archetype. We used the smallest
3110
+ // type by depth to limit expansion of the type graph.
3111
+ auto basePA = baseEquivClass->members .front ();
3103
3112
auto nestedPA =
3104
- baseAnchorPA->updateNestedTypeForConformance (nestedTypeDecl,
3105
- resolutionKind);
3113
+ basePA->updateNestedTypeForConformance (nestedTypeDecl, resolutionKind);
3106
3114
if (!nestedPA)
3107
3115
return ResolveResult::forUnresolved (baseEquivClass);
3108
3116
3109
3117
// If base resolved to the anchor, then the nested potential archetype
3110
3118
// we found is the resolved potential archetype. Return it directly,
3111
3119
// so it doesn't need to be resolved again.
3112
- if (baseAnchorPA == resolvedBase.getAsPotentialArchetype ())
3120
+ if (basePA == resolvedBase.getAsPotentialArchetype ())
3113
3121
return ResolveResult (nestedPA);
3114
3122
3115
3123
// Compute the resolved dependent type to return.
@@ -3978,7 +3986,7 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenArchetypes(
3978
3986
auto equivClass1Members = equivClass->members ;
3979
3987
auto equivClass2Members = T2->getEquivalenceClassMembers ();
3980
3988
for (auto equiv : equivClass2Members)
3981
- equivClass->members . push_back (equiv);
3989
+ equivClass->addMember (equiv);
3982
3990
3983
3991
// Grab the old equivalence class, if present. We'll deallocate it at the end.
3984
3992
auto equivClass2 = T2->getEquivalenceClassIfPresent ();
@@ -5656,9 +5664,10 @@ static void collapseSameTypeComponentsThroughDelayedRequirements(
5656
5664
// / associated, for a type that we haven't tried to resolve yet.
5657
5665
auto getUnknownTypeVirtualComponent = [&](Type type) {
5658
5666
if (auto pa =
5659
- builder.resolvePotentialArchetype (type,
5667
+ builder.maybeResolveEquivalenceClass (
5668
+ type,
5660
5669
ArchetypeResolutionKind::AlreadyKnown)
5661
- .dyn_cast <PotentialArchetype *> ())
5670
+ .getAsPotentialArchetype ())
5662
5671
return getPotentialArchetypeVirtualComponent (pa);
5663
5672
5664
5673
return getTypeVirtualComponent (type);
@@ -6537,9 +6546,9 @@ GenericSignature *GenericSignatureBuilder::computeRequirementSignature(
6537
6546
proto->getSelfInterfaceType ()->castTo <GenericTypeParamType>();
6538
6547
builder.addGenericParameter (selfType);
6539
6548
auto selfPA =
6540
- builder.resolvePotentialArchetype (selfType,
6541
- ArchetypeResolutionKind::WellFormed)
6542
- . get <PotentialArchetype *> ();
6549
+ builder.resolveEquivalenceClass (selfType,
6550
+ ArchetypeResolutionKind::WellFormed)
6551
+ -> members . front ();
6543
6552
6544
6553
// Add the conformance of 'self' to the protocol.
6545
6554
auto requirement =
0 commit comments