Skip to content

Commit 8f23048

Browse files
authored
Merge pull request #17097 from brentdax/noescape-from-the-ast-dump-scrape
2 parents 0b33a69 + fb79b8f commit 8f23048

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,11 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
23002300
OS << " ";
23012301
E->getCaptureInfo().print(PrintWithColorRAII(OS, CapturesColor).getOS());
23022302
}
2303+
// Printing a function type doesn't indicate whether it's escaping because it doesn't
2304+
// matter in 99% of contexts. AbstractClosureExpr nodes are one of the only exceptions.
2305+
if (auto Ty = GetTypeOfExpr(E))
2306+
if (!Ty->getAs<AnyFunctionType>()->getExtInfo().isNoEscape())
2307+
PrintWithColorRAII(OS, ClosureModifierColor) << " escaping";
23032308

23042309
return OS;
23052310
}

test/Driver/dump-parse.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,16 @@ func generic<T: Hashable>(_: T) {}
6161
// CHECK-AST: (pattern_binding_decl
6262
// CHECK-AST: (declref_expr type='(Int) -> ()' location={{.*}} range={{.*}} decl=main.(file).generic@{{.*}} [with (substitution_map generic_signature=<T where T : Hashable> (substitution T -> Int))] function_ref=unapplied))
6363
let _: (Int) -> () = generic
64+
65+
// Closures should be marked as escaping or not.
66+
func escaping(_: @escaping (Int) -> Int) {}
67+
escaping({ $0 })
68+
// CHECK-AST: (declref_expr type='(@escaping (Int) -> Int) -> ()'
69+
// CHECK-AST-NEXT: (paren_expr
70+
// CHECK-AST-NEXT: (closure_expr type='(Int) -> Int' {{.*}} discriminator=0 escaping single-expression
71+
72+
func nonescaping(_: (Int) -> Int) {}
73+
nonescaping({ $0 })
74+
// CHECK-AST: (declref_expr type='((Int) -> Int) -> ()'
75+
// CHECK-AST-NEXT: (paren_expr
76+
// CHECK-AST-NEXT: (closure_expr type='(Int) -> Int' {{.*}} discriminator=1 single-expression

test/expr/capture/generic_params.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ func doSomething<T>(_ t: T) {}
66

77
func outerGeneric<T>(t: T, x: AnyObject) {
88
// Simple case -- closure captures outer generic parameter
9-
// CHECK: closure_expr type='() -> ()' {{.*}} discriminator=0 captures=(<generic> t) single-expression
9+
// CHECK: closure_expr type='() -> ()' {{.*}} discriminator=0 captures=(<generic> t) escaping single-expression
1010
_ = { doSomething(t) }
1111

1212
// Special case -- closure does not capture outer generic parameters
13-
// CHECK: closure_expr type='() -> ()' {{.*}} discriminator=1 captures=(x) single-expression
13+
// CHECK: closure_expr type='() -> ()' {{.*}} discriminator=1 captures=(x) escaping single-expression
1414
_ = { doSomething(x) }
1515

1616
// Special case -- closure captures outer generic parameter, but it does not

0 commit comments

Comments
 (0)