From: Lang Hames Date: Sat, 12 Nov 2016 02:19:31 +0000 (+0000) Subject: [ORC] Add a WrappedHandlerReturn type to map handler return types onto error X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4258590d559371819954e0d6273d27339800799e;p=llvm [ORC] Add a WrappedHandlerReturn type to map handler return types onto error return types. This class allows user provided handlers to return either error-wrapped types or plain types. In the latter case, the plain type is wrapped with a success value of Error or Expected type to fit it into the rest of the serialization machinery. This patch allows us to remove the RPC unit-test workaround added in r286646. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286701 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ExecutionEngine/Orc/RPCUtils.h b/include/llvm/ExecutionEngine/Orc/RPCUtils.h index 043fb5f4510..e30651712dc 100644 --- a/include/llvm/ExecutionEngine/Orc/RPCUtils.h +++ b/include/llvm/ExecutionEngine/Orc/RPCUtils.h @@ -314,6 +314,37 @@ static Error respond(ChannelT &C, const FunctionIdT &ResponseId, return C.endSendMessage(); } +// Converts a given type to the equivalent error return type. +template +class WrappedHandlerReturn { +public: + using Type = Expected; +}; + +template +class WrappedHandlerReturn> { +public: + using Type = Expected; +}; + +template <> +class WrappedHandlerReturn { +public: + using Type = Error; +}; + +template <> +class WrappedHandlerReturn { +public: + using Type = Error; +}; + +template <> +class WrappedHandlerReturn { +public: + using Type = Error; +}; + // This template class provides utilities related to RPC function handlers. // The base case applies to non-function types (the template class is // specialized for function types) and inherits from the appropriate @@ -342,7 +373,7 @@ public: // Call the given handler with the given arguments. template - static typename ResultTraits::ErrorReturnType + static typename WrappedHandlerReturn::Type runHandler(HandlerT &Handler, ArgStorage &Args) { return runHandlerHelper(Handler, Args, llvm::index_sequence_for()); @@ -366,9 +397,7 @@ private: // For non-void user handlers: unwrap the args tuple and call the handler, // returning the result. template - static typename std::enable_if< - !std::is_void::value, - typename ResultTraits::ErrorReturnType>::type + static typename std::enable_if::value, RetT>::type runHandlerHelper(HandlerT &Handler, ArgStorage &Args, llvm::index_sequence) { return Handler(std::move(std::get(Args))...); @@ -377,13 +406,11 @@ private: // For void user handlers: unwrap the args tuple and call the handler, then // return Error::success(). template - static typename std::enable_if< - std::is_void::value, - typename ResultTraits::ErrorReturnType>::type + static typename std::enable_if::value, Error>::type runHandlerHelper(HandlerT &Handler, ArgStorage &Args, llvm::index_sequence) { Handler(std::move(std::get(Args))...); - return ResultTraits::ErrorReturnType::success(); + return Error::success(); } template diff --git a/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp b/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp index 565ebfa3f8f..4d703c78a0e 100644 --- a/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp +++ b/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp @@ -191,7 +191,7 @@ TEST(DummyRPC, TestSerialization) { Server.addHandler( [&](int8_t S8, uint8_t U8, int16_t S16, uint16_t U16, int32_t S32, uint32_t U32, int64_t S64, uint64_t U64, - bool B, std::string S, std::vector V) -> Error { + bool B, std::string S, std::vector V) { EXPECT_EQ(S8, -101) << "int8_t serialization broken"; EXPECT_EQ(U8, 250) << "uint8_t serialization broken";