From 03418af0464063af381a6a715d00f749da95f6e2 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Sat, 12 Nov 2016 02:19:31 +0000 Subject: [PATCH] [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. llvm-svn: 286701 --- llvm/include/llvm/ExecutionEngine/Orc/RPCUtils.h | 43 ++++++++++++++++++---- .../unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp | 2 +- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/llvm/include/llvm/ExecutionEngine/Orc/RPCUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/RPCUtils.h index 043fb5f..e306517 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/RPCUtils.h +++ b/llvm/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/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp index 565ebfa..4d703c7 100644 --- a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp +++ b/llvm/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"; -- 2.7.4