Skip to content

Commit 42e1952

Browse files
authored
Merge pull request #36332 from slavapestov/gsb-cleanup-potential-archetype
GSB: Rename updateNestedTypeForConformance() to getOrCreateNestedType() and simplify it
2 parents 6e0e4dc + 124b8fd commit 42e1952

File tree

2 files changed

+32
-46
lines changed

2 files changed

+32
-46
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,9 +1590,9 @@ class GenericSignatureBuilder::PotentialArchetype {
15901590
/// type of the given protocol, unless the \c kind implies that
15911591
/// a potential archetype should not be created if it's missing.
15921592
PotentialArchetype *
1593-
updateNestedTypeForConformance(GenericSignatureBuilder &builder,
1594-
AssociatedTypeDecl *assocType,
1595-
ArchetypeResolutionKind kind);
1593+
getOrCreateNestedType(GenericSignatureBuilder &builder,
1594+
AssociatedTypeDecl *assocType,
1595+
ArchetypeResolutionKind kind);
15961596

15971597
/// Retrieve the dependent type that describes this potential
15981598
/// archetype.

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,7 +2808,7 @@ static void concretizeNestedTypeFromConcreteParent(
28082808
SameTypeConflictCheckedLater());
28092809
}
28102810

2811-
PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(
2811+
PotentialArchetype *PotentialArchetype::getOrCreateNestedType(
28122812
GenericSignatureBuilder &builder, AssociatedTypeDecl *assocType,
28132813
ArchetypeResolutionKind kind) {
28142814
if (!assocType)
@@ -2819,57 +2819,45 @@ PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(
28192819

28202820
Identifier name = assocType->getName();
28212821

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+
28222829
// Look for a potential archetype with the appropriate associated type.
2823-
PotentialArchetype *resultPA = nullptr;
28242830
auto knownNestedTypes = NestedTypes.find(name);
2825-
bool shouldUpdatePA = false;
28262831
if (knownNestedTypes != NestedTypes.end()) {
28272832
for (auto existingPA : knownNestedTypes->second) {
28282833
// Do we have an associated-type match?
28292834
if (assocType && existingPA->getResolvedType() == assocType) {
2830-
resultPA = existingPA;
2831-
break;
2835+
return existingPA;
28322836
}
28332837
}
28342838
}
28352839

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;
28442842

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.
28472844

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);
28532848

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);
28582851

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);
28682854

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+
}
28732861

28742862
return resultPA;
28752863
}
@@ -3889,8 +3877,7 @@ ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass(
38893877
}
38903878

38913879
auto nestedPA =
3892-
basePA->updateNestedTypeForConformance(*this, assocType,
3893-
resolutionKind);
3880+
basePA->getOrCreateNestedType(*this, assocType, resolutionKind);
38943881
if (!nestedPA)
38953882
return ResolvedType::forUnresolved(baseEquivClass);
38963883

@@ -4726,10 +4713,9 @@ void GenericSignatureBuilder::addedNestedType(PotentialArchetype *nestedPA) {
47264713
if (parentPA == parentRepPA) return;
47274714

47284715
PotentialArchetype *existingPA =
4729-
parentRepPA->updateNestedTypeForConformance(
4730-
*this,
4731-
nestedPA->getResolvedType(),
4732-
ArchetypeResolutionKind::WellFormed);
4716+
parentRepPA->getOrCreateNestedType(*this,
4717+
nestedPA->getResolvedType(),
4718+
ArchetypeResolutionKind::WellFormed);
47334719

47344720
auto sameNamedSource =
47354721
FloatingRequirementSource::forNestedTypeNameMatch(

0 commit comments

Comments
 (0)