Skip to content

Commit d82e748

Browse files
authored
Merge pull request #61575 from hamishknight/etc
2 parents 155eee3 + 6aa44a1 commit d82e748

32 files changed

+347
-223
lines changed

include/swift/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ class ASTContext final {
13571357
/// Get a generic signature where the generic parameter τ_d_i represents
13581358
/// the element of the pack generic parameter τ_d_i… in \p baseGenericSig.
13591359
///
1360-
/// This drops the @_typeSequence attribute from each generic parameter,
1360+
/// This drops the parameter pack bit from each generic parameter,
13611361
/// and converts same-element requirements to same-type requirements.
13621362
CanGenericSignature getOpenedElementSignature(CanGenericSignature baseGenericSig);
13631363

include/swift/AST/Attr.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,20 +2190,6 @@ class NonSendableAttr : public DeclAttribute {
21902190
}
21912191
};
21922192

2193-
/// The @_typeSequence attribute, which treats a generic param decl as a variadic
2194-
/// sequence of value/type pairs.
2195-
class TypeSequenceAttr : public DeclAttribute {
2196-
TypeSequenceAttr(SourceLoc atLoc, SourceRange Range);
2197-
2198-
public:
2199-
static TypeSequenceAttr *create(ASTContext &Ctx, SourceLoc atLoc,
2200-
SourceRange Range);
2201-
2202-
static bool classof(const DeclAttribute *DA) {
2203-
return DA->getKind() == DAK_TypeSequence;
2204-
}
2205-
};
2206-
22072193
/// The @_unavailableFromAsync attribute, used to make function declarations
22082194
/// unavailable from async contexts.
22092195
class UnavailableFromAsyncAttr : public DeclAttribute {

include/swift/AST/Decl.h

Lines changed: 110 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,15 +3166,20 @@ class AbstractTypeParamDecl : public TypeDecl {
31663166
/// \code
31673167
/// func min<T : Comparable>(x : T, y : T) -> T { ... }
31683168
/// \endcode
3169-
class GenericTypeParamDecl final :
3170-
public AbstractTypeParamDecl,
3171-
private llvm::TrailingObjects<GenericTypeParamDecl, TypeRepr *>{
3169+
class GenericTypeParamDecl final
3170+
: public AbstractTypeParamDecl,
3171+
private llvm::TrailingObjects<GenericTypeParamDecl, TypeRepr *,
3172+
SourceLoc> {
31723173
friend TrailingObjects;
31733174

3174-
size_t numTrailingObjects(OverloadToken<OpaqueReturnTypeRepr *>) const {
3175+
size_t numTrailingObjects(OverloadToken<TypeRepr *>) const {
31753176
return isOpaqueType() ? 1 : 0;
31763177
}
31773178

3179+
size_t numTrailingObjects(OverloadToken<SourceLoc>) const {
3180+
return isParameterPack() ? 1 : 0;
3181+
}
3182+
31783183
/// Construct a new generic type parameter.
31793184
///
31803185
/// \param dc The DeclContext in which the generic type parameter's owner
@@ -3183,11 +3188,20 @@ class GenericTypeParamDecl final :
31833188
///
31843189
/// \param name The name of the generic parameter.
31853190
/// \param nameLoc The location of the name.
3191+
/// \param ellipsisLoc The location of the ellipsis for a type parameter pack.
3192+
/// \param depth The generic signature depth.
3193+
/// \param index The index of the parameter in the generic signature.
3194+
/// \param isParameterPack Whether the generic parameter is for a type
3195+
/// parameter pack, denoted by \c <T...>.
3196+
/// \param isOpaqueType Whether the generic parameter is written as an opaque
3197+
/// parameter e.g 'some Collection'.
3198+
/// \param opaqueTypeRepr The TypeRepr of an opaque generic parameter.
3199+
///
31863200
GenericTypeParamDecl(DeclContext *dc, Identifier name, SourceLoc nameLoc,
3187-
bool isParameterPack, unsigned depth, unsigned index,
3188-
bool isOpaqueType, TypeRepr *typeRepr);
3201+
SourceLoc ellipsisLoc, unsigned depth, unsigned index,
3202+
bool isParameterPack, bool isOpaqueType,
3203+
TypeRepr *opaqueTypeRepr);
31893204

3190-
public:
31913205
/// Construct a new generic type parameter.
31923206
///
31933207
/// \param dc The DeclContext in which the generic type parameter's owner
@@ -3196,17 +3210,91 @@ class GenericTypeParamDecl final :
31963210
///
31973211
/// \param name The name of the generic parameter.
31983212
/// \param nameLoc The location of the name.
3199-
GenericTypeParamDecl(DeclContext *dc, Identifier name, SourceLoc nameLoc,
3200-
bool isParameterPack, unsigned depth, unsigned index)
3201-
: GenericTypeParamDecl(dc, name, nameLoc, isParameterPack, depth, index,
3202-
false, nullptr) { }
3213+
/// \param ellipsisLoc The location of the ellipsis for a type parameter pack.
3214+
/// \param depth The generic signature depth.
3215+
/// \param index The index of the parameter in the generic signature.
3216+
/// \param isParameterPack Whether the generic parameter is for a type
3217+
/// parameter pack, denoted by \c <T...>.
3218+
/// \param isOpaqueType Whether the generic parameter is written as an opaque
3219+
/// parameter e.g 'some Collection'.
3220+
/// \param opaqueTypeRepr The TypeRepr of an opaque generic parameter.
3221+
///
3222+
static GenericTypeParamDecl *create(DeclContext *dc, Identifier name,
3223+
SourceLoc nameLoc, SourceLoc ellipsisLoc,
3224+
unsigned depth, unsigned index,
3225+
bool isParameterPack, bool isOpaqueType,
3226+
TypeRepr *opaqueTypeRepr);
32033227

3228+
public:
32043229
static const unsigned InvalidDepth = 0xFFFF;
32053230

3231+
/// Construct a new generic type parameter. This should only be used by the
3232+
/// ClangImporter, use \c GenericTypeParamDecl::create[...] instead.
3233+
GenericTypeParamDecl(DeclContext *dc, Identifier name, SourceLoc nameLoc,
3234+
SourceLoc ellipsisLoc, unsigned depth, unsigned index,
3235+
bool isParameterPack)
3236+
: GenericTypeParamDecl(dc, name, nameLoc, ellipsisLoc, depth, index,
3237+
isParameterPack, /*isOpaqueType*/ false, nullptr) {
3238+
}
3239+
3240+
/// Construct a deserialized generic type parameter.
3241+
///
3242+
/// \param dc The DeclContext in which the generic type parameter's owner
3243+
/// occurs. This should later be overwritten with the actual declaration
3244+
/// context that owns the type parameter.
3245+
///
3246+
/// \param name The name of the generic parameter.
3247+
/// \param depth The generic signature depth.
3248+
/// \param index The index of the parameter in the generic signature.
3249+
/// \param isParameterPack Whether the generic parameter is for a type
3250+
/// parameter pack, denoted by \c <T...>.
3251+
/// \param isOpaqueType Whether the generic parameter is written as an opaque
3252+
/// parameter e.g 'some Collection'.
3253+
///
3254+
static GenericTypeParamDecl *
3255+
createDeserialized(DeclContext *dc, Identifier name, unsigned depth,
3256+
unsigned index, bool isParameterPack, bool isOpaqueType);
3257+
3258+
/// Construct a new parsed generic type parameter.
3259+
///
3260+
/// \param dc The DeclContext in which the generic type parameter's owner
3261+
/// occurs. This should later be overwritten with the actual declaration
3262+
/// context that owns the type parameter.
3263+
///
3264+
/// \param name The name of the generic parameter.
3265+
/// \param nameLoc The location of the name.
3266+
/// \param ellipsisLoc The location of the ellipsis for a type parameter pack.
3267+
/// \param index The index of the parameter in the generic signature.
3268+
/// \param isParameterPack Whether the generic parameter is for a type
3269+
/// parameter pack, denoted by \c <T...>.
3270+
///
3271+
static GenericTypeParamDecl *
3272+
createParsed(DeclContext *dc, Identifier name, SourceLoc nameLoc,
3273+
SourceLoc ellipsisLoc, unsigned index, bool isParameterPack);
3274+
3275+
/// Construct a new implicit generic type parameter.
3276+
///
3277+
/// \param dc The DeclContext in which the generic type parameter's owner
3278+
/// occurs. This should later be overwritten with the actual declaration
3279+
/// context that owns the type parameter.
3280+
///
3281+
/// \param name The name of the generic parameter.
3282+
/// \param depth The generic signature depth.
3283+
/// \param index The index of the parameter in the generic signature.
3284+
/// \param isParameterPack Whether the generic parameter is for a type
3285+
/// parameter pack, denoted by \c <T...>.
3286+
/// \param isOpaqueType Whether the generic parameter is written as an opaque
3287+
/// parameter e.g 'some Collection'.
3288+
/// \param opaqueTypeRepr The TypeRepr of an opaque generic parameter.
3289+
/// \param nameLoc The location of the name.
3290+
/// \param ellipsisLoc The location of the ellipsis for a type parameter pack.
3291+
///
32063292
static GenericTypeParamDecl *
3207-
create(DeclContext *dc, Identifier name, SourceLoc nameLoc,
3208-
bool isParameterPack, unsigned depth, unsigned index,
3209-
bool isOpaqueType, TypeRepr *typeRepr);
3293+
createImplicit(DeclContext *dc, Identifier name, unsigned depth,
3294+
unsigned index, bool isParameterPack = false,
3295+
bool isOpaqueType = false, TypeRepr *opaqueTypeRepr = nullptr,
3296+
SourceLoc nameLoc = SourceLoc(),
3297+
SourceLoc ellipsisLoc = SourceLoc());
32103298

32113299
/// The depth of this generic type parameter, i.e., the number of outer
32123300
/// levels of generic parameter lists that enclose this type parameter.
@@ -3273,6 +3361,14 @@ class GenericTypeParamDecl final :
32733361
/// Here 'T' and 'U' have indexes 0 and 1, respectively. 'V' has index 0.
32743362
unsigned getIndex() const { return Bits.GenericTypeParamDecl.Index; }
32753363

3364+
/// Retrieve the ellipsis location for a type parameter pack \c T...
3365+
SourceLoc getEllipsisLoc() const {
3366+
if (!isParameterPack())
3367+
return SourceLoc();
3368+
3369+
return *getTrailingObjects<SourceLoc>();
3370+
}
3371+
32763372
SourceLoc getStartLoc() const { return getNameLoc(); }
32773373
SourceRange getSourceRange() const;
32783374

include/swift/AST/DiagnosticsParse.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,13 @@ ERROR(attr_requires_concurrency, none,
19641964
"concurrency is enabled",
19651965
(StringRef, bool))
19661966

1967+
//------------------------------------------------------------------------------
1968+
// MARK: Variadics
1969+
//------------------------------------------------------------------------------
1970+
1971+
ERROR(associatedtype_cannot_be_variadic,none,
1972+
"associated types cannot be variadic", ())
1973+
19671974
//------------------------------------------------------------------------------
19681975
// MARK: Consistency diagnostics
19691976
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6482,14 +6482,6 @@ ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
64826482
ERROR(noimplicitcopy_attr_invalid_in_generic_context,
64836483
none, "'@_noImplicitCopy' attribute cannot be applied to entities in generic contexts", ())
64846484

6485-
//------------------------------------------------------------------------------
6486-
// MARK: variadics
6487-
//------------------------------------------------------------------------------
6488-
6489-
ERROR(type_sequence_on_non_generic_param, none,
6490-
"'@_typeSequence' must appear on a generic parameter",
6491-
())
6492-
64936485
//------------------------------------------------------------------------------
64946486
// MARK: Type inference from default expressions
64956487
//------------------------------------------------------------------------------

include/swift/Parse/Parser.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,9 @@ class Parser {
807807
/// Check whether the current token starts with '>'.
808808
bool startsWithGreater(Token Tok) { return startsWithSymbol(Tok, '>'); }
809809

810+
/// Check whether the current token starts with '...'.
811+
bool startsWithEllipsis(Token Tok);
812+
810813
/// Returns true if token is an identifier with the given value.
811814
bool isIdentifier(Token Tok, StringRef value) {
812815
return Tok.is(tok::identifier) && Tok.getText() == value;
@@ -822,6 +825,11 @@ class Parser {
822825
/// e.g., '>>'.
823826
SourceLoc consumeStartingGreater();
824827

828+
/// Consume the starting '...' of the current token, which may either be a
829+
/// complete '...' token or some kind of operator token starting with '...',
830+
/// e.g '...>'.
831+
SourceLoc consumeStartingEllipsis();
832+
825833
/// Consume the starting character of the current token, and split the
826834
/// remainder of the token into a new token (or tokens).
827835
SourceLoc

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ struct ASTContext::Implementation {
352352
ExistentialSignatures;
353353

354354
/// The element signature for a generic signature, constructed by dropping
355-
/// @_typeSequence attributes from generic parameters.
355+
/// the parameter pack bit from generic parameters.
356356
llvm::DenseMap<const GenericSignatureImpl *,
357357
CanGenericSignature> ElementSignatures;
358358

@@ -5459,10 +5459,8 @@ GenericParamList *ASTContext::getSelfGenericParamList(DeclContext *dc) const {
54595459
// Note: we always return a GenericParamList rooted at the first
54605460
// DeclContext this was called with. Since this is just a giant
54615461
// hack for SIL mode, that should be OK.
5462-
auto *selfParam = GenericTypeParamDecl::create(
5463-
dc, Id_Self, SourceLoc(),
5464-
/*isParameterPack=*/false, /*depth=*/0, /*index=*/0,
5465-
/*isOpaqueType=*/false, /*opaqueTypeRepr=*/nullptr);
5462+
auto *selfParam = GenericTypeParamDecl::createImplicit(
5463+
dc, Id_Self, /*depth*/ 0, /*index*/ 0);
54665464

54675465
theParamList = GenericParamList::create(
54685466
const_cast<ASTContext &>(*this), SourceLoc(), {selfParam}, SourceLoc());

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,9 +1684,6 @@ void PrintAST::printSingleDepthOfGenericSignature(
16841684
llvm::interleave(
16851685
genericParams,
16861686
[&](GenericTypeParamType *param) {
1687-
if (param->isParameterPack())
1688-
Printer.printAttrName("@_typeSequence ");
1689-
16901687
if (!subMap.empty()) {
16911688
printType(substParam(param));
16921689
} else if (auto *GP = param->getDecl()) {
@@ -1699,6 +1696,8 @@ void PrintAST::printSingleDepthOfGenericSignature(
16991696
} else {
17001697
printType(param);
17011698
}
1699+
if (param->isParameterPack())
1700+
Printer << "...";
17021701
},
17031702
[&] { Printer << ", "; });
17041703
}
@@ -3502,9 +3501,9 @@ void PrintAST::visitTypeAliasDecl(TypeAliasDecl *decl) {
35023501

35033502
void PrintAST::visitGenericTypeParamDecl(GenericTypeParamDecl *decl) {
35043503
recordDeclLoc(decl, [&] {
3505-
if (decl->isParameterPack())
3506-
Printer.printAttrName("@_typeSequence ");
35073504
Printer.printName(decl->getName(), PrintNameContext::GenericParameter);
3505+
if (decl->isParameterPack())
3506+
Printer << "...";
35083507
});
35093508

35103509
printInherited(decl);

lib/AST/Attr.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,11 +1264,6 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
12641264
break;
12651265
}
12661266

1267-
case DAK_TypeSequence: {
1268-
Printer.printAttrName("@_typeSequence");
1269-
break;
1270-
}
1271-
12721267
case DAK_UnavailableFromAsync: {
12731268
Printer.printAttrName("@_unavailableFromAsync");
12741269
const UnavailableFromAsyncAttr *attr = cast<UnavailableFromAsyncAttr>(this);
@@ -1454,8 +1449,6 @@ StringRef DeclAttribute::getAttrName() const {
14541449
return "derivative";
14551450
case DAK_Transpose:
14561451
return "transpose";
1457-
case DAK_TypeSequence:
1458-
return "_typeSequence";
14591452
case DAK_UnavailableFromAsync:
14601453
return "_unavailableFromAsync";
14611454
case DAK_BackDeploy:
@@ -2289,15 +2282,6 @@ bool CustomAttr::isArgUnsafe() const {
22892282
return isArgUnsafeBit;
22902283
}
22912284

2292-
TypeSequenceAttr::TypeSequenceAttr(SourceLoc atLoc, SourceRange range)
2293-
: DeclAttribute(DAK_TypeSequence, atLoc, range, /*Implicit=*/false) {}
2294-
2295-
TypeSequenceAttr *TypeSequenceAttr::create(ASTContext &Ctx, SourceLoc atLoc,
2296-
SourceRange range) {
2297-
void *mem = Ctx.Allocate(sizeof(TypeSequenceAttr), alignof(TypeSequenceAttr));
2298-
return new (mem) TypeSequenceAttr(atLoc, range);
2299-
}
2300-
23012285
const DeclAttribute *
23022286
DeclAttributes::getEffectiveSendableAttr() const {
23032287
const NonSendableAttr *assumedAttr = nullptr;

lib/AST/Builtins.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,8 @@ static GenericTypeParamDecl*
234234
createGenericParam(ASTContext &ctx, const char *name, unsigned index) {
235235
ModuleDecl *M = ctx.TheBuiltinModule;
236236
Identifier ident = ctx.getIdentifier(name);
237-
auto genericParam = GenericTypeParamDecl::create(
238-
&M->getMainFile(FileUnitKind::Builtin), ident, SourceLoc(),
239-
/*isParameterPack*/ false, 0, index, /*opaque type=*/false, nullptr);
240-
return genericParam;
237+
return GenericTypeParamDecl::createImplicit(
238+
&M->getMainFile(FileUnitKind::Builtin), ident, /*depth*/ 0, index);
241239
}
242240

243241
/// Create a generic parameter list with multiple generic parameters.

0 commit comments

Comments
 (0)