Skip to content

Commit db54207

Browse files
committed
AST: Introduce TypeBase::hasPrimaryArchetype()
The existing hasArchetype() is now deprecated. It is equivalent to: hasPrimaryArchetype() || hasLocalArchetype() Callers should be changed to check one or both of the above predicates in the most precise way possible.
1 parent d598515 commit db54207

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

include/swift/AST/Types.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,9 @@ class RecursiveTypeProperties {
128128
/// This type expression contains a TypeVariableType.
129129
HasTypeVariable = 0x01,
130130

131-
/// This type expression contains a context-dependent archetype, either a
132-
/// \c PrimaryArchetypeType, \c OpenedArchetypeType,
133-
/// \c ElementArchetypeType, or \c PackArchetype.
134-
HasArchetype = 0x02,
131+
/// This type expression contains a PrimaryArchetypeType
132+
/// or PackArchetypeType.
133+
HasPrimaryArchetype = 0x02,
135134

136135
/// This type expression contains a GenericTypeParamType.
137136
HasTypeParameter = 0x04,
@@ -171,7 +170,7 @@ class RecursiveTypeProperties {
171170
/// This type contains a parameterized existential type \c any P<T>.
172171
HasParameterizedExistential = 0x2000,
173172

174-
/// This type contains an ElementArchetype.
173+
/// This type contains an ElementArchetypeType.
175174
HasElementArchetype = 0x4000,
176175

177176
/// Whether the type is allocated in the constraint solver arena. This can
@@ -205,9 +204,9 @@ class RecursiveTypeProperties {
205204
/// variable?
206205
bool hasTypeVariable() const { return Bits & HasTypeVariable; }
207206

208-
/// Does a type with these properties structurally contain a
209-
/// context-dependent archetype (that is, a Primary- or OpenedArchetype)?
210-
bool hasArchetype() const { return Bits & HasArchetype; }
207+
/// Does a type with these properties structurally contain a primary
208+
/// archetype?
209+
bool hasPrimaryArchetype() const { return Bits & HasPrimaryArchetype; }
211210

212211
/// Does a type with these properties structurally contain an
213212
/// archetype from an opaque type declaration?
@@ -696,9 +695,21 @@ class alignas(1 << TypeAlignInBits) TypeBase
696695
return getRecursiveProperties().hasPlaceholder();
697696
}
698697

699-
/// Determine whether the type involves a context-dependent archetype.
698+
/// Determine whether the type involves a primary archetype.
699+
bool hasPrimaryArchetype() const {
700+
return getRecursiveProperties().hasPrimaryArchetype();
701+
}
702+
703+
/// Whether the type contains a PackArchetypeType.
704+
bool hasPackArchetype() const {
705+
return getRecursiveProperties().hasPackArchetype();
706+
}
707+
708+
/// Determine whether the type involves a primary, pack or local archetype.
709+
///
710+
/// FIXME: Replace all remaining callers with a more precise check.
700711
bool hasArchetype() const {
701-
return getRecursiveProperties().hasArchetype();
712+
return hasPrimaryArchetype() || hasLocalArchetype();
702713
}
703714

704715
/// Determine whether the type involves an opened existential archetype.
@@ -727,11 +738,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
727738
return getRecursiveProperties().hasPack();
728739
}
729740

730-
/// Whether the type contains a PackArchetypeType.
731-
bool hasPackArchetype() const {
732-
return getRecursiveProperties().hasPackArchetype();
733-
}
734-
735741
/// Whether the type has any flavor of pack.
736742
bool hasAnyPack() const {
737743
return hasParameterPack() || hasPack() || hasPackArchetype();

lib/AST/Type.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,7 +3454,7 @@ PrimaryArchetypeType::PrimaryArchetypeType(const ASTContext &Ctx,
34543454
ArrayRef<ProtocolDecl *> ConformsTo,
34553455
Type Superclass, LayoutConstraint Layout)
34563456
: ArchetypeType(TypeKind::PrimaryArchetype, Ctx,
3457-
RecursiveTypeProperties::HasArchetype,
3457+
RecursiveTypeProperties::HasPrimaryArchetype,
34583458
InterfaceType, ConformsTo, Superclass, Layout, GenericEnv)
34593459
{
34603460
assert(!InterfaceType->isParameterPack());
@@ -3518,8 +3518,7 @@ OpenedArchetypeType::OpenedArchetypeType(
35183518
LayoutConstraint layout)
35193519
: LocalArchetypeType(TypeKind::OpenedArchetype,
35203520
interfaceType->getASTContext(),
3521-
RecursiveTypeProperties::HasArchetype
3522-
| RecursiveTypeProperties::HasOpenedExistential,
3521+
RecursiveTypeProperties::HasOpenedExistential,
35233522
interfaceType, conformsTo, superclass, layout,
35243523
environment)
35253524
{
@@ -3535,8 +3534,8 @@ PackArchetypeType::PackArchetypeType(
35353534
ArrayRef<ProtocolDecl *> ConformsTo, Type Superclass,
35363535
LayoutConstraint Layout, PackShape Shape)
35373536
: ArchetypeType(TypeKind::PackArchetype, Ctx,
3538-
RecursiveTypeProperties::HasArchetype |
3539-
RecursiveTypeProperties::HasPackArchetype,
3537+
RecursiveTypeProperties::HasPrimaryArchetype |
3538+
RecursiveTypeProperties::HasPackArchetype,
35403539
InterfaceType, ConformsTo, Superclass, Layout, GenericEnv) {
35413540
assert(InterfaceType->isParameterPack());
35423541
*getTrailingObjects<PackShape>() = Shape;
@@ -3586,7 +3585,6 @@ ElementArchetypeType::ElementArchetypeType(
35863585
ArrayRef<ProtocolDecl *> ConformsTo, Type Superclass,
35873586
LayoutConstraint Layout)
35883587
: LocalArchetypeType(TypeKind::ElementArchetype, Ctx,
3589-
RecursiveTypeProperties::HasArchetype |
35903588
RecursiveTypeProperties::HasElementArchetype,
35913589
InterfaceType,
35923590
ConformsTo, Superclass, Layout, GenericEnv) {

0 commit comments

Comments
 (0)