forked from OSchip/llvm-project
[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.
This commit is contained in:
parent
2542bfa43a
commit
ea9826ff77
|
@ -116,14 +116,14 @@ private:
|
|||
namespace detail {
|
||||
|
||||
template <typename SPSArgListT, typename... ArgTs>
|
||||
Expected<WrapperFunctionResult>
|
||||
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<StringError>(
|
||||
return WrapperFunctionResult::createOutOfBandError(
|
||||
"Error serializing arguments to blob in call");
|
||||
return std::move(Result);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename RetT> class WrapperFunctionHandlerCaller {
|
||||
|
@ -171,12 +171,8 @@ public:
|
|||
auto HandlerResult = WrapperFunctionHandlerCaller<RetT>::call(
|
||||
std::forward<HandlerT>(H), Args, ArgIndices{});
|
||||
|
||||
if (auto Result = ResultSerializer<decltype(HandlerResult)>::serialize(
|
||||
std::move(HandlerResult)))
|
||||
return std::move(*Result);
|
||||
else
|
||||
return WrapperFunctionResult::createOutOfBandError(
|
||||
toString(Result.takeError()));
|
||||
return ResultSerializer<decltype(HandlerResult)>::serialize(
|
||||
std::move(HandlerResult));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -186,7 +182,6 @@ private:
|
|||
SPSInputBuffer IB(ArgData, ArgSize);
|
||||
return SPSArgList<SPSTagTs...>::deserialize(IB, std::get<I>(Args)...);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Map function references to function types.
|
||||
|
@ -215,7 +210,7 @@ class WrapperFunctionHandlerHelper<RetT (ClassT::*)(ArgTs...) const,
|
|||
|
||||
template <typename SPSRetTagT, typename RetT> class ResultSerializer {
|
||||
public:
|
||||
static Expected<WrapperFunctionResult> serialize(RetT Result) {
|
||||
static WrapperFunctionResult serialize(RetT Result) {
|
||||
return serializeViaSPSToWrapperFunctionResult<SPSArgList<SPSRetTagT>>(
|
||||
Result);
|
||||
}
|
||||
|
@ -223,7 +218,7 @@ public:
|
|||
|
||||
template <typename SPSRetTagT> class ResultSerializer<SPSRetTagT, Error> {
|
||||
public:
|
||||
static Expected<WrapperFunctionResult> serialize(Error Err) {
|
||||
static WrapperFunctionResult serialize(Error Err) {
|
||||
return serializeViaSPSToWrapperFunctionResult<SPSArgList<SPSRetTagT>>(
|
||||
toSPSSerializable(std::move(Err)));
|
||||
}
|
||||
|
@ -232,7 +227,7 @@ public:
|
|||
template <typename SPSRetTagT, typename T>
|
||||
class ResultSerializer<SPSRetTagT, Expected<T>> {
|
||||
public:
|
||||
static Expected<WrapperFunctionResult> serialize(Expected<T> E) {
|
||||
static WrapperFunctionResult serialize(Expected<T> E) {
|
||||
return serializeViaSPSToWrapperFunctionResult<SPSArgList<SPSRetTagT>>(
|
||||
toSPSSerializable(std::move(E)));
|
||||
}
|
||||
|
@ -310,12 +305,11 @@ public:
|
|||
auto ArgBuffer =
|
||||
detail::serializeViaSPSToWrapperFunctionResult<SPSArgList<SPSTagTs...>>(
|
||||
Args...);
|
||||
if (!ArgBuffer)
|
||||
return ArgBuffer.takeError();
|
||||
if (const char *ErrMsg = ArgBuffer.getOutOfBandError())
|
||||
return make_error<StringError>(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<StringError>(ErrMsg);
|
||||
|
||||
|
|
Loading…
Reference in New Issue