Skip to content

Commit 98f1636

Browse files
committed
Sema: Remove the older '@tuple (Int)' syntax
1 parent d7c5e3b commit 98f1636

File tree

8 files changed

+16
-46
lines changed

8 files changed

+16
-46
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(); }

lib/AST/ASTPrinter.cpp

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

5561-
// Single-element tuples can only appear in SIL mode.
5562-
if (T->getNumElements() == 1 &&
5563-
!T->getElement(0).hasName() &&
5564-
!T->getElementType(0)->is<PackExpansionType>()) {
5565-
Printer << "@tuple ";
5566-
}
5567-
55685561
Printer << "(";
55695562

55705563
auto Fields = T->getElements();
@@ -5582,6 +5575,10 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
55825575
if (TD.hasName()) {
55835576
Printer.printName(TD.getName(), PrintNameContext::TupleElement);
55845577
Printer << ": ";
5578+
} else if (e == 1 && !EltType->is<PackExpansionType>()) {
5579+
// Unlabeled one-element tuples always print the empty label to
5580+
// distinguish them from the older syntax for ParenType.
5581+
Printer << "_: ";
55855582
}
55865583
visit(EltType);
55875584
}

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
@@ -4679,7 +4679,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
46794679
return true;
46804680

46814681
unsigned Field = 0;
4682-
TupleType *TT = Val->getType().getAs<TupleType>();
4682+
TupleType *TT = Val->getType().castTo<TupleType>();
46834683
if (P.Tok.isNot(tok::integer_literal) ||
46844684
parseIntegerLiteral(P.Tok.getText(), 10, Field) ||
46854685
Field >= TT->getNumElements()) {

lib/Sema/TypeCheckType.cpp

Lines changed: 2 additions & 13 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>() &&
@@ -4199,7 +4187,8 @@ NeverNullType TypeResolver::resolveTupleType(TupleTypeRepr *repr,
41994187
diagnose(repr->getLoc(), diag::tuple_duplicate_label);
42004188
}
42014189

4202-
if (ctx.LangOpts.hasFeature(Feature::VariadicGenerics)) {
4190+
if (options.contains(TypeResolutionFlags::SILType) ||
4191+
ctx.LangOpts.hasFeature(Feature::VariadicGenerics)) {
42034192
if (repr->isParenType())
42044193
return ParenType::get(ctx, elements[0].getType());
42054194
} 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)