Skip to content

Commit 36c01e8

Browse files
authored
Merge pull request #61537 from hborla/variadic-generics-terminology
[AST] Use consistent variadic generics terminology.
2 parents 9b8f7e4 + c4b9461 commit 36c01e8

Some content is hidden

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

68 files changed

+299
-370
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/Expr.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,18 +3399,6 @@ class BridgeToObjCExpr : public ImplicitConversionExpr {
33993399
}
34003400
};
34013401

3402-
/// ReifyPackExpr - Drop the pack structure and reify it either as a tuple or
3403-
/// single value.
3404-
class ReifyPackExpr : public ImplicitConversionExpr {
3405-
public:
3406-
ReifyPackExpr(Expr *subExpr, Type type)
3407-
: ImplicitConversionExpr(ExprKind::ReifyPack, subExpr, type) {}
3408-
3409-
static bool classof(const Expr *E) {
3410-
return E->getKind() == ExprKind::ReifyPack;
3411-
}
3412-
};
3413-
34143402
/// UnresolvedSpecializeExpr - Represents an explicit specialization using
34153403
/// a type parameter list (e.g. "Vector<Int>") that has not been resolved.
34163404
class UnresolvedSpecializeExpr final : public Expr,
@@ -5926,8 +5914,7 @@ class OneWayExpr : public Expr {
59265914
///
59275915
/// There is no user-visible way to spell a pack expression, they are always
59285916
/// implicitly created at applies. As such, any appearance of pack types outside
5929-
/// of applies are illegal. In general, packs appearing in such positions should
5930-
/// have a \c ReifyPackExpr to convert them to a user-available AST type.
5917+
/// of applies are illegal.
59315918
class PackExpr final : public Expr,
59325919
private llvm::TrailingObjects<PackExpr, Expr *> {
59335920
friend TrailingObjects;

include/swift/AST/ExprNodes.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ ABSTRACT_EXPR(ImplicitConversion, Expr)
184184
EXPR(DifferentiableFunctionExtractOriginal, ImplicitConversionExpr)
185185
EXPR(LinearFunctionExtractOriginal, ImplicitConversionExpr)
186186
EXPR(LinearToDifferentiableFunction, ImplicitConversionExpr)
187-
EXPR(ReifyPack, ImplicitConversionExpr)
188-
EXPR_RANGE(ImplicitConversion, Load, ReifyPack)
187+
EXPR_RANGE(ImplicitConversion, Load, LinearToDifferentiableFunction)
189188
ABSTRACT_EXPR(ExplicitCast, Expr)
190189
ABSTRACT_EXPR(CheckedCast, ExplicitCastExpr)
191190
EXPR(ForcedCheckedCast, CheckedCastExpr)

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/TypeNodes.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ ABSTRACT_TYPE(Substitutable, Type)
148148
ALWAYS_CANONICAL_TYPE(PrimaryArchetype, ArchetypeType)
149149
ALWAYS_CANONICAL_TYPE(OpaqueTypeArchetype, ArchetypeType)
150150
ALWAYS_CANONICAL_TYPE(OpenedArchetype, ArchetypeType)
151-
ALWAYS_CANONICAL_TYPE(SequenceArchetype, ArchetypeType)
152-
TYPE_RANGE(Archetype, PrimaryArchetype, SequenceArchetype)
151+
ALWAYS_CANONICAL_TYPE(PackArchetype, ArchetypeType)
152+
TYPE_RANGE(Archetype, PrimaryArchetype, PackArchetype)
153153
TYPE(GenericTypeParam, SubstitutableType)
154154
TYPE_RANGE(Substitutable, PrimaryArchetype, GenericTypeParam)
155155
TYPE(DependentMember, Type)

include/swift/AST/Types.h

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class RecursiveTypeProperties {
126126

127127
/// This type expression contains a context-dependent archetype, either a
128128
/// \c PrimaryArchetypeType, \c OpenedArchetypeType, or
129-
/// \c SequenceArchetype.
129+
/// \c PackArchetype.
130130
HasArchetype = 0x02,
131131

132132
/// This type expression contains a GenericTypeParamType.
@@ -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
///
@@ -6002,15 +6001,11 @@ BEGIN_CAN_TYPE_WRAPPER(OpenedArchetypeType, ArchetypeType)
60026001
}
60036002
END_CAN_TYPE_WRAPPER(OpenedArchetypeType, ArchetypeType)
60046003

6005-
/// An archetype that represents an opaque element of a type sequence in context.
6006-
///
6007-
/// \code
6008-
/// struct Foo<@_typeSequence Ts> { var xs: @_typeSequence Ts }
6009-
/// func foo<@_typeSequence T>(_ xs: T...) where T: P { }
6010-
/// \endcode
6011-
class SequenceArchetypeType final
6004+
/// An archetype that represents an opaque element of a type
6005+
/// parameter pack in context.
6006+
class PackArchetypeType final
60126007
: public ArchetypeType,
6013-
private ArchetypeTrailingObjects<SequenceArchetypeType> {
6008+
private ArchetypeTrailingObjects<PackArchetypeType> {
60146009
friend TrailingObjects;
60156010
friend ArchetypeType;
60166011

@@ -6019,23 +6014,23 @@ class SequenceArchetypeType final
60196014
///
60206015
/// The ConformsTo array will be minimized then copied into the ASTContext
60216016
/// by this routine.
6022-
static CanTypeWrapper<SequenceArchetypeType>
6017+
static CanTypeWrapper<PackArchetypeType>
60236018
get(const ASTContext &Ctx, GenericEnvironment *GenericEnv,
60246019
Type InterfaceType,
60256020
SmallVectorImpl<ProtocolDecl *> &ConformsTo, Type Superclass,
60266021
LayoutConstraint Layout);
60276022

60286023
static bool classof(const TypeBase *T) {
6029-
return T->getKind() == TypeKind::SequenceArchetype;
6024+
return T->getKind() == TypeKind::PackArchetype;
60306025
}
60316026

60326027
private:
6033-
SequenceArchetypeType(const ASTContext &Ctx, GenericEnvironment *GenericEnv,
6034-
Type InterfaceType, ArrayRef<ProtocolDecl *> ConformsTo,
6035-
Type Superclass, LayoutConstraint Layout);
6028+
PackArchetypeType(const ASTContext &Ctx, GenericEnvironment *GenericEnv,
6029+
Type InterfaceType, ArrayRef<ProtocolDecl *> ConformsTo,
6030+
Type Superclass, LayoutConstraint Layout);
60366031
};
6037-
BEGIN_CAN_TYPE_WRAPPER(SequenceArchetypeType, ArchetypeType)
6038-
END_CAN_TYPE_WRAPPER(SequenceArchetypeType, ArchetypeType)
6032+
BEGIN_CAN_TYPE_WRAPPER(PackArchetypeType, ArchetypeType)
6033+
END_CAN_TYPE_WRAPPER(PackArchetypeType, ArchetypeType)
60396034

60406035
template<typename Type>
60416036
const Type *ArchetypeType::getSubclassTrailingObjects() const {
@@ -6048,7 +6043,7 @@ const Type *ArchetypeType::getSubclassTrailingObjects() const {
60486043
if (auto openedTy = dyn_cast<OpenedArchetypeType>(this)) {
60496044
return openedTy->getTrailingObjects<Type>();
60506045
}
6051-
if (auto childTy = dyn_cast<SequenceArchetypeType>(this)) {
6046+
if (auto childTy = dyn_cast<PackArchetypeType>(this)) {
60526047
return childTy->getTrailingObjects<Type>();
60536048
}
60546049
llvm_unreachable("unhandled ArchetypeType subclass?");
@@ -6067,7 +6062,7 @@ class GenericTypeParamType : public SubstitutableType {
60676062

60686063
public:
60696064
/// Retrieve a generic type parameter at the given depth and index.
6070-
static GenericTypeParamType *get(bool isTypeSequence, unsigned depth,
6065+
static GenericTypeParamType *get(bool isParameterPack, unsigned depth,
60716066
unsigned index, const ASTContext &ctx);
60726067

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

6106-
/// Returns \c true if this generic type parameter is declared as a type
6107-
/// sequence.
6101+
/// Returns \c true if this type parameter is declared as a pack.
61086102
///
61096103
/// \code
6110-
/// func foo<@_typeSequence T>(_ : T...) { }
6111-
/// struct Foo<@_typeSequence T> { }
6112-
/// \encode
6113-
bool isTypeSequence() const;
6104+
/// func foo<T...>() { }
6105+
/// struct Foo<T...> { }
6106+
/// \endcode
6107+
bool isParameterPack() const;
61146108

61156109
// Implement isa/cast/dyncast/etc.
61166110
static bool classof(const TypeBase *T) {
@@ -6125,18 +6119,18 @@ class GenericTypeParamType : public SubstitutableType {
61256119
: SubstitutableType(TypeKind::GenericTypeParam, nullptr, props),
61266120
ParamOrDepthIndex(param) { }
61276121

6128-
explicit GenericTypeParamType(bool isTypeSequence, unsigned depth,
6122+
explicit GenericTypeParamType(bool isParameterPack, unsigned depth,
61296123
unsigned index, RecursiveTypeProperties props,
61306124
const ASTContext &ctx)
61316125
: SubstitutableType(TypeKind::GenericTypeParam, &ctx, props),
61326126
ParamOrDepthIndex(depth << 16 | index |
6133-
((isTypeSequence ? 1 : 0) << 30)) {}
6127+
((isParameterPack ? 1 : 0) << 30)) {}
61346128
};
61356129
BEGIN_CAN_TYPE_WRAPPER(GenericTypeParamType, SubstitutableType)
6136-
static CanGenericTypeParamType get(bool isTypeSequence, unsigned depth,
6130+
static CanGenericTypeParamType get(bool isParameterPack, unsigned depth,
61376131
unsigned index, const ASTContext &C) {
61386132
return CanGenericTypeParamType(
6139-
GenericTypeParamType::get(isTypeSequence, depth, index, C));
6133+
GenericTypeParamType::get(isParameterPack, depth, index, C));
61406134
}
61416135
END_CAN_TYPE_WRAPPER(GenericTypeParamType, SubstitutableType)
61426136

@@ -6475,8 +6469,8 @@ class PackExpansionType : public TypeBase, public llvm::FoldingSetNode {
64756469
/// a variadic generic parameter, but any variadic generic parameters
64766470
/// appearing in the pattern type must have the same count as \p countType.
64776471
///
6478-
/// As for \p countType itself, it must be a type sequence generic parameter
6479-
/// 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.
64806474
static PackExpansionType *get(Type pattern, Type countType);
64816475

64826476
public:
@@ -6548,14 +6542,14 @@ inline bool TypeBase::isTypeParameter() {
65486542
return t->is<GenericTypeParamType>();
65496543
}
65506544

6551-
inline bool TypeBase::isTypeSequenceParameter() {
6545+
inline bool TypeBase::isParameterPack() {
65526546
Type t(this);
65536547

65546548
while (auto *memberTy = t->getAs<DependentMemberType>())
65556549
t = memberTy->getBase();
65566550

65576551
return t->is<GenericTypeParamType>() &&
6558-
t->castTo<GenericTypeParamType>()->isTypeSequence();
6552+
t->castTo<GenericTypeParamType>()->isParameterPack();
65596553
}
65606554

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

68446838
inline GenericParamKey::GenericParamKey(const GenericTypeParamType *p)
6845-
: TypeSequence(p->isTypeSequence()), Depth(p->getDepth()),
6839+
: ParameterPack(p->isParameterPack()), Depth(p->getDepth()),
68466840
Index(p->getIndex()) {}
68476841

68486842
inline TypeBase *TypeBase::getDesugaredType() {

include/swift/Sema/Constraint.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,6 @@ enum class ConversionRestrictionKind {
307307
/// - Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int>
308308
/// - Unsafe[Mutable]Pointer<Int{8, 16, ...}> <-> Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
309309
PointerToCPointer,
310-
// Convert a pack into a type with an equivalent arity.
311-
// - If the arity of the pack is 1, drops the pack structure <T> => T
312-
// - If the arity of the pack is n >= 1, converts the pack structure into a tuple <T, U, V> => (T, U, V)
313-
ReifyPackToType,
314310
};
315311

316312
/// Specifies whether a given conversion requires the creation of a temporary

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) {

0 commit comments

Comments
 (0)