Skip to content

Commit 2d5985b

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 44c2466 commit 2d5985b

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
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/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3837,7 +3837,7 @@ isAnyFunctionTypeCanonical(ArrayRef<AnyFunctionType::Param> params,
38373837
static RecursiveTypeProperties
38383838
getGenericFunctionRecursiveProperties(ArrayRef<AnyFunctionType::Param> params,
38393839
Type result) {
3840-
static_assert(RecursiveTypeProperties::BitWidth == 14,
3840+
static_assert(RecursiveTypeProperties::BitWidth == 15,
38413841
"revisit this if you add new recursive type properties");
38423842
RecursiveTypeProperties properties;
38433843

@@ -4464,7 +4464,7 @@ CanSILFunctionType SILFunctionType::get(
44644464
void *mem = ctx.Allocate(bytes, alignof(SILFunctionType));
44654465

44664466
RecursiveTypeProperties properties;
4467-
static_assert(RecursiveTypeProperties::BitWidth == 14,
4467+
static_assert(RecursiveTypeProperties::BitWidth == 15,
44684468
"revisit this if you add new recursive type properties");
44694469
for (auto &param : params)
44704470
properties |= param.getInterfaceType()->getRecursiveProperties();

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)