Skip to content

Commit 6aaccf0

Browse files
authored
Merge pull request swiftlang#65214 from hborla/enable-parameter-pack-functions
[SE-0393] Enable parameter packs for generic functions.
2 parents ad4eae0 + e48a9b5 commit 6aaccf0

35 files changed

+89
-114
lines changed

include/swift/AST/DiagnosticsCommon.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ ERROR(macro_experimental,none,
228228
ERROR(ambiguous_macro_reference,none,
229229
"ambiguous reference to macro %0", (DeclName))
230230

231+
//------------------------------------------------------------------------------
232+
// MARK: tuple conformances
233+
//------------------------------------------------------------------------------
234+
ERROR(experimental_tuple_extension,none,
235+
"tuple extensions are experimental",
236+
())
237+
231238
//------------------------------------------------------------------------------
232239
// MARK: bridged diagnostics
233240
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5375,6 +5375,10 @@ ERROR(tuple_pack_element_label,none,
53755375
ERROR(vararg_not_allowed,none,
53765376
"variadic parameter cannot appear outside of a function parameter list",
53775377
())
5378+
5379+
ERROR(experimental_type_with_parameter_pack,none,
5380+
"generic types with parameter packs are experimental",
5381+
())
53785382
ERROR(expansion_not_allowed,none,
53795383
"pack expansion %0 can only appear in a function parameter list, "
53805384
"tuple element, or generic argument list", (Type))

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ EXPERIMENTAL_FEATURE(NamedOpaqueTypes, false)
114114
EXPERIMENTAL_FEATURE(FlowSensitiveConcurrencyCaptures, false)
115115
EXPERIMENTAL_FEATURE(FreestandingMacros, true)
116116
EXPERIMENTAL_FEATURE(CodeItemMacros, true)
117+
EXPERIMENTAL_FEATURE(TupleConformances, false)
117118

118119
// FIXME: MoveOnlyClasses is not intended to be in production,
119120
// but our tests currently rely on it, and we want to run those

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,6 +3208,10 @@ static bool usesFeatureVariadicGenerics(Decl *decl) {
32083208
return false;
32093209
}
32103210

3211+
static bool usesFeatureTupleConformances(Decl *decl) {
3212+
return false;
3213+
}
3214+
32113215
static bool usesFeatureLayoutPrespecialization(Decl *decl) {
32123216
auto &attrs = decl->getAttrs();
32133217
return std::any_of(attrs.begin(), attrs.end(), [](auto *attr) {

lib/AST/NameLookup.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2981,7 +2981,16 @@ ExtendedNominalRequest::evaluate(Evaluator &evaluator,
29812981

29822982
// If there is more than 1 element, we will emit a warning or an error
29832983
// elsewhere, so don't handle that case here.
2984-
return nominalTypes.empty() ? nullptr : nominalTypes[0];
2984+
if (nominalTypes.empty())
2985+
return nullptr;
2986+
2987+
// Diagnose experimental tuple extensions.
2988+
if (isa<BuiltinTupleDecl>(nominalTypes[0]) &&
2989+
!ctx.LangOpts.hasFeature(Feature::TupleConformances)) {
2990+
ext->diagnose(diag::experimental_tuple_extension);
2991+
}
2992+
2993+
return nominalTypes[0];
29852994
}
29862995

29872996
/// Whether there are only associated types in the set of declarations.

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6459,8 +6459,7 @@ ParserResult<TypeDecl> Parser::parseDeclAssociatedType(Parser::ParseDeclOptions
64596459
}
64606460

64616461
// Reject variadic associated types with a specific error.
6462-
if (Context.LangOpts.hasFeature(Feature::VariadicGenerics) &&
6463-
Tok.isContextualKeyword("each")) {
6462+
if (Tok.isContextualKeyword("each")) {
64646463
const auto EachLoc = consumeToken();
64656464
diagnose(EachLoc, diag::associatedtype_cannot_be_variadic)
64666465
.fixItRemoveChars(EachLoc, Tok.getLoc());
@@ -6484,8 +6483,7 @@ ParserResult<TypeDecl> Parser::parseDeclAssociatedType(Parser::ParseDeclOptions
64846483
}
64856484

64866485
// Reject (early syntax) variadic associated types with a specific error.
6487-
if (Context.LangOpts.hasFeature(Feature::VariadicGenerics) &&
6488-
startsWithEllipsis(Tok)) {
6486+
if (startsWithEllipsis(Tok)) {
64896487
const auto EllipsisLoc = consumeStartingEllipsis();
64906488
const auto EllipsisEnd = Lexer::getLocForEndOfToken(SourceMgr, EllipsisLoc);
64916489
diagnose(EllipsisLoc, diag::associatedtype_cannot_be_variadic)

lib/Parse/ParseExpr.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,7 @@ ParserResult<Expr> Parser::parseExprUnary(Diag<> Message, bool isExprBasic) {
531531
tryLexRegexLiteral(/*forUnappliedOperator*/ false);
532532

533533
// 'repeat' as an expression prefix is a pack expansion expression.
534-
if (Context.LangOpts.hasFeature(Feature::VariadicGenerics) &&
535-
Tok.is(tok::kw_repeat)) {
534+
if (Tok.is(tok::kw_repeat)) {
536535
SourceLoc repeatLoc = consumeToken();
537536
auto patternExpr = parseExpr(Message);
538537
if (patternExpr.isNull())
@@ -3024,17 +3023,10 @@ ParserResult<Expr> Parser::parseTupleOrParenExpr(tok leftTok, tok rightTok) {
30243023
rightLoc);
30253024

30263025
// A tuple with a single, unlabeled element is just parentheses.
3027-
if (Context.LangOpts.hasFeature(Feature::VariadicGenerics)) {
3028-
if (elts.size() == 1 && !isa<PackExpansionExpr>(elts[0].E) &&
3029-
elts[0].LabelLoc.isInvalid()) {
3030-
return makeParserResult(
3031-
status, new (Context) ParenExpr(leftLoc, elts[0].E, rightLoc));
3032-
}
3033-
} else {
3034-
if (elts.size() == 1 && elts[0].Label.empty()) {
3035-
return makeParserResult(
3036-
status, new (Context) ParenExpr(leftLoc, elts[0].E, rightLoc));
3037-
}
3026+
if (elts.size() == 1 && !isa<PackExpansionExpr>(elts[0].E) &&
3027+
elts[0].Label.empty()) {
3028+
return makeParserResult(
3029+
status, new (Context) ParenExpr(leftLoc, elts[0].E, rightLoc));
30383030
}
30393031

30403032
SmallVector<Expr *, 8> exprs;

lib/Parse/ParseGeneric.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ Parser::parseGenericParametersBeforeWhere(SourceLoc LAngleLoc,
6060

6161
// Parse the 'each' keyword for a type parameter pack 'each T'.
6262
SourceLoc EachLoc;
63-
if (Context.LangOpts.hasFeature(Feature::VariadicGenerics) &&
64-
Tok.isContextualKeyword("each")) {
63+
if (Tok.isContextualKeyword("each")) {
6564
TokReceiver->registerTokenKindChange(Tok.getLoc(),
6665
tok::contextual_keyword);
6766
EachLoc = consumeToken();
@@ -78,8 +77,7 @@ Parser::parseGenericParametersBeforeWhere(SourceLoc LAngleLoc,
7877

7978
// Parse and diagnose the unsupported ellipsis for a type parameter pack
8079
// 'T...'.
81-
if (Context.LangOpts.hasFeature(Feature::VariadicGenerics) &&
82-
startsWithEllipsis(Tok)) {
80+
if (startsWithEllipsis(Tok)) {
8381
const auto EllipsisLoc = consumeStartingEllipsis();
8482
// TODO: token length hardcoded because calculation for ellipsis
8583
// incorrectly includes '>' if one follows (as can occur in this parse).

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ bool Parser::isStartOfStmt() {
6868
// is a pack expansion expression.
6969
// FIXME: 'repeat' followed by '{' could be a pack expansion
7070
// with a closure pattern.
71-
return !Context.LangOpts.hasFeature(Feature::VariadicGenerics) ||
72-
peekToken().is(tok::l_brace);
71+
return peekToken().is(tok::l_brace);
7372

7473
case tok::pound_line:
7574
// #line at the start of a line is a directive, when within, it is an expr.

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,8 +1755,7 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
17551755
// We pull these out special because variadic parameters ban lots of
17561756
// the more interesting typing constructs called out below like
17571757
// inout and @autoclosure.
1758-
if (cs.getASTContext().LangOpts.hasFeature(Feature::VariadicGenerics) &&
1759-
paramInfo.isVariadicGenericParameter(paramIdx)) {
1758+
if (paramInfo.isVariadicGenericParameter(paramIdx)) {
17601759
// If generic parameter comes from a variadic type declaration it's
17611760
// possible that it got specialized early and is no longer represented
17621761
// by a pack expansion type. For example, consider expression -

0 commit comments

Comments
 (0)