Skip to content

Commit 05ff1a4

Browse files
nate-chandlerhamishknight
authored andcommitted
[AST] Added hasConcretePack recursive property.
1 parent 57169f2 commit 05ff1a4

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
@@ -3340,7 +3340,7 @@ CanPackType CanPackType::get(const ASTContext &C,
33403340
}
33413341

33423342
PackType *PackType::get(const ASTContext &C, ArrayRef<Type> elements) {
3343-
RecursiveTypeProperties properties;
3343+
RecursiveTypeProperties properties = RecursiveTypeProperties::HasConcretePack;
33443344
bool isCanonical = true;
33453345
for (Type eltTy : elements) {
33463346
assert(!eltTy->is<PackType>() &&
@@ -3380,7 +3380,7 @@ void PackType::Profile(llvm::FoldingSetNodeID &ID, ArrayRef<Type> Elements) {
33803380

33813381
CanSILPackType SILPackType::get(const ASTContext &C, ExtInfo info,
33823382
ArrayRef<CanType> elements) {
3383-
RecursiveTypeProperties properties;
3383+
RecursiveTypeProperties properties = RecursiveTypeProperties::HasConcretePack;
33843384
for (CanType eltTy : elements) {
33853385
assert(!isa<SILPackType>(eltTy) &&
33863386
"Cannot have pack directly inside another pack");
@@ -3972,7 +3972,7 @@ isAnyFunctionTypeCanonical(ArrayRef<AnyFunctionType::Param> params,
39723972
static RecursiveTypeProperties
39733973
getGenericFunctionRecursiveProperties(ArrayRef<AnyFunctionType::Param> params,
39743974
Type result) {
3975-
static_assert(RecursiveTypeProperties::BitWidth == 16,
3975+
static_assert(RecursiveTypeProperties::BitWidth == 17,
39763976
"revisit this if you add new recursive type properties");
39773977
RecursiveTypeProperties properties;
39783978

@@ -4632,7 +4632,7 @@ CanSILFunctionType SILFunctionType::get(
46324632
void *mem = ctx.Allocate(bytes, alignof(SILFunctionType));
46334633

46344634
RecursiveTypeProperties properties;
4635-
static_assert(RecursiveTypeProperties::BitWidth == 16,
4635+
static_assert(RecursiveTypeProperties::BitWidth == 17,
46364636
"revisit this if you add new recursive type properties");
46374637
for (auto &param : params)
46384638
properties |= param.getInterfaceType()->getRecursiveProperties();

0 commit comments

Comments
 (0)