diff --git a/test/IRGen/async_wasm.swift b/test/IRGen/async_wasm.swift index 933bbe58afcb2..cd27584748d78 100644 --- a/test/IRGen/async_wasm.swift +++ b/test/IRGen/async_wasm.swift @@ -1,5 +1,5 @@ // RUN: %target-swift-frontend -primary-file %S/async.swift -enable-builtin-module -emit-ir -disable-availability-checking | %FileCheck %s --check-prefix=NOTAIL -// TODO(katei): %target-swift-frontend -primary-file %S/async.swift -enable-builtin-module -emit-ir -disable-availability-checking -Xcc -mtail-call | %FileCheck %s --check-prefix=TAIL +// RUN: %target-swift-frontend -primary-file %S/async.swift -enable-builtin-module -emit-ir -disable-availability-checking -Xcc -mtail-call | %FileCheck %s --check-prefix=TAIL // REQUIRES: concurrency && CPU=wasm32 @@ -11,3 +11,11 @@ // NOTAIL-NOT: @swift_task_alloc // NOTAIL-NOT: musttail call // NOTAIL: call swiftcc void @swift_task_future_wait_throwing(ptr {{.*}}, ptr {{.*}}, ptr {{.*}}, ptr {{.*}}, ptr {{.*}}) + +// TAIL: "$s5async1fyyYaF" +// TAIL: "$s5async1gyyYaKF" +// TAIL: "$s5async1hyyS2iYbXEF" + +// TAIL: define{{.*}} swifttailcc void @"$s5async8testThisyyBonYaF"(ptr swiftasync %0{{.*}} +// TAIL-NOT: @swift_task_alloc +// TAIL: musttail call swifttailcc void @swift_task_future_wait_throwing(ptr {{.*}}, ptr {{.*}}, ptr {{.*}}, ptr {{.*}}, ptr {{.*}}) diff --git a/test/IRGen/async_wasm_tailcall.swift b/test/IRGen/async_wasm_tailcall.swift new file mode 100644 index 0000000000000..b7bacc65ecaff --- /dev/null +++ b/test/IRGen/async_wasm_tailcall.swift @@ -0,0 +1,34 @@ +// Verify that async coroutine splitting on Wasm uses musttail/return_call +// with the tail-call feature and regular calls without it. + +// IR-level checks: +// RUN: %target-swift-frontend %s -emit-ir -module-name test -disable-availability-checking | %FileCheck %s --check-prefix=NOTAIL +// RUN: %target-swift-frontend %s -emit-ir -module-name test -disable-availability-checking -Xcc -mtail-call | %FileCheck %s --check-prefix=TAIL + +// Assembly-level checks: +// RUN: %target-swift-frontend %s -S -module-name test -disable-availability-checking -Xcc -mtail-call | %FileCheck %s --check-prefix=TAIL-ASM +// RUN: %target-swift-frontend %s -S -module-name test -disable-availability-checking | %FileCheck %s --check-prefix=NOTAIL-ASM + +// REQUIRES: concurrency +// REQUIRES: CPU=wasm32 + +func callee() async -> Int { return 42 } + +public func caller() async -> Int { + return await callee() +} + +// Without -mtail-call: async functions use swiftcc, no musttail +// NOTAIL: define {{.*}}swiftcc void @"$s4test6callerSiyYaF"(ptr swiftasync +// NOTAIL-NOT: musttail call + +// With -mtail-call: async functions use swifttailcc with musttail +// TAIL: define {{.*}}swifttailcc void @"$s4test6callerSiyYaF"(ptr swiftasync +// TAIL: musttail call swifttailcc void + +// Assembly with -mtail-call: return_call Wasm instruction +// TAIL-ASM: return_call + +// Assembly without -mtail-call: no return_call Wasm instruction +// NOTAIL-ASM: .functype +// NOTAIL-ASM-NOT: return_call diff --git a/test/embedded/concurrency-tailcall.swift b/test/embedded/concurrency-tailcall.swift new file mode 100644 index 0000000000000..67857b4059fac --- /dev/null +++ b/test/embedded/concurrency-tailcall.swift @@ -0,0 +1,38 @@ +// Verify that embedded async coroutine splitting on Wasm uses +// musttail/return_call with the tail-call feature and regular calls without it. + +// IR-level checks: +// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -module-name test %s -emit-ir | %FileCheck %s --check-prefix=NOTAIL +// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -module-name test %s -emit-ir -Xcc -mtail-call | %FileCheck %s --check-prefix=TAIL + +// Assembly-level checks: +// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -module-name test %s -S -Xcc -mtail-call | %FileCheck %s --check-prefix=TAIL-ASM +// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -module-name test %s -S | %FileCheck %s --check-prefix=NOTAIL-ASM + +// REQUIRES: swift_in_compiler +// REQUIRES: optimized_stdlib +// REQUIRES: OS=wasip1 +// REQUIRES: swift_feature_Embedded + +import _Concurrency + +func callee() async -> Int { return 42 } + +public func caller() async -> Int { + return await callee() +} + +// Without -mtail-call: async functions use swiftcc, no musttail +// NOTAIL: define {{.*}}swiftcc void @"$e4test6callerSiyYaF"(ptr swiftasync +// NOTAIL-NOT: musttail call + +// With -mtail-call: async functions use swifttailcc with musttail +// TAIL: define {{.*}}swifttailcc void @"$e4test6callerSiyYaF"(ptr swiftasync +// TAIL: musttail call swifttailcc void + +// Assembly with -mtail-call: return_call Wasm instruction +// TAIL-ASM: return_call + +// Assembly without -mtail-call: no return_call Wasm instruction +// NOTAIL-ASM: .functype +// NOTAIL-ASM-NOT: return_call