mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Fixes Embedded Swift concurrency tests that crash with this stack trace:
```
Error: Trap: indirect call type mismatch, expected FunctionType(parameters: [WasmTypes.ValueType.i32, WasmTypes.ValueType.i32], results: []), got FunctionType(parameters: [W
asmTypes.ValueType.i32, WasmTypes.ValueType.i32, WasmTypes.ValueType.i32], results: [WasmTypes.ValueType.i32])
0: swift::AsyncTask::completeFuture(swift::AsyncContext*)
1: completeTaskAndRelease(swift::AsyncContext*, swift::SwiftError*)
2: completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*)
3: $exIeAgHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRyt_Tg5TATQ0_
4: $exIeAgHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRyt_Tg5TQ0_
5: $e1a4MainV4mainyyYaFZyyYacfU_TATQ0_
6: $e1a4MainV4mainyyYaFZyyYacfU_TY1_
7: swift_task_switch
8: $e1a4MainV4mainyyYaFZyyYacfU_TQ0_
9: $e1a4testSiyYaFTY0_
10: swift::runJobInEstablishedExecutorContext(swift::Job*)
11: swift_job_run
12: $es19CooperativeExecutorC8runUntilyySbyXEKF
13: $es19CooperativeExecutorCs07RunLoopB0ssACP3runyyKFTW
14: swift_task_asyncMainDrainQueueImpl
15: swift_task_asyncMainDrainQueue
16: main
17: __main_void
18: _start
19: unknown
```
54 lines
1.2 KiB
Swift
54 lines
1.2 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library %s -c -o %t/a.o
|
|
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%module-target-triple %target-clang-resource-dir-opt -lswift_Concurrency %target-swift-default-executor-opt -dead_strip
|
|
// RUN: %target-run %t/a.out | %FileCheck %s
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: swift_in_compiler
|
|
// REQUIRES: optimized_stdlib
|
|
// REQUIRES: OS=macosx || OS=wasip1
|
|
// REQUIRES: swift_feature_Embedded
|
|
|
|
import _Concurrency
|
|
|
|
func fib(_ n: Int) -> Int {
|
|
var first = 0
|
|
var second = 1
|
|
for _ in 0..<n {
|
|
let temp = first
|
|
first = second
|
|
second = temp + first
|
|
}
|
|
return first
|
|
}
|
|
|
|
@available(SwiftStdlib 5.1, *)
|
|
func asyncFib(_ n: Int) async -> Int {
|
|
if n == 0 || n == 1 {
|
|
return n
|
|
}
|
|
|
|
async let first = await asyncFib(n-2)
|
|
async let second = await asyncFib(n-1)
|
|
|
|
let result = await first + second
|
|
|
|
return result
|
|
}
|
|
|
|
@available(SwiftStdlib 5.1, *)
|
|
func runFibonacci(_ n: Int) async {
|
|
let result = await asyncFib(n)
|
|
|
|
print("")
|
|
print(result == fib(n) ? "OK!" : "???")
|
|
// CHECK: OK!
|
|
}
|
|
|
|
@available(SwiftStdlib 5.1, *)
|
|
@main struct Main {
|
|
static func main() async {
|
|
await runFibonacci(10)
|
|
}
|
|
}
|