Skip to content

Commit 91bd2b1

Browse files
committed
AST: Remove OpenedArchetypeType::getOpenedExistentialType()
Clients can explicitly ask for the opened existential type on the archetype's generic environment, or use `getExistentialType` to obtain a specific archetype's upper bounds.
1 parent 8fc787e commit 91bd2b1

File tree

11 files changed

+33
-34
lines changed

11 files changed

+33
-34
lines changed

include/swift/AST/Types.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5770,9 +5770,6 @@ class OpenedArchetypeType final : public ArchetypeType,
57705770

57715771
/// Retrieve the ID number of this opened existential.
57725772
UUID getOpenedExistentialID() const;
5773-
5774-
/// Retrieve the opened existential type
5775-
Type getOpenedExistentialType() const;
57765773

57775774
/// Return the archetype that represents the root generic parameter of its
57785775
/// interface type.
@@ -6412,8 +6409,7 @@ inline bool TypeBase::isOpenedExistentialWithError() {
64126409

64136410
CanType T = getCanonicalType();
64146411
if (auto archetype = dyn_cast<OpenedArchetypeType>(T)) {
6415-
auto openedExistentialType = archetype->getOpenedExistentialType();
6416-
return openedExistentialType->isExistentialWithError();
6412+
return archetype->getExistentialType()->isExistentialWithError();
64176413
}
64186414
return false;
64196415
}

include/swift/SIL/SILCloner.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
249249
}
250250

