|
| 1 | +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -Xllvm -verify-continue-on-failure=true -parse-sil %s -emit-sil -I %t -L %t -o /dev/null 2>&1 | %FileCheck %s |
| 2 | +// REQUIRES: asserts |
| 3 | +// REQUIRES: concurrency |
| 4 | + |
| 5 | +import Swift |
| 6 | +import Builtin |
| 7 | +import _Concurrency |
| 8 | + |
| 9 | +sil @create_error : $@convention(thin) () -> @owned Error |
| 10 | + |
| 11 | +sil [ossa] @asynccallee1 : $@async @convention(thin) () -> () { |
| 12 | +bb0: |
| 13 | + %result = tuple() |
| 14 | + return %result : $() |
| 15 | +} |
| 16 | + |
| 17 | +sil [ossa] @asynccallee2 : $@async @convention(thin) () -> ((), @error Error) { |
| 18 | +bb0: |
| 19 | + cond_br undef, bb1, bb2 |
| 20 | +bb1: |
| 21 | + %result = tuple() |
| 22 | + return %result : $() |
| 23 | +bb2: |
| 24 | + %0 = function_ref @create_error : $@convention(thin) () -> @owned Error |
| 25 | + %1 = apply %0() : $@convention(thin) () -> @owned Error |
| 26 | + throw %1 : $Error |
| 27 | +} |
| 28 | + |
| 29 | +// CHECK-NOT: Function: 'async_apply_caller' |
| 30 | +sil [ossa] @async_apply_caller : $@async @convention(thin) () -> () { |
| 31 | +bb0: |
| 32 | + %call1 = function_ref @asynccallee1 : $@async @convention(thin) () -> () |
| 33 | + %callres1 = apply %call1() : $@async @convention(thin) () -> () |
| 34 | + %result = tuple() |
| 35 | + return %result : $() |
| 36 | +} |
| 37 | + |
| 38 | +// CHECK-LABEL: Begin Error in function nonasync_apply_caller |
| 39 | +// CHECK: SIL verification failed: cannot call an async function from a non-async function: !fnType->isAsync() || FRI->getFunction()->isAsync() |
| 40 | +// CHECK: Verifying instruction: |
| 41 | +// CHECK: -> // function_ref asynccallee1 |
| 42 | +// CHECK: %0 = function_ref @asynccallee1 : $@convention(thin) @async () -> () // user: %1 |
| 43 | +// CHECK: %1 = apply %0() : $@convention(thin) @async () -> () |
| 44 | +// CHECK-LABEL: End Error in function nonasync_apply_caller |
| 45 | +sil [ossa] @nonasync_apply_caller : $@convention(thin) () -> () { |
| 46 | +bb0: |
| 47 | + %call = function_ref @asynccallee1 : $@async @convention(thin) () -> () |
| 48 | + %callres = apply %call() : $@async @convention(thin) () -> () |
| 49 | + %result = tuple() |
| 50 | + return %result : $() |
| 51 | +} |
| 52 | + |
| 53 | +// CHECK-NOT: Function: 'async_try_apply_caller' |
| 54 | +sil [ossa] @async_try_apply_caller : $@async @convention(thin) () -> () { |
| 55 | +bb0: |
| 56 | + %call1 = function_ref @asynccallee2 : $@async @convention(thin) () -> ((), @error Error) |
| 57 | + try_apply %call1() : $@async @convention(thin) () -> ((), @error Error), normal bb1, error bb2 |
| 58 | +bb1(%result : $()): |
| 59 | + return %result : $() |
| 60 | +bb2(%result_error : $Error): |
| 61 | + unreachable |
| 62 | +} |
| 63 | + |
| 64 | +// CHECK-LABEL: Begin Error in function nonasync_try_apply_caller |
| 65 | +// CHECK: SIL verification failed: cannot call an async function from a non-async function: !fnType->isAsync() || FRI->getFunction()->isAsync() |
| 66 | +// CHECK: Verifying instruction: |
| 67 | +// CHECK: -> // function_ref asynccallee2 |
| 68 | +// CHECK: %0 = function_ref @asynccallee2 : $@convention(thin) @async () -> ((), @error Error) // user: %1 |
| 69 | +// CHECK: try_apply %0() : $@convention(thin) @async () -> ((), @error Error), normal bb1, error bb2 // id: %1 |
| 70 | +// CHECK-LABEL: End Error in function nonasync_try_apply_caller |
| 71 | +sil [ossa] @nonasync_try_apply_caller : $@convention(thin) () -> () { |
| 72 | +bb0: |
| 73 | + %call1 = function_ref @asynccallee2 : $@async @convention(thin) () -> ((), @error Error) |
| 74 | + try_apply %call1() : $@async @convention(thin) () -> ((), @error Error), normal bb1, error bb2 |
| 75 | +bb1(%result : $()): |
| 76 | + return %result : $() |
| 77 | +bb2(%result_error : $Error): |
| 78 | + unreachable |
| 79 | +} |
| 80 | + |
| 81 | +// CHECK-NOT: Function: 'async_partial_apply_caller' |
| 82 | +sil [ossa] @async_partial_apply_caller : $@async @convention(thin) () -> @owned @async @callee_owned () -> () { |
| 83 | +bb0: |
| 84 | + %1 = function_ref @asynccallee1 : $@async @convention(thin) () -> () |
| 85 | + %2 = partial_apply %1() : $@async @convention(thin) () -> () |
| 86 | + return %2 : $@async @callee_owned () -> () |
| 87 | +} |
| 88 | + |
| 89 | +// CHECK-LABEL: Begin Error in function nonasync_partial_apply_caller |
| 90 | +// CHECK: SIL verification failed: cannot call an async function from a non-async function: !fnType->isAsync() || FRI->getFunction()->isAsync() |
| 91 | +// CHECK: Verifying instruction: |
| 92 | +// CHECK: -> // function_ref asynccallee1 |
| 93 | +// CHECK: %0 = function_ref @asynccallee1 : $@convention(thin) @async () -> () // user: %1 |
| 94 | +// CHECK: %1 = partial_apply %0() : $@convention(thin) @async () -> () // user: %2 |
| 95 | +// CHECK-LABEL: End Error in function nonasync_partial_apply_caller |
| 96 | +sil [ossa] @nonasync_partial_apply_caller : $@convention(thin) () -> @owned @async @callee_owned () -> () { |
| 97 | +bb0: |
| 98 | + %1 = function_ref @asynccallee1 : $@async @convention(thin) () -> () |
| 99 | + %2 = partial_apply %1() : $@async @convention(thin) () -> () |
| 100 | + return %2 : $@async @callee_owned () -> () |
| 101 | +} |
| 102 | + |
| 103 | +protocol P { |
| 104 | + func printMe() async -> Int64 |
| 105 | +} |
| 106 | + |
| 107 | +// CHECK-NOT: Function: 'async_witness_method_caller' |
| 108 | +sil hidden @async_witness_method_caller : $@async @convention(thin) <T where T : P> (@in_guaranteed T) -> Int64 { |
| 109 | +bb0(%t : $*T): |
| 110 | + %method = witness_method $T, #P.printMe : <Self where Self : P> (Self) -> () async -> Int64 : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 |
| 111 | + %result = apply %method<T>(%t) : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 |
| 112 | + return %result : $Int64 |
| 113 | +} |
| 114 | + |
| 115 | +// CHECK-LABEL: Begin Error in function nonasync_witness_method_caller |
| 116 | +// CHECK: SIL verification failed: cannot call an async function from a non-async function: !methodType->isAsync() || AMI->getFunction()->isAsync() |
| 117 | +// CHECK: Verifying instruction: |
| 118 | +// CHECK: -> %1 = witness_method $T, #P.printMe : <Self where Self : P> (Self) -> () async -> Int64 : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 // user: %2 |
| 119 | +// CHECK: %2 = apply %1<T>(%0) : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 // user: %3 |
| 120 | +// CHECK-LABEL: End Error in function nonasync_witness_method_caller |
| 121 | +sil hidden @nonasync_witness_method_caller : $@convention(thin) <T where T : P> (@in_guaranteed T) -> Int64 { |
| 122 | +bb0(%t : $*T): |
| 123 | + %method = witness_method $T, #P.printMe : <Self where Self : P> (Self) -> () async -> Int64 : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 |
| 124 | + %result = apply %method<T>(%t) : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 |
| 125 | + return %result : $Int64 |
| 126 | +} |
| 127 | + |
| 128 | +class S { |
| 129 | + func method(_ int: Int64) async |
| 130 | + deinit |
| 131 | + init() |
| 132 | +} |
| 133 | + |
| 134 | +// CHECK-NOT: Function: 'async_class_method_caller' |
| 135 | +sil hidden @async_class_method_caller : $@async @convention(thin) (Int64, S) -> () { |
| 136 | +bb0(%int : $Int64, %instance : $S): |
| 137 | + %func = class_method %instance : $S, #S.method : (S) -> (Int64) async -> (), $@convention(method) @async (Int64, @guaranteed S) -> () |
| 138 | + %result = apply %func(%int, %instance) : $@convention(method) @async (Int64, @guaranteed S) -> () |
| 139 | + %res = tuple () |
| 140 | + return %res : $() |
| 141 | +} |
| 142 | + |
| 143 | +// CHECK-LABEL: Begin Error in function nonasync_class_method_caller |
| 144 | +// CHECK: SIL verification failed: cannot call an async function from a non-async function: !methodType->isAsync() || CMI->getFunction()->isAsync() |
| 145 | +// CHECK: Verifying instruction: |
| 146 | +// CHECK: %1 = argument of bb0 : $S // users: %3, %2 |
| 147 | +// CHECK: -> %2 = class_method %1 : $S, #S.method : (S) -> (Int64) async -> (), $@convention(method) @async (Int64, @guaranteed S) -> () // user: %3 |
| 148 | +// CHECK: %3 = apply %2(%0, %1) : $@convention(method) @async (Int64, @guaranteed S) -> () |
| 149 | +// CHECK-LABEL: End Error in function nonasync_class_method_caller |
| 150 | +sil hidden @nonasync_class_method_caller : $@convention(thin) (Int64, S) -> () { |
| 151 | +bb0(%int : $Int64, %instance : $S): |
| 152 | + %func = class_method %instance : $S, #S.method : (S) -> (Int64) async -> (), $@convention(method) @async (Int64, @guaranteed S) -> () |
| 153 | + %result = apply %func(%int, %instance) : $@convention(method) @async (Int64, @guaranteed S) -> () |
| 154 | + %res = tuple () |
| 155 | + return %res : $() |
| 156 | +} |
0 commit comments