Skip to content

Commit f5e407e

Browse files
committed
[Concurrency] Add basic tests for function isolation extraction.
1 parent 7e0f534 commit f5e407e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

test/Concurrency/isolated_any.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,16 @@ func extractFunctionIsolation(_ fn: @isolated(any) @escaping () async -> Void) {
8383
let _: (any Actor)? = extractIsolation(myActor.asyncThrowsActorFunction)
8484
let _: (any Actor)? = extractIsolation(myActor.actorFunctionWithArgs(value:))
8585
}
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+
}

test/SILGen/isolated_any.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,17 @@ extension MyActor {
452452
func testEraseAsyncActorIsolatedPartialApplication(a: MyActor) {
453453
takeAsyncIsolatedAny(fn: a.asyncAction)
454454
}
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+
}

0 commit comments

Comments
 (0)