251251
void remapOpenedType(CanOpenedArchetypeType archetypeTy) {
252-
auto existentialTy = archetypeTy->getOpenedExistentialType()->getCanonicalType();
252+
assert(archetypeTy->isRoot());
253+
254+
auto existentialTy = archetypeTy->getExistentialType()->getCanonicalType();
253255
auto replacementTy = OpenedArchetypeType::get(
254256
getOpASTType(existentialTy),
255257
archetypeTy->getInterfaceType());

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4504,10 +4504,10 @@ CanOpenedArchetypeType OpenedArchetypeType::get(CanType existential,
45044504
auto found = openedExistentialEnvironments.find(*knownID);
45054505

45064506
if (found != openedExistentialEnvironments.end()) {
4507+
assert(found->second->getOpenedExistentialType()->isEqual(existential) &&
4508+
"Retrieved the wrong generic environment?");
45074509
auto result = found->second->mapTypeIntoContext(interfaceType)
45084510
->castTo<OpenedArchetypeType>();
4509-
assert(result->getOpenedExistentialType()->isEqual(existential) &&
4510-
"Retrieved the wrong opened existential type?");
45114511
return CanOpenedArchetypeType(result);
45124512
}
45134513
} else {

lib/AST/ASTDumper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3743,7 +3743,8 @@ namespace {
37433743
}
37443744
void visitOpenedArchetypeType(OpenedArchetypeType *T, StringRef label) {
37453745
printArchetypeCommon(T, "opened_archetype_type", label);
3746-
printRec("opened_existential", T->getOpenedExistentialType());
3746+
printRec("opened_existential",
3747+
T->getGenericEnvironment()->getOpenedExistentialType());
37473748
printField("opened_existential_id", T->getOpenedExistentialID());
37483749
PrintWithColorRAII(OS, ParenthesisColor) << ')';
37493750
}

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -943,13 +943,10 @@ class PrintAST : public ASTVisitor<PrintAST> {
943943
// so we can't use it for TypeTransformContext.
944944
// To work around this, replace the OpenedArchetypeType with the type of
945945
// the protocol itself.
946-
CurrentType = CurrentType.transform([](Type T) -> Type {
947-
if (auto *Opened = T->getAs<OpenedArchetypeType>()) {
948-
return Opened->getOpenedExistentialType();
949-
} else {
950-
return T;
951-
}
952-
});
946+
if (auto *Opened = CurrentType->getAs<OpenedArchetypeType>()) {
947+
assert(Opened->isRoot());
948+
CurrentType = Opened->getExistentialType();
949+
}
953950
CurrentType = CurrentType->mapTypeOutOfContext();
954951
}
955952
setCurrentType(CurrentType);
@@ -5979,7 +5976,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
59795976

59805977
if (Options.PrintForSIL)
59815978
Printer << "@opened(\"" << T->getOpenedExistentialID() << "\") ";
5982-
visit(T->getOpenedExistentialType());
5979+
visit(T->getExistentialType());
59835980
}
59845981

59855982
void printArchetypeCommon(ArchetypeType *T,

lib/AST/Type.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ Type TypeBase::typeEraseOpenedArchetypesWithRoot(
483483
return type;
484484

485485
const auto sig = root->getASTContext().getOpenedArchetypeSignature(
486-
root->getOpenedExistentialType());
486+
root->getExistentialType());
487487

488488
unsigned metatypeDepth = 0;
489489

@@ -519,7 +519,7 @@ Type TypeBase::typeEraseOpenedArchetypesWithRoot(
519519

520520
Type erasedTy;
521521
if (root->isEqual(archetype)) {
522-
erasedTy = root->getOpenedExistentialType();
522+
erasedTy = root->getExistentialType();
523523
} else {
524524
erasedTy =
525525
sig->getNonDependentUpperBounds(archetype->getInterfaceType());
@@ -3346,9 +3346,12 @@ bool ArchetypeType::isRoot() const {
33463346

33473347
Type ArchetypeType::getExistentialType() const {
33483348
// Opened types hold this directly.
3349-
if (auto opened = dyn_cast<OpenedArchetypeType>(this))
3350-
return opened->getOpenedExistentialType();
3351-
3349+
if (auto *opened = dyn_cast<OpenedArchetypeType>(this)) {
3350+
if (opened->isRoot()) {
3351+
return getGenericEnvironment()->getOpenedExistentialType();
3352+
}
3353+
}
3354+
33523355
// Otherwise, compute it from scratch.
33533356
SmallVector<Type, 4> constraintTypes;
33543357

@@ -3399,10 +3402,6 @@ UUID OpenedArchetypeType::getOpenedExistentialID() const {
33993402
return getGenericEnvironment()->getOpenedExistentialUUID();
34003403
}
34013404

3402-
Type OpenedArchetypeType::getOpenedExistentialType() const {
3403-
return getGenericEnvironment()->getOpenedExistentialType();
3404-
}
3405-
34063405
OpaqueTypeArchetypeType::OpaqueTypeArchetypeType(
34073406
GenericEnvironment *environment,
34083407
RecursiveTypeProperties properties,

lib/IDE/Utils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,8 +1299,10 @@ void swift::ide::getReceiverType(Expr *Base,
12991299
ReceiverTy = SelfT->getSelfType();
13001300

13011301
// TODO: Handle generics and composed protocols
1302-
if (auto OpenedTy = ReceiverTy->getAs<OpenedArchetypeType>())
1303-
ReceiverTy = OpenedTy->getOpenedExistentialType();
1302+
if (auto OpenedTy = ReceiverTy->getAs<OpenedArchetypeType>()) {
1303+
assert(OpenedTy->isRoot());
1304+
ReceiverTy = OpenedTy->getExistentialType();
1305+
}
13041306

13051307
if (auto TyD = ReceiverTy->getAnyNominal()) {
13061308
Types.push_back(TyD);

lib/SILGen/ResultPlan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ mapTypeOutOfOpenedExistentialContext(CanType t) {
100100
params.push_back(param);
101101

102102
const auto constraintTy = openedTypes[i]
103-
->getOpenedExistentialType()
103+
->getExistentialType()
104104
->castTo<ExistentialType>()
105105
->getConstraintType();
106106
requirements.emplace_back(RequirementKind::Conformance, param,

lib/SILGen/SILGenPoly.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,8 @@ buildThunkSignature(SILGenFunction &SGF,
30493049
auto *newGenericParam =
30503050
GenericTypeParamType::get(/*type sequence*/ false, depth, 0, ctx);
30513051

3052-
auto constraint = openedExistential->getOpenedExistentialType();
3052+
assert(openedExistential->isRoot());
3053+
auto constraint = openedExistential->getExistentialType();
30533054
if (auto existential = constraint->getAs<ExistentialType>())
30543055
constraint = existential->getConstraintType();
30553056

lib/SILOptimizer/Differentiation/Thunk.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ CanGenericSignature buildThunkSignature(SILFunction *fn, bool inheritGenericSig,
6767
auto *newGenericParam =
6868
GenericTypeParamType::get(/*type sequence*/ false, depth, 0, ctx);
6969

70-
auto constraint = openedExistential->getOpenedExistentialType();
70+
assert(openedExistential->isRoot());
71+
auto constraint = openedExistential->getExistentialType();
7172
if (auto existential = constraint->getAs<ExistentialType>())
7273
constraint = existential->getConstraintType();
7374

0 commit comments

Comments
 (0)