Skip to content

Commit c4b9461

Browse files
committed
[AST] Replace the "type sequence" terminology with "parameter pack".
1 parent 9bb837a commit c4b9461

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+230
-228
lines changed

include/swift/AST/Decl.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
505505

506506
Depth : 16,
507507
Index : 16,
508-
TypeSequence : 1,
508+
ParameterPack : 1,
509509

510510
/// Whether this generic parameter represents an opaque type.
511511
IsOpaqueType : 1
@@ -3179,7 +3179,7 @@ class GenericTypeParamDecl final :
31793179
/// \param name The name of the generic parameter.
31803180
/// \param nameLoc The location of the name.
31813181
GenericTypeParamDecl(DeclContext *dc, Identifier name, SourceLoc nameLoc,
3182-
bool isTypeSequence, unsigned depth, unsigned index,
3182+
bool isParameterPack, unsigned depth, unsigned index,
31833183
bool isOpaqueType, TypeRepr *typeRepr);
31843184

31853185
public:
@@ -3192,15 +3192,15 @@ class GenericTypeParamDecl final :
31923192
/// \param name The name of the generic parameter.
31933193
/// \param nameLoc The location of the name.
31943194
GenericTypeParamDecl(DeclContext *dc, Identifier name, SourceLoc nameLoc,
3195-
bool isTypeSequence, unsigned depth, unsigned index)
3196-
: GenericTypeParamDecl(dc, name, nameLoc, isTypeSequence, depth, index,
3195+
bool isParameterPack, unsigned depth, unsigned index)
3196+
: GenericTypeParamDecl(dc, name, nameLoc, isParameterPack, depth, index,
31973197
false, nullptr) { }
31983198

31993199
static const unsigned InvalidDepth = 0xFFFF;
32003200

32013201
static GenericTypeParamDecl *
32023202
create(DeclContext *dc, Identifier name, SourceLoc nameLoc,
3203-
bool isTypeSequence, unsigned depth, unsigned index,
3203+
bool isParameterPack, unsigned depth, unsigned index,
32043204
bool isOpaqueType, TypeRepr *typeRepr);
32053205

32063206
/// The depth of this generic type parameter, i.e., the number of outer
@@ -3224,13 +3224,13 @@ class GenericTypeParamDecl final :
32243224
}
32253225

32263226
/// Returns \c true if this generic type parameter is declared as a type
3227-
/// sequence.
3227+
/// parameter pack.
32283228
///
32293229
/// \code
3230-
/// func foo<@_typeSequence T>(_ : T...) { }
3231-
/// struct Foo<@_typeSequence T> { }
3230+
/// func foo<T...>(_ : T...) { }
3231+
/// struct Foo<T...> { }
32323232
/// \endcode
3233-
bool isTypeSequence() const { return Bits.GenericTypeParamDecl.TypeSequence; }
3233+
bool isParameterPack() const { return Bits.GenericTypeParamDecl.ParameterPack; }
32343234

32353235
/// Determine whether this generic parameter represents an opaque type.
32363236
///
@@ -8238,7 +8238,7 @@ inline bool Decl::isSyntacticallyOverridable() const {
82388238
}
82398239

82408240
inline GenericParamKey::GenericParamKey(const GenericTypeParamDecl *d)
8241-
: TypeSequence(d->isTypeSequence()), Depth(d->getDepth()),
8241+
: ParameterPack(d->isParameterPack()), Depth(d->getDepth()),
82428242
Index(d->getIndex()) {}
82438243

