Skip to content

GSB: Rename updateNestedTypeForConformance() to getOrCreateNestedType() and simplify it #36332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/swift/AST/GenericSignatureBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1590,9 +1590,9 @@ class GenericSignatureBuilder::PotentialArchetype {
/// type of the given protocol, unless the \c kind implies that
/// a potential archetype should not be created if it's missing.
PotentialArchetype *
updateNestedTypeForConformance(GenericSignatureBuilder &builder,
AssociatedTypeDecl *assocType,
ArchetypeResolutionKind kind);
getOrCreateNestedType(GenericSignatureBuilder &builder,
AssociatedTypeDecl *assocType,
ArchetypeResolutionKind kind);

/// Retrieve the dependent type that describes this potential
/// archetype.
Expand Down
72 changes: 29 additions & 43 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2808,7 +2808,7 @@ static void concretizeNestedTypeFromConcreteParent(
SameTypeConflictCheckedLater());
}

PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(
PotentialArchetype *PotentialArchetype::getOrCreateNestedType(
GenericSignatureBuilder &builder, AssociatedTypeDecl *assocType,
ArchetypeResolutionKind kind) {
if (!assocType)
Expand All @@ -2819,57 +2819,45 @@ PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(

Identifier name = assocType->getName();

SWIFT_DEFER {
// If we were asked for a complete, well-formed archetype, make sure we
// process delayed requirements if anything changed.
if (kind == ArchetypeResolutionKind::CompleteWellFormed)
builder.processDelayedRequirements();
};

// Look for a potential archetype with the appropriate associated type.
PotentialArchetype *resultPA = nullptr;
auto knownNestedTypes = NestedTypes.find(name);
bool shouldUpdatePA = false;
if (knownNestedTypes != NestedTypes.end()) {
for (auto existingPA : knownNestedTypes->second) {
// Do we have an associated-type match?
if (assocType && existingPA->getResolvedType() == assocType) {
resultPA = existingPA;
break;
return existingPA;
}
}
}

// If we don't have a result potential archetype yet, we may need to add one.
if (!resultPA) {
switch (kind) {
case ArchetypeResolutionKind::CompleteWellFormed:
case ArchetypeResolutionKind::WellFormed: {
// Creating a new potential archetype in an equivalence class is a
// modification.
getOrCreateEquivalenceClass(builder)->modified(builder);
if (kind == ArchetypeResolutionKind::AlreadyKnown)
return nullptr;

void *mem = builder.Impl->Allocator.Allocate<PotentialArchetype>();
resultPA = new (mem) PotentialArchetype(this, assocType);
// We don't have a result potential archetype, so we need to add one.

NestedTypes[name].push_back(resultPA);
builder.addedNestedType(resultPA);
shouldUpdatePA = true;
break;
}
// Creating a new potential archetype in an equivalence class is a
// modification.
getOrCreateEquivalenceClass(builder)->modified(builder);

case ArchetypeResolutionKind::AlreadyKnown:
return nullptr;
}
}
void *mem = builder.Impl->Allocator.Allocate<PotentialArchetype>();
auto *resultPA = new (mem) PotentialArchetype(this, assocType);

// If we have a potential archetype that requires more processing, do so now.
if (shouldUpdatePA) {
// We know something concrete about the parent PA, so we need to propagate
// that information to this new archetype.
if (auto equivClass = getEquivalenceClassIfPresent()) {
if (equivClass->concreteType || equivClass->superclass)
concretizeNestedTypeFromConcreteParent(this, resultPA, builder);
}
}
NestedTypes[name].push_back(resultPA);
builder.addedNestedType(resultPA);

// If we were asked for a complete, well-formed archetype, make sure we
// process delayed requirements if anything changed.
if (kind == ArchetypeResolutionKind::CompleteWellFormed)
builder.processDelayedRequirements();
// If we know something concrete about the parent PA, we need to propagate
// that information to this new archetype.
if (auto equivClass = getEquivalenceClassIfPresent()) {
if (equivClass->concreteType || equivClass->superclass)
concretizeNestedTypeFromConcreteParent(this, resultPA, builder);
}

return resultPA;
}
Expand Down Expand Up @@ -3889,8 +3877,7 @@ ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass(
}

auto nestedPA =
basePA->updateNestedTypeForConformance(*this, assocType,
resolutionKind);
basePA->getOrCreateNestedType(*this, assocType, resolutionKind);
if (!nestedPA)
return ResolvedType::forUnresolved(baseEquivClass);

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

PotentialArchetype *existingPA =
parentRepPA->updateNestedTypeForConformance(
*this,
nestedPA->getResolvedType(),
ArchetypeResolutionKind::WellFormed);
parentRepPA->getOrCreateNestedType(*this,
nestedPA->getResolvedType(),
ArchetypeResolutionKind::WellFormed);

auto sameNamedSource =
FloatingRequirementSource::forNestedTypeNameMatch(
Expand Down