[llvm] [orc-rt] Add Session::attach for pre-mode ControllerAccesses. (PR #222227)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 20:50:11 PDT 2026
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/222227
Allow clients to attach a session using a pre-constructed ControllerAccess object. This allows clients to use non-trivial construction methods (e.g. factories) to build ControllerAccess objects.
>From 38f34ba3aeedea8f9d403f322c91f2557af0650e Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Wed, 9 Sep 2026 13:24:57 +1000
Subject: [PATCH] [orc-rt] Add Session::attach for pre-mode ControllerAccesses.
Allow clients to attach a session using a pre-constructed
ControllerAccess object. This allows clients to use non-trivial
construction methods (e.g. factories) to build ControllerAccess objects.
---
orc-rt/include/orc-rt/bedrock/Session.h | 12 ++++++++++++
orc-rt/test/unit/bedrock/SessionTest.cpp | 18 ++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/orc-rt/include/orc-rt/bedrock/Session.h b/orc-rt/include/orc-rt/bedrock/Session.h
index 771d195410703..7cdb45f59a000 100644
--- a/orc-rt/include/orc-rt/bedrock/Session.h
+++ b/orc-rt/include/orc-rt/bedrock/Session.h
@@ -424,6 +424,18 @@ class Session {
return addService(std::move(*Srv));
}
+ /// Attach to an already constructed ControllerAccess instance.
+ ///
+ /// A Session may be attached at most once, and attach must not be called
+ /// after -- or concurrently with -- detach or shutdown: by the time a detach
+ /// has been requested it may be arbitrarily far along, so there is no point
+ /// at which a newly attached controller could be connected, or its
+ /// disconnection coherently reported. Violating this is a programming error,
+ /// checked by assertion.
+ void attach(std::shared_ptr<ControllerAccess> CA, BootstrapInfo BI) noexcept {
+ doAttach(std::move(CA), std::move(BI));
+ }
+
/// Construct a ControllerAccessT and immediately attach using the given
/// BootstrapInfo.
///
diff --git a/orc-rt/test/unit/bedrock/SessionTest.cpp b/orc-rt/test/unit/bedrock/SessionTest.cpp
index a96631896775e..df51db33a63c4 100644
--- a/orc-rt/test/unit/bedrock/SessionTest.cpp
+++ b/orc-rt/test/unit/bedrock/SessionTest.cpp
@@ -897,6 +897,24 @@ TEST(ControllerAccessTest, BootstrapInfoPassedToConnect) {
ASSERT_TRUE(OnConnectRan);
}
+TEST(ControllerAccessTest, PlainAttach) {
+ // Attach a with pre-constructed ControllerAccess instance.
+ QueueingRunner<>::WorkQueue Tasks;
+ Session S(mockExecutorProcessInfo(), QueueingRunner(Tasks), noErrors);
+ auto CA = cantFail(MockControllerAccess::Create(S, false, postOnto(Tasks)));
+ S.attach(std::move(CA), BootstrapInfo(S));
+
+ int32_t Result = 0;
+ SPSWrapperFunction<int32_t(int32_t, int32_t)>::call(
+ S.controllerCaller(
+ reinterpret_cast<orc_rt_ControllerHandlerTag>(add_sps_wrapper)),
+ [&](Expected<int32_t> R) { Result = cantFail(std::move(R)); }, 41, 1);
+
+ QueueingRunner<>::runFIFOUntilEmpty(Tasks);
+
+ EXPECT_EQ(Result, 42);
+}
+
TEST(ControllerAccessTest, TryAttachSuccess) {
// A successful Create attaches the controller, which then services calls
// just like one attached via attach<T>.
More information about the llvm-commits
mailing list