Skip to content

Commit 8850aef

Browse files
committed
Track whether a type contains an element archetype in the recursive properties.
Being able to efficiently query for a local archetype is important in SIL.
1 parent 142f3ac commit 8850aef

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

include/swift/AST/Types.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ class RecursiveTypeProperties {
168168
/// This type contains a parameterized existential type \c any P<T>.
169169
HasParameterizedExistential = 0x2000,
170170

171-
Last_Property = HasParameterizedExistential
171+
/// This type contains an ElementArchetype.
172+
HasElementArchetype = 0x4000,
173+
174+
Last_Property = HasElementArchetype
172175
};
173176
enum { BitWidth = countBitsUsed(Property::Last_Property) };
174177

@@ -212,9 +215,19 @@ class RecursiveTypeProperties {
212215
bool hasDependentMember() const { return Bits & HasDependentMember; }
213216

214217
/// Does a type with these properties structurally contain an
215-
/// archetype?
218+
/// opened existential archetype?
216219
bool hasOpenedExistential() const { return Bits & HasOpenedExistential; }
217220

221+
/// Does a type with these properties structurally contain an
222+
/// opened element archetype?
223+
bool hasElementArchetype() const { return Bits & HasElementArchetype; }
224+
225+
/// Does a type with these properties structurally contain a local
226+
/// archetype?
227+
bool hasLocalArchetype() const {
228+
return hasOpenedExistential() || hasElementArchetype();
229+
}
230+
218231
/// Does a type with these properties structurally contain a
219232
/// reference to DynamicSelf?
220233
bool hasDynamicSelf() const { return Bits & HasDynamicSelf; }
@@ -629,6 +642,16 @@ class alignas(1 << TypeAlignInBits) TypeBase
629642
return getRecursiveProperties().hasOpenedExistential();
630643
}
631644

645+
/// Determine whether the type involves an opened element archetype.
646+
bool hasElementArchetype() const {
647+
return getRecursiveProperties().hasElementArchetype();
648+
}
649+
650+
/// Determine whether the type involves a local archetype.
651+
bool hasLocalArchetype() const {
652+
return getRecursiveProperties().hasLocalArchetype();
653+
}
654+
632655
bool hasParameterPack() const {
633656
return getRecursiveProperties().hasParameterPack();
634657
}

lib/AST/Type.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4024,7 +4024,8 @@ ElementArchetypeType::ElementArchetypeType(
40244024
ArrayRef<ProtocolDecl *> ConformsTo, Type Superclass,
40254025
LayoutConstraint Layout)
40264026
: LocalArchetypeType(TypeKind::ElementArchetype, Ctx,
4027-
RecursiveTypeProperties::HasArchetype,
4027+
RecursiveTypeProperties::HasArchetype |
4028+
RecursiveTypeProperties::HasElementArchetype,
40284029
InterfaceType,
40294030
ConformsTo, Superclass, Layout, GenericEnv) {
40304031
}

0 commit comments

Comments
 (0)