From 5b56af86182878b41c7dbd8159f0f28472ea5b04 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 6 Oct 2025 23:01:43 +1100 Subject: [PATCH] [orc-rt] Enable transparent SPS conversion for Expected. Expected values will be converted to/from Expected values. --- orc-rt/include/orc-rt/SPSWrapperFunction.h | 15 +++++++++++++ orc-rt/unittests/SPSWrapperFunctionTest.cpp | 24 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/orc-rt/include/orc-rt/SPSWrapperFunction.h b/orc-rt/include/orc-rt/SPSWrapperFunction.h index e5ed14f5cd721..5cf387345e6ba 100644 --- a/orc-rt/include/orc-rt/SPSWrapperFunction.h +++ b/orc-rt/include/orc-rt/SPSWrapperFunction.h @@ -63,6 +63,21 @@ 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/unittests/SPSWrapperFunctionTest.cpp b/orc-rt/unittests/SPSWrapperFunctionTest.cpp index 7f88ce0434ddb..9d0d9e46d1958 100644 --- a/orc-rt/unittests/SPSWrapperFunctionTest.cpp +++ b/orc-rt/unittests/SPSWrapperFunctionTest.cpp @@ -242,6 +242,30 @@ TEST(SPSWrapperFunctionUtilsTest, TransparentSerializationPointers) { 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, TransparentSerializationExpectedPointers) { + 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 {