Skip to content

[IRGen] Skip async context params before handling direct error return… #75316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3231,7 +3231,19 @@ class AsyncCallEmission final : public CallEmission {

bool mayReturnErrorDirectly = mayReturnTypedErrorDirectly();
if (mayReturnErrorDirectly && !nativeSchema.requiresIndirect()) {
return emitToUnmappedExplosionWithDirectTypedError(resultType, result,
llvm::Value *resultAgg;
if (resultTys.size() == 1) {
resultAgg = Builder.CreateExtractValue(result, numAsyncContextParams);
} else {
auto resultTy = llvm::StructType::get(IGM.getLLVMContext(), resultTys);
resultAgg = llvm::UndefValue::get(resultTy);
for (unsigned i = 0, e = resultTys.size(); i != e; ++i) {
llvm::Value *elt =
Builder.CreateExtractValue(result, numAsyncContextParams + i);
resultAgg = Builder.CreateInsertValue(resultAgg, elt, i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little unfortunate to build up an aggregate value only to break it down again, but it works.

}
}
return emitToUnmappedExplosionWithDirectTypedError(resultType, resultAgg,
out);
} else if (resultTys.size() == 1) {
result = Builder.CreateExtractValue(result, numAsyncContextParams);
Expand Down
17 changes: 17 additions & 0 deletions test/IRGen/typed_throws.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,20 @@ func throwsGenericAsync<T: Error>(x: Bool, y: T) async throws(T) -> Int {

return 32
}

enum TinyError: Error {
case a
}

@available(SwiftStdlib 6.0, *)
func mayThrowAsyncTiny(x: Bool) async throws(TinyError) -> Bool {
guard x else {
throw .a
}
return false
}

@available(SwiftStdlib 6.0, *)
func callsMayThrowAsyncTiny(x: Bool) async {
_ = try! await mayThrowAsyncTiny(x: x)
}