Skip to content

Commit c7e7b81

Browse files
committed
AST: Re-implement ArchetypeType::getExistentialType() using getDependentUpperBounds()
1 parent 7ffbf58 commit c7e7b81

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

lib/AST/Type.cpp

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3493,40 +3493,22 @@ bool ArchetypeType::isRoot() const {
34933493
}
34943494

34953495
Type ArchetypeType::getExistentialType() const {
3496+
auto *genericEnv = getGenericEnvironment();
3497+
34963498
// Opened types hold this directly.
34973499
if (auto *opened = dyn_cast<OpenedArchetypeType>(this)) {
34983500
if (opened->isRoot()) {
3499-
return getGenericEnvironment()->getOpenedExistentialType();
3501+
return genericEnv->getOpenedExistentialType();
35003502
}
35013503
}
35023504

3503-
// Otherwise, compute it from scratch.
3504-
SmallVector<Type, 4> constraintTypes;
3505-
3506-
bool hasExplicitAnyObject = requiresClass();
3507-
3508-
if (auto super = getSuperclass()) {
3509-
hasExplicitAnyObject = false;
3510-
constraintTypes.push_back(super);
3511-
}
3512-
for (auto proto : getConformsTo()) {
3513-
if (proto->requiresClass())
3514-
hasExplicitAnyObject = false;
3515-
constraintTypes.push_back(proto->getDeclaredInterfaceType());
3516-
}
3517-
3518-
auto &ctx = const_cast<ArchetypeType*>(this)->getASTContext();
3519-
auto constraint = ProtocolCompositionType::get(
3520-
ctx, constraintTypes, hasExplicitAnyObject);
3505+
// Otherwise we compute it via a generic signature query.
3506+
auto interfaceType = getInterfaceType();
3507+
auto genericSig = genericEnv->getGenericSignature();
35213508

3522-
// If the archetype is only constrained to a class type,
3523-
// return the class type directly.
3524-
if (!constraint->isConstraintType()) {
3525-
assert(constraint->getClassOrBoundGenericClass());
3526-
return constraint;
3527-
}
3509+
auto upperBound = genericSig->getDependentUpperBounds(interfaceType);
35283510

3529-
return ExistentialType::get(constraint);
3511+
return genericEnv->mapTypeIntoContext(upperBound);
35303512
}
35313513

35323514
bool ArchetypeType::requiresClass() const {

0 commit comments

Comments
 (0)