File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -83,3 +83,16 @@ func extractFunctionIsolation(_ fn: @isolated(any) @escaping () async -> Void) {
83
83
let _: ( any Actor ) ? = extractIsolation ( myActor. asyncThrowsActorFunction)
84
84
let _: ( any Actor ) ? = extractIsolation ( myActor. actorFunctionWithArgs ( value: ) )
85
85
}
86
+
87
+ func extractFunctionIsolationExpr(
88
+ _ fn1: @isolated ( any) @escaping ( ) async -> Void ,
89
+ _ fn2: @isolated ( any) @escaping ( Int , String ) -> Bool
90
+ ) {
91
+ let _: ( any Actor ) ? = fn1. isolation
92
+ let _: ( any Actor ) ? = fn2. isolation
93
+
94
+ // Only `@isolated(any)` functions have `.isolation`
95
+ let myActor = A ( )
96
+ let _: ( any Actor ) ? = myActor. asyncActorFunction. isolation // expected-error {{value of type '@Sendable () async -> ()' has no member 'isolation'}}
97
+ let _: ( any Actor ) ? = globalNonisolatedFunction. isolation // expected-error {{value of type '@Sendable () -> ()' has no member 'isolation'}}
98
+ }
Original file line number Diff line number Diff line change @@ -452,3 +452,17 @@ extension MyActor {
452
452
func testEraseAsyncActorIsolatedPartialApplication( a: MyActor ) {
453
453
takeAsyncIsolatedAny ( fn: a. asyncAction)
454
454
}
455
+
456
+ /*-- Isolation extraction --*/
457
+
458
+ // CHECK-LABEL: sil hidden [ossa] @$s4test16extractIsolation2fnScA_pSgyyYAc_tF
459
+ // CHECK: [[FN:%.*]] = copy_value %0 : $@isolated(any) @callee_guaranteed () -> ()
460
+ // CHECK-NEXT: [[FN_BORROW:%.*]] = begin_borrow [[FN]] : $@isolated(any) @callee_guaranteed () -> ()
461
+ // CHECK-NEXT: [[ISOLATION:%.*]] = function_extract_isolation [[FN_BORROW]] : $@isolated(any) @callee_guaranteed () -> ()
462
+ // CHECK-NEXT: [[RESULT:%.*]] = copy_value [[ISOLATION]] : $Optional<any Actor>
463
+ // CHECK-NEXT: end_borrow [[FN_BORROW]] : $@isolated(any) @callee_guaranteed () -> ()
464
+ // CHECK-NEXT: destroy_value [[FN]] : $@isolated(any) @callee_guaranteed () -> ()
465
+ // CHECK-NEXT: return [[RESULT]] : $Optional<any Actor>
466
+ func extractIsolation( fn: @escaping @isolated ( any) ( ) -> Void ) -> ( any Actor ) ? {
467
+ fn. isolation
468
+ }
You can’t perform that action at this time.
0 commit comments