Skip to content

Commit 217c4a5

Browse files
committed
Sema: Remove the older '@tuple (Int)' syntax
1 parent da76e1e commit 217c4a5

File tree

9 files changed

+28
-51
lines changed

9 files changed

+28
-51
lines changed

include/swift/AST/Attr.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ TYPE_ATTR(Sendable)
5858
TYPE_ATTR(unchecked)
5959
TYPE_ATTR(_typeSequence)
6060
TYPE_ATTR(_local)
61-
TYPE_ATTR(tuple)
6261

6362
// SIL-specific attributes
6463
TYPE_ATTR(block_storage)

include/swift/AST/Attr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,9 +2542,6 @@ class TypeAttributes {
25422542
};
25432543
Optional<OpaqueReturnTypeRef> OpaqueReturnTypeOf;
25442544

2545-
// Force construction of a one-element tuple type.
2546-
bool IsTuple = false;
2547-
25482545
TypeAttributes() {}
25492546

25502547
bool isValid() const { return AtLoc.isValid(); }

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5179,8 +5179,6 @@ ERROR(opened_bad_interface_type,none,
51795179
"@opened interface type %0 is not a type parameter", (Type))
51805180
ERROR(sil_function_input_label,PointsToFirstBadToken,
51815181
"SIL function types cannot have labeled inputs", ())
5182-
ERROR(sil_function_output_label,PointsToFirstBadToken,
5183-
"SIL function types cannot have labeled results", ())
51845182
ERROR(sil_non_coro_yields,PointsToFirstBadToken,
51855183
"non-coroutine SIL function types cannot have @yield results", ())
51865184
ERROR(sil_function_repeat_convention,PointsToFirstBadToken,

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5568,13 +5568,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
55685568
Printer.callPrintStructurePre(PrintStructureKind::TupleType);
55695569
SWIFT_DEFER { Printer.printStructurePost(PrintStructureKind::TupleType); };
55705570

5571-
// Single-element tuples can only appear in SIL mode.
5572-
if (T->getNumElements() == 1 &&
5573-
!T->getElement(0).hasName() &&
5574-
!T->getElementType(0)->is<PackExpansionType>()) {
5575-
Printer << "@tuple ";
5576-
}
5577-
55785571
Printer << "(";
55795572

55805573
auto Fields = T->getElements();
@@ -5592,6 +5585,10 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
55925585
if (TD.hasName()) {
55935586
Printer.printName(TD.getName(), PrintNameContext::TupleElement);
55945587
Printer << ": ";
5588+
} else if (e == 1 && !EltType->is<PackExpansionType>()) {
5589+
// Unlabeled one-element tuples always print the empty label to
5590+
// distinguish them from the older syntax for ParenType.
5591+
Printer << "_: ";
55955592
}
55965593
visit(EltType);
55975594
}

lib/AST/TypeRepr.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ void AttributedTypeRepr::printAttrs(ASTPrinter &Printer,
261261
Printer.printSimpleAttr("@async") << " ";
262262
if (hasAttr(TAK_opened))
263263
Printer.printSimpleAttr("@opened") << " ";
264-
265-
if (hasAttr(TAK_tuple))
266-
Printer.printSimpleAttr("@tuple") << " ";
267264
}
268265

269266
IdentTypeRepr *IdentTypeRepr::create(ASTContext &C,

lib/Parse/ParseDecl.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,15 +3945,6 @@ ParserStatus Parser::parseTypeAttribute(TypeAttributes &Attributes,
39453945
Attributes.setOpaqueReturnTypeOf(mangling, index);
39463946
break;
39473947
}
3948-
3949-
case TAK_tuple: {
3950-
if (!isInSILMode()) {
3951-
diagnose(AtLoc, diag::only_allowed_in_sil, "tuple");
3952-
return makeParserSuccess();
3953-
}
3954-
3955-
Attributes.IsTuple = true;
3956-
}
39573948
}
39583949

39593950
Attributes.setAttr(attr, AtLoc);

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4736,7 +4736,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
47364736
return true;
47374737

