Skip to content

Commit fc68fb3

Browse files
Refactoring the C++ thunk to directly return the Swift::Expected intead od the SWIFT_RETURN_THUNK macro
1 parent 23e66f7 commit fc68fb3

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Diff for: lib/PrintAsClang/PrintClangFunction.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1248,22 +1248,22 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
12481248
os << " throw (Swift::Error(opaqueError));\n";
12491249
os << "#else\n";
12501250
if (resultTy->isVoid()) {
1251-
os << " return SWIFT_RETURN_THUNK(void, Swift::Error(opaqueError));\n";
1251+
os << " return Swift::Expected<void>(Swift::Error(opaqueError));\n";
12521252
os << "#endif\n";
12531253
} else {
12541254
auto directResultType = signature.getDirectResultType();
12551255
printDirectReturnOrParamCType(
12561256
*directResultType, resultTy, moduleContext, os, cPrologueOS,
12571257
typeMapping, interopContext, [&]() {
1258-
os << " return SWIFT_RETURN_THUNK(";
1258+
os << " return Swift::Expected<";
12591259
OptionalTypeKind retKind;
12601260
Type objTy;
12611261
std::tie(objTy, retKind) =
12621262
DeclAndTypePrinter::getObjectTypeAndOptionality(FD, resultTy);
12631263

12641264
auto s = printClangFunctionReturnType(objTy, retKind, const_cast<ModuleDecl *>(moduleContext),
12651265
OutputLanguageMode::Cxx);
1266-
os << ", Swift::Error(opaqueError));\n";
1266+
os << ">(Swift::Error(opaqueError));\n";
12671267
os << "#endif\n";
12681268

12691269
// Return the function result value if it doesn't throw.

Diff for: test/Interop/SwiftToCxx/functions/swift-functions-errors.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public func emptyThrowFunction() throws { print("passEmptyThrowFunction") }
3838
// CHECK: #ifdef __cpp_exceptions
3939
// CHECK: throw (Swift::Error(opaqueError));
4040
// CHECK: #else
41-
// CHECK: return SWIFT_RETURN_THUNK(void, Swift::Error(opaqueError));
41+
// CHECK: return Swift::Expected<void>(Swift::Error(opaqueError));
4242
// CHECK: #endif
4343
// CHECK: }
4444

@@ -64,7 +64,7 @@ public func testDestroyedError() throws { throw DestroyedError() }
6464
// CHECK: #ifdef __cpp_exceptions
6565
// CHECK: throw (Swift::Error(opaqueError));
6666
// CHECK: #else
67-
// CHECK: return SWIFT_RETURN_THUNK(void, Swift::Error(opaqueError));
67+
// CHECK: return Swift::Expected<void>(Swift::Error(opaqueError));
6868
// CHECK: #endif
6969
// CHECK: }
7070

@@ -82,7 +82,7 @@ public func throwFunction() throws {
8282
// CHECK: #ifdef __cpp_exceptions
8383
// CHECK: throw (Swift::Error(opaqueError));
8484
// CHECK: #else
85-
// CHECK: return SWIFT_RETURN_THUNK(void, Swift::Error(opaqueError));
85+
// CHECK: return Swift::Expected<void>(Swift::Error(opaqueError));
8686
// CHECK: #endif
8787
// CHECK: }
8888

@@ -103,7 +103,7 @@ public func throwFunctionWithPossibleReturn(_ a: Int) throws -> Int {
103103
// CHECK: #ifdef __cpp_exceptions
104104
// CHECK: throw (Swift::Error(opaqueError));
105105
// CHECK: #else
106-
// CHECK: return SWIFT_RETURN_THUNK(swift::Int, Swift::Error(opaqueError));
106+
// CHECK: return Swift::Expected<swift::Int>(Swift::Error(opaqueError));
107107
// CHECK: #endif
108108
// CHECK: return SWIFT_RETURN_THUNK(swift::Int, returnValue);
109109
// CHECK: }
@@ -122,7 +122,7 @@ public func throwFunctionWithReturn() throws -> Int {
122122
// CHECK: #ifdef __cpp_exceptions
123123
// CHECK: throw (Swift::Error(opaqueError));
124124
// CHECK: #else
125-
// CHECK: return SWIFT_RETURN_THUNK(swift::Int, Swift::Error(opaqueError));
125+
// CHECK: return Swift::Expected<swift::Int>(Swift::Error(opaqueError));
126126
// CHECK: #endif
127127
// CHECK: return SWIFT_RETURN_THUNK(swift::Int, returnValue);
128128
// CHECK: }

0 commit comments

Comments
 (0)