@@ -3493,40 +3493,22 @@ bool ArchetypeType::isRoot() const {
3493
3493
}
3494
3494
3495
3495
Type ArchetypeType::getExistentialType () const {
3496
+ auto *genericEnv = getGenericEnvironment ();
3497
+
3496
3498
// Opened types hold this directly.
3497
3499
if (auto *opened = dyn_cast<OpenedArchetypeType>(this )) {
3498
3500
if (opened->isRoot ()) {
3499
- return getGenericEnvironment () ->getOpenedExistentialType ();
3501
+ return genericEnv ->getOpenedExistentialType ();
3500
3502
}
3501
3503
}
3502
3504
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 ();
3521
3508
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);
3528
3510
3529
- return ExistentialType::get (constraint );
3511
+ return genericEnv-> mapTypeIntoContext (upperBound );
3530
3512
}
3531
3513
3532
3514
bool ArchetypeType::requiresClass () const {
0 commit comments