Skip to content

Commit 6ba1bb7

Browse files
committed
[noescape by default] Incorporate Slav's feedback
1 parent d031e5a commit 6ba1bb7

File tree

8 files changed

+21
-40
lines changed

8 files changed

+21
-40
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Swift 3.0
66
* [SE-103](https://github.com/apple/swift-evolution/blob/master/proposals/0103-make-noescape-default.md)
77

88
Closure parameters are non-escaping by default, rather than explicitly being
9-
annotated @noescape. Use @escaping to say that a closure parameter may escape.
10-
@autoclosure(escaping) is now spelled @autoclosure @escaping. @noescape and
11-
@autoclosure(escaping) are deprecated.
9+
annotated `@noescape`. Use `@escaping` to say that a closure parameter may
10+
escape. `@autoclosure(escaping)` is now spelled `@autoclosure @escaping`.
11+
`@noescape` and `@autoclosure(escaping)` are deprecated.
1212

1313
* [SE-0115](https://github.com/apple/swift-evolution/blob/master/proposals/0115-literal-syntax-protocols.md)
1414

include/swift/AST/Attr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ class TypeAttributes {
5252
SourceLoc AtLoc;
5353
Optional<StringRef> convention = None;
5454

55-
/// For the deprecated @autoclosure(escaping) syntax
56-
bool isDeprecatedAutoclosureEscaping = false;
57-
5855
// For an opened existential type, the known ID.
5956
Optional<UUID> OpenedID;
6057

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,16 +3742,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
37423742
void printFunctionExtInfo(AnyFunctionType::ExtInfo info) {
37433743
if (Options.SkipAttributes)
37443744
return;
3745-
if (info.isAutoClosure()) {
3746-
if (info.isNoEscape())
3747-
Printer << "@autoclosure ";
3748-
else
3749-
Printer << "@autoclosure @escaping ";
3750-
} else if (inParameterPrinting) {
3751-
if (!info.isNoEscape()) {
3752-
Printer << "@escaping ";
3753-
}
3754-
}
3745+
3746+
if (info.isAutoClosure())
3747+
Printer << "@autoclosure ";
3748+
if (inParameterPrinting && !info.isNoEscape())
3749+
Printer << "@escaping ";
37553750

37563751
if (Options.PrintFunctionRepresentationAttrs) {
37573752
// TODO: coalesce into a single convention attribute.

lib/AST/TypeRepr.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,8 @@ void AttributedTypeRepr::printAttrs(llvm::raw_ostream &OS) const {
276276
void AttributedTypeRepr::printAttrs(ASTPrinter &Printer) const {
277277
const TypeAttributes &Attrs = getAttrs();
278278

279-
if (Attrs.isDeprecatedAutoclosureEscaping) {
280-
// Deprecated:
281-
Printer << "@autoclosure(escaping) ";
282-
} else {
283-
if (Attrs.has(TAK_autoclosure)) Printer << "@autoclosure ";
284-
if (Attrs.has(TAK_escaping)) Printer << "@escaping ";
285-
}
279+
if (Attrs.has(TAK_autoclosure)) Printer << "@autoclosure ";
280+
if (Attrs.has(TAK_escaping)) Printer << "@escaping ";
286281

287282
if (Attrs.has(TAK_thin)) Printer << "@thin ";
288283
if (Attrs.has(TAK_thick)) Printer << "@thick ";

lib/Parse/ParseDecl.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,8 +1512,6 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, bool justChecking) {
15121512
case TAK_autoclosure:
15131513
// Handle @autoclosure(escaping)
15141514
if (isAutoclosureEscaping) {
1515-
Attributes.isDeprecatedAutoclosureEscaping = true;
1516-
15171515
// @noescape @autoclosure(escaping) makes no sense.
15181516
if (Attributes.has(TAK_noescape)) {
15191517
diagnose(Loc, diag::attr_noescape_conflicts_escaping_autoclosure);
@@ -1522,27 +1520,24 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, bool justChecking) {
15221520
.fixItReplace({Loc, autoclosureEscapingRightParenLoc},
15231521
"@autoclosure @escaping ");
15241522
}
1523+
Attributes.setAttr(TAK_escaping, Loc);
15251524
} else if (Attributes.has(TAK_noescape)) {
15261525
diagnose(Loc, diag::attr_noescape_implied_by_autoclosure);
15271526
}
15281527
break;
15291528

15301529
case TAK_noescape:
1531-
// You can't specify @noescape and @autoclosure(escaping) together, and
1532-
// @noescape after @autoclosure is redundant.
1533-
if (Attributes.has(TAK_autoclosure) &&
1534-
Attributes.isDeprecatedAutoclosureEscaping) {
1535-
diagnose(Loc, diag::attr_noescape_conflicts_escaping_autoclosure);
1536-
return false;
1537-
} else if (Attributes.has(TAK_autoclosure)) {
1538-
diagnose(Loc, diag::attr_noescape_implied_by_autoclosure);
1539-
}
15401530
// You can't specify @noescape and @escaping together.
15411531
if (Attributes.has(TAK_escaping)) {
15421532
diagnose(Loc, diag::attr_escaping_conflicts_noescape);
15431533
return false;
15441534
}
15451535

1536+
// @noescape after @autoclosure is redundant.
1537+
if (Attributes.has(TAK_autoclosure)) {
1538+
diagnose(Loc, diag::attr_noescape_implied_by_autoclosure);
1539+
}
1540+
15461541
// @noescape is deprecated and no longer used
15471542
diagnose(Loc, diag::attr_noescape_deprecated)
15481543
.fixItRemove({Attributes.AtLoc,Loc});

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,8 +1889,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
18891889
}
18901890

18911891
bool defaultNoEscape = false;
1892-
if (isFunctionParam && !attrs.has(TAK_escaping) &&
1893-
!attrs.isDeprecatedAutoclosureEscaping) {
1892+
if (isFunctionParam && !attrs.has(TAK_escaping)) {
18941893
defaultNoEscape = isDefaultNoEscapeContext(DC);
18951894
}
18961895

test/attr/attr_autoclosure.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct AutoclosureEscapeTest {
7474
func func10(@autoclosure(escaping _: () -> ()) { } // expected-error{{expected ')' in @autoclosure}}
7575
// expected-note@-1{{to match this opening '('}}
7676
77-
func func11(_: @autoclosure(escaping) @noescape () -> ()) { } // expected-error{{@noescape conflicts with @autoclosure(escaping)}}
77+
func func11(_: @autoclosure(escaping) @noescape () -> ()) { } // expected-error{{@escaping conflicts with @noescape}}
7878
// expected-warning@-1{{@autoclosure(escaping) is deprecated; use @autoclosure @escaping instead}} {{17-38=@autoclosure @escaping }}
7979

8080
class Super {

test/decl/overload.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ func throwsFunc(code: Int) throws { } // expected-error{{invalid redeclaration o
226226
func throwsFuncParam(_ fn: () throws -> ()) { }
227227
func throwsFuncParam(_ fn: () -> ()) { }
228228

229-
// @noescape
230-
func noescape(x: (Int) -> Int) { } // expected-note{{previously declared}}
231-
func noescape(x: (Int) -> Int) { } // expected-error{{invalid redeclaration of 'noescape(x:)'}}
229+
// @escaping
230+
func escaping(x: @escaping (Int) -> Int) { } // expected-note{{previously declared}}
231+
func escaping(x: (Int) -> Int) { } // expected-error{{invalid redeclaration of 'escaping(x:)'}}
232232

233233
// @autoclosure
234234
func autoclosure(f: () -> Int) { }

0 commit comments

Comments
 (0)