@@ -703,6 +703,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
703703 return getRecursiveProperties ().hasDependentMember ();
704704 }
705705
706+ // / Whether this type represents a generic constraint.
707+ bool isConstraintType () const ;
708+
706709 // / isExistentialType - Determines whether this type is an existential type,
707710 // / whose real (runtime) type is unknown but which is known to conform to
708711 // / some set of protocols. Protocol and protocol-conformance types are
@@ -2704,6 +2707,8 @@ class ExistentialMetatypeType : public AnyMetatypeType {
27042707 static bool classof (const TypeBase *T) {
27052708 return T->getKind () == TypeKind::ExistentialMetatype;
27062709 }
2710+
2711+ Type getExistentialInstanceType ();
27072712
27082713private:
27092714 ExistentialMetatypeType (Type T, const ASTContext *C,
@@ -5213,7 +5218,7 @@ class ExistentialType final : public TypeBase {
52135218 ConstraintType (constraintType) {}
52145219
52155220public:
5216- static ExistentialType * get (Type constraint);
5221+ static Type get (Type constraint);
52175222
52185223 Type getConstraintType () const { return ConstraintType; }
52195224
@@ -6181,6 +6186,15 @@ inline GenericTypeParamType *TypeBase::getRootGenericParam() {
61816186 return t->castTo <GenericTypeParamType>();
61826187}
61836188
6189+ inline bool TypeBase::isConstraintType () const {
6190+ return getCanonicalType ().isConstraintType ();
6191+ }
6192+
6193+ inline bool CanType::isConstraintTypeImpl (CanType type) {
6194+ return (isa<ProtocolType>(type) ||
6195+ isa<ProtocolCompositionType>(type));
6196+ }
6197+
61846198inline bool TypeBase::isExistentialType () {
61856199 return getCanonicalType ().isExistentialType ();
61866200}
@@ -6287,6 +6301,8 @@ inline NominalTypeDecl *TypeBase::getNominalOrBoundGenericNominal() {
62876301inline NominalTypeDecl *CanType::getNominalOrBoundGenericNominal () const {
62886302 if (auto Ty = dyn_cast<NominalOrBoundGenericNominalType>(*this ))
62896303 return Ty->getDecl ();
6304+ if (auto Ty = dyn_cast<ExistentialType>(*this ))
6305+ return Ty->getConstraintType ()->getNominalOrBoundGenericNominal ();
62906306 return nullptr ;
62916307}
62926308
@@ -6295,6 +6311,9 @@ inline NominalTypeDecl *TypeBase::getAnyNominal() {
62956311}
62966312
62976313inline Type TypeBase::getNominalParent () {
6314+ if (auto existential = getAs<ExistentialType>())
6315+ return existential->getConstraintType ()->getNominalParent ();
6316+
62986317 return castTo<AnyGenericType>()->getParent ();
62996318}
63006319
0 commit comments