Skip to content

Commit 090b14e

Browse files
committed
[AST] NFC: Refactor pack recursive properties.
Eliminated HasConcretePack and added HasPack and HasPackArchetype. Renamed the old `hasPack` to `hasAnyPack`; as before, it means that the type has a parameter pack, a pack, or a pack archetype.
1 parent 8e5ea9b commit 090b14e

File tree

5 files changed

+43
-25
lines changed

5 files changed

+43
-25
lines changed

include/swift/AST/Types.h

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,13 @@ class RecursiveTypeProperties {
180180
/// they have a type variable originator.
181181
SolverAllocated = 0x8000,
182182

183-
/// This type contains a concrete pack.
184-
HasConcretePack = 0x10000,
183+
/// Contains a PackType.
184+
HasPack = 0x10000,
185185

186-
Last_Property = HasConcretePack
186+
/// Contains a PackArchetypeType.
187+
HasPackArchetype = 0x20000,
188+
189+
Last_Property = HasPackArchetype
187190
};
188191
enum { BitWidth = countBitsUsed(Property::Last_Property) };
189192

@@ -259,7 +262,9 @@ class RecursiveTypeProperties {
259262

260263
bool hasParameterPack() const { return Bits & HasParameterPack; }
261264

262-
bool hasConcretePack() const { return Bits & HasConcretePack; }
265+
bool hasPack() const { return Bits & HasPack; }
266+
267+
bool hasPackArchetype() const { return Bits & HasPackArchetype; }
263268

264269
/// Does a type with these properties structurally contain a
265270
/// parameterized existential type?
@@ -419,12 +424,12 @@ class alignas(1 << TypeAlignInBits) TypeBase
419424
NumProtocols : 16
420425
);
421426

