|
| 1 | +// RUN: %target-swift-frontend -emit-silgen %s -module-name test -swift-version 5 -enable-experimental-concurrency | %FileCheck %s |
| 2 | +// REQUIRES: concurrency |
| 3 | + |
| 4 | + |
| 5 | +actor class MyActor { |
| 6 | + |
| 7 | + private var p: Int |
| 8 | + |
| 9 | + // CHECK-LABEL: sil hidden [ossa] @$s4test7MyActorC6calleeyySiYF : $@convention(method) @async (Int, @guaranteed MyActor) -> () { |
| 10 | + // CHECK-NOT: hop_to_executor |
| 11 | + // CHECK: } // end sil function '$s4test7MyActorC6calleeyySiYF' |
| 12 | + @actorIndependent |
| 13 | + func callee(_ x: Int) async { |
| 14 | + print(x) |
| 15 | + } |
| 16 | + |
| 17 | + // CHECK-LABEL: sil hidden [ossa] @$s4test7MyActorC14throwingCalleeyySiYKF : $@convention(method) @async (Int, @guaranteed MyActor) -> @error Error { |
| 18 | + // CHECK-NOT: hop_to_executor |
| 19 | + // CHECK: } // end sil function '$s4test7MyActorC14throwingCalleeyySiYKF' |
| 20 | + @actorIndependent |
| 21 | + func throwingCallee(_ x: Int) async throws { |
| 22 | + print(x) |
| 23 | + } |
| 24 | + |
| 25 | + // CHECK-LABEL: sil hidden [ossa] @$s4test7MyActorC0A13AsyncFunctionyyYKF : $@convention(method) @async (@guaranteed MyActor) -> @error Error { |
| 26 | + // CHECK: hop_to_executor %0 : $MyActor |
| 27 | + // CHECK: = apply {{.*}} : $@convention(method) @async (Int, @guaranteed MyActor) -> () |
| 28 | + // CHECK-NEXT: hop_to_executor %0 : $MyActor |
| 29 | + // CHECK: try_apply {{.*}}, normal bb1, error bb2 |
| 30 | + // CHECK: bb1({{.*}}): |
| 31 | + // CHECK-NEXT: hop_to_executor %0 : $MyActor |
| 32 | + // CHECK: bb2({{.*}}): |
| 33 | + // CHECK-NEXT: hop_to_executor %0 : $MyActor |
| 34 | + // CHECK: } // end sil function '$s4test7MyActorC0A13AsyncFunctionyyYKF' |
| 35 | + func testAsyncFunction() async throws { |
| 36 | + await callee(p) |
| 37 | + try await throwingCallee(p) |
| 38 | + } |
| 39 | + |
| 40 | + // CHECK-LABEL: sil hidden [ossa] @$s4test7MyActorC0A22ConsumingAsyncFunctionyyYF : $@convention(method) @async (@owned MyActor) -> () { |
| 41 | + // CHECK: [[BORROWED_SELF:%[0-9]+]] = begin_borrow %0 : $MyActor |
| 42 | + // CHECK: hop_to_executor [[BORROWED_SELF]] : $MyActor |
| 43 | + // CHECK: = apply {{.*}} : $@convention(method) @async (Int, @guaranteed MyActor) -> () |
| 44 | + // CHECK-NEXT: hop_to_executor [[BORROWED_SELF]] : $MyActor |
| 45 | + // CHECK: } // end sil function '$s4test7MyActorC0A22ConsumingAsyncFunctionyyYF' |
| 46 | + __consuming func testConsumingAsyncFunction() async { |
| 47 | + await callee(p) |
| 48 | + } |
| 49 | + |
| 50 | + init() { |
| 51 | + p = 27 |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +@globalActor |
| 56 | +struct GlobalActor { |
| 57 | + static var shared: MyActor = MyActor() |
| 58 | +} |
| 59 | + |
| 60 | +// CHECK-LABEL: sil hidden [ossa] @$s4test0A11GlobalActoryyYF : $@convention(thin) () -> () { |
| 61 | +// CHECK: [[F:%[0-9]+]] = function_ref @$s4test11GlobalActorV6sharedAA02MyC0Cvau : $@convention(thin) () -> Builtin.RawPointer |
| 62 | +// CHECK: [[P:%[0-9]+]] = apply [[F]]() : $@convention(thin) () -> Builtin.RawPointer |
| 63 | +// CHECK: [[A:%[0-9]+]] = pointer_to_address %2 : $Builtin.RawPointer to [strict] $*MyActor |
| 64 | +// CHECK: [[ACC:%[0-9]+]] = begin_access [read] [dynamic] [[A]] : $*MyActor |
| 65 | +// CHECK: [[L:%[0-9]+]] = load [copy] [[ACC]] : $*MyActor |
| 66 | +// CHECK: [[B:%[0-9]+]] = begin_borrow [[L]] : $MyActor |
| 67 | +// CHECK: hop_to_executor [[B]] : $MyActor |
| 68 | +// CHECK: } // end sil function '$s4test0A11GlobalActoryyYF' |
| 69 | +@GlobalActor |
| 70 | +func testGlobalActor() async { |
| 71 | +} |
| 72 | + |
| 73 | +@globalActor |
| 74 | +struct GenericGlobalActorWithGetter<T> { |
| 75 | + static var shared: MyActor { return MyActor() } |
| 76 | +} |
| 77 | + |
| 78 | +// CHECK-LABEL: sil hidden [ossa] @$s4test0A28GenericGlobalActorWithGetteryyYF : $@convention(thin) () -> () { |
| 79 | +// CHECK: [[MT:%[0-9]+]] = metatype $@thin GenericGlobalActorWithGetter<Int>.Type |
| 80 | +// CHECK: [[F:%[0-9]+]] = function_ref @$s4test28GenericGlobalActorWithGetterV6sharedAA02MyD0CvgZ : $@convention(method) <τ_0_0> (@thin GenericGlobalActorWithGetter<τ_0_0>.Type) -> @owned MyActor |
| 81 | +// CHECK: [[A:%[0-9]+]] = apply [[F]]<Int>([[MT]]) : $@convention(method) <τ_0_0> (@thin GenericGlobalActorWithGetter<τ_0_0>.Type) -> @owned MyActor |
| 82 | +// CHECK: [[B:%[0-9]+]] = begin_borrow [[A]] : $MyActor |
| 83 | +// CHECK: hop_to_executor [[B]] : $MyActor |
| 84 | +// CHECK: } // end sil function '$s4test0A28GenericGlobalActorWithGetteryyYF' |
| 85 | +@GenericGlobalActorWithGetter<Int> |
| 86 | +func testGenericGlobalActorWithGetter() async { |
| 87 | +} |
| 88 | + |
0 commit comments