|
| 1 | +// RUN: %target-swift-frontend -emit-silgen %s -disable-availability-checking | %FileCheck %s |
| 2 | + |
| 3 | +// REQUIRES: concurrency |
| 4 | + |
| 5 | +class NotSendable {} |
| 6 | + |
| 7 | +func callee(_ ns: NotSendable) {} |
| 8 | + |
| 9 | +actor MyActor { |
| 10 | + func isolatedToSelf(ns: NotSendable) { |
| 11 | + // CHECK-LABEL: sil private [ossa] @$s24local_function_isolation7MyActorC14isolatedToSelf2nsyAA11NotSendableC_tF08implicitH7CaptureL_yyYaF : $@convention(thin) @async (@guaranteed NotSendable, @sil_isolated @guaranteed MyActor) -> () { |
| 12 | + func implicitSelfCapture() async { |
| 13 | + |
| 14 | + // CHECK: [[COPY:%.*]] = copy_value %1 : $MyActor |
| 15 | + // CHECK-NEXT: [[BORROW:%.*]] = begin_borrow [[COPY]] : $MyActor |
| 16 | + // CHECK-NEXT: hop_to_executor [[BORROW]] : $MyActor |
| 17 | + |
| 18 | + // CHECK: [[FN:%.*]] = function_ref @$s24local_function_isolation4testyyYaF : $@convention(thin) @async () -> () |
| 19 | + // CHECK-NEXT: apply [[FN]]() : $@convention(thin) @async () -> () |
| 20 | + await test() |
| 21 | + |
| 22 | + // CHECK: hop_to_executor [[BORROW]] : $MyActor |
| 23 | + // CHECK: [[FN:%.*]] = function_ref @$s24local_function_isolation6calleeyyAA11NotSendableCF : $@convention(thin) (@guaranteed NotSendable) -> () |
| 24 | + // CHECK-NEXT: apply [[FN]](%0) : $@convention(thin) (@guaranteed NotSendable) -> () |
| 25 | + |
| 26 | + // we need to hop back to 'self' here |
| 27 | + callee(ns) |
| 28 | + |
| 29 | + // CHECK: end_borrow [[BORROW]] : $MyActor |
| 30 | + // CHECK-NEXT: destroy_value [[COPY]] : $MyActor |
| 31 | + } |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func f(isolation: isolated MyActor, ns: NotSendable) { |
| 36 | + // CHECK-LABEL: sil private [ossa] @$s24local_function_isolation1f0C02nsyAA7MyActorCYi_AA11NotSendableCtF23implicitIsolatedCaptureL_yyYaF : $@convention(thin) @async (@guaranteed NotSendable, @sil_isolated @guaranteed MyActor) -> () { |
| 37 | + func implicitIsolatedCapture() async { |
| 38 | + |
| 39 | + // CHECK: [[COPY:%.*]] = copy_value %1 : $MyActor |
| 40 | + // CHECK-NEXT: [[BORROW:%.*]] = begin_borrow [[COPY]] : $MyActor |
| 41 | + // CHECK-NEXT: hop_to_executor [[BORROW]] : $MyActor |
| 42 | + |
| 43 | + // CHECK: [[FN:%.*]] = function_ref @$s24local_function_isolation4testyyYaF : $@convention(thin) @async () -> () |
| 44 | + // CHECK-NEXT: apply [[FN]]() : $@convention(thin) @async () -> () |
| 45 | + await test() |
| 46 | + |
| 47 | + // we need to hop back to 'isolation' here |
| 48 | + callee(ns) |
| 49 | + |
| 50 | + // CHECK: end_borrow [[BORROW]] : $MyActor |
| 51 | + // CHECK-NEXT: destroy_value [[COPY]] : $MyActor |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +func test() async {} |
0 commit comments