File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -2300,6 +2300,11 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
2300
2300
OS << " " ;
2301
2301
E->getCaptureInfo ().print (PrintWithColorRAII (OS, CapturesColor).getOS ());
2302
2302
}
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" ;
2303
2308
2304
2309
return OS;
2305
2310
}
Original file line number Diff line number Diff line change @@ -61,3 +61,16 @@ func generic<T: Hashable>(_: T) {}
61
61
// CHECK-AST: (pattern_binding_decl
62
62
// 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))
63
63
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
Original file line number Diff line number Diff line change @@ -6,11 +6,11 @@ func doSomething<T>(_ t: T) {}
6
6
7
7
func outerGeneric< T> ( t: T , x: AnyObject ) {
8
8
// 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
10
10
_ = { doSomething ( t) }
11
11
12
12
// 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
14
14
_ = { doSomething ( x) }
15
15
16
16
// Special case -- closure captures outer generic parameter, but it does not
You can’t perform that action at this time.
0 commit comments