From ea9826ff77195c12dfba698d5fcb90786c949aa2 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 18 Oct 2021 22:11:16 -0700 Subject: [PATCH] [ORC-RT] Avoid switching out-of-band error value into __orc_rt::Error and back. WrapperFunctionResult can already convey serialization errors as out-of-band error values, so there's no need to wrap it in an Expected here. Removing the wrapper simplifies the plumbing and call sites. --- compiler-rt/lib/orc/wrapper_function_utils.h | 30 +++++++++++----------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/compiler-rt/lib/orc/wrapper_function_utils.h b/compiler-rt/lib/orc/wrapper_function_utils.h index db6c897..a78c999 100644 --- a/compiler-rt/lib/orc/wrapper_function_utils.h +++ b/compiler-rt/lib/orc/wrapper_function_utils.h @@ -116,14 +116,14 @@ private: namespace detail { template -Expected +WrapperFunctionResult serializeViaSPSToWrapperFunctionResult(const ArgTs &...Args) { auto Result = WrapperFunctionResult::allocate(SPSArgListT::size(Args...)); SPSOutputBuffer OB(Result.data(), Result.size()); if (!SPSArgListT::serialize(OB, Args...)) - return make_error( + return WrapperFunctionResult::createOutOfBandError( "Error serializing arguments to blob in call"); - return std::move(Result); + return Result; } template class WrapperFunctionHandlerCaller { @@ -171,12 +171,8 @@ public: auto HandlerResult = WrapperFunctionHandlerCaller::call( std::forward(H), Args, ArgIndices{}); - if (auto Result = ResultSerializer::serialize( - std::move(HandlerResult))) - return std::move(*Result); - else - return WrapperFunctionResult::createOutOfBandError( - toString(Result.takeError())); + return ResultSerializer::serialize( + std::move(HandlerResult)); } private: @@ -186,7 +182,6 @@ private: SPSInputBuffer IB(ArgData, ArgSize); return SPSArgList::deserialize(IB, std::get(Args)...); } - }; // Map function references to function types. @@ -215,7 +210,7 @@ class WrapperFunctionHandlerHelper class ResultSerializer { public: - static Expected serialize(RetT Result) { + static WrapperFunctionResult serialize(RetT Result) { return serializeViaSPSToWrapperFunctionResult>( Result); } @@ -223,7 +218,7 @@ public: template class ResultSerializer { public: - static Expected serialize(Error Err) { + static WrapperFunctionResult serialize(Error Err) { return serializeViaSPSToWrapperFunctionResult>( toSPSSerializable(std::move(Err))); } @@ -232,7 +227,7 @@ public: template class ResultSerializer> { public: - static Expected serialize(Expected E) { + static WrapperFunctionResult serialize(Expected E) { return serializeViaSPSToWrapperFunctionResult>( toSPSSerializable(std::move(E))); } @@ -310,12 +305,11 @@ public: auto ArgBuffer = detail::serializeViaSPSToWrapperFunctionResult>( Args...); - if (!ArgBuffer) - return ArgBuffer.takeError(); + if (const char *ErrMsg = ArgBuffer.getOutOfBandError()) + return make_error(ErrMsg); - WrapperFunctionResult ResultBuffer = - __orc_rt_jit_dispatch(&__orc_rt_jit_dispatch_ctx, FnTag, - ArgBuffer->data(), ArgBuffer->size()); + WrapperFunctionResult ResultBuffer = __orc_rt_jit_dispatch( + &__orc_rt_jit_dispatch_ctx, FnTag, ArgBuffer.data(), ArgBuffer.size()); if (auto ErrMsg = ResultBuffer.getOutOfBandError()) return make_error(ErrMsg); -- 2.7.4