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