Skip to content

Commit f46ad6c

Browse files
committed
[Concurrency] Emit thunk for synchronous -> async function conversion.
1 parent 50cddda commit f46ad6c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,6 +3014,10 @@ TypeConverter::checkForABIDifferences(SILModule &M,
30143014
// trivial.
30153015
if (auto fnTy1 = type1.getAs<SILFunctionType>()) {
30163016
if (auto fnTy2 = type2.getAs<SILFunctionType>()) {
3017+
// Async/synchronous conversions always need a thunk.
3018+
if (fnTy1->isAsync() != fnTy2->isAsync())
3019+
return ABIDifference::NeedsThunk;
3020+
30173021
// @convention(block) is a single retainable pointer so optionality
30183022
// change is allowed.
30193023
if (optionalityChange)

test/SILGen/async_conversion.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend -emit-silgen %s -module-name test -swift-version 5 -enable-experimental-concurrency | %FileCheck %s
2+
// REQUIRES: concurrency
3+
4+
func f(_: Int, _: String) -> String? { nil }
5+
6+
// CHECK-LABEL: sil hidden [ossa] @$s4testAAyyF : $@convention(thin) () -> () {
7+
func test() {
8+
// CHECK: [[F:%.*]] = function_ref @$s4test1fySSSgSi_SStF : $@convention(thin) (Int, @guaranteed String) -> @owned Optional<String>
9+
// CHECK: [[THICK_F:%.*]] = thin_to_thick_function [[F]] : $@convention(thin) (Int, @guaranteed String) -> @owned Optional<String> to $@callee_guaranteed (Int, @guaranteed String) -> @owned Optional<String>
10+
// CHECK: [[THUNK:%.*]] = function_ref @$sSiS2SSgIegygo_SiSSAAIegHygo_TR : $@convention(thin) @async (Int, @guaranteed String, @guaranteed @callee_guaranteed (Int, @guaranteed String) -> @owned Optional<String>) -> @owned Optional<String>
11+
// CHECK: partial_apply [callee_guaranteed] [[THUNK]]([[THICK_F]]) : $@convention(thin) @async (Int, @guaranteed String, @guaranteed @callee_guaranteed (Int, @guaranteed String) -> @owned Optional<String>) -> @owned Optional<String>
12+
let _: (Int, String) async -> String? = f
13+
}

0 commit comments

Comments
 (0)