422-
SWIFT_INLINE_BITFIELD_FULL(TypeVariableType, TypeBase, 7+30,
427+
SWIFT_INLINE_BITFIELD_FULL(TypeVariableType, TypeBase, 7+29,
423428
/// Type variable options.
424429
Options : 7,
425430
: NumPadBits,
426431
/// The unique number assigned to this type variable.
427-
ID : 30
432+
ID : 29
428433
);
429434

430435
SWIFT_INLINE_BITFIELD(SILFunctionType, TypeBase, NumSILExtInfoBits+1+4+1+2+1+1,
@@ -687,16 +692,26 @@ class alignas(1 << TypeAlignInBits) TypeBase
687692
return getRecursiveProperties().hasLocalArchetype();
688693
}
689694

695+
/// Whether the type contains a generic parameter declared as a parameter
696+
/// pack.
690697
bool hasParameterPack() const {
691698
return getRecursiveProperties().hasParameterPack();
692699
}
693700

694-
bool hasConcretePack() const {
695-
return getRecursiveProperties().hasConcretePack();
701+
/// Whether the type contains a PackType.
702+
bool hasPack() const {
703+
return getRecursiveProperties().hasPack();
696704
}
697705

698-
/// Whether the type has some flavor of pack.
699-
bool hasPack() const { return hasParameterPack() || hasConcretePack(); }
706+
/// Whether the type contains a PackArchetypeType.
707+
bool hasPackArchetype() const {
708+
return getRecursiveProperties().hasPackArchetype();
709+
}
710+
711+
/// Whether the type has any flavor of pack.
712+
bool hasAnyPack() const {
713+
return hasParameterPack() || hasPack() || hasPackArchetype();
714+
}
700715

701716
/// Determine whether the type involves a parameterized existential type.
702717
bool hasParameterizedExistential() const {

include/swift/SIL/SILType.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,15 @@ class SILType {
352352
/// pack.
353353
bool hasParameterPack() const { return getASTType()->hasParameterPack(); }
354354

355-
/// Whether the type contains a concrete pack.
356-
bool hasConcretePack() const { return getASTType()->hasConcretePack(); }
357-
358-
/// Whether the type contains some flavor of pack.
355+
/// Whether the type contains a PackType.
359356
bool hasPack() const { return getASTType()->hasPack(); }
360357

358+
/// Whether the type contains a PackArchetypeType.
359+
bool hasPackArchetype() const { return getASTType()->hasPackArchetype(); }
360+
361+
/// Whether the type contains any flavor of pack.
362+
bool hasAnyPack() const { return getASTType()->hasAnyPack(); }
363+
361364
/// True if the type is an empty tuple or an empty struct or a tuple or
362365
/// struct containing only empty types.
363366
bool isEmpty(const SILFunction &F) const;

lib/AST/ASTContext.cpp

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

34063406
PackType *PackType::get(const ASTContext &C, ArrayRef<Type> elements) {
3407-
RecursiveTypeProperties properties = RecursiveTypeProperties::HasConcretePack;
3407+
RecursiveTypeProperties properties = RecursiveTypeProperties::HasPack;
34083408
bool isCanonical = true;
34093409
for (Type eltTy : elements) {
34103410
assert(!eltTy->is<PackType>() &&
@@ -3444,7 +3444,7 @@ void PackType::Profile(llvm::FoldingSetNodeID &ID, ArrayRef<Type> Elements) {
34443444

34453445
CanSILPackType SILPackType::get(const ASTContext &C, ExtInfo info,
34463446
ArrayRef<CanType> elements) {
3447-
RecursiveTypeProperties properties = RecursiveTypeProperties::HasConcretePack;
3447+
RecursiveTypeProperties properties;
34483448
for (CanType eltTy : elements) {
34493449
assert(!isa<SILPackType>(eltTy) &&
34503450
"Cannot have pack directly inside another pack");
@@ -4036,7 +4036,7 @@ isAnyFunctionTypeCanonical(ArrayRef<AnyFunctionType::Param> params,
40364036
static RecursiveTypeProperties
40374037
getGenericFunctionRecursiveProperties(ArrayRef<AnyFunctionType::Param> params,
40384038
Type result) {
4039-
static_assert(RecursiveTypeProperties::BitWidth == 17,
4039+
static_assert(RecursiveTypeProperties::BitWidth == 18,
40404040
"revisit this if you add new recursive type properties");
40414041
RecursiveTypeProperties properties;
40424042

@@ -4677,7 +4677,7 @@ CanSILFunctionType SILFunctionType::get(
46774677
void *mem = ctx.Allocate(bytes, alignof(SILFunctionType));
46784678

46794679
RecursiveTypeProperties properties;
4680-
static_assert(RecursiveTypeProperties::BitWidth == 17,
4680+
static_assert(RecursiveTypeProperties::BitWidth == 18,
46814681
"revisit this if you add new recursive type properties");
46824682
for (auto &param : params)
46834683
properties |= param.getInterfaceType()->getRecursiveProperties();

lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3704,7 +3704,7 @@ PackArchetypeType::PackArchetypeType(
37043704
LayoutConstraint Layout, PackShape Shape)
37053705
: ArchetypeType(TypeKind::PackArchetype, Ctx,
37063706
RecursiveTypeProperties::HasArchetype |
3707-
RecursiveTypeProperties::HasConcretePack,
3707+
RecursiveTypeProperties::HasPackArchetype,
37083708
InterfaceType, ConformsTo, Superclass, Layout, GenericEnv) {
37093709
assert(InterfaceType->isParameterPack());
37103710
*getTrailingObjects<PackShape>() = Shape;

lib/SIL/IR/SILInstruction.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,11 +1305,11 @@ bool SILInstruction::mayRequirePackMetadata() const {
13051305
case SILInstructionKind::TryApplyInst: {
13061306
// Check the function type for packs.
13071307
auto apply = ApplySite::isa(const_cast<SILInstruction *>(this));
1308-
if (apply.getCallee()->getType().hasPack())
1308+
if (apply.getCallee()->getType().hasAnyPack())
13091309
return true;
13101310
// Check the substituted types for packs.
13111311
for (auto ty : apply.getSubstitutionMap().getReplacementTypes()) {
1312-
if (ty->hasPack())
1312+
if (ty->hasAnyPack())
13131313
return true;
13141314
}
13151315
return false;
@@ -1320,20 +1320,20 @@ bool SILInstruction::mayRequirePackMetadata() const {
13201320
case SILInstructionKind::DestroyValueInst:
13211321
// Unary instructions.
13221322
{
1323-
return getOperand(0)->getType().hasPack();
1323+
return getOperand(0)->getType().hasAnyPack();
13241324
}
13251325
case SILInstructionKind::AllocStackInst: {
13261326
auto *asi = cast<AllocStackInst>(this);
1327-
return asi->getType().hasPack();
1327+
return asi->getType().hasAnyPack();
13281328
}
13291329
case SILInstructionKind::MetatypeInst: {
13301330
auto *mi = cast<MetatypeInst>(this);
1331-
return mi->getType().hasPack();
1331+
return mi->getType().hasAnyPack();
13321332
}
13331333
case SILInstructionKind::WitnessMethodInst: {
13341334
auto *wmi = cast<WitnessMethodInst>(this);
13351335
auto ty = wmi->getLookupType();
1336-
return ty->hasPack();
1336+
return ty->hasAnyPack();
13371337
}
13381338
default:
13391339
return false;

0 commit comments

Comments
 (0)