mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The `coro.end.async` intrinsic allow specifying a function that is to be
tail-called as the last thing before returning.
LLVM lowering will inline the `must-tail-call` function argument to
`coro.end.async`. This `must-tail-call` function can contain a
`musttail` call.
```
define @my_must_tail_call_func(void (*)(i64) %fnptr, i64 %args) {
musttail call void %fnptr(i64 %args)
ret void
}
define @async_func() {
...
coro.end.async(..., @my_must_tail_call_func, %return_continuation, i64 %args)
unreachable
}
```
15 lines
419 B
Swift
15 lines
419 B
Swift
// RUN: %target-swift-frontend -primary-file %s -g -emit-ir -enable-experimental-concurrency -disable-llvm-optzns -disable-swift-specific-llvm-optzns | %FileCheck %s
|
|
// REQUIRES: concurrency
|
|
|
|
// CHECK: call i1 (i8*, i1, ...) @llvm.coro.end.async
|
|
func foo() async -> Never {
|
|
await bar()
|
|
fatalError()
|
|
}
|
|
|
|
// CHECK: call i1 (i8*, i1, ...) @llvm.coro.end.async
|
|
func bar() async -> Never {
|
|
await foo()
|
|
fatalError()
|
|
}
|