@@ -76,7 +76,7 @@ namespace swift {
76
76
// / on structural types.
77
77
class RecursiveTypeProperties {
78
78
public:
79
- enum { BitWidth = 5 };
79
+ enum { BitWidth = 6 };
80
80
81
81
// / A single property.
82
82
// /
@@ -99,6 +99,9 @@ class RecursiveTypeProperties {
99
99
// / This type expression contains an LValueType and can be loaded to convert
100
100
// / to an rvalue.
101
101
IsLValue = 0x10 ,
102
+
103
+ // / This type expression contains an opened existential ArchetypeType.
104
+ HasOpenedExistential = 0x20 ,
102
105
};
103
106
104
107
private:
@@ -132,6 +135,10 @@ class RecursiveTypeProperties {
132
135
// / Is a type with these properties an lvalue?
133
136
bool isLValue () const { return Bits & IsLValue; }
134
137
138
+ // / Does a type with these properties structurally contain an
139
+ // / archetype?
140
+ bool hasOpenedExistential () const { return Bits & HasOpenedExistential; }
141
+
135
142
// / Returns the set of properties present in either set.
136
143
friend RecursiveTypeProperties operator +(Property lhs, Property rhs) {
137
144
return RecursiveTypeProperties (lhs | rhs);
@@ -365,6 +372,29 @@ class alignas(1 << TypeAlignInBits) TypeBase {
365
372
return getRecursiveProperties ().hasArchetype ();
366
373
}
367
374
375
+ // / Determine whether the type involves an opened existential archetype.
376
+ bool hasOpenedExistential () const {
377
+ return getRecursiveProperties ().hasOpenedExistential ();
378
+ }
379
+
380
+ // / Determine whether the type involves the given opend existential
381
+ // / archetype.
382
+ bool hasOpenedExistential (ArchetypeType *opened);
383
+
384
+ // / Determine whether the type is an opened existential type.
385
+ // /
386
+ // / To determine whether there is an opened existential type
387
+ // / anywhere in the type, use \c hasOpenedExistential.
388
+ bool isOpenedExistential ();
389
+
390
+ // / Retrieve the set of opened existential archetypes that occur
391
+ // / within this type.
392
+ void getOpenedExistentials (SmallVectorImpl<ArchetypeType *> &opened);
393
+
394
+ // / Erase the given opened existential type by replacing it with its
395
+ // / existential type throughout the given type.
396
+ Type eraseOpenedExistential (Module *module , ArchetypeType *opened);
397
+
368
398
// / \brief Compute and return the set of type variables that occur within this
369
399
// / type.
370
400
// /
@@ -3486,7 +3516,9 @@ class ArchetypeType : public SubstitutableType {
3486
3516
ArrayRef<ProtocolDecl *> ConformsTo,
3487
3517
Type Superclass, bool isRecursive = false )
3488
3518
: SubstitutableType (TypeKind::Archetype, &Ctx,
3489
- RecursiveTypeProperties::HasArchetype),
3519
+ RecursiveTypeProperties (
3520
+ RecursiveTypeProperties::HasArchetype |
3521
+ RecursiveTypeProperties::HasOpenedExistential)),
3490
3522
ConformsTo (ConformsTo), Superclass (Superclass),
3491
3523
ParentOrOpened (Existential.getPointer ()),
3492
3524
isRecursive (isRecursive) { }
@@ -3901,6 +3933,16 @@ inline bool TypeBase::isClassExistentialType() {
3901
3933
return false ;
3902
3934
}
3903
3935
3936
+ inline bool TypeBase::isOpenedExistential () {
3937
+ if (!hasOpenedExistential ())
3938
+ return false ;
3939
+
3940
+ CanType T = getCanonicalType ();
3941
+ if (auto archetype = dyn_cast<ArchetypeType>(T))
3942
+ return !archetype->getOpenedExistentialType ().isNull ();
3943
+ return false ;
3944
+ }
3945
+
3904
3946
inline ClassDecl *TypeBase::getClassOrBoundGenericClass () {
3905
3947
return getCanonicalType ().getClassOrBoundGenericClass ();
3906
3948
}
0 commit comments