Skip to content

Commit ba8b7e4

Browse files
Merge pull request #76396 from aschwaighofer/async_typed_throws_empty_errors
IRGen: Async throwing functions with empty error types pass the error indirectly
2 parents 4693a47 + ede9f33 commit ba8b7e4

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

lib/IRGen/GenCall.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -3030,7 +3030,10 @@ class AsyncCallEmission final : public CallEmission {
30303030
IGF.IGM.getTypeInfo(silErrorTy).nativeReturnValueSchema(IGF.IGM);
30313031

30323032
if (nativeSchema.requiresIndirect() ||
3033-
errorSchema.shouldReturnTypedErrorIndirectly()) {
3033+
errorSchema.shouldReturnTypedErrorIndirectly() ||
3034+
(errorSchema.empty() && fnConv.hasIndirectSILResults())) { // direct empty typed errors are passed
3035+
// indirectly for compatibility with generic
3036+
// functions.
30343037
// Return the error indirectly.
30353038
auto buf = IGF.getCalleeTypedErrorResultSlot(silErrorTy);
30363039
Args[--LastArgWritten] = buf.getAddress();

test/IRGen/typed_throws.sil

+58
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,61 @@ bb6:
458458
%t = tuple()
459459
return %t : $()
460460
}
461+
462+
sil @callee : $@convention(thin) @async (Int64) -> (@out (), @error Never) {
463+
bb0(%0 : $*(), %1: $Int64):
464+
%17 = tuple ()
465+
return %17 : $()
466+
}
467+
468+
// CHECK: define{{.*}} swifttailcc void @callee(ptr {{.*}} %0, ptr swiftasync %1, i64 %2, ptr %3)
469+
470+
// CHECK: define{{.*}} swifttailcc void @caller(ptr swiftasync %0) {{.*}} {
471+
// CHECK-NOT: define
472+
// CHECK: [[CTXT:%.*]] = call swiftcc ptr @swift_task_alloc
473+
// CHECK-NOT: define
474+
// CHECK: call {{.*}} @llvm.coro.suspend.async.sl_p0p0s(i32 256, ptr {{.*}}, ptr @__swift_async_resume_project_context, ptr @caller.0, ptr @callee, ptr undef, ptr [[CTXT]], i64 66, ptr %swifterror)
475+
476+
sil @caller : $@convention(thin) @async () -> () {
477+
bb0:
478+
%5 = integer_literal $Builtin.Int64, 66
479+
%6 = struct $Int64 (%5 : $Builtin.Int64)
480+
%9 = alloc_stack $()
481+
%10 = function_ref @callee : $@convention(thin) @async (Int64) -> (@out (), @error Never)
482+
try_apply %10(%9, %6) : $@convention(thin) @async (Int64) -> (@out (), @error Never), normal bb1, error bb2
483+
484+
bb1(%12 : $()):
485+
dealloc_stack %9 : $*()
486+
%17 = tuple ()
487+
return %17 : $()
488+
489+
bb2(%19 : $Never):
490+
unreachable
491+
}
492+
493+
sil @callee2 : $@convention(thin) @async (Int) -> (Int, @error Never) {
494+
bb0(%0 : $Int):
495+
%5 = integer_literal $Builtin.Int64, 66
496+
%6 = struct $Int (%5 : $Builtin.Int64)
497+
return %6 : $Int
498+
}
499+
500+
// CHECK: define{{.*}} swifttailcc void @callee2(ptr swiftasync %0, i64 %1)
501+
502+
// CHECK: define{{.*}} swifttailcc void @caller2(ptr swiftasync %0)
503+
// CHECK: [[CTXT:%.*]] = call swiftcc ptr @swift_task_alloc
504+
// CHECK: @llvm.coro.suspend.async.sl_p0i64p0s({{.*}} ptr @callee2, ptr [[CTXT]], i64 67)
505+
sil @caller2 : $@convention(thin) @async () -> () {
506+
bb0:
507+
%5 = integer_literal $Builtin.Int64, 67
508+
%6 = struct $Int (%5 : $Builtin.Int64)
509+
%10 = function_ref @callee2 : $@convention(thin) @async (Int) -> (Int, @error Never)
510+
try_apply %10(%6) : $@convention(thin) @async (Int) -> (Int, @error Never), normal bb1, error bb2
511+
512+
bb1(%12 : $Int):
513+
%17 = tuple ()
514+
return %17 : $()
515+
516+
bb2(%19 : $Never):
517+
unreachable
518+
}

0 commit comments

Comments
 (0)