@@ -703,6 +703,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
703
703
return getRecursiveProperties ().hasDependentMember ();
704
704
}
705
705
706
+ // / Whether this type represents a generic constraint.
707
+ bool isConstraintType () const ;
708
+
706
709
// / isExistentialType - Determines whether this type is an existential type,
707
710
// / whose real (runtime) type is unknown but which is known to conform to
708
711
// / some set of protocols. Protocol and protocol-conformance types are
@@ -2704,6 +2707,8 @@ class ExistentialMetatypeType : public AnyMetatypeType {
2704
2707
static bool classof (const TypeBase *T) {
2705
2708
return T->getKind () == TypeKind::ExistentialMetatype;
2706
2709
}
2710
+
2711
+ Type getExistentialInstanceType ();
2707
2712
2708
2713
private:
2709
2714
ExistentialMetatypeType (Type T, const ASTContext *C,
@@ -5213,7 +5218,7 @@ class ExistentialType final : public TypeBase {
5213
5218
ConstraintType (constraintType) {}
5214
5219
5215
5220
public:
5216
- static ExistentialType * get (Type constraint);
5221
+ static Type get (Type constraint);
5217
5222
5218
5223
Type getConstraintType () const { return ConstraintType; }
5219
5224
@@ -6181,6 +6186,15 @@ inline GenericTypeParamType *TypeBase::getRootGenericParam() {
6181
6186
return t->castTo <GenericTypeParamType>();
6182
6187
}
6183
6188
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
+
6184
6198
inline bool TypeBase::isExistentialType () {
6185
6199
return getCanonicalType ().isExistentialType ();
6186
6200
}
@@ -6287,6 +6301,8 @@ inline NominalTypeDecl *TypeBase::getNominalOrBoundGenericNominal() {
6287
6301
inline NominalTypeDecl *CanType::getNominalOrBoundGenericNominal () const {
6288
6302
if (auto Ty = dyn_cast<NominalOrBoundGenericNominalType>(*this ))
6289
6303
return Ty->getDecl ();
6304
+ if (auto Ty = dyn_cast<ExistentialType>(*this ))
6305
+ return Ty->getConstraintType ()->getNominalOrBoundGenericNominal ();
6290
6306
return nullptr ;
6291
6307
}
6292
6308
@@ -6295,6 +6311,9 @@ inline NominalTypeDecl *TypeBase::getAnyNominal() {
6295
6311
}
6296
6312
6297
6313
inline Type TypeBase::getNominalParent () {
6314
+ if (auto existential = getAs<ExistentialType>())
6315
+ return existential->getConstraintType ()->getNominalParent ();
6316
+
6298
6317
return castTo<AnyGenericType>()->getParent ();
6299
6318
}
6300
6319
0 commit comments