Skip to content

Commit 003a9a4

Browse files
committed
Parse: Remove obsolete @autoclosure(escaping) and @NoEscape type attributes
Some diagnostics got worse, but I think the reduction in compiler complexity is worth it, and copy-and-pasting Swift 2 code is not likely to produce great results anyway. Also, this corrects an oversight where we did not reject @pseudogeneric on function types in AST parsing.
1 parent 9ac0dc3 commit 003a9a4

File tree

10 files changed

+64
-159
lines changed

10 files changed

+64
-159
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,21 +1377,6 @@ WARNING(attr_availability_nonspecific_platform_unexpected_version,none,
13771377
"unexpected version number in '%0' attribute for non-specific platform "
13781378
"'*'", (StringRef))
13791379

1380-
// autoclosure
1381-
ERROR(attr_autoclosure_expected_r_paren,PointsToFirstBadToken,
1382-
"expected ')' in @autoclosure", ())
1383-
ERROR(attr_noescape_conflicts_escaping_autoclosure,none,
1384-
"@noescape conflicts with @autoclosure(escaping)", ())
1385-
ERROR(attr_noescape_implied_by_autoclosure,none,
1386-
"@noescape is implied by @autoclosure and should not be "
1387-
"redundantly specified", ())
1388-
ERROR(attr_autoclosure_escaping_deprecated,none,
1389-
"@autoclosure(escaping) has been removed; use @autoclosure @escaping instead",
1390-
())
1391-
ERROR(attr_noescape_deprecated,none,
1392-
"@noescape is the default and has been removed",
1393-
())
1394-
13951380
// convention
13961381
ERROR(convention_attribute_expected_lparen,none,
13971382
"expected '(' after 'convention' attribute", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,8 +3500,6 @@ NOTE(overridden_required_initializer_here,none,
35003500
// Functions
35013501
ERROR(attribute_requires_function_type,none,
35023502
"@%0 attribute only applies to function types", (StringRef))
3503-
ERROR(attribute_not_supported,none,
3504-
"this attribute is not supported", ())
35053503
ERROR(unsupported_convention,none,
35063504
"convention '%0' not supported", (StringRef))
35073505
ERROR(unreferenced_generic_parameter,none,

include/swift/Migrator/FixitFilter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ struct FixitFilter {
127127
Info.ID == diag::where_inside_brackets.ID ||
128128
Info.ID == diag::selector_construction_suggest.ID ||
129129
Info.ID == diag::selector_literal_deprecated_suggest.ID ||
130-
Info.ID == diag::attr_noescape_deprecated.ID ||
131-
Info.ID == diag::attr_autoclosure_escaping_deprecated.ID ||
132130
Info.ID == diag::attr_warn_unused_result_removed.ID ||
133131
Info.ID == diag::any_as_anyobject_fixit.ID ||
134132
Info.ID == diag::deprecated_protocol_composition.ID ||

lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,31 +1999,10 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, bool justChecking) {
19991999
StringRef Text = Tok.getText();
20002000
SourceLoc Loc = consumeToken();
20012001

2002-
bool isAutoclosureEscaping = false;
2003-
SourceRange autoclosureEscapingParenRange;
20042002
StringRef conventionName;
20052003
StringRef witnessMethodProtocol;
20062004

2007-
// Handle @autoclosure(escaping)
2008-
if (attr == TAK_autoclosure) {
2009-
// We need to do a bit of lookahead here to make sure we parse a (weird)
2010-
// type like: "@autoclosure (escaping) -> Int" correctly (escaping is the
2011-
// name of a type here). We also want to support the case where the
2012-
// function type coming up is a typealias, e.g. "@autoclosure (escaping) T".
2013-
if (Tok.is(tok::l_paren) && peekToken().getText() == "escaping") {
2014-
Parser::BacktrackingScope Backtrack(*this);
2015-
consumeToken(tok::l_paren);
2016-
consumeToken(tok::identifier);
2017-
isAutoclosureEscaping =
2018-
Tok.is(tok::r_paren) && peekToken().isNot(tok::arrow);
2019-
}
2020-
2021-
if (isAutoclosureEscaping) {
2022-
autoclosureEscapingParenRange.Start = consumeToken(tok::l_paren);
2023-
consumeToken(tok::identifier);
2024-
autoclosureEscapingParenRange.End = consumeToken(tok::r_paren);
2025-
}
2026-
} else if (attr == TAK_convention) {
2005+
if (attr == TAK_convention) {
20272006
SourceLoc LPLoc;
20282007
if (!consumeIfNotAtStartOfLine(tok::l_paren)) {
20292008
if (!justChecking)
@@ -2086,48 +2065,10 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, bool justChecking) {
20862065
switch (attr) {
20872066
default: break;
20882067
case TAK_autoclosure:
2089-
// Handle @autoclosure(escaping)
2090-
if (isAutoclosureEscaping) {
2091-
// @noescape @autoclosure(escaping) makes no sense.
2092-
if (Attributes.has(TAK_noescape)) {
2093-
diagnose(Loc, diag::attr_noescape_conflicts_escaping_autoclosure);
2094-
} else {
2095-
diagnose(Loc, diag::attr_autoclosure_escaping_deprecated)
2096-
.fixItReplace(autoclosureEscapingParenRange, " @escaping ");
2097-
}
2098-
Attributes.setAttr(TAK_escaping, Loc);
2099-
} else if (Attributes.has(TAK_noescape) && !isInSILMode()) {
2100-
diagnose(Loc, diag::attr_noescape_implied_by_autoclosure);
2101-
}
2102-
break;
2103-
2104-
case TAK_noescape:
2105-
// You can't specify @noescape and @escaping together.
2106-
if (Attributes.has(TAK_escaping)) {
2107-
diagnose(Loc, diag::attr_escaping_conflicts_noescape);
2108-
return false;
2109-
}
2110-
2111-
// @noescape after @autoclosure is redundant.
2112-
if (Attributes.has(TAK_autoclosure) && !isInSILMode()) {
2113-
diagnose(Loc, diag::attr_noescape_implied_by_autoclosure);
2114-
}
2115-
2116-
// @noescape is deprecated and no longer used
2117-
// In SIL, the polarity of @escaping is reversed.
2118-
// @escaping is the default and @noescape is explicit.
2119-
if (!isInSILMode()) {
2120-
diagnose(Loc, diag::attr_noescape_deprecated)
2121-
.fixItRemove({Attributes.AtLoc, Loc});
2122-
}
2123-
break;
21242068
case TAK_escaping:
2125-
// You can't specify @noescape and @escaping together.
2126-
if (Attributes.has(TAK_noescape)) {
2127-
diagnose(Loc, diag::attr_escaping_conflicts_noescape);
2128-
return false;
2129-
}
2069+
case TAK_noescape:
21302070
break;
2071+
21312072
case TAK_out:
21322073
case TAK_in:
21332074
case TAK_owned:

lib/Sema/TypeCheckType.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/Strings.h"
2525
#include "swift/AST/ASTVisitor.h"
2626
#include "swift/AST/ASTWalker.h"
27+
#include "swift/AST/DiagnosticsParse.h"
2728
#include "swift/AST/ExistentialLayout.h"
2829
#include "swift/AST/ForeignErrorConvention.h"
2930
#include "swift/AST/GenericEnvironment.h"
@@ -2053,15 +2054,21 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
20532054

20542055
auto checkUnsupportedAttr = [&](TypeAttrKind attr) {
20552056
if (attrs.has(attr)) {
2056-
diagnose(attrs.getLoc(attr), diag::attribute_not_supported);
2057+
diagnose(attrs.getLoc(attr), diag::unknown_attribute,
2058+
TypeAttributes::getAttrName(attr));
20572059
attrs.clearAttribute(attr);
20582060
}
20592061
};
20602062

20612063
// Some function representation attributes are not supported at source level;
20622064
// only SIL knows how to handle them. Reject them unless this is a SIL input.
20632065
if (!(options & TypeResolutionFlags::SILType)) {
2064-
for (auto silOnlyAttr : {TAK_callee_owned, TAK_callee_guaranteed}) {
2066+
for (auto silOnlyAttr : {TAK_pseudogeneric,
2067+
TAK_callee_owned,
2068+
TAK_callee_guaranteed,
2069+
TAK_noescape,
2070+
TAK_yield_once,
2071+
TAK_yield_many}) {
20652072
checkUnsupportedAttr(silOnlyAttr);
20662073
}
20672074
}
@@ -2181,7 +2188,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
21812188
}
21822189

21832190
// Resolve the function type directly with these attributes.
2184-
FunctionType::ExtInfo extInfo(rep, attrs.has(TAK_noescape),
2191+
FunctionType::ExtInfo extInfo(rep, /*noescape=*/false,
21852192
fnRepr->throws());
21862193

21872194
ty = resolveASTFunctionType(fnRepr, options, extInfo);
@@ -2208,7 +2215,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
22082215
}
22092216

22102217
// Handle @escaping
2211-
if (hasFunctionAttr && ty->is<FunctionType>()) {
2218+
if (ty->is<FunctionType>()) {
22122219
if (attrs.has(TAK_escaping)) {
22132220
// The attribute is meaningless except on non-variadic parameter types.
22142221
if (!isParam || options.getBaseContext() == TypeResolverContext::EnumElementDecl) {
@@ -2233,9 +2240,6 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
22332240

22342241
if (hasFunctionAttr && !fnRepr) {
22352242
if (attrs.has(TAK_autoclosure)) {
2236-
// @autoclosure usually auto-implies @noescape,
2237-
// don't complain about both of them.
2238-
attrs.clearAttribute(TAK_noescape);
22392243
// @autoclosure is going to be diagnosed when type of
22402244
// the parameter is validated, because that attribute
22412245
// applies to the declaration now.

test/Parse/swift3_warnings_swift4_errors_version_4.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ let x: protocol<> // expected-error {{'protocol<>' syntax has been removed; use
1313
let y: protocol<P1> // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}}}
1414
let z: protocol<P1, P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}}
1515

16-
func bar(f: @noescape () -> ()) {} // expected-error {{@noescape is the default and has been removed}}
16+
func bar(f: @noescape () -> ()) {} // expected-error {{unknown attribute 'noescape'}}
1717

18-
func baz(f: @autoclosure(escaping) () -> ()) {} // expected-error {{@autoclosure(escaping) has been removed; use @autoclosure @escaping instead}}
18+
func baz(f: @autoclosure(escaping) () -> ()) {}
19+
// expected-error @-1 {{use of undeclared type 'escaping'}}
20+
// expected-error @-2 {{unnamed parameters must be written with the empty name '_'}}
21+
// expected-error @-3 {{expected ',' separator}}
1922

2023
prefix operator +++ {} // expected-error {{operator should no longer be declared with body}}
2124
postfix operator +++ {} // expected-error {{operator should no longer be declared with body}}

test/attr/attr_autoclosure.swift

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,40 +68,22 @@ struct AutoclosureEscapeTest {
6868
@autoclosure let delayed: () -> Int // expected-error {{attribute can only be applied to types, not declarations}}
6969
}
7070

71-
// @autoclosure(escaping)
71+
// @autoclosure(escaping) is no longer a thing; just make sure we don't crash
7272
// expected-error @+1 {{attribute can only be applied to types, not declarations}}
7373
func func10(@autoclosure(escaping _: () -> ()) { } // expected-error{{expected parameter name followed by ':'}}
7474
75-
func func11(_: @autoclosure(escaping) @noescape () -> ()) { } // expected-error{{@escaping conflicts with @noescape}}
76-
// expected-error@-1{{@autoclosure(escaping) has been removed; use @autoclosure @escaping instead}} {{28-38= @escaping}}
77-
78-
class Super {
79-
func f1(_ x: @autoclosure(escaping) () -> ()) { }
80-
// expected-error@-1{{@autoclosure(escaping) has been removed; use @autoclosure @escaping instead}} {{28-38= @escaping}}
81-
func f2(_ x: @autoclosure(escaping) () -> ()) { } // expected-note {{potential overridden instance method 'f2' here}}
82-
// expected-error@-1{{@autoclosure(escaping) has been removed; use @autoclosure @escaping instead}} {{28-38= @escaping}}
83-
func f3(x: @autoclosure () -> ()) { }
84-
}
85-
86-
class Sub : Super {
87-
override func f1(_ x: @autoclosure(escaping)() -> ()) { }
88-
// expected-error@-1{{@autoclosure(escaping) has been removed; use @autoclosure @escaping instead}} {{37-47= @escaping }}
89-
override func f2(_ x: @autoclosure () -> ()) { } // expected-error{{does not override any method}} // expected-note{{type does not match superclass instance method with type '(@autoclosure @escaping () -> ()) -> ()'}}
90-
override func f3(_ x: @autoclosure(escaping) () -> ()) { } // expected-error{{does not override any method}}
91-
// expected-error@-1{{@autoclosure(escaping) has been removed; use @autoclosure @escaping instead}} {{37-47= @escaping}}
92-
}
75+
func func11(_: @autoclosure(escaping) @noescape () -> ()) { } // expected-error{{use of undeclared type 'escaping'}}
76+
// expected-error @-1 {{attribute can only be applied to types, not declarations}}
77+
// expected-error @-2 {{expected ',' separator}}
78+
// expected-error @-3 {{expected parameter name followed by ':'}}
9379

9480
func func12_sink(_ x: @escaping () -> Int) { }
9581

9682
func func12a(_ x: @autoclosure () -> Int) {
97-
// expected-note@-1{{parameter 'x' is implicitly non-escaping}}
83+
// expected-note@-1{{parameter 'x' is implicitly non-escaping}}
9884

9985
func12_sink(x) // expected-error {{passing non-escaping parameter 'x' to function expecting an @escaping closure}}
10086
}
101-
func func12b(_ x: @autoclosure(escaping) () -> Int) {
102-
// expected-error@-1{{@autoclosure(escaping) has been removed; use @autoclosure @escaping instead}} {{31-41= @escaping}}
103-
func12_sink(x) // ok
104-
}
10587
func func12c(_ x: @autoclosure @escaping () -> Int) {
10688
func12_sink(x) // ok
10789
}
@@ -116,7 +98,7 @@ class TestFunc12 {
11698

11799
func test() {
118100
func12a(x + foo()) // okay
119-
func12b(x + foo())
101+
func12c(x + foo())
120102
// expected-error@-1{{reference to property 'x' in closure requires explicit 'self.' to make capture semantics explicit}} {{13-13=self.}}
121103
// expected-error@-2{{call to method 'foo' in closure requires explicit 'self.' to make capture semantics explicit}} {{17-17=self.}}
122104
}
@@ -131,8 +113,6 @@ enum AutoclosureFailableOf<T> {
131113
let _ : AutoclosureFailableOf<Int> = .Success(42)
132114

133115
let _ : (@autoclosure () -> ()) -> ()
134-
let _ : (@autoclosure(escaping) () -> ()) -> ()
135-
// expected-error@-1{{@autoclosure(escaping) has been removed; use @autoclosure @escaping instead}} {{22-32= @escaping}}
136116

137117
// escaping is the name of param type
138118
let _ : (@autoclosure(escaping) -> ()) -> () // expected-error {{use of undeclared type 'escaping'}}

test/attr/attr_escaping.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ func paramDeclEscaping(@escaping fn: (Int) -> Void) {} // expected-error {{attri
55

66
func wrongParamType(a: @escaping Int) {} // expected-error {{@escaping attribute only applies to function types}}
77

8-
func conflictingAttrs(_ fn: @noescape @escaping () -> Int) {} // expected-error {{@escaping conflicts with @noescape}}
9-
// expected-error@-1{{@noescape is the default and has been removed}} {{29-39=}}
8+
func conflictingAttrs(_ fn: @noescape @escaping () -> Int) {} // expected-error {{unknown attribute 'noescape'}}
109

1110
func takesEscaping(_ fn: @escaping () -> Int) {} // ok
1211

0 commit comments

Comments
 (0)