Skip to content

Commit 07b697e

Browse files
authored
Merge pull request #76030 from slavapestov/open-existential-get
AST: Remove OpenedArchetypeType::get() overload taking an interface type
2 parents 1861375 + e9b6f0b commit 07b697e

File tree

3 files changed

+13
-48
lines changed

3 files changed

+13
-48
lines changed

include/swift/AST/Types.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6817,29 +6817,6 @@ class OpenedArchetypeType final : public LocalArchetypeType,
68176817
static CanTypeWrapper<OpenedArchetypeType>
68186818
get(CanType existential, std::optional<UUID> knownID = std::nullopt);
68196819

6820-
/// Get or create an archetype that represents the opened type
6821-
/// of an existential value.
6822-
///
6823-
/// \param existential The existential type to open.
6824-
/// \param interfaceType The interface type represented by this archetype.
6825-
///
6826-
/// \param knownID When non-empty, the known ID of the archetype. When empty,
6827-
/// a fresh archetype with a unique ID will be opened.
6828-
static CanTypeWrapper<OpenedArchetypeType>
6829-
get(CanType existential, Type interfaceType,
6830-
std::optional<UUID> knownID = std::nullopt);
6831-
6832-
/// Create a new archetype that represents the opened type
6833-
/// of an existential value.
6834-
///
6835-
/// Use this function when you are unsure of whether the
6836-
/// \c existential type is a metatype or an instance type. This function
6837-
/// will unwrap any existential metatype containers.
6838-
///
6839-
/// \param existential The existential type or existential metatype to open.
6840-
/// \param interfaceType The interface type represented by this archetype.
6841-
static Type getAny(Type existential, Type interfaceType);
6842-
68436820
/// Create a new archetype that represents the opened type
68446821
/// of an existential value.
68456822
///

lib/AST/ASTContext.cpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5336,19 +5336,14 @@ CanTypeWrapper<OpenedArchetypeType> OpenedArchetypeType::getNew(
53365336
properties));
53375337
}
53385338

5339-
CanTypeWrapper<OpenedArchetypeType>
5340-
OpenedArchetypeType::get(CanType existential, std::optional<UUID> knownID) {
5341-
assert(existential->isExistentialType());
5342-
auto interfaceType = OpenedArchetypeType::getSelfInterfaceTypeFromContext(
5343-
GenericSignature(), existential->getASTContext());
5344-
return get(existential, interfaceType, knownID);
5345-
}
5346-
53475339
CanOpenedArchetypeType OpenedArchetypeType::get(CanType existential,
5348-
Type interfaceType,
53495340
std::optional<UUID> knownID) {
5341+
assert(existential->isExistentialType());
53505342
assert(!existential->hasTypeParameter());
53515343

5344+
auto interfaceType = OpenedArchetypeType::getSelfInterfaceTypeFromContext(
5345+
GenericSignature(), existential->getASTContext());
5346+
53525347
if (!knownID)
53535348
knownID = UUID::fromTime();
53545349

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

5365-
Type OpenedArchetypeType::getAny(Type existential, Type interfaceTy) {
5360+
Type OpenedArchetypeType::getAny(Type existential) {
53665361
assert(existential->isAnyExistentialType());
5362+
53675363
if (auto metatypeTy = existential->getAs<ExistentialMetatypeType>()) {
5368-
auto instanceTy =
5369-
metatypeTy->getExistentialInstanceType()->getCanonicalType();
5370-
auto openedInstanceTy = OpenedArchetypeType::getAny(
5371-
instanceTy, interfaceTy);
5364+
auto instanceTy = metatypeTy->getExistentialInstanceType();
5365+
auto openedInstanceTy = OpenedArchetypeType::getAny(instanceTy);
53725366
if (metatypeTy->hasRepresentation()) {
53735367
return MetatypeType::get(openedInstanceTy,
53745368
metatypeTy->getRepresentation());
53755369
}
53765370
return MetatypeType::get(openedInstanceTy);
53775371
}
5378-
assert(existential->isExistentialType());
5379-
return OpenedArchetypeType::get(existential->getCanonicalType(),
5380-
interfaceTy);
5381-
}
53825372

5383-
Type OpenedArchetypeType::getAny(Type existential) {
5384-
auto interfaceTy = OpenedArchetypeType::getSelfInterfaceTypeFromContext(
5385-
GenericSignature(), existential->getASTContext());
5386-
return getAny(existential, interfaceTy);
5373+
return OpenedArchetypeType::get(existential->getCanonicalType());
53875374
}
53885375

53895376
void SubstitutionMap::Storage::Profile(

lib/Sema/TypeCheckType.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,9 +2862,10 @@ TypeResolver::resolveOpenedExistentialArchetype(
28622862

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

28702871
return archetypeType;

0 commit comments

Comments
 (0)