[llvm] r286701 - [ORC] Add a WrappedHandlerReturn type to map handler return types onto error

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 11 18:19:32 PST 2016


Author: lhames
Date: Fri Nov 11 20:19:31 2016
New Revision: 286701

URL: http://llvm.org/viewvc/llvm-project?rev=286701&view=rev
Log:
[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<T> 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.


Modified:
    llvm/trunk/include/llvm/ExecutionEngine/Orc/RPCUtils.h
    llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp

Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/RPCUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/RPCUtils.h?rev=286701&r1=286700&r2=286701&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/RPCUtils.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/RPCUtils.h Fri Nov 11 20:19:31 2016
@@ -314,6 +314,37 @@ static Error respond(ChannelT &C, const
   return C.endSendMessage();
 }
 
+// Converts a given type to the equivalent error return type.
+template <typename T>
+class WrappedHandlerReturn {
+public:
+  using Type = Expected<T>;
+};
+
+template <typename T>
+class WrappedHandlerReturn<Expected<T>> {
+public:
+  using Type = Expected<T>;
+};
+
+template <>
+class WrappedHandlerReturn<void> {
+public:
+  using Type = Error;
+};
+
+template <>
+class WrappedHandlerReturn<Error> {
+public:
+  using Type = Error;
+};
+
+template <>
+class WrappedHandlerReturn<ErrorSuccess> {
+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 <typename HandlerT>
-  static typename ResultTraits<RetT>::ErrorReturnType
+  static typename WrappedHandlerReturn<RetT>::Type
   runHandler(HandlerT &Handler, ArgStorage &Args) {
     return runHandlerHelper<RetT>(Handler, Args,
                                   llvm::index_sequence_for<ArgTs...>());
@@ -366,9 +397,7 @@ private:
   // For non-void user handlers: unwrap the args tuple and call the handler,
   // returning the result.
   template <typename RetTAlt, typename HandlerT, size_t... Indexes>
-  static typename std::enable_if<
-                    !std::is_void<RetTAlt>::value,
-                    typename ResultTraits<RetT>::ErrorReturnType>::type
+  static typename std::enable_if<!std::is_void<RetTAlt>::value, RetT>::type
   runHandlerHelper(HandlerT &Handler, ArgStorage &Args,
                    llvm::index_sequence<Indexes...>) {
     return Handler(std::move(std::get<Indexes>(Args))...);
@@ -377,13 +406,11 @@ private:
   // For void user handlers: unwrap the args tuple and call the handler, then
   // return Error::success().
   template <typename RetTAlt, typename HandlerT, size_t... Indexes>
-  static typename std::enable_if<
-                    std::is_void<RetTAlt>::value,
-                    typename ResultTraits<RetT>::ErrorReturnType>::type
+  static typename std::enable_if<std::is_void<RetTAlt>::value, Error>::type
   runHandlerHelper(HandlerT &Handler, ArgStorage &Args,
                    llvm::index_sequence<Indexes...>) {
     Handler(std::move(std::get<Indexes>(Args))...);
-    return ResultTraits<RetT>::ErrorReturnType::success();
+    return Error::success();
   }
 
   template <typename ChannelT, typename... CArgTs, size_t... Indexes>

Modified: llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp?rev=286701&r1=286700&r2=286701&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp Fri Nov 11 20:19:31 2016
@@ -191,7 +191,7 @@ TEST(DummyRPC, TestSerialization) {
       Server.addHandler<DummyRPCAPI::AllTheTypes>(
           [&](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<int> V) -> Error {
+              bool B, std::string S, std::vector<int> V) {
 
             EXPECT_EQ(S8, -101) << "int8_t serialization broken";
             EXPECT_EQ(U8, 250) << "uint8_t serialization broken";




More information about the llvm-commits mailing list