[llvm] 666540c - [ORC] Swap handleAsync handler and send-result arguments.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 10 19:17:32 PDT 2025


Author: Lang Hames
Date: 2025-03-11T13:17:25+11:00
New Revision: 666540cb65331970e4953891cb8525a32e7da6b8

URL: https://github.com/llvm/llvm-project/commit/666540cb65331970e4953891cb8525a32e7da6b8
DIFF: https://github.com/llvm/llvm-project/commit/666540cb65331970e4953891cb8525a32e7da6b8.diff

LOG: [ORC] Swap handleAsync handler and send-result arguments.

Placing the handler argument last improves readability when passing a lambda
value (the common case for this API).

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/Core.h
    llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
    llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/Core.h b/llvm/include/llvm/ExecutionEngine/Orc/Core.h
index fbbd0d3d74b15..b333ef8d9ecd5 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Core.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Core.h
@@ -1653,11 +1653,11 @@ class ExecutionSession {
   /// (using registerJITDispatchHandler) and called from the executor.
   template <typename SPSSignature, typename HandlerT>
   static JITDispatchHandlerFunction wrapAsyncWithSPS(HandlerT &&H) {
-    return [H = std::forward<HandlerT>(H)](
-               SendResultFunction SendResult,
-               const char *ArgData, size_t ArgSize) mutable {
-      shared::WrapperFunction<SPSSignature>::handleAsync(ArgData, ArgSize, H,
-                                                         std::move(SendResult));
+    return [H = std::forward<HandlerT>(H)](SendResultFunction SendResult,
+                                           const char *ArgData,
+                                           size_t ArgSize) mutable {
+      shared::WrapperFunction<SPSSignature>::handleAsync(
+          ArgData, ArgSize, std::move(SendResult), H);
     };
   }
 

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
index 2521bda0b42cf..7ac8bd3489683 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
@@ -527,7 +527,7 @@ class WrapperFunction<SPSRetTagT(SPSTagTs...)> {
   /// Handle a call to an async wrapper function.
   template <typename HandlerT, typename SendResultT>
   static void handleAsync(const char *ArgData, size_t ArgSize,
-                          HandlerT &&Handler, SendResultT &&SendResult) {
+                          SendResultT &&SendResult, HandlerT &&Handler) {
     using WFAHH = detail::WrapperFunctionAsyncHandlerHelper<
         std::remove_reference_t<HandlerT>, ResultSerializer, SPSTagTs...>;
     WFAHH::applyAsync(std::forward<HandlerT>(Handler),

diff  --git a/llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp
index 1ed690ae9b986..8de2412fed4d0 100644
--- a/llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp
@@ -118,8 +118,9 @@ static WrapperFunctionResult voidNoopAsyncWrapper(const char *ArgData,
   auto RF = RP.get_future();
 
   WrapperFunction<void()>::handleAsync(
-      ArgData, ArgSize, voidNoopAsync,
-      [&](WrapperFunctionResult R) { RP.set_value(std::move(R)); });
+      ArgData, ArgSize,
+      [&](WrapperFunctionResult R) { RP.set_value(std::move(R)); },
+      voidNoopAsync);
 
   return RF.get();
 }
@@ -131,10 +132,10 @@ static WrapperFunctionResult addAsyncWrapper(const char *ArgData,
 
   WrapperFunction<int32_t(int32_t, int32_t)>::handleAsync(
       ArgData, ArgSize,
+      [&](WrapperFunctionResult R) { RP.set_value(std::move(R)); },
       [](unique_function<void(int32_t)> SendResult, int32_t X, int32_t Y) {
         SendResult(X + Y);
-      },
-      [&](WrapperFunctionResult R) { RP.set_value(std::move(R)); });
+      });
   return RF.get();
 }
 


        


More information about the llvm-commits mailing list