@@ -727,6 +727,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
727727 return getRecursiveProperties ().hasDependentMember ();
728728 }
729729
730+ // / Whether this type represents a generic constraint.
731+ bool isConstraintType () const ;
732+
730733 // / isExistentialType - Determines whether this type is an existential type,
731734 // / whose real (runtime) type is unknown but which is known to conform to
732735 // / some set of protocols. Protocol and protocol-conformance types are
@@ -2731,6 +2734,8 @@ class ExistentialMetatypeType : public AnyMetatypeType {
27312734 static bool classof (const TypeBase *T) {
27322735 return T->getKind () == TypeKind::ExistentialMetatype;
27332736 }
2737+
2738+ Type getExistentialInstanceType ();
27342739
27352740private:
27362741 ExistentialMetatypeType (Type T, const ASTContext *C,
@@ -5243,7 +5248,7 @@ class ExistentialType final : public TypeBase {
52435248 ConstraintType (constraintType) {}
52445249
52455250public:
5246- static ExistentialType * get (Type constraint);
5251+ static Type get (Type constraint);
52475252
52485253 Type getConstraintType () const { return ConstraintType; }
52495254
@@ -6335,6 +6340,15 @@ inline GenericTypeParamType *TypeBase::getRootGenericParam() {
63356340 return t->castTo <GenericTypeParamType>();
63366341}
63376342
6343+ inline bool TypeBase::isConstraintType () const {
6344+ return getCanonicalType ().isConstraintType ();
6345+ }
6346+
6347+ inline bool CanType::isConstraintTypeImpl (CanType type) {
6348+ return (isa<ProtocolType>(type) ||
6349+ isa<ProtocolCompositionType>(type));
6350+ }
6351+
63386352inline bool TypeBase::isExistentialType () {
63396353 return getCanonicalType ().isExistentialType ();
63406354}
@@ -6441,6 +6455,8 @@ inline NominalTypeDecl *TypeBase::getNominalOrBoundGenericNominal() {
64416455inline NominalTypeDecl *CanType::getNominalOrBoundGenericNominal () const {
64426456 if (auto Ty = dyn_cast<NominalOrBoundGenericNominalType>(*this ))
64436457 return Ty->getDecl ();
6458+ if (auto Ty = dyn_cast<ExistentialType>(*this ))
6459+ return Ty->getConstraintType ()->getNominalOrBoundGenericNominal ();
64446460 return nullptr ;
64456461}
64466462
@@ -6449,6 +6465,9 @@ inline NominalTypeDecl *TypeBase::getAnyNominal() {
64496465}
64506466
64516467inline Type TypeBase::getNominalParent () {
6468+ if (auto existential = getAs<ExistentialType>())
6469+ return existential->getConstraintType ()->getNominalParent ();
6470+
64526471 return castTo<AnyGenericType>()->getParent ();
64536472}
64546473
0 commit comments