Skip to content

Commit 5ce3de8

Browse files
committed
remove & dial back three old bits of syntax auto-upgrading support:
1. Array type parsing for postfix array types Int[]. We now handle this in the parser, but remove the AST representation of this old form. We also stop making vague promises about the future by saying that "fixed size arrays aren't supported... yet". Removal of this fixes a compiler crasher too. 2. Remove the special case support for migrating @autoclosure from types to parameters, which was Swift 1.0/1.1 syntax. The world has moved or we don't care anymore. 3. Remove upgrade support for # arguments (nee "backtick" arguments), which was a Swift 1.x'ism abolished in an effort to simplify method naming rules. NFC on valid code.
1 parent b3e75dd commit 5ce3de8

23 files changed

+85
-421
lines changed

include/swift/AST/DiagnosticsCommon.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ ERROR(class_var_not_in_class,common,none,
7474
ERROR(func_decl_without_brace,decl_parsing,PointsToFirstBadToken,
7575
"expected '{' in body of function declaration", ())
7676

77-
ERROR(new_array_syntax,type_parsing,none,
78-
"array types are now written with the brackets around the element type",
79-
())
80-
8177
NOTE(convert_let_to_var,sema,none,
8278
"change 'let' to 'var' to make it mutable", ())
8379
NOTE(change_let_to_var_param,sema,none,

include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ ERROR(decl_already_static,decl_parsing,none,
188188
ERROR(autoclosure_is_decl_attribute,attribute_parsing,none,
189189
"@autoclosure is now an attribute of the parameter "
190190
"declaration, not its type", ())
191-
ERROR(autoclosure_not_on_enums,attribute_parsing,none,
192-
"@autoclosure is only allowed on parameters, not on enum cases", ())
193191

194192
ERROR(enum_case_dot_prefix,decl_parsing,none,
195193
"extraneous '.' in enum 'case' declaration", ())
@@ -598,10 +596,9 @@ ERROR(nonliteral_enum_case_raw_value,type_parsing,PointsToFirstBadToken,
598596
"raw value for enum case must be a literal", ())
599597

600598
// Collection Types
601-
ERROR(unsupported_fixed_length_array,type_parsing,none,
602-
"fixed-length arrays are not yet supported", ())
603-
ERROR(expected_expr_array_type,expr_parsing,PointsToFirstBadToken,
604-
"expected expression for size of array type", ())
599+
ERROR(new_array_syntax,type_parsing,none,
600+
"array types are now written with the brackets around the element type",
601+
())
605602
ERROR(expected_rbracket_array_type,type_parsing,PointsToFirstBadToken,
606603
"expected ']' in array type", ())
607604
ERROR(expected_element_type,type_parsing,PointsToFirstBadToken,
@@ -662,26 +659,13 @@ ERROR(multiple_parameter_ellipsis,decl_parsing,none,
662659
"only a single variadic parameter '...' is permitted", ())
663660
ERROR(parameter_vararg_default,decl_parsing,none,
664661
"variadic parameter cannot have a default value", ())
665-
ERROR(parameter_backtick_missing_name,decl_parsing,PointsToFirstBadToken,
666-
"expected parameter name after '#'", ())
667-
ERROR(parameter_backtick_empty_name,decl_parsing,none,
668-
"expected non-empty parameter name after '#'", ())
669662
ERROR(parameter_inout_var_let,decl_parsing,none,
670663
"parameter may not have multiple 'inout', 'var', or 'let' specifiers",
671664
())
672665

673-
WARNING(parameter_backtick_two_names,decl_parsing,none,
674-
"extraneous '#' in parameter; keyword argument and parameter name "
675-
"already specified separately", ())
676666
WARNING(parameter_extraneous_double_up,decl_parsing,none,
677667
"extraneous duplicate parameter name; %0 already has an argument "
678668
"label", (Identifier))
679-
ERROR(parameter_extraneous_pound,decl_parsing,none,
680-
"'#' has been removed from Swift; %0 already has an argument label",
681-
(Identifier))
682-
ERROR(parameter_pound_double_up,decl_parsing,none,
683-
"'#' has been removed from Swift; double up '%0 %0' to make the "
684-
"argument label the same as the parameter name", (StringRef))
685669
WARNING(parameter_extraneous_empty_name,decl_parsing,none,
686670
"extraneous '_' in parameter: %0 has no keyword argument name",
687671
(Identifier))

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,12 +2052,6 @@ ERROR(type_pattern_missing_is,sema_tcp,none,
20522052

20532053
ERROR(pattern_type_mismatch_context,sema_tcp,none,
20542054
"type annotation does not match contextual type %0", (Type))
2055-
ERROR(label_single_entry_tuple,sema_tcp,none,
2056-
"label is not allowed on single element tuple pattern", ())
2057-
NOTE(remove_parens_for_type_annotation,sema_tcp,none,
2058-
"remove the parentheses to make this a type annotation", ())
2059-
NOTE(remove_label_for_tuple_pattern,sema_tcp,none,
2060-
"remove the label to make this a tuple pattern", ())
20612055

20622056
ERROR(tuple_pattern_in_non_tuple_context,sema_tcp,none,
20632057
"tuple pattern cannot match values of the non-tuple type %0", (Type))

include/swift/AST/TypeRepr.h

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -392,41 +392,24 @@ class FunctionTypeRepr : public TypeRepr {
392392
/// [Foo]
393393
/// \endcode
394394
class ArrayTypeRepr : public TypeRepr {
395-
// FIXME: Tail allocation. Use bits to determine whether Base/Size are
396-
// available.
397-
llvm::PointerIntPair<TypeRepr *, 1, bool> BaseAndIsOldSyntax;
395+
TypeRepr *Base;
398396
SourceRange Brackets;
399397

400398
public:
401-
ArrayTypeRepr(TypeRepr *Base, SourceRange Brackets, bool OldSyntax)
402-
: TypeRepr(TypeReprKind::Array), BaseAndIsOldSyntax(Base, OldSyntax),
403-
Brackets(Brackets) { }
399+
ArrayTypeRepr(TypeRepr *Base, SourceRange Brackets)
400+
: TypeRepr(TypeReprKind::Array), Base(Base), Brackets(Brackets) { }
404401

405-
TypeRepr *getBase() const { return BaseAndIsOldSyntax.getPointer(); }
402+
TypeRepr *getBase() const { return Base; }
406403
SourceRange getBrackets() const { return Brackets; }
407404

408-
bool usesOldSyntax() const { return BaseAndIsOldSyntax.getInt(); }
409-
410405
static bool classof(const TypeRepr *T) {
411406
return T->getKind() == TypeReprKind::Array;
412407
}
413408
static bool classof(const ArrayTypeRepr *T) { return true; }
414409

415410
private:
416-
SourceLoc getStartLocImpl() const {
417-
if (usesOldSyntax())
418-
return getBase()->getStartLoc();
419-
420-
return Brackets.Start;
421-
}
422-
SourceLoc getEndLocImpl() const {
423-
// This test is necessary because the type Int[][] is represented as
424-
// ArrayTypeRepr(ArrayTypeRepr(Int)), so the range needs to cover both
425-
// sets of brackets.
426-
if (usesOldSyntax() && isa<ArrayTypeRepr>(getBase()))
427-
return getBase()->getEndLoc();
428-
return Brackets.End;
429-
}
411+
SourceLoc getStartLocImpl() const { return Brackets.Start; }
412+
SourceLoc getEndLocImpl() const { return Brackets.End; }
430413
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
431414
friend class TypeRepr;
432415
};
@@ -778,10 +761,8 @@ inline bool TypeRepr::isSimple() const {
778761
case TypeReprKind::ProtocolComposition:
779762
case TypeReprKind::Tuple:
780763
case TypeReprKind::Fixed:
781-
return true;
782-
783764
case TypeReprKind::Array:
784-
return !cast<ArrayTypeRepr>(this)->usesOldSyntax();
765+
return true;
785766
}
786767
llvm_unreachable("bad TypeRepr kind");
787768
}

include/swift/Parse/Parser.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ class Parser {
860860

861861
ParserResult<ProtocolCompositionTypeRepr> parseTypeComposition();
862862
ParserResult<TupleTypeRepr> parseTypeTupleBody();
863-
ParserResult<ArrayTypeRepr> parseTypeArray(TypeRepr *Base);
863+
ParserResult<TypeRepr> parseTypeArray(TypeRepr *Base);
864864

865865
/// Parse a collection type.
866866
/// type-simple:
@@ -923,10 +923,6 @@ class Parser {
923923
};
924924
SpecifierKindTy SpecifierKind = Let; // Defaults to let.
925925

926-
927-
/// The location of the back-tick preceding the first name, if any.
928-
SourceLoc PoundLoc;
929-
930926
/// The location of the first name.
931927
///
932928
/// \c FirstName is the name.

lib/AST/TypeRepr.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ TypeRepr *CloneVisitor::visitFunctionTypeRepr(FunctionTypeRepr *T) {
158158
}
159159

160160
TypeRepr *CloneVisitor::visitArrayTypeRepr(ArrayTypeRepr *T) {
161-
return new (Ctx) ArrayTypeRepr(visit(T->getBase()), T->getBrackets(),
162-
T->usesOldSyntax());
161+
return new (Ctx) ArrayTypeRepr(visit(T->getBase()), T->getBrackets());
163162
}
164163

165164
TypeRepr *CloneVisitor::visitDictionaryTypeRepr(DictionaryTypeRepr *T) {
@@ -338,14 +337,9 @@ void FunctionTypeRepr::printImpl(ASTPrinter &Printer,
338337

339338
void ArrayTypeRepr::printImpl(ASTPrinter &Printer,
340339
const PrintOptions &Opts) const {
341-
if (usesOldSyntax()) {
342-
printTypeRepr(getBase(), Printer, Opts);
343-
Printer << "[]";
344-
} else {
345-
Printer << "[";
346-
printTypeRepr(getBase(), Printer, Opts);
347-
Printer << "]";
348-
}
340+
Printer << "[";
341+
printTypeRepr(getBase(), Printer, Opts);
342+
Printer << "]";
349343
}
350344

351345
void DictionaryTypeRepr::printImpl(ASTPrinter &Printer,

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,40 +1440,26 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, bool justChecking) {
14401440
// Otherwise this is a valid decl attribute so they should have put it on
14411441
// the decl instead of the type.
14421442

1443-
auto diagID = diag::decl_attribute_applied_to_type;
1444-
if (declAttrID == DAK_AutoClosure) {
1445-
// Special case handling of @autoclosure attribute on the type, which
1446-
// was supported in Swift 1.0 and 1.1, but removed in Swift 1.2.
1447-
diagID = diag::autoclosure_is_decl_attribute;
1448-
1449-
// Further special case handling of @autoclosure attribute in
1450-
// enumerators in EnumDecl's to produce a nice diagnostic.
1451-
if (CurDeclContext && isa<EnumDecl>(CurDeclContext))
1452-
diagID = diag::autoclosure_not_on_enums;
1453-
}
1454-
14551443
// If this is the first attribute, and if we are on a simple decl, emit a
14561444
// fixit to move the attribute. Otherwise, we don't have the location of
14571445
// the @ sign, or we don't have confidence that the fixit will be right.
14581446
if (!Attributes.empty() || StructureMarkers.empty() ||
14591447
StructureMarkers.back().Kind != StructureMarkerKind::Declaration ||
14601448
StructureMarkers.back().Loc.isInvalid() ||
14611449
peekToken().is(tok::equal)) {
1462-
diagnose(Tok, diagID);
1450+
diagnose(Tok, diag::decl_attribute_applied_to_type);
14631451
} else {
14641452
// Otherwise, this is the first type attribute and we know where the
14651453
// declaration is. Emit the same diagnostic, but include a fixit to
14661454
// move the attribute. Unfortunately, we don't have enough info to add
14671455
// the attribute to DeclAttributes.
1468-
diagnose(Tok, diagID)
1456+
diagnose(Tok, diag::decl_attribute_applied_to_type)
14691457
.fixItRemove(SourceRange(Attributes.AtLoc, Tok.getLoc()))
14701458
.fixItInsert(StructureMarkers.back().Loc,
14711459
"@" + Tok.getText().str()+" ");
14721460
}
14731461
}
14741462

1475-
1476-
14771463
// Recover by eating @foo when foo is not known.
14781464
consumeToken();
14791465

lib/Parse/ParsePattern.cpp

Lines changed: 4 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -199,38 +199,14 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
199199
consumeToken();
200200
}
201201

202-
// '#'?
203-
if (Tok.is(tok::pound))
204-
param.PoundLoc = consumeToken(tok::pound);
205-
206-
if (param.PoundLoc.isValid() || startsParameterName(*this, isClosure)) {
202+
if (startsParameterName(*this, isClosure)) {
207203
// identifier-or-none for the first name
208204
if (Tok.is(tok::kw__)) {
209-
// A back-tick cannot precede an empty name marker.
210-
if (param.PoundLoc.isValid()) {
211-
diagnose(Tok, diag::parameter_backtick_empty_name)
212-
.fixItRemove(param.PoundLoc);
213-
param.PoundLoc = SourceLoc();
214-
}
215-
216205
param.FirstNameLoc = consumeToken();
217-
} else if (Tok.canBeArgumentLabel()) {
206+
} else {
207+
assert(Tok.canBeArgumentLabel() && "startsParameterName() lied");
218208
param.FirstName = Context.getIdentifier(Tok.getText());
219209
param.FirstNameLoc = consumeToken();
220-
221-
// Operators cannot have API names.
222-
if (paramContext == ParameterContextKind::Operator &&
223-
param.PoundLoc.isValid()) {
224-
diagnose(param.PoundLoc,
225-
diag::parameter_operator_keyword_argument)
226-
.fixItRemove(param.PoundLoc);
227-
param.PoundLoc = SourceLoc();
228-
}
229-
} else {
230-
assert(param.PoundLoc.isValid() && "startsParameterName() lied");
231-
diagnose(Tok, diag::parameter_backtick_missing_name);
232-
param.FirstNameLoc = param.PoundLoc;
233-
param.PoundLoc = SourceLoc();
234210
}
235211

236212
// identifier-or-none? for the second name
@@ -254,31 +230,10 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
254230
param.SecondNameLoc = SourceLoc();
255231
}
256232

257-
// Cannot have a pound and two names.
258-
if (param.PoundLoc.isValid() && param.SecondNameLoc.isValid()) {
259-
diagnose(param.PoundLoc, diag::parameter_backtick_two_names)
260-
.fixItRemove(param.PoundLoc);
261-
param.PoundLoc = SourceLoc();
262-
}
263-
264233
// (':' type)?
265234
if (Tok.is(tok::colon)) {
266235
param.ColonLoc = consumeToken();
267236

268-
// Special case handling of @autoclosure attribute on the type, which
269-
// was supported in Swift 1.0 and 1.1, but removed in Swift 1.2 (moved
270-
// to a decl attribute).
271-
if (Tok.is(tok::at_sign) &&
272-
peekToken().isContextualKeyword("autoclosure")) {
273-
SourceLoc AtLoc = consumeToken(tok::at_sign);
274-
SourceLoc ACLoc = consumeToken(tok::identifier);
275-
diagnose(AtLoc, diag::autoclosure_is_decl_attribute)
276-
.fixItRemove(SourceRange(AtLoc, ACLoc))
277-
.fixItInsert(StartLoc, "@autoclosure ");
278-
param.Attrs.add(new (Context) AutoClosureAttr(AtLoc, ACLoc,
279-
/*escaping=*/false));
280-
}
281-
282237
auto type = parseType(diag::expected_parameter_type);
283238
status |= type;
284239
param.Type = type.getPtrOrNull();
@@ -447,25 +402,8 @@ mapParsedParameters(Parser &parser,
447402
.fixItRemoveChars(param.FirstNameLoc, param.SecondNameLoc);
448403
}
449404
} else {
450-
// If it's an API name by default, or there was a pound, we have an
451-
// API name.
452-
if (isKeywordArgumentByDefault || param.PoundLoc.isValid()) {
405+
if (isKeywordArgumentByDefault)
453406
argName = param.FirstName;
454-
455-
// The pound is going away. Complain.
456-
if (param.PoundLoc.isValid()) {
457-
if (isKeywordArgumentByDefault) {
458-
parser.diagnose(param.PoundLoc, diag::parameter_extraneous_pound,
459-
argName)
460-
.fixItRemove(param.PoundLoc);
461-
} else {
462-
parser.diagnose(param.PoundLoc, diag::parameter_pound_double_up,
463-
argName.str())
464-
.fixItReplace(param.PoundLoc, (argName.str() + " ").str());
465-
}
466-
}
467-
}
468-
469407
paramName = param.FirstName;
470408

471409
result = createParamPattern(param.LetVarInOutLoc, param.SpecifierKind,

0 commit comments

Comments
 (0)