Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions orc-rt/include/orc-rt/SPSWrapperFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ template <typename... SPSArgTs> struct WFSPSHelper {
static T &&from(T &&Arg) noexcept { return std::forward<T>(Arg); }
};

template <typename T> struct Serializable<T *> {
typedef ExecutorAddr serializable_type;
static ExecutorAddr to(T *Arg) { return ExecutorAddr::fromPtr(Arg); }
static T *from(ExecutorAddr A) { return A.toPtr<T *>(); }
};

template <> struct Serializable<Error> {
typedef SPSSerializableError serializable_type;
static SPSSerializableError to(Error Err) {
Expand All @@ -66,21 +60,6 @@ template <typename... SPSArgTs> struct WFSPSHelper {
}
};

template <typename T> struct Serializable<Expected<T *>> {
typedef SPSSerializableExpected<ExecutorAddr> serializable_type;
static SPSSerializableExpected<ExecutorAddr> to(Expected<T *> Val) {
return SPSSerializableExpected<ExecutorAddr>(
Val ? Expected<ExecutorAddr>(ExecutorAddr::fromPtr(*Val))
: Expected<ExecutorAddr>(Val.takeError()));
}
static Expected<T *> from(SPSSerializableExpected<ExecutorAddr> Val) {
if (auto Tmp = Val.toExpected())
return Tmp->toPtr<T *>();
else
return Tmp.takeError();
}
};

template <typename... Ts> struct DeserializableTuple;

template <typename... Ts> struct DeserializableTuple<std::tuple<Ts...>> {
Expand Down
20 changes: 20 additions & 0 deletions orc-rt/include/orc-rt/SimplePackedSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,26 @@ template <> class SPSSerializationTraits<SPSExecutorAddr, ExecutorAddr> {
}
};

/// Allow SPSExectorAddr serialization to/from T*.
template <typename T> class SPSSerializationTraits<SPSExecutorAddr, T *> {
public:
static size_t size(T *const &P) {
return SPSArgList<SPSExecutorAddr>::size(ExecutorAddr::fromPtr(P));
}

static bool serialize(SPSOutputBuffer &OB, T *const &P) {
return SPSArgList<SPSExecutorAddr>::serialize(OB, ExecutorAddr::fromPtr(P));
}

static bool deserialize(SPSInputBuffer &IB, T *&P) {
ExecutorAddr Value;
if (!SPSArgList<SPSExecutorAddr>::deserialize(IB, Value))
return false;
P = Value.toPtr<T *>();
return true;
}
};

/// Helper type for serializing Errors.
///
/// llvm::Errors are move-only, and not inspectable except by consuming them.
Expand Down
56 changes: 0 additions & 56 deletions orc-rt/unittests/SPSWrapperFunctionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SPSExecutorAddr(SPSExecutorAddr)>::handle(
Session, CallCtx, Return, ArgBytes,
[](move_only_function<void(int32_t *)> Return, int32_t *P) {
Return(P);
});
}

TEST(SPSWrapperFunctionUtilsTest, TransparentConversionPointers) {
int X = 42;
int *P = nullptr;
SPSWrapperFunction<SPSExecutorAddr(SPSExecutorAddr)>::call(
DirectCaller(nullptr, round_trip_int_pointer_sps_wrapper),
[&](Expected<int32_t *> R) { P = cantFail(std::move(R)); }, &X);

EXPECT_EQ(P, &X);
}

TEST(SPSWrapperFunctionUtilsTest, TransparentConversionReferenceArguments) {
int X = 42;
int *P = nullptr;
SPSWrapperFunction<SPSExecutorAddr(SPSExecutorAddr)>::call(
DirectCaller(nullptr, round_trip_int_pointer_sps_wrapper),
[&](Expected<int32_t *> R) { P = cantFail(std::move(R)); },
static_cast<int *const &>(&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<SPSExpected<SPSExecutorAddr>(SPSExecutorAddr)>::handle(
Session, CallCtx, Return, ArgBytes,
[](move_only_function<void(Expected<int32_t *>)> Return, int32_t *P) {
Return(P);
});
}

TEST(SPSWrapperFunctionUtilsTest, TransparentConversionExpectedPointers) {
int X = 42;
int *P = nullptr;
SPSWrapperFunction<SPSExpected<SPSExecutorAddr>(SPSExecutorAddr)>::call(
DirectCaller(nullptr, expected_int_pointer_sps_wrapper),
[&](Expected<Expected<int32_t *>> R) {
P = cantFail(cantFail(std::move(R)));
},
&X);

EXPECT_EQ(P, &X);
}

template <size_t N> struct SPSOpCounter {};

namespace orc_rt {
Expand Down
6 changes: 6 additions & 0 deletions orc-rt/unittests/SimplePackedSerializationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ TEST(SimplePackedSerializationTest, StdOptionalValueSerialization) {
blobSerializationRoundTrip<SPSOptional<int64_t>>(Value);
}

TEST(SimplePackedSerializationTest, Pointers) {
int X = 42;
int *P = &X;
blobSerializationRoundTrip<SPSExecutorAddr>(P);
}

TEST(SimplePackedSerializationTest, ArgListSerialization) {
using BAL = SPSArgList<bool, int32_t, SPSString>;

Expand Down
Loading