@@ -2808,7 +2808,7 @@ static void concretizeNestedTypeFromConcreteParent(
2808
2808
SameTypeConflictCheckedLater ());
2809
2809
}
2810
2810
2811
- PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance (
2811
+ PotentialArchetype *PotentialArchetype::getOrCreateNestedType (
2812
2812
GenericSignatureBuilder &builder, AssociatedTypeDecl *assocType,
2813
2813
ArchetypeResolutionKind kind) {
2814
2814
if (!assocType)
@@ -2819,57 +2819,45 @@ PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(
2819
2819
2820
2820
Identifier name = assocType->getName ();
2821
2821
2822
+ SWIFT_DEFER {
2823
+ // If we were asked for a complete, well-formed archetype, make sure we
2824
+ // process delayed requirements if anything changed.
2825
+ if (kind == ArchetypeResolutionKind::CompleteWellFormed)
2826
+ builder.processDelayedRequirements ();
2827
+ };
2828
+
2822
2829
// Look for a potential archetype with the appropriate associated type.
2823
- PotentialArchetype *resultPA = nullptr ;
2824
2830
auto knownNestedTypes = NestedTypes.find (name);
2825
- bool shouldUpdatePA = false ;
2826
2831
if (knownNestedTypes != NestedTypes.end ()) {
2827
2832
for (auto existingPA : knownNestedTypes->second ) {
2828
2833
// Do we have an associated-type match?
2829
2834
if (assocType && existingPA->getResolvedType () == assocType) {
2830
- resultPA = existingPA;
2831
- break ;
2835
+ return existingPA;
2832
2836
}
2833
2837
}
2834
2838
}
2835
2839
2836
- // If we don't have a result potential archetype yet, we may need to add one.
2837
- if (!resultPA) {
2838
- switch (kind) {
2839
- case ArchetypeResolutionKind::CompleteWellFormed:
2840
- case ArchetypeResolutionKind::WellFormed: {
2841
- // Creating a new potential archetype in an equivalence class is a
2842
- // modification.
2843
- getOrCreateEquivalenceClass (builder)->modified (builder);
2840
+ if (kind == ArchetypeResolutionKind::AlreadyKnown)
2841
+ return nullptr ;
2844
2842
2845
- void *mem = builder.Impl ->Allocator .Allocate <PotentialArchetype>();
2846
- resultPA = new (mem) PotentialArchetype (this , assocType);
2843
+ // We don't have a result potential archetype, so we need to add one.
2847
2844
2848
- NestedTypes[name].push_back (resultPA);
2849
- builder.addedNestedType (resultPA);
2850
- shouldUpdatePA = true ;
2851
- break ;
2852
- }
2845
+ // Creating a new potential archetype in an equivalence class is a
2846
+ // modification.
2847
+ getOrCreateEquivalenceClass (builder)->modified (builder);
2853
2848
2854
- case ArchetypeResolutionKind::AlreadyKnown:
2855
- return nullptr ;
2856
- }
2857
- }
2849
+ void *mem = builder.Impl ->Allocator .Allocate <PotentialArchetype>();
2850
+ auto *resultPA = new (mem) PotentialArchetype (this , assocType);
2858
2851
2859
- // If we have a potential archetype that requires more processing, do so now.
2860
- if (shouldUpdatePA) {
2861
- // We know something concrete about the parent PA, so we need to propagate
2862
- // that information to this new archetype.
2863
- if (auto equivClass = getEquivalenceClassIfPresent ()) {
2864
- if (equivClass->concreteType || equivClass->superclass )
2865
- concretizeNestedTypeFromConcreteParent (this , resultPA, builder);
2866
- }
2867
- }
2852
+ NestedTypes[name].push_back (resultPA);
2853
+ builder.addedNestedType (resultPA);
2868
2854
2869
- // If we were asked for a complete, well-formed archetype, make sure we
2870
- // process delayed requirements if anything changed.
2871
- if (kind == ArchetypeResolutionKind::CompleteWellFormed)
2872
- builder.processDelayedRequirements ();
2855
+ // If we know something concrete about the parent PA, we need to propagate
2856
+ // that information to this new archetype.
2857
+ if (auto equivClass = getEquivalenceClassIfPresent ()) {
2858
+ if (equivClass->concreteType || equivClass->superclass )
2859
+ concretizeNestedTypeFromConcreteParent (this , resultPA, builder);
2860
+ }
2873
2861
2874
2862
return resultPA;
2875
2863
}
@@ -3889,8 +3877,7 @@ ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass(
3889
3877
}
3890
3878
3891
3879
auto nestedPA =
3892
- basePA->updateNestedTypeForConformance (*this , assocType,
3893
- resolutionKind);
3880
+ basePA->getOrCreateNestedType (*this , assocType, resolutionKind);
3894
3881
if (!nestedPA)
3895
3882
return ResolvedType::forUnresolved (baseEquivClass);
3896
3883
@@ -4726,10 +4713,9 @@ void GenericSignatureBuilder::addedNestedType(PotentialArchetype *nestedPA) {
4726
4713
if (parentPA == parentRepPA) return ;
4727
4714
4728
4715
PotentialArchetype *existingPA =
4729
- parentRepPA->updateNestedTypeForConformance (
4730
- *this ,
4731
- nestedPA->getResolvedType (),
4732
- ArchetypeResolutionKind::WellFormed);
4716
+ parentRepPA->getOrCreateNestedType (*this ,
4717
+ nestedPA->getResolvedType (),
4718
+ ArchetypeResolutionKind::WellFormed);
4733
4719
4734
4720
auto sameNamedSource =
4735
4721
FloatingRequirementSource::forNestedTypeNameMatch (
0 commit comments