diff --git a/orc-rt/include/orc-rt/SPSWrapperFunction.h b/orc-rt/include/orc-rt/SPSWrapperFunction.h index dc688223d9924..46c08a0c688d0 100644 --- a/orc-rt/include/orc-rt/SPSWrapperFunction.h +++ b/orc-rt/include/orc-rt/SPSWrapperFunction.h @@ -42,12 +42,6 @@ template struct WFSPSHelper { static T &&from(T &&Arg) noexcept { return std::forward(Arg); } }; - template struct Serializable { - typedef ExecutorAddr serializable_type; - static ExecutorAddr to(T *Arg) { return ExecutorAddr::fromPtr(Arg); } - static T *from(ExecutorAddr A) { return A.toPtr(); } - }; - template <> struct Serializable { typedef SPSSerializableError serializable_type; static SPSSerializableError to(Error Err) { @@ -66,21 +60,6 @@ template struct WFSPSHelper { } }; - template struct Serializable> { - typedef SPSSerializableExpected serializable_type; - static SPSSerializableExpected to(Expected Val) { - return SPSSerializableExpected( - Val ? Expected(ExecutorAddr::fromPtr(*Val)) - : Expected(Val.takeError())); - } - static Expected from(SPSSerializableExpected Val) { - if (auto Tmp = Val.toExpected()) - return Tmp->toPtr(); - else - return Tmp.takeError(); - } - }; - template struct DeserializableTuple; template struct DeserializableTuple> { diff --git a/orc-rt/include/orc-rt/SimplePackedSerialization.h b/orc-rt/include/orc-rt/SimplePackedSerialization.h index f60ccad666ab1..0f291c40a8b5e 100644 --- a/orc-rt/include/orc-rt/SimplePackedSerialization.h +++ b/orc-rt/include/orc-rt/SimplePackedSerialization.h @@ -556,6 +556,26 @@ template <> class SPSSerializationTraits { } }; +/// Allow SPSExectorAddr serialization to/from T*. +template class SPSSerializationTraits { +public: + static size_t size(T *const &P) { + return SPSArgList::size(ExecutorAddr::fromPtr(P)); + } + + static bool serialize(SPSOutputBuffer &OB, T *const &P) { + return SPSArgList::serialize(OB, ExecutorAddr::fromPtr(P)); + } + + static bool deserialize(SPSInputBuffer &IB, T *&P) { + ExecutorAddr Value; + if (!SPSArgList::deserialize(IB, Value)) + return false; + P = Value.toPtr(); + return true; + } +}; + /// Helper type for serializing Errors. /// /// llvm::Errors are move-only, and not inspectable except by consuming them. diff --git a/orc-rt/unittests/SPSWrapperFunctionTest.cpp b/orc-rt/unittests/SPSWrapperFunctionTest.cpp index ed085f2fef76c..81e5755e821f3 100644 --- a/orc-rt/unittests/SPSWrapperFunctionTest.cpp +++ b/orc-rt/unittests/SPSWrapperFunctionTest.cpp @@ -192,62 +192,6 @@ TEST(SPSWrapperFunctionUtilsTest, TransparentConversionExpectedFailureCase) { EXPECT_EQ(ErrMsg, "N is not a multiple of 2"); } -static void -round_trip_int_pointer_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx, - orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { - SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, - [](move_only_function Return, int32_t *P) { - Return(P); - }); -} - -TEST(SPSWrapperFunctionUtilsTest, TransparentConversionPointers) { - int X = 42; - int *P = nullptr; - SPSWrapperFunction::call( - DirectCaller(nullptr, round_trip_int_pointer_sps_wrapper), - [&](Expected R) { P = cantFail(std::move(R)); }, &X); - - EXPECT_EQ(P, &X); -} - -TEST(SPSWrapperFunctionUtilsTest, TransparentConversionReferenceArguments) { - int X = 42; - int *P = nullptr; - SPSWrapperFunction::call( - DirectCaller(nullptr, round_trip_int_pointer_sps_wrapper), - [&](Expected R) { P = cantFail(std::move(R)); }, - static_cast(&X)); - - EXPECT_EQ(P, &X); -} - -static void -expected_int_pointer_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx, - orc_rt_WrapperFunctionReturn Return, - orc_rt_WrapperFunctionBuffer ArgBytes) { - SPSWrapperFunction(SPSExecutorAddr)>::handle( - Session, CallCtx, Return, ArgBytes, - [](move_only_function)> Return, int32_t *P) { - Return(P); - }); -} - -TEST(SPSWrapperFunctionUtilsTest, TransparentConversionExpectedPointers) { - int X = 42; - int *P = nullptr; - SPSWrapperFunction(SPSExecutorAddr)>::call( - DirectCaller(nullptr, expected_int_pointer_sps_wrapper), - [&](Expected> R) { - P = cantFail(cantFail(std::move(R))); - }, - &X); - - EXPECT_EQ(P, &X); -} - template struct SPSOpCounter {}; namespace orc_rt { diff --git a/orc-rt/unittests/SimplePackedSerializationTest.cpp b/orc-rt/unittests/SimplePackedSerializationTest.cpp index c3df499da510f..17f0e9c17e19e 100644 --- a/orc-rt/unittests/SimplePackedSerializationTest.cpp +++ b/orc-rt/unittests/SimplePackedSerializationTest.cpp @@ -169,6 +169,12 @@ TEST(SimplePackedSerializationTest, StdOptionalValueSerialization) { blobSerializationRoundTrip>(Value); } +TEST(SimplePackedSerializationTest, Pointers) { + int X = 42; + int *P = &X; + blobSerializationRoundTrip(P); +} + TEST(SimplePackedSerializationTest, ArgListSerialization) { using BAL = SPSArgList;