Skip to content

AST: Remove OpenedArchetypeType::get() overload taking an interface type #76030

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 1 commit into from
Aug 22, 2024
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
23 changes: 0 additions & 23 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6817,29 +6817,6 @@ class OpenedArchetypeType final : public LocalArchetypeType,
static CanTypeWrapper<OpenedArchetypeType>
get(CanType existential, std::optional<UUID> knownID = std::nullopt);

/// Get or create an archetype that represents the opened type
/// of an existential value.
///
/// \param existential The existential type to open.
/// \param interfaceType The interface type represented by this archetype.
///
/// \param knownID When non-empty, the known ID of the archetype. When empty,
/// a fresh archetype with a unique ID will be opened.
static CanTypeWrapper<OpenedArchetypeType>
get(CanType existential, Type interfaceType,
std::optional<UUID> knownID = std::nullopt);

/// Create a new archetype that represents the opened type
/// of an existential value.
///
/// Use this function when you are unsure of whether the
/// \c existential type is a metatype or an instance type. This function
/// will unwrap any existential metatype containers.
///
/// \param existential The existential type or existential metatype to open.
/// \param interfaceType The interface type represented by this archetype.
static Type getAny(Type existential, Type interfaceType);

/// Create a new archetype that represents the opened type
/// of an existential value.
///
Expand Down
31 changes: 9 additions & 22 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5336,19 +5336,14 @@ CanTypeWrapper<OpenedArchetypeType> OpenedArchetypeType::getNew(
properties));
}

CanTypeWrapper<OpenedArchetypeType>
OpenedArchetypeType::get(CanType existential, std::optional<UUID> knownID) {
assert(existential->isExistentialType());
auto interfaceType = OpenedArchetypeType::getSelfInterfaceTypeFromContext(
GenericSignature(), existential->getASTContext());
return get(existential, interfaceType, knownID);
}

CanOpenedArchetypeType OpenedArchetypeType::get(CanType existential,
Type interfaceType,
std::optional<UUID> knownID) {
assert(existential->isExistentialType());
assert(!existential->hasTypeParameter());

auto interfaceType = OpenedArchetypeType::getSelfInterfaceTypeFromContext(
GenericSignature(), existential->getASTContext());

if (!knownID)
knownID = UUID::fromTime();

Expand All @@ -5362,28 +5357,20 @@ CanOpenedArchetypeType OpenedArchetypeType::get(CanType existential,
return CanOpenedArchetypeType(result);
}

Type OpenedArchetypeType::getAny(Type existential, Type interfaceTy) {
Type OpenedArchetypeType::getAny(Type existential) {
assert(existential->isAnyExistentialType());

if (auto metatypeTy = existential->getAs<ExistentialMetatypeType>()) {
auto instanceTy =
metatypeTy->getExistentialInstanceType()->getCanonicalType();
auto openedInstanceTy = OpenedArchetypeType::getAny(
instanceTy, interfaceTy);
auto instanceTy = metatypeTy->getExistentialInstanceType();
auto openedInstanceTy = OpenedArchetypeType::getAny(instanceTy);
if (metatypeTy->hasRepresentation()) {
return MetatypeType::get(openedInstanceTy,
metatypeTy->getRepresentation());
}
return MetatypeType::get(openedInstanceTy);
}
assert(existential->isExistentialType());
return OpenedArchetypeType::get(existential->getCanonicalType(),
interfaceTy);
}

Type OpenedArchetypeType::getAny(Type existential) {
auto interfaceTy = OpenedArchetypeType::getSelfInterfaceTypeFromContext(
GenericSignature(), existential->getASTContext());
return getAny(existential, interfaceTy);
return OpenedArchetypeType::get(existential->getCanonicalType());
}

void SubstitutionMap::Storage::Profile(
Expand Down
7 changes: 4 additions & 3 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2862,9 +2862,10 @@ TypeResolver::resolveOpenedExistentialArchetype(

// The opened existential type is formed by mapping the interface type
// into a new opened generic environment.
archetypeType = OpenedArchetypeType::get(constraintType->getCanonicalType(),
interfaceType,
openedAttr->getUUID());
auto *env = GenericEnvironment::forOpenedExistential(
constraintType->getCanonicalType(), SubstitutionMap(),
openedAttr->getUUID());
return env->mapTypeIntoContext(interfaceType);
}

return archetypeType;
Expand Down