Skip to content

Commit 2866ad4

Browse files
committed
[AST] Added hasConcretePack recursive property.
1 parent 7ff5fea commit 2866ad4

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

include/swift/AST/Types.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ class RecursiveTypeProperties {
179179
/// they have a type variable originator.
180180
SolverAllocated = 0x8000,
181181

182-
Last_Property = SolverAllocated
182+
/// This type contains a concrete pack.
183+
HasConcretePack = 0x10000,
184+
185+
Last_Property = HasConcretePack
183186
};
184187
enum { BitWidth = countBitsUsed(Property::Last_Property) };
185188

@@ -255,6 +258,8 @@ class RecursiveTypeProperties {
255258

256259
bool hasParameterPack() const { return Bits & HasParameterPack; }
257260

261+
bool hasConcretePack() const { return Bits & HasConcretePack; }
262+
258263
/// Does a type with these properties structurally contain a
259264
/// parameterized existential type?
260265
bool hasParameterizedExistential() const {
@@ -412,12 +417,12 @@ class alignas(1 << TypeAlignInBits) TypeBase
412417
NumProtocols : 16
413418
);
414419

415-
SWIFT_INLINE_BITFIELD_FULL(TypeVariableType, TypeBase, 7+31,
420+
SWIFT_INLINE_BITFIELD_FULL(TypeVariableType, TypeBase, 7+30,
416421
/// Type variable options.
417422
Options : 7,
418423
: NumPadBits,
419424
/// The unique number assigned to this type variable.
420-
ID : 31
425+
ID : 30
421426
);
422427

423428
SWIFT_INLINE_BITFIELD(SILFunctionType, TypeBase, NumSILExtInfoBits+1+4+1+2+1+1,
@@ -684,6 +689,13 @@ class alignas(1 << TypeAlignInBits) TypeBase
684689
return getRecursiveProperties().hasParameterPack();
685690
}
686691

692+
bool hasConcretePack() const {
693+
return getRecursiveProperties().hasConcretePack();
694+
}
695+
696+
/// Whether the type has some flavor of pack.
697+
bool hasPack() const { return hasParameterPack() || hasConcretePack(); }
698+
687699
/// Determine whether the type involves a parameterized existential type.
688700
bool hasParameterizedExistential() const {
689701
return getRecursiveProperties().hasParameterizedExistential();

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,7 +3396,7 @@ CanPackType CanPackType::get(const ASTContext &C,
33963396
}
33973397

33983398
PackType *PackType::get(const ASTContext &C, ArrayRef<Type> elements) {
3399-
RecursiveTypeProperties properties;
3399+
RecursiveTypeProperties properties = RecursiveTypeProperties::HasConcretePack;
34003400
bool isCanonical = true;
34013401
for (Type eltTy : elements) {
34023402
assert(!eltTy->is<PackType>() &&
@@ -3436,7 +3436,7 @@ void PackType::Profile(llvm::FoldingSetNodeID &ID, ArrayRef<Type> Elements) {
34363436

34373437
CanSILPackType SILPackType::get(const ASTContext &C, ExtInfo info,
34383438
ArrayRef<CanType> elements) {
3439-
RecursiveTypeProperties properties;
3439+
RecursiveTypeProperties properties = RecursiveTypeProperties::HasConcretePack;
34403440
for (CanType eltTy : elements) {
34413441
assert(!isa<SILPackType>(eltTy) &&
34423442
"Cannot have pack directly inside another pack");
@@ -4028,7 +4028,7 @@ isAnyFunctionTypeCanonical(ArrayRef<AnyFunctionType::Param> params,
40284028
static RecursiveTypeProperties
40294029
getGenericFunctionRecursiveProperties(ArrayRef<AnyFunctionType::Param> params,
40304030
Type result) {
4031-
static_assert(RecursiveTypeProperties::BitWidth == 16,
4031+
static_assert(RecursiveTypeProperties::BitWidth == 17,
40324032
"revisit this if you add new recursive type properties");
40334033
RecursiveTypeProperties properties;
40344034

@@ -4689,7 +4689,7 @@ CanSILFunctionType SILFunctionType::get(
46894689
void *mem = ctx.Allocate(bytes, alignof(SILFunctionType));
46904690

46914691
RecursiveTypeProperties properties;
4692-
static_assert(RecursiveTypeProperties::BitWidth == 16,
4692+
static_assert(RecursiveTypeProperties::BitWidth == 17,
46934693
"revisit this if you add new recursive type properties");
46944694
for (auto &param : params)
46954695
properties |= param.getInterfaceType()->getRecursiveProperties();

0 commit comments

Comments
 (0)