Files
swift-mirror/test/IRGen/async/async_calls_verifier.sil
2022-08-18 01:15:12 -04:00

151 lines
7.0 KiB
Plaintext

// 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 : $()
}