Skip to content

Commit b8ea2d6

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 083e28b commit b8ea2d6

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

include/swift/AST/Types.h

Lines changed: 25 additions & 16 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
@@ -183,7 +182,7 @@ class RecursiveTypeProperties {
183182
/// Contains a PackType.
184183
HasPack = 0x10000,
185184

186-
/// Contains a PackArchetypeType.
185+
/// Contains a PackArchetypeType. Also implies HasPrimaryArchetype.
187186
HasPackArchetype = 0x20000,
188187

189188
Last_Property = HasPackArchetype
@@ -205,9 +204,10 @@ 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+
/// or pack archetype? These are the archetypes instantiated from a
209+
/// primary generic environment.
210+
bool hasPrimaryArchetype() const { return Bits & HasPrimaryArchetype; }
211211

212212
/// Does a type with these properties structurally contain an
213213
/// archetype from an opaque type declaration?
@@ -696,9 +696,23 @@ class alignas(1 << TypeAlignInBits) TypeBase
696696
return getRecursiveProperties().hasPlaceholder();
697697
}
698698

699-
/// Determine whether the type involves a context-dependent archetype.
699+
/// Determine whether the type involves a PrimaryArchetypeType *or* a
700+
/// PackArchetypeType. These are the archetypes instantiated from a
701+
/// primary generic environment.
702+
bool hasPrimaryArchetype() const {
703+
return getRecursiveProperties().hasPrimaryArchetype();
704+
}
705+
706+
/// Whether the type contains a PackArchetypeType.
707+
bool hasPackArchetype() const {
708+
return getRecursiveProperties().hasPackArchetype();
709+
}
710+
711+
/// Determine whether the type involves a primary, pack or local archetype.
712+
///
713+
/// FIXME: Replace all remaining callers with a more precise check.
700714
bool hasArchetype() const {
701-
return getRecursiveProperties().hasArchetype();
715+
return hasPrimaryArchetype() || hasLocalArchetype();
702716
}
703717

704718
/// Determine whether the type involves an opened existential archetype.
@@ -727,11 +741,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
727741
return getRecursiveProperties().hasPack();
728742
}
729743

730-
/// Whether the type contains a PackArchetypeType.
731-
bool hasPackArchetype() const {
732-
return getRecursiveProperties().hasPackArchetype();
733-
}
734-
735744
/// Whether the type has any flavor of pack.
736745
bool hasAnyPack() const {
737746
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)