47384738
unsigned Field = 0;
4739-
TupleType *TT = Val->getType().getAs<TupleType>();
4739+
TupleType *TT = Val->getType().castTo<TupleType>();
47404740
if (P.Tok.isNot(tok::integer_literal) ||
47414741
parseIntegerLiteral(P.Tok.getText(), 10, Field) ||
47424742
Field >= TT->getNumElements()) {

lib/Sema/TypeCheckType.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,18 +2925,6 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
29252925
if (!ty) ty = resolveType(repr, instanceOptions);
29262926
if (!ty || ty->hasError()) return ty;
29272927

2928-
// In SIL mode only, build one-element tuples.
2929-
if (attrs.has(TAK_tuple)) {
2930-
SmallVector<TupleTypeElt, 1> elements;
2931-
if (auto *parenTy = dyn_cast<ParenType>(ty.getPointer()))
2932-
ty = parenTy->getUnderlyingType();
2933-
2934-
elements.emplace_back(ty);
2935-
ty = TupleType::get(elements, getASTContext());
2936-
2937-
attrs.clearAttribute(TAK_tuple);
2938-
}
2939-
29402928
// Type aliases inside protocols are not yet resolved in the structural
29412929
// stage of type resolution
29422930
if (ty->is<DependentMemberType>() &&
@@ -3780,19 +3768,28 @@ bool TypeResolver::resolveSILResults(TypeRepr *repr,
37803768
SmallVectorImpl<SILResultInfo> &ordinaryResults,
37813769
Optional<SILResultInfo> &errorResult) {
37823770
if (auto tuple = dyn_cast<TupleTypeRepr>(repr)) {
3783-
bool hadError = false;
3771+
// If any of the elements have a label, or an explicit missing label (_:),
3772+
// resolve the entire result type as a single tuple type.
37843773
for (auto &element : tuple->getElements()) {
3785-
if (element.UnderscoreLoc.isValid())
3786-
diagnose(element.UnderscoreLoc, diag::sil_function_output_label);
3774+
if (element.NameLoc.isValid()) {
3775+
return resolveSingleSILResult(repr, options,
3776+
yields, ordinaryResults, errorResult);
3777+
}
37873778
}
3779+
3780+
// Otherwise, resolve each tuple element into its own result type.
3781+
bool hadError = false;
3782+
37883783
for (auto elt : tuple->getElements()) {
37893784
if (resolveSingleSILResult(elt.Type, options,
37903785
yields, ordinaryResults, errorResult))
37913786
hadError = true;
37923787
}
3788+
37933789
return hadError;
37943790
}
37953791

3792+
// Not a tuple type.
37963793
return resolveSingleSILResult(repr, options,
37973794
yields, ordinaryResults, errorResult);
37983795
}
@@ -4199,7 +4196,8 @@ NeverNullType TypeResolver::resolveTupleType(TupleTypeRepr *repr,
41994196
diagnose(repr->getLoc(), diag::tuple_duplicate_label);
42004197
}
42014198

4202-
if (ctx.LangOpts.hasFeature(Feature::VariadicGenerics)) {
4199+
if (options.contains(TypeResolutionFlags::SILType) ||
4200+
ctx.LangOpts.hasFeature(Feature::VariadicGenerics)) {
42034201
if (repr->isParenType())
42044202
return ParenType::get(ctx, elements[0].getType());
42054203
} else {

test/SIL/Parser/one_element_tuple.sil

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ sil_stage canonical
44

55
import Swift
66

7-
// CHECK-LABEL: sil [ossa] @tuple_test : $@convention(thin) (@tuple (Int)) -> @tuple (Int) {
8-
// CHECK: bb0(%0 : $@tuple (Int)):
9-
// CHECK-NEXT: %1 = tuple_extract %0 : $@tuple (Int), 0
7+
// CHECK-LABEL: sil [ossa] @tuple_test : $@convention(thin) ((_: Int)) -> (_: Int) {
8+
// CHECK: bb0(%0 : $(_: Int)):
9+
// CHECK-NEXT: %1 = tuple_extract %0 : $(_: Int), 0
1010
// CHECK-NEXT: %2 = tuple (%1 : $Int)
11-
// CHECK-NEXT: return %2 : $@tuple (Int)
11+
// CHECK-NEXT: return %2 : $(_: Int)
1212
// CHECK-NEXT: }
1313

14-
sil [ossa] @tuple_test : $@convention(thin) (@tuple (Int)) -> @tuple (Int) {
15-
bb0(%0 : $@tuple (Int)):
16-
%1 = tuple_extract %0 : $@tuple (Int), 0
17-
%2 = tuple $@tuple (Int) (%1)
18-
return %2 : $@tuple (Int)
14+
sil [ossa] @tuple_test : $@convention(thin) ((_: Int)) -> (_: Int) {
15+
bb0(%0 : $(_: Int)):
16+
%1 = tuple_extract %0 : $(_: Int), 0
17+
%2 = tuple $(_: Int) (%1)
18+
return %2 : $(_: Int)
1919
}

0 commit comments

Comments
 (0)