82448244
inline const GenericContext *Decl::getAsGenericContext() const {

include/swift/AST/GenericParamKey.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ class GenericTypeParamType;
2424
/// A fully-abstracted generic type parameter key, maintaining only the depth
2525
/// and index of the generic parameter.
2626
struct GenericParamKey {
27-
unsigned TypeSequence : 1;
27+
unsigned ParameterPack : 1;
2828
unsigned Depth : 15;
2929
unsigned Index : 16;
3030

31-
GenericParamKey(bool isTypeSequence, unsigned depth, unsigned index)
32-
: TypeSequence(isTypeSequence), Depth(depth), Index(index) {}
31+
GenericParamKey(bool isParameterPack, unsigned depth, unsigned index)
32+
: ParameterPack(isParameterPack), Depth(depth), Index(index) {}
3333

3434
GenericParamKey(const GenericTypeParamDecl *d);
3535
GenericParamKey(const GenericTypeParamType *d);
3636

3737
friend bool operator==(GenericParamKey lhs, GenericParamKey rhs) {
38-
return lhs.TypeSequence == rhs.TypeSequence && lhs.Depth == rhs.Depth &&
38+
return lhs.ParameterPack == rhs.ParameterPack &&
39+
lhs.Depth == rhs.Depth &&
3940
lhs.Index == rhs.Index;
4041
}
4142

@@ -110,11 +111,12 @@ struct DenseMapInfo<swift::GenericParamKey> {
110111

111112
static inline unsigned getHashValue(swift::GenericParamKey k) {
112113
return DenseMapInfo<unsigned>::getHashValue(
113-
k.Depth << 16 | k.Index | ((k.TypeSequence ? 1 : 0) << 30));
114+
k.Depth << 16 | k.Index | ((k.ParameterPack ? 1 : 0) << 30));
114115
}
115116
static bool isEqual(swift::GenericParamKey a,
116117
swift::GenericParamKey b) {
117-
return a.TypeSequence == b.TypeSequence && a.Depth == b.Depth &&
118+
return a.ParameterPack == b.ParameterPack &&
119+
a.Depth == b.Depth &&
118120
a.Index == b.Index;
119121
}
120122
};

include/swift/AST/Types.h

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ class RecursiveTypeProperties {
161161
HasPlaceholder = 0x800,
162162

163163
/// This type contains a generic type parameter that is declared as a
164-
/// type sequence
165-
HasTypeSequence = 0x1000,
164+
/// parameter pack.
165+
HasParameterPack = 0x1000,
166166

167167
/// This type contains a parameterized existential type \c any P<T>.
168168
HasParameterizedExistential = 0x2000,
@@ -225,7 +225,7 @@ class RecursiveTypeProperties {
225225
/// Does a type with these properties structurally contain a placeholder?
226226
bool hasPlaceholder() const { return Bits & HasPlaceholder; }
227227

228-
bool hasTypeSequence() const { return Bits & HasTypeSequence; }
228+
bool hasParameterPack() const { return Bits & HasParameterPack; }
229229

230230
/// Does a type with these properties structurally contain a
231231
/// parameterized existential type?
@@ -624,8 +624,8 @@ class alignas(1 << TypeAlignInBits) TypeBase
624624
return getRecursiveProperties().hasOpenedExistential();
625625
}
626626

627-
bool hasTypeSequence() const {
628-
return getRecursiveProperties().hasTypeSequence();
627+
bool hasParameterPack() const {
628+
return getRecursiveProperties().hasParameterPack();
629629
}
630630

631631
/// Determine whether the type involves a parameterized existential type.
@@ -655,10 +655,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
655655
void getRootOpenedExistentials(
656656
SmallVectorImpl<OpenedArchetypeType *> &rootOpenedArchetypes) const;
657657

658-
/// Retrieve the set of type sequence generic parameters that occur
659-
/// within this type.
660-
void getTypeSequenceParameters(
661-
SmallVectorImpl<Type> &rootTypeSequenceParams) const;
658+
/// Retrieve the set of type parameter packs that occur within this type.
659+
void getTypeParameterPacks(
660+
SmallVectorImpl<Type> &rootParameterPacks) const;
662661

663662
/// Replace opened archetypes with the given root with their most
664663
/// specific non-dependent upper bounds throughout this type.
@@ -689,12 +688,12 @@ class alignas(1 << TypeAlignInBits) TypeBase
689688
/// whether a type parameter exists at any position.
690689
bool isTypeParameter();
691690

692-
/// Determine whether this type is a type sequence parameter, which is
691+
/// Determine whether this type is a type parameter pack, which is
693692
/// either a GenericTypeParamType or a DependentMemberType.
694693
///
695694
/// Like \c isTypeParameter, this routine will return \c false for types that
696695
/// include type parameters in nested positions e.g. \c X<T...>.
697-
bool isTypeSequenceParameter();
696+
bool isParameterPack();
698697

699698
/// Determine whether this type can dynamically be an optional type.
700699
///
@@ -6063,7 +6062,7 @@ class GenericTypeParamType : public SubstitutableType {
60636062

60646063
public:
60656064
/// Retrieve a generic type parameter at the given depth and index.
6066-
static GenericTypeParamType *get(bool isTypeSequence, unsigned depth,
6065+
static GenericTypeParamType *get(bool isParameterPack, unsigned depth,
60676066
unsigned index, const ASTContext &ctx);
60686067

60696068
/// Retrieve the declaration of the generic type parameter, or null if
@@ -6099,14 +6098,13 @@ class GenericTypeParamType : public SubstitutableType {
60996098
/// Here 'T' and 'U' have indexes 0 and 1, respectively. 'V' has index 0.
61006099
unsigned getIndex() const;
61016100

6102-
/// Returns \c true if this generic type parameter is declared as a type
6103-
/// sequence.
6101+
/// Returns \c true if this type parameter is declared as a pack.
61046102
///
61056103
/// \code
6106-
/// func foo<@_typeSequence T>(_ : T...) { }
6107-
/// struct Foo<@_typeSequence T> { }
6108-
/// \encode
6109-
bool isTypeSequence() const;
6104+
/// func foo<T...>() { }
6105+
/// struct Foo<T...> { }
6106+
/// \endcode
6107+
bool isParameterPack() const;
61106108

61116109
// Implement isa/cast/dyncast/etc.
61126110
static bool classof(const TypeBase *T) {
@@ -6121,18 +6119,18 @@ class GenericTypeParamType : public SubstitutableType {
61216119
: SubstitutableType(TypeKind::GenericTypeParam, nullptr, props),
61226120
ParamOrDepthIndex(param) { }
61236121

6124-
explicit GenericTypeParamType(bool isTypeSequence, unsigned depth,
6122+
explicit GenericTypeParamType(bool isParameterPack, unsigned depth,
61256123
unsigned index, RecursiveTypeProperties props,
61266124
const ASTContext &ctx)
61276125
: SubstitutableType(TypeKind::GenericTypeParam, &ctx, props),
61286126
ParamOrDepthIndex(depth << 16 | index |
6129-
((isTypeSequence ? 1 : 0) << 30)) {}
6127+
((isParameterPack ? 1 : 0) << 30)) {}
61306128
};
61316129
BEGIN_CAN_TYPE_WRAPPER(GenericTypeParamType, SubstitutableType)
6132-
static CanGenericTypeParamType get(bool isTypeSequence, unsigned depth,
6130+
static CanGenericTypeParamType get(bool isParameterPack, unsigned depth,
61336131
unsigned index, const ASTContext &C) {
61346132
return CanGenericTypeParamType(
6135-
GenericTypeParamType::get(isTypeSequence, depth, index, C));
6133+
GenericTypeParamType::get(isParameterPack, depth, index, C));
61366134
}
61376135
END_CAN_TYPE_WRAPPER(GenericTypeParamType, SubstitutableType)
61386136

@@ -6471,8 +6469,8 @@ class PackExpansionType : public TypeBase, public llvm::FoldingSetNode {
64716469
/// a variadic generic parameter, but any variadic generic parameters
64726470
/// appearing in the pattern type must have the same count as \p countType.
64736471
///
6474-
/// As for \p countType itself, it must be a type sequence generic parameter
6475-
/// type, or a sequence archetype type.
6472+
/// As for \p countType itself, it must be a type parameter pack
6473+
/// type, or a pack archetype type.
64766474
static PackExpansionType *get(Type pattern, Type countType);
64776475

64786476
public:
@@ -6544,14 +6542,14 @@ inline bool TypeBase::isTypeParameter() {
65446542
return t->is<GenericTypeParamType>();
65456543
}
65466544

6547-
inline bool TypeBase::isTypeSequenceParameter() {
6545+
inline bool TypeBase::isParameterPack() {
65486546
Type t(this);
65496547

65506548
while (auto *memberTy = t->getAs<DependentMemberType>())
65516549
t = memberTy->getBase();
65526550

65536551
return t->is<GenericTypeParamType>() &&
6554-
t->castTo<GenericTypeParamType>()->isTypeSequence();
6552+
t->castTo<GenericTypeParamType>()->isParameterPack();
65556553
}
65566554

65576555
// TODO: This will become redundant once InOutType is removed.
@@ -6838,7 +6836,7 @@ constexpr bool TypeBase::isSugaredType<id##Type>() { \
68386836
#include "swift/AST/TypeNodes.def"
68396837

68406838
inline GenericParamKey::GenericParamKey(const GenericTypeParamType *p)
6841-
: TypeSequence(p->isTypeSequence()), Depth(p->getDepth()),
6839+
: ParameterPack(p->isParameterPack()), Depth(p->getDepth()),
68426840
Index(p->getIndex()) {}
68436841

68446842
inline TypeBase *TypeBase::getDesugaredType() {

include/swift/Sema/ConstraintLocator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,9 @@ class LocatorPathElt::GenericParameter final : public StoredPointerElement<Gener
792792
GenericTypeParamType *getType() const {
793793
return getStoredPointer();
794794
}
795-
796-
bool isTypeSequence() const {
797-
return getType()->isTypeSequence();
795+
796+
bool isParameterPack() const {
797+
return getType()->isParameterPack();
798798
}
799799

800800
static bool classof(const LocatorPathElt *elt) {

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ class TypeVariableType::Implementation {
472472
/// Determine whether this type variable represents a subscript result type.
473473
bool isSubscriptResultType() const;
474474

475-
bool isTypeSequence() const;
475+
/// Determine whether this type variable represents an opened
476+
/// type parameter pack.
477+
bool isParameterPack() const;
476478

477479
/// Determine whether this type variable represents a code completion
478480
/// expression.

lib/AST/ASTContext.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,7 +3175,7 @@ PackExpansionType::PackExpansionType(Type patternType, Type countType,
31753175
patternType(patternType), countType(countType) {
31763176
assert(countType->is<TypeVariableType>() ||
31773177
countType->is<PackArchetypeType>() ||
3178-
countType->castTo<GenericTypeParamType>()->isTypeSequence());
3178+
countType->castTo<GenericTypeParamType>()->isParameterPack());
31793179
}
31803180

31813181
PackExpansionType *PackExpansionType::get(Type patternType, Type countType) {
@@ -3221,7 +3221,7 @@ PackType *PackType::get(const ASTContext &C, ArrayRef<Type> elements) {
32213221
bool isCanonical = true;
32223222
for (Type eltTy : elements) {
32233223
assert(!eltTy->isTypeParameter() ||
3224-
!eltTy->getRootGenericParam()->isTypeSequence() &&
3224+
!eltTy->getRootGenericParam()->isParameterPack() &&
32253225
"Pack type parameter outside of a pack expansion");
32263226
assert(!eltTy->is<PackArchetypeType>() &&
32273227
"Pack type archetype outside of a pack expansion");
@@ -4118,20 +4118,20 @@ GenericFunctionType::GenericFunctionType(
41184118
}
41194119
}
41204120

4121-
GenericTypeParamType *GenericTypeParamType::get(bool isTypeSequence,
4121+
GenericTypeParamType *GenericTypeParamType::get(bool isParameterPack,
41224122
unsigned depth, unsigned index,
41234123
const ASTContext &ctx) {
4124-
const auto depthKey = depth | ((isTypeSequence ? 1 : 0) << 30);
4124+
const auto depthKey = depth | ((isParameterPack ? 1 : 0) << 30);
41254125
auto known = ctx.getImpl().GenericParamTypes.find({depthKey, index});
41264126
if (known != ctx.getImpl().GenericParamTypes.end())
41274127
return known->second;
41284128

41294129
RecursiveTypeProperties props = RecursiveTypeProperties::HasTypeParameter;
4130-
if (isTypeSequence)
4131-
props |= RecursiveTypeProperties::HasTypeSequence;
4130+
if (isParameterPack)
4131+
props |= RecursiveTypeProperties::HasParameterPack;
41324132

41334133
auto result = new (ctx, AllocationArena::Permanent)
4134-
GenericTypeParamType(isTypeSequence, depth, index, props, ctx);
4134+
GenericTypeParamType(isParameterPack, depth, index, props, ctx);
41354135
ctx.getImpl().GenericParamTypes[{depthKey, index}] = result;
41364136
return result;
41374137
}
@@ -5461,7 +5461,7 @@ GenericParamList *ASTContext::getSelfGenericParamList(DeclContext *dc) const {
54615461
// hack for SIL mode, that should be OK.
54625462
auto *selfParam = GenericTypeParamDecl::create(
54635463
dc, Id_Self, SourceLoc(),
5464-
/*isTypeSequence=*/false, /*depth=*/0, /*index=*/0,
5464+
/*isParameterPack=*/false, /*depth=*/0, /*index=*/0,
54655465
/*isOpaqueType=*/false, /*opaqueTypeRepr=*/nullptr);
54665466

54675467
theParamList = GenericParamList::create(
@@ -5475,7 +5475,7 @@ CanGenericSignature ASTContext::getSingleGenericParameterSignature() const {
54755475
if (auto theSig = getImpl().SingleGenericParameterSignature)
54765476
return theSig;
54775477

5478-
auto param = GenericTypeParamType::get(/*type sequence*/ false,
5478+
auto param = GenericTypeParamType::get(/*isParameterPack*/ false,
54795479
/*depth*/ 0, /*index*/ 0, *this);
54805480
auto sig = GenericSignature::get(param, { });
54815481
auto canonicalSig = CanGenericSignature(sig);
@@ -5488,7 +5488,7 @@ Type OpenedArchetypeType::getSelfInterfaceTypeFromContext(GenericSignature paren
54885488
unsigned depth = 0;
54895489
if (!parentSig.getGenericParams().empty())
54905490
depth = parentSig.getGenericParams().back()->getDepth() + 1;
5491-
return GenericTypeParamType::get(/*isTypeSequence=*/ false,
5491+
return GenericTypeParamType::get(/*isParameterPack=*/ false,
54925492
/*depth=*/ depth, /*index=*/ 0,
54935493
ctx);
54945494
}
@@ -5555,7 +5555,7 @@ ASTContext::getOpenedElementSignature(CanGenericSignature baseGenericSig) {
55555555
auto found = std::find_if(baseGenericSig.getGenericParams().begin(),
55565556
baseGenericSig.getGenericParams().end(),
55575557
[](GenericTypeParamType *paramType) {
5558-
return paramType->isTypeSequence();
5558+
return paramType->isParameterPack();
55595559
});
55605560
assert(found != baseGenericSig.getGenericParams().end());
55615561
}
@@ -5564,20 +5564,20 @@ ASTContext::getOpenedElementSignature(CanGenericSignature baseGenericSig) {
55645564
SmallVector<GenericTypeParamType *, 2> genericParams;
55655565
SmallVector<Requirement, 2> requirements;
55665566

5567-
auto eraseTypeSequence = [&](GenericTypeParamType *paramType) {
5567+
auto eraseParameterPack = [&](GenericTypeParamType *paramType) {
55685568
return GenericTypeParamType::get(
55695569
paramType->getDepth(), paramType->getIndex(),
5570-
/*isTypeSequence=*/false, *this);
5570+
/*isParameterPack=*/false, *this);
55715571
};
55725572

55735573
for (auto paramType : baseGenericSig.getGenericParams()) {
5574-
genericParams.push_back(eraseTypeSequence(paramType));
5574+
genericParams.push_back(eraseParameterPack(paramType));
55755575
}
55765576

5577-
auto eraseTypeSequenceRec = [&](Type type) -> Type {
5577+
auto eraseParameterPackRec = [&](Type type) -> Type {
55785578
return type.transformRec([&](Type t) -> Optional<Type> {
55795579
if (auto *paramType = t->getAs<GenericTypeParamType>())
5580-
return Type(eraseTypeSequence(paramType));
5580+
return Type(eraseParameterPack(paramType));
55815581
return None;
55825582
});
55835583
};
@@ -5592,13 +5592,13 @@ ASTContext::getOpenedElementSignature(CanGenericSignature baseGenericSig) {
55925592
case RequirementKind::SameType:
55935593
requirements.emplace_back(
55945594
requirement.getKind(),
5595-
eraseTypeSequenceRec(requirement.getFirstType()),
5596-
eraseTypeSequenceRec(requirement.getSecondType()));
5595+
eraseParameterPackRec(requirement.getFirstType()),
5596+
eraseParameterPackRec(requirement.getSecondType()));
55975597
break;
55985598
case RequirementKind::Layout:
55995599
requirements.emplace_back(
56005600
requirement.getKind(),
5601-
eraseTypeSequenceRec(requirement.getFirstType()),
5601+
eraseParameterPackRec(requirement.getFirstType()),
56025602
requirement.getLayoutConstraint());
56035603
break;
56045604
}

0 commit comments

Comments
 (0)