diff --git a/orc-rt/docs/CodingConventions.md b/orc-rt/docs/CodingConventions.md index 80dab8ad2fd2..44228fb2da8b 100644 --- a/orc-rt/docs/CodingConventions.md +++ b/orc-rt/docs/CodingConventions.md @@ -59,3 +59,30 @@ the `Error` type; `orc_rt_log_formatCheck` is the `formatCheck` function in the C++ code follows the LLVM Coding Standards directly: symbols live in real namespaces (e.g. `orc_rt`), types/values/variables are `PascalCase`, functions are `camelBack`, and macros are `UPPER_CASE`. + +## Parameter ordering for asynchronous APIs + +Many ORC-RT entry points are asynchronous: they take a completion callback that +is invoked, possibly on another thread, when the operation finishes. Because C +has no closures, such a callback is paired with an opaque context (a `void *` +supplied by the caller, or a framework-issued token such as a call id) that is +threaded back to it. To keep these APIs learnable as a family, order their +parameters consistently: + +1. The primary handle or receiver (e.g. `orc_rt_SessionRef`) comes first. +2. The call inputs follow (e.g. a target/tag, an argument buffer). +3. The completion callback comes next, immediately followed by its context. +4. The context/token is always **last** -- in both the call and the callback + signature. + +For example, `orc_rt_WrapperFunction` is +`(S, ArgBytes, Return, CallId)` and its return callback +`orc_rt_WrapperFunctionReturn` is `(S, ResultBytes, CallId)`: the `CallId` +token that the framework threads from the call to its completion is last in +both. C++ helpers that mirror these signatures (e.g. `WrapperFunction::handle`) +follow the same order, appending any implementation-only parameters (such as a +serializer or handler) after the token. + +This ordering is a convention, not a hard rule; where an existing API or an +external interface being wrapped dictates otherwise, match that instead. + diff --git a/orc-rt/include/orc-rt-c/WrapperFunction.h b/orc-rt/include/orc-rt-c/WrapperFunction.h index d1159eb12d15..9a9be67bd397 100644 --- a/orc-rt/include/orc-rt-c/WrapperFunction.h +++ b/orc-rt/include/orc-rt-c/WrapperFunction.h @@ -55,20 +55,21 @@ typedef struct { * Asynchronous return function for an orc-rt wrapper function. */ typedef void (*orc_rt_WrapperFunctionReturn)( - orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionBuffer ResultBytes); + orc_rt_SessionRef S, orc_rt_WrapperFunctionBuffer ResultBytes, + uint64_t CallId); /** * orc-rt wrapper function prototype. * - * ArgBytes contains the serialized arguments for the wrapper function. * Session holds a reference to the session object. - * CallId holds a pointer to the context object for this particular call. + * ArgBytes contains the serialized arguments for the wrapper function. * Return holds a pointer to the return function. + * CallId holds a pointer to the context object for this particular call. */ -typedef void (*orc_rt_WrapperFunction)(orc_rt_SessionRef S, uint64_t CallId, +typedef void (*orc_rt_WrapperFunction)(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ArgBytes, orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes); + uint64_t CallId); /** * Zero-initialize an orc_rt_WrapperFunctionBuffer. diff --git a/orc-rt/include/orc-rt/InProcessControllerAccess.h b/orc-rt/include/orc-rt/InProcessControllerAccess.h index 8278c02b2a73..7416c95bd74b 100644 --- a/orc-rt/include/orc-rt/InProcessControllerAccess.h +++ b/orc-rt/include/orc-rt/InProcessControllerAccess.h @@ -112,8 +112,8 @@ public: void callController(OnControllerCallReturn OnComplete, orc_rt_ControllerHandlerTag T, WrapperFunctionBuffer ArgBytes) override; - void sendWrapperResult(uint64_t CallId, - WrapperFunctionBuffer ResultBytes) override; + void sendWrapperResult(WrapperFunctionBuffer ResultBytes, + uint64_t CallId) override; private: uint64_t registerPendingHandler(OnControllerCallReturn OnComplete); diff --git a/orc-rt/include/orc-rt/SPSWrapperFunction.h b/orc-rt/include/orc-rt/SPSWrapperFunction.h index dbce32430ed6..777c32527a57 100644 --- a/orc-rt/include/orc-rt/SPSWrapperFunction.h +++ b/orc-rt/include/orc-rt/SPSWrapperFunction.h @@ -19,10 +19,9 @@ #include "orc-rt/WrapperFunction.h" #define ORC_RT_SPS_WRAPPER(Name, SPSSig, Handle) \ - static void Name(orc_rt_SessionRef S, uint64_t CallId, \ - orc_rt_WrapperFunctionReturn Return, \ - orc_rt_WrapperFunctionBuffer ArgBytes) { \ - orc_rt::SPSWrapperFunction::handle(S, CallId, Return, ArgBytes, \ + static void Name(orc_rt_SessionRef S, orc_rt_WrapperFunctionBuffer ArgBytes, \ + orc_rt_WrapperFunctionReturn Return, uint64_t CallId) { \ + orc_rt::SPSWrapperFunction::handle(S, ArgBytes, Return, CallId, \ Handle); \ } @@ -130,10 +129,10 @@ template struct SPSWrapperFunction { } template - static void handle(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionReturn Return, - WrapperFunctionBuffer ArgBytes, Handler &&H) { - WrapperFunction::handle(S, CallId, Return, std::move(ArgBytes), + static void handle(orc_rt_SessionRef S, WrapperFunctionBuffer ArgBytes, + orc_rt_WrapperFunctionReturn Return, uint64_t CallId, + Handler &&H) { + WrapperFunction::handle(S, std::move(ArgBytes), Return, CallId, WrapperFunctionSPSSerializer(), std::forward(H)); } @@ -141,10 +140,10 @@ template struct SPSWrapperFunction { /// Convenience override that takes ArgBytes as an /// orc_rt_WrapperFunctionBuffer. template - static void handle(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes, Handler &&H) { - handle(S, CallId, Return, WrapperFunctionBuffer(ArgBytes), + static void handle(orc_rt_SessionRef S, orc_rt_WrapperFunctionBuffer ArgBytes, + orc_rt_WrapperFunctionReturn Return, uint64_t CallId, + Handler &&H) { + handle(S, WrapperFunctionBuffer(ArgBytes), Return, CallId, std::forward(H)); } }; diff --git a/orc-rt/include/orc-rt/Session.h b/orc-rt/include/orc-rt/Session.h index f7d1b5100470..e464b3438769 100644 --- a/orc-rt/include/orc-rt/Session.h +++ b/orc-rt/include/orc-rt/Session.h @@ -217,8 +217,8 @@ public: WrapperFunctionBuffer ArgBytes) = 0; /// Send the result of the given wrapper function call to the controller. - virtual void sendWrapperResult(uint64_t CallId, - WrapperFunctionBuffer ResultBytes) = 0; + virtual void sendWrapperResult(WrapperFunctionBuffer ResultBytes, + uint64_t CallId) = 0; /// Notify the Session that the controller has disconnected. /// @@ -237,9 +237,9 @@ public: /// Ask the Session to run the given wrapper function. /// /// Subclasses must not call this method after notifyDisconnected is called. - void handleWrapperCall(uint64_t CallId, orc_rt_WrapperFunction Fn, - WrapperFunctionBuffer ArgBytes) { - S.handleWrapperCall(CallId, Fn, std::move(ArgBytes)); + void handleWrapperCall(orc_rt_WrapperFunction Fn, + WrapperFunctionBuffer ArgBytes, uint64_t CallId) { + S.handleWrapperCall(Fn, std::move(ArgBytes), CallId); } /// Complete a controller call with a result the controller returned, by @@ -559,8 +559,8 @@ private: void shutdownServices(std::vector ToNotify); void completeShutdown(); - void handleWrapperCall(uint64_t CallId, orc_rt_WrapperFunction Fn, - WrapperFunctionBuffer ArgBytes) { + void handleWrapperCall(orc_rt_WrapperFunction Fn, + WrapperFunctionBuffer ArgBytes, uint64_t CallId) { TaskGroup::Token T(ManagedCodeTaskGroup); if (!T) { // The ManagedCodeTaskGroup is only closed after detach, so if token @@ -572,7 +572,7 @@ private: Dispatch([this, CallId, Fn, ArgBytes = std::move(ArgBytes), T = std::move(T)]() mutable { - Fn(wrap(this), CallId, &wrapperReturn, ArgBytes.release()); + Fn(wrap(this), ArgBytes.release(), &wrapperReturn, CallId); }); } @@ -618,9 +618,10 @@ private: OnComplete.Wrapped(disconnectError()); } - void sendWrapperResult(uint64_t CallId, WrapperFunctionBuffer ResultBytes); - static void wrapperReturn(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionBuffer ResultBytes); + void sendWrapperResult(WrapperFunctionBuffer ResultBytes, uint64_t CallId); + static void wrapperReturn(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ResultBytes, + uint64_t CallId); ExecutorProcessInfo EPI; DispatchFn Dispatch; diff --git a/orc-rt/include/orc-rt/WrapperFunction.h b/orc-rt/include/orc-rt/WrapperFunction.h index 2474db601e27..652288a495a4 100644 --- a/orc-rt/include/orc-rt/WrapperFunction.h +++ b/orc-rt/include/orc-rt/WrapperFunction.h @@ -143,14 +143,14 @@ using WFHandlerTraits = CallableTraitsHelper; template class StructuredYieldBase { public: - StructuredYieldBase(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionReturn Return, Serializer &&Z) - : S(S), CallId(CallId), Return(Return), Z(std::forward(Z)) {} + StructuredYieldBase(orc_rt_SessionRef S, orc_rt_WrapperFunctionReturn Return, + uint64_t CallId, Serializer &&Z) + : S(S), Return(Return), CallId(CallId), Z(std::forward(Z)) {} protected: orc_rt_SessionRef S; - uint64_t CallId; orc_rt_WrapperFunctionReturn Return; + uint64_t CallId; std::decay_t Z; }; @@ -163,12 +163,13 @@ public: using StructuredYieldBase::StructuredYieldBase; void operator()(RetT &&R) { if (auto ResultBytes = this->Z.result().serialize(std::forward(R))) - this->Return(this->S, this->CallId, ResultBytes->release()); + this->Return(this->S, ResultBytes->release(), this->CallId); else - this->Return(this->S, this->CallId, + this->Return(this->S, WrapperFunctionBuffer::createOutOfBandError( "Could not serialize wrapper function result data") - .release()); + .release(), + this->CallId); } }; @@ -178,7 +179,7 @@ class StructuredYield, Serializer> public: using StructuredYieldBase::StructuredYieldBase; void operator()() { - this->Return(this->S, this->CallId, WrapperFunctionBuffer().release()); + this->Return(this->S, WrapperFunctionBuffer().release(), this->CallId); } }; @@ -255,12 +256,11 @@ struct WrapperFunction { /// /// /// static void adder_add_async_sps_wrapper( - /// orc_rt_SessionRef S, uint64_t CallId, - /// orc_rt_WrapperFunctionReturn Return, - /// orc_rt_WrapperFunctionBuffer ArgBytes) { + /// orc_rt_SessionRef S, orc_rt_WrapperFunctionBuffer ArgBytes, + /// orc_rt_WrapperFunctionReturn Return, uint64_t CallId) { /// using SPSSig = SPSString(SPSExecutorAddr, int32_t, bool); /// SPSWrapperFunction::handle( - /// S, CallId, Return, ArgBytes, + /// S, ArgBytes, Return, CallId, /// WrapperFunction::handleWithAsyncMethod(&MyClass::myMethod)); /// } /// @endcode @@ -317,12 +317,11 @@ struct WrapperFunction { /// /// /// static void adder_add_sync_sps_wrapper( - /// orc_rt_SessionRef S, uint64_t CallId, - /// orc_rt_WrapperFunctionReturn Return, - /// orc_rt_WrapperFunctionBuffer ArgBytes) { + /// orc_rt_SessionRef S, orc_rt_WrapperFunctionBuffer ArgBytes, + /// orc_rt_WrapperFunctionReturn Return, uint64_t CallId) { /// using SPSSig = SPSString(SPSExecutorAddr, int32_t, bool); /// SPSWrapperFunction::handle( - /// S, CallId, Return, ArgBytes, + /// S, ArgBytes, Return, CallId, /// WrapperFunction::handleWithSyncMethod(&Adder::addSync)); /// } /// @endcode @@ -371,10 +370,9 @@ struct WrapperFunction { /// This utility deserializes and serializes arguments and return values /// (using the given Serializer), and calls the given handler. template - static void handle(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionReturn Return, - WrapperFunctionBuffer ArgBytes, Serializer &&Z, - Handler &&H) { + static void handle(orc_rt_SessionRef S, WrapperFunctionBuffer ArgBytes, + orc_rt_WrapperFunctionReturn Return, uint64_t CallId, + Serializer &&Z, Handler &&H) { typedef detail::WFHandlerTraits HandlerTraits; typedef typename HandlerTraits::ArgTupleType ArgTuple; typedef typename HandlerTraits::YieldType Yield; @@ -383,19 +381,20 @@ struct WrapperFunction { typedef typename CallableArgInfo::args_tuple_type RetTupleType; if (ArgBytes.getOutOfBandError()) - return Return(S, CallId, ArgBytes.release()); + return Return(S, ArgBytes.release(), CallId); if (auto Args = Z.arguments().template deserialize(ArgBytes)) std::apply(HandlerTraits::forwardArgsAsRequested(bind_front( std::forward(H), detail::StructuredYield( - S, CallId, Return, std::move(Z)))), + S, Return, CallId, std::move(Z)))), *Args); else - Return(S, CallId, + Return(S, WrapperFunctionBuffer::createOutOfBandError( "Could not deserialize wrapper function arg data") - .release()); + .release(), + CallId); } }; diff --git a/orc-rt/lib/executor/InProcessControllerAccess.cpp b/orc-rt/lib/executor/InProcessControllerAccess.cpp index dfc2680a6cf9..a4a39f10ca4f 100644 --- a/orc-rt/lib/executor/InProcessControllerAccess.cpp +++ b/orc-rt/lib/executor/InProcessControllerAccess.cpp @@ -215,7 +215,7 @@ void InProcessControllerAccess::callController( } void InProcessControllerAccess::sendWrapperResult( - uint64_t CallId, WrapperFunctionBuffer ResultBytes) { + WrapperFunctionBuffer ResultBytes, uint64_t CallId) { assert(C && "sendWrapperResult called before connect"); if (C->EnterMessageScope(C)) { C->ReturnWrapperResult(C->IPEPC, CallId, ResultBytes.release()); @@ -245,8 +245,8 @@ void InProcessControllerAccess::doDisconnect() { void InProcessControllerAccess::callWrapper( uint64_t CallId, void *Fn, orc_rt_WrapperFunctionBuffer ArgBytes) { - handleWrapperCall(CallId, reinterpret_cast(Fn), - WrapperFunctionBuffer(ArgBytes)); + handleWrapperCall(reinterpret_cast(Fn), + WrapperFunctionBuffer(ArgBytes), CallId); } void InProcessControllerAccess::callWrapperEntry( diff --git a/orc-rt/lib/executor/Session.cpp b/orc-rt/lib/executor/Session.cpp index 3f0f8dc873cb..a7312e1445fc 100644 --- a/orc-rt/lib/executor/Session.cpp +++ b/orc-rt/lib/executor/Session.cpp @@ -360,15 +360,16 @@ void Session::completeShutdown() { CV.notify_all(); } -void Session::sendWrapperResult(uint64_t CallId, - WrapperFunctionBuffer ResultBytes) { +void Session::sendWrapperResult(WrapperFunctionBuffer ResultBytes, + uint64_t CallId) { if (auto TmpCA = std::atomic_load(&CA)) - TmpCA->sendWrapperResult(CallId, std::move(ResultBytes)); + TmpCA->sendWrapperResult(std::move(ResultBytes), CallId); } -void Session::wrapperReturn(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionBuffer ResultBytes) { - unwrap(S)->sendWrapperResult(CallId, WrapperFunctionBuffer(ResultBytes)); +void Session::wrapperReturn(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ResultBytes, + uint64_t CallId) { + unwrap(S)->sendWrapperResult(WrapperFunctionBuffer(ResultBytes), CallId); } // --- C API Implementation --- diff --git a/orc-rt/test/unit/DirectCaller.h b/orc-rt/test/unit/DirectCaller.h index ef3de06e430f..f08ab7f5d597 100644 --- a/orc-rt/test/unit/DirectCaller.h +++ b/orc-rt/test/unit/DirectCaller.h @@ -22,8 +22,9 @@ private: virtual ~DirectResultSender() {} virtual void send(orc_rt_SessionRef S, orc_rt::WrapperFunctionBuffer ResultBytes) = 0; - static void send(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionBuffer ResultBytes) { + static void send(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ResultBytes, + uint64_t CallId) { std::unique_ptr( reinterpret_cast( static_cast(CallId))) @@ -59,8 +60,8 @@ public: orc_rt::WrapperFunctionBuffer ArgBytes) { auto DR = makeDirectResultSender(std::forward(HandleResult)); - Fn(S, static_cast(reinterpret_cast(DR.release())), - DirectResultSender::send, ArgBytes.release()); + Fn(S, ArgBytes.release(), DirectResultSender::send, + static_cast(reinterpret_cast(DR.release()))); } private: diff --git a/orc-rt/test/unit/InProcessControllerAccessTest.cpp b/orc-rt/test/unit/InProcessControllerAccessTest.cpp index 671143477dd5..45eee3d6cf8a 100644 --- a/orc-rt/test/unit/InProcessControllerAccessTest.cpp +++ b/orc-rt/test/unit/InProcessControllerAccessTest.cpp @@ -280,10 +280,10 @@ TEST(InProcessControllerAccessTest, DisconnectDrainsPendingCalls) { // Wrapper function that echoes ArgBytes back as the result. Used to exercise // the controller-initiated wrapper-call path without pulling in SPS. -static void echoWrapper(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { - Return(S, CallId, ArgBytes); +static void echoWrapper(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ArgBytes, + orc_rt_WrapperFunctionReturn Return, uint64_t CallId) { + Return(S, ArgBytes, CallId); } TEST(InProcessControllerAccessTest, CallFromControllerSuccess) { diff --git a/orc-rt/test/unit/SPSWrapperFunctionTest.cpp b/orc-rt/test/unit/SPSWrapperFunctionTest.cpp index 27e936c4aec9..e025e9fa028d 100644 --- a/orc-rt/test/unit/SPSWrapperFunctionTest.cpp +++ b/orc-rt/test/unit/SPSWrapperFunctionTest.cpp @@ -33,11 +33,12 @@ ORC_RT_SPS_WRAPPER(add_via_function_sps_wrapper, int32_t(int32_t, int32_t), using namespace orc_rt; -static void void_noop_sps_wrapper(orc_rt_SessionRef S, uint64_t CallId, +static void void_noop_sps_wrapper(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ArgBytes, orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { + uint64_t CallId) { SPSWrapperFunction::handle( - S, CallId, Return, ArgBytes, + S, ArgBytes, Return, CallId, [](move_only_function Return) { Return(); }); } @@ -51,11 +52,12 @@ TEST(SPSWrapperFunctionUtilsTest, VoidNoop) { EXPECT_TRUE(Ran); } -static void add_via_lambda_sps_wrapper(orc_rt_SessionRef S, uint64_t CallId, +static void add_via_lambda_sps_wrapper(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ArgBytes, orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { + uint64_t CallId) { SPSWrapperFunction::handle( - S, CallId, Return, ArgBytes, + S, ArgBytes, Return, CallId, [](move_only_function Return, int32_t X, int32_t Y) { Return(X + Y); }); @@ -77,12 +79,11 @@ TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunction) { EXPECT_EQ(Result, 42); } -static void -add_via_function_pointer_sps_wrapper(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { +static void add_via_function_pointer_sps_wrapper( + orc_rt_SessionRef S, orc_rt_WrapperFunctionBuffer ArgBytes, + orc_rt_WrapperFunctionReturn Return, uint64_t CallId) { SPSWrapperFunction::handle( - S, CallId, Return, ArgBytes, &add_via_function); + S, ArgBytes, Return, CallId, &add_via_function); } TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunctionPointer) { @@ -93,12 +94,11 @@ TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunctionPointer) { EXPECT_EQ(Result, 42); } -static void -round_trip_string_via_span_sps_wrapper(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { +static void round_trip_string_via_span_sps_wrapper( + orc_rt_SessionRef S, orc_rt_WrapperFunctionBuffer ArgBytes, + orc_rt_WrapperFunctionReturn Return, uint64_t CallId) { SPSWrapperFunction::handle( - S, CallId, Return, ArgBytes, + S, ArgBytes, Return, CallId, [](move_only_function Return, span S) { Return({S.data(), S.size()}); }); @@ -116,11 +116,12 @@ TEST(SPSWrapperFunctionUtilsTest, RoundTripStringViaSpan) { EXPECT_EQ(Result, "hello, world!"); } -static void improbable_feat_sps_wrapper(orc_rt_SessionRef S, uint64_t CallId, +static void improbable_feat_sps_wrapper(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ArgBytes, orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { + uint64_t CallId) { SPSWrapperFunction::handle( - S, CallId, Return, ArgBytes, + S, ArgBytes, Return, CallId, [](move_only_function Return, bool LuckyHat) { if (LuckyHat) Return(Error::success()); @@ -152,11 +153,12 @@ TEST(SPSWrapperFunctionUtilsTest, TransparentConversionErrorFailureCase) { EXPECT_EQ(ErrMsg, "crushed by boulder"); } -static void halve_number_sps_wrapper(orc_rt_SessionRef S, uint64_t CallId, +static void halve_number_sps_wrapper(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ArgBytes, orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { + uint64_t CallId) { SPSWrapperFunction(int32_t)>::handle( - S, CallId, Return, ArgBytes, + S, ArgBytes, Return, CallId, [](move_only_function)> Return, int N) { if (N % 2 == 0) Return(N >> 1); @@ -203,13 +205,12 @@ public: }; } // namespace orc_rt -static void -handle_with_reference_types_sps_wrapper(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { +static void handle_with_reference_types_sps_wrapper( + orc_rt_SessionRef S, orc_rt_WrapperFunctionBuffer ArgBytes, + orc_rt_WrapperFunctionReturn Return, uint64_t CallId) { SPSWrapperFunction, SPSOpCounter<1>, SPSOpCounter<2>, - SPSOpCounter<3>)>::handle(S, CallId, Return, ArgBytes, + SPSOpCounter<3>)>::handle(S, ArgBytes, Return, CallId, [](move_only_function Return, OpCounter<0>, OpCounter<1> &, const OpCounter<2> &, @@ -276,11 +277,12 @@ public: }; } // namespace -static void adder_add_async_sps_wrapper(orc_rt_SessionRef S, uint64_t CallId, +static void adder_add_async_sps_wrapper(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ArgBytes, orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { + uint64_t CallId) { SPSWrapperFunction::handle( - S, CallId, Return, ArgBytes, + S, ArgBytes, Return, CallId, WrapperFunction::handleWithAsyncMethod(&Adder::addAsync)); } @@ -295,11 +297,12 @@ TEST(SPSWrapperFunctionUtilsTest, HandleWtihAsyncMethod) { EXPECT_EQ(Result, 42); } -static void adder_add_sync_sps_wrapper(orc_rt_SessionRef S, uint64_t CallId, +static void adder_add_sync_sps_wrapper(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ArgBytes, orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { + uint64_t CallId) { SPSWrapperFunction::handle( - S, CallId, Return, ArgBytes, + S, ArgBytes, Return, CallId, WrapperFunction::handleWithSyncMethod(&Adder::addSync)); } diff --git a/orc-rt/test/unit/SessionTest.cpp b/orc-rt/test/unit/SessionTest.cpp index 33bb8bfa5a83..a6d411c1c34a 100644 --- a/orc-rt/test/unit/SessionTest.cpp +++ b/orc-rt/test/unit/SessionTest.cpp @@ -203,13 +203,13 @@ public: runOrPost([this, CId, T, ArgBytes = std::move(ArgBytes)]() mutable { auto Fn = reinterpret_cast(T); - Fn(reinterpret_cast(this), CId, ccReturn, - ArgBytes.release()); + Fn(reinterpret_cast(this), ArgBytes.release(), + ccReturn, CId); }); } - void sendWrapperResult(uint64_t CallId, - WrapperFunctionBuffer ResultBytes) override { + void sendWrapperResult(WrapperFunctionBuffer ResultBytes, + uint64_t CallId) override { // Respond to a simulated call by the controller. ConnectGuard CG; Session::OnControllerCallReturnFn OnComplete; @@ -269,7 +269,7 @@ public: "Controller disconnected")); }); - handleWrapperCall(CId, Fn, std::move(ArgBytes)); + handleWrapperCall(Fn, std::move(ArgBytes), CId); } private: @@ -280,8 +280,9 @@ private: Work(); } - static void ccReturn(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionBuffer ResultBytes) { + static void ccReturn(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ResultBytes, + uint64_t CallId) { // Abuse "session" to refer to the ControllerAccess object. // We can just re-use sendFunctionResult for this. reinterpret_cast(S)->returnFromController( @@ -638,7 +639,7 @@ public: WrapperFunctionBuffer) override { failControllerCallInline(std::move(OnComplete)); } - void sendWrapperResult(uint64_t, WrapperFunctionBuffer) override {} + void sendWrapperResult(WrapperFunctionBuffer, uint64_t) override {} }; TEST(ControllerAccessTest, SynchronousCallControllerFailureRunsInline) { @@ -666,11 +667,12 @@ TEST(ControllerAccessTest, SynchronousCallControllerFailureRunsInline) { EXPECT_EQ(ErrMsg, "disconnected"); } -static void add_sps_wrapper(orc_rt_SessionRef S, uint64_t CallId, +static void add_sps_wrapper(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ArgBytes, orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { + uint64_t CallId) { SPSWrapperFunction::handle( - S, CallId, Return, ArgBytes, + S, ArgBytes, Return, CallId, [](move_only_function Return, int32_t X, int32_t Y) { Return(X + Y); }); @@ -679,10 +681,10 @@ static void add_sps_wrapper(orc_rt_SessionRef S, uint64_t CallId, // Wrapper handler that echoes its argument bytes straight back as the result. // Used to exercise the C callController entry point without pulling in SPS // (de)serialization -- the payload is opaque to the code under test. -static void echo_wrapper(orc_rt_SessionRef S, uint64_t CallId, - orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { - Return(S, CallId, ArgBytes); +static void echo_wrapper(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ArgBytes, + orc_rt_WrapperFunctionReturn Return, uint64_t CallId) { + Return(S, ArgBytes, CallId); } // Captures what orc_rt_Session_callController threads back to its C return @@ -802,11 +804,12 @@ TEST(ControllerAccessTest, CallFromController) { // Stashes Return, via the address passed as the wrapper call's argument, // instead of calling it -- simulating a wrapper function that defers // completion past its own return. -static void deferred_wrapper(orc_rt_SessionRef S, uint64_t CallId, +static void deferred_wrapper(orc_rt_SessionRef S, + orc_rt_WrapperFunctionBuffer ArgBytes, orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { + uint64_t CallId) { SPSWrapperFunction::handle( - S, CallId, Return, ArgBytes, + S, ArgBytes, Return, CallId, [](move_only_function Return, ExecutorAddr P) { *P.toPtr *>() = std::move(Return); });