From b784dc178f4ba66bf4d478b21cb36234df0e5f1d Mon Sep 17 00:00:00 2001 From: Cra3z Date: Fri, 13 Nov 2026 16:32:11 +0800 Subject: [PATCH 1/4] Add `inlinable_receiver` concept --- include/stdexec/__detail/__receivers.hpp | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/stdexec/__detail/__receivers.hpp b/include/stdexec/__detail/__receivers.hpp index 9d4bbafe6..9551ba623 100644 --- a/include/stdexec/__detail/__receivers.hpp +++ b/include/stdexec/__detail/__receivers.hpp @@ -366,6 +366,49 @@ namespace STDEXEC struct _THE_RECEIVER_DOES_NOT_ACCEPT_ALL_OF_THE_SENDERS_COMPLETION_SIGNALS_ {}; + //! @brief A receiver that can be reconstructed from its child operation state. + //! + //! `inlinable_receiver` refines @c receiver and requires the + //! decayed receiver type to provide a class-level `make_receiver_for` + //! function. The function is called with a pointer to the child operation + //! state and must be non-throwing and return exactly the decayed receiver + //! type: + //! + //! @code{.cpp} + //! struct my_receiver { + //! using receiver_concept = stdexec::receiver_tag; + //! + //! template + //! static my_receiver make_receiver_for(ChildOp*) noexcept; + //! + //! // set_value, set_error, set_stopped, and get_env ... + //! }; + //! @endcode + //! + //! An operation state that uses such a receiver can recreate it on demand + //! with `R::make_receiver_for(this)` instead of storing a receiver object. + //! This can reduce the size of nested operation states when the receiver's + //! state is recoverable from the operation-state address. `ChildOp` only + //! appears as a pointer parameter, so it may be incomplete when the concept + //! is checked in an operation-state definition. + //! + //! The concept checks the syntactic protocol only. For a receiver object + //! `rcvr` connected to an operation state `op`, the semantic requirement is + //! that `R::make_receiver_for(std::addressof(op))` recreate a receiver equal + //! to `rcvr`. + //! + //! See [exec.recv.concepts] in the C++26 working draft. + //! + //! @see stdexec::receiver + //! @see stdexec::operation_state + STDEXEC_MODULE_EXPORT + template + concept inlinable_receiver = receiver<_Receiver> && requires(_ChildOp *__child_op) { + { + std::remove_cvref_t<_Receiver>::make_receiver_for(__child_op) + } noexcept -> __std::same_as>; + }; + namespace __detail { template From 7d7e8b7c7671a5649e113ca515b41a2d7218bed7 Mon Sep 17 00:00:00 2001 From: Cra3z Date: Fri, 13 Nov 2026 17:32:22 +0800 Subject: [PATCH 2/4] Add `inlinable_receiver` tests --- .../concepts/test_concepts_receiver.cpp | 210 ++++++++++++++++++ 1 file changed, 210 insertions(+) diff --git a/test/stdexec/concepts/test_concepts_receiver.cpp b/test/stdexec/concepts/test_concepts_receiver.cpp index b6f06ed23..e56c78e82 100644 --- a/test/stdexec/concepts/test_concepts_receiver.cpp +++ b/test/stdexec/concepts/test_concepts_receiver.cpp @@ -19,6 +19,13 @@ #include +#include +#include +#include +#include +#include +#include + namespace ex = STDEXEC; struct recv_no_set_value @@ -125,6 +132,176 @@ struct recv_non_movable } }; +template +struct test_basic_receiver +{ + using receiver_concept = ex::receiver_tag; + + template + static test_basic_receiver make_receiver_for(_ChildOp *__child) noexcept + { + // `_ChildOp` is the first non-static data member of `_ParentOp`. + auto const address = reinterpret_cast(__child); + // NOTE: Actually, it's still UB. Under the current standard, pointer conversion/arithmetic cannot achieve + // this. A truly well-defined approach will likely have to wait until proposals like P3407 are adopted into the + // standard. + return test_basic_receiver{reinterpret_cast<_ParentOp *>(address)}; + } + + template + void set_value(_Args &&...__args) noexcept + { + ex::set_value(std::move(__parent->get_receiver()), static_cast<_Args &&>(__args)...); + } + + template + void set_error(_Error &&__error) noexcept + { + ex::set_error(std::move(__parent->get_receiver()), static_cast<_Error &&>(__error)); + } + + void set_stopped() noexcept + { + ex::set_stopped(std::move(__parent->get_receiver())); + } + + _Env get_env() const noexcept + { + return ex::get_env(__parent->get_receiver()); + } + + _ParentOp *__parent; +}; + +template +struct test_basic_state +{ + using operation_state_concept = ex::operation_state_tag; + + using receiver_t = test_basic_receiver>; + using child_op_t = ex::connect_result_t<_Sender, receiver_t>; + + test_basic_state(_Sender __sender, _Receiver __receiver) + : receiver(std::move(__receiver)) + { + // The child operation state should be created after `receiver` constructed + ::new (static_cast(storage)) + child_op_t(ex::connect(std::move(__sender), receiver_t{this})); + } + + void start() & noexcept + { + ex::start(*::std::launder(reinterpret_cast(storage))); + } + + _Receiver &get_receiver() noexcept + { + return receiver; + } + + alignas(child_op_t) std::byte storage[sizeof(child_op_t)]; + _Receiver receiver; +}; + +template + requires ex::inlinable_receiver<_Receiver, test_basic_state<_Sender, _Receiver>> +struct test_basic_state<_Sender, _Receiver> +{ + using operation_state_concept = ex::operation_state_tag; + + using receiver_t = test_basic_receiver>; + using child_op_t = ex::connect_result_t<_Sender, receiver_t>; + + test_basic_state(_Sender __sender, _Receiver const &) + : child_op(ex::connect(std::move(__sender), receiver_t{this})) + {} + + void start() & noexcept + { + ex::start(child_op); + } + + _Receiver get_receiver() noexcept + { + return _Receiver::make_receiver_for(this); + } + + child_op_t child_op; +}; + +template +struct test_basic_sender +{ + using sender_concept = ex::sender_tag; + + _Tag tag; + _Child child; + + template + requires ex::sender_in<_Child, _Env...> + static consteval auto get_completion_signatures() + { + return ex::get_completion_signatures<_Child, _Env...>(); + } + + template + auto connect(_Receiver __receiver) + { + return test_basic_state<_Child, _Receiver>{std::move(child), std::move(__receiver)}; + } +}; + +struct test_adaptor : ex::sender_adaptor_closure +{ + template + auto operator()(_Sender __sender) + { + return test_basic_sender{*this, std::move(__sender)}; + } +}; + +struct inlinable_state +{}; + +struct non_inlinable_state +{}; + +struct normal_receiver +{ + using receiver_concept = ex::receiver_tag; + + static void set_value(auto const &...) noexcept {} + static void set_error(auto const &) noexcept {} + static void set_stopped() noexcept {} +}; + +struct inlinable_receiver +{ + using receiver_concept = ex::receiver_tag; + + static inlinable_receiver make_receiver_for(inlinable_state *) noexcept + { + return {}; + } + + static normal_receiver make_receiver_for(non_inlinable_state *) noexcept + { + return {}; + } + + template + static inlinable_receiver make_receiver_for(test_basic_state<_Child, _Receiver> *) noexcept + { + return {}; + } + + static void set_value(auto const &...) noexcept {} + static void set_error(auto const &) noexcept {} + static void set_stopped() noexcept {} +}; + +static_assert(ex::receiver); + TEST_CASE("receiver types satisfy the receiver concept", "[concepts][receiver]") { using namespace empty_recv; @@ -185,3 +362,36 @@ TEST_CASE("non-movable type is not a receiver", "[concepts][receiver]") REQUIRE(!ex::receiver); REQUIRE(!ex::receiver_of>); } + +TEST_CASE("inlinable_receiver", "[concepts][receiver]") +{ + static_assert(!ex::inlinable_receiver); + static_assert(!ex::inlinable_receiver); + static_assert(ex::inlinable_receiver); + + auto sender = ex::just(42) | test_adaptor{}; + using normal_state = ex::connect_result_t; + using inlinable_state_t = ex::connect_result_t; + static_assert(ex::operation_state); + static_assert(ex::operation_state); + + auto nested_sender = sender | test_adaptor{}; + using nested_normal_state = ex::connect_result_t; + using nested_inlinable_state = ex::connect_result_t; + static_assert(sizeof(normal_state) == sizeof(nested_normal_state)); + static_assert(sizeof(inlinable_state_t) == sizeof(nested_inlinable_state)); + + auto [result] = ex::sync_wait(nested_sender).value(); + REQUIRE(result == 42); + + auto nested_4_sender = ex::just(67) | test_adaptor{} | test_adaptor{} | test_adaptor{} + | test_adaptor{}; + using nested_4_normal_state = ex::connect_result_t; + using nested_4_inlinable_state = + ex::connect_result_t; + static_assert(sizeof(normal_state) == sizeof(nested_4_normal_state)); + static_assert(sizeof(inlinable_state_t) == sizeof(nested_4_inlinable_state)); + + auto [result1] = ex::sync_wait(nested_4_sender).value(); + REQUIRE(result1 == 67); +} From 9d89576499c44f4c7a3950562c510020053d9562 Mon Sep 17 00:00:00 2001 From: Cra3z <3324654761@qq.com> Date: Sat, 14 Nov 2026 10:19:52 +0800 Subject: [PATCH 3/4] Fix inlinable_receiver concept test helper lifetime and adaptor constness --- test/stdexec/concepts/test_concepts_receiver.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/stdexec/concepts/test_concepts_receiver.cpp b/test/stdexec/concepts/test_concepts_receiver.cpp index e56c78e82..2a0aa5d95 100644 --- a/test/stdexec/concepts/test_concepts_receiver.cpp +++ b/test/stdexec/concepts/test_concepts_receiver.cpp @@ -189,9 +189,14 @@ struct test_basic_state child_op_t(ex::connect(std::move(__sender), receiver_t{this})); } + ~test_basic_state() + { + std::destroy_at(std::launder(reinterpret_cast(storage))); + } + void start() & noexcept { - ex::start(*::std::launder(reinterpret_cast(storage))); + ex::start(*std::launder(reinterpret_cast(storage))); } _Receiver &get_receiver() noexcept @@ -254,7 +259,7 @@ struct test_basic_sender struct test_adaptor : ex::sender_adaptor_closure { template - auto operator()(_Sender __sender) + auto operator()(_Sender __sender) const noexcept { return test_basic_sender{*this, std::move(__sender)}; } From 5b052b11582017f39dc7ccd4e6f48fb908fa2a60 Mon Sep 17 00:00:00 2001 From: Cra3z <3324654761@qq.com> Date: Sat, 14 Nov 2026 11:02:30 +0800 Subject: [PATCH 4/4] Use `STATIC_REQUIRE` instead of `static_assert` --- .../concepts/test_concepts_receiver.cpp | 121 +++++++++--------- 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/test/stdexec/concepts/test_concepts_receiver.cpp b/test/stdexec/concepts/test_concepts_receiver.cpp index 2a0aa5d95..5e8fd9b28 100644 --- a/test/stdexec/concepts/test_concepts_receiver.cpp +++ b/test/stdexec/concepts/test_concepts_receiver.cpp @@ -116,10 +116,10 @@ struct recv_non_movable recv_non_movable() = default; ~recv_non_movable() = default; - recv_non_movable(recv_non_movable&&) = delete; - recv_non_movable& operator=(recv_non_movable&&) = delete; + recv_non_movable(recv_non_movable &&) = delete; + recv_non_movable &operator=(recv_non_movable &&) = delete; recv_non_movable(recv_non_movable const &) = default; - recv_non_movable& operator=(recv_non_movable const &) = default; + recv_non_movable &operator=(recv_non_movable const &) = default; void set_value() noexcept {} void set_stopped() noexcept {} @@ -138,15 +138,7 @@ struct test_basic_receiver using receiver_concept = ex::receiver_tag; template - static test_basic_receiver make_receiver_for(_ChildOp *__child) noexcept - { - // `_ChildOp` is the first non-static data member of `_ParentOp`. - auto const address = reinterpret_cast(__child); - // NOTE: Actually, it's still UB. Under the current standard, pointer conversion/arithmetic cannot achieve - // this. A truly well-defined approach will likely have to wait until proposals like P3407 are adopted into the - // standard. - return test_basic_receiver{reinterpret_cast<_ParentOp *>(address)}; - } + static test_basic_receiver make_receiver_for(_ChildOp *__child) noexcept; // undefined template void set_value(_Args &&...__args) noexcept @@ -189,6 +181,10 @@ struct test_basic_state child_op_t(ex::connect(std::move(__sender), receiver_t{this})); } + test_basic_state(test_basic_state const &) = delete; + + test_basic_state &operator=(test_basic_state const &) = delete; + ~test_basic_state() { std::destroy_at(std::launder(reinterpret_cast(storage))); @@ -221,6 +217,12 @@ struct test_basic_state<_Sender, _Receiver> : child_op(ex::connect(std::move(__sender), receiver_t{this})) {} + test_basic_state(test_basic_state const &) = delete; + + test_basic_state &operator=(test_basic_state const &) = delete; + + ~test_basic_state() {} // NOLINT(*-use-equals-default) + void start() & noexcept { ex::start(child_op); @@ -311,92 +313,89 @@ TEST_CASE("receiver types satisfy the receiver concept", "[concepts][receiver]") { using namespace empty_recv; - REQUIRE(ex::receiver); - REQUIRE(ex::receiver); - REQUIRE(ex::receiver); - REQUIRE(ex::receiver); - REQUIRE(ex::receiver>); - REQUIRE(ex::receiver); - REQUIRE(ex::receiver, int>>); - REQUIRE(ex::receiver, double>>); - REQUIRE(ex::receiver>); - REQUIRE(ex::receiver>); - REQUIRE(ex::receiver>); - REQUIRE(ex::receiver>); - REQUIRE(ex::receiver); + STATIC_REQUIRE(ex::receiver); + STATIC_REQUIRE(ex::receiver); + STATIC_REQUIRE(ex::receiver); + STATIC_REQUIRE(ex::receiver); + STATIC_REQUIRE(ex::receiver>); + STATIC_REQUIRE(ex::receiver); + STATIC_REQUIRE(ex::receiver, int>>); + STATIC_REQUIRE(ex::receiver, double>>); + STATIC_REQUIRE(ex::receiver>); + STATIC_REQUIRE(ex::receiver>); + STATIC_REQUIRE(ex::receiver>); + STATIC_REQUIRE(ex::receiver>); + STATIC_REQUIRE(ex::receiver); } TEST_CASE("receiver types satisfy the receiver_of concept", "[concepts][receiver]") { using namespace empty_recv; - REQUIRE(ex::receiver_of>); - REQUIRE(ex::receiver_of>); - REQUIRE( + STATIC_REQUIRE(ex::receiver_of>); + STATIC_REQUIRE( + ex::receiver_of>); + STATIC_REQUIRE( ex::receiver_of>); - REQUIRE(ex::receiver_of>); - REQUIRE(ex::receiver_of, int>, - ex::completion_signatures>); - REQUIRE(ex::receiver_of, double>, - ex::completion_signatures>); - REQUIRE( + STATIC_REQUIRE(ex::receiver_of>); + STATIC_REQUIRE(ex::receiver_of, int>, + ex::completion_signatures>); + STATIC_REQUIRE(ex::receiver_of, double>, + ex::completion_signatures>); + STATIC_REQUIRE( ex::receiver_of, ex::completion_signatures>); - REQUIRE(ex::receiver_of, - ex::completion_signatures>); - REQUIRE( + STATIC_REQUIRE(ex::receiver_of, + ex::completion_signatures>); + STATIC_REQUIRE( ex::receiver_of, ex::completion_signatures>); - REQUIRE(ex::receiver_of, - ex::completion_signatures>); - REQUIRE(ex::receiver_of>); + STATIC_REQUIRE(ex::receiver_of, + ex::completion_signatures>); + STATIC_REQUIRE( + ex::receiver_of>); } TEST_CASE("receiver type w/o set_value models receiver but not receiver_of", "[concepts][receiver]") { - REQUIRE(ex::receiver); - REQUIRE(!ex::receiver_of>); + STATIC_REQUIRE(ex::receiver); + STATIC_REQUIRE(!ex::receiver_of>); } TEST_CASE("type with set_value noexcept is a receiver", "[concepts][receiver]") { - REQUIRE(ex::receiver); - REQUIRE(ex::receiver_of>); + STATIC_REQUIRE(ex::receiver); + STATIC_REQUIRE( + ex::receiver_of>); } TEST_CASE("non-movable type is not a receiver", "[concepts][receiver]") { - REQUIRE(!ex::receiver); - REQUIRE(!ex::receiver_of>); + STATIC_REQUIRE(!ex::receiver); + STATIC_REQUIRE(!ex::receiver_of>); } TEST_CASE("inlinable_receiver", "[concepts][receiver]") { - static_assert(!ex::inlinable_receiver); - static_assert(!ex::inlinable_receiver); - static_assert(ex::inlinable_receiver); + STATIC_REQUIRE(!ex::inlinable_receiver); + STATIC_REQUIRE(!ex::inlinable_receiver); + STATIC_REQUIRE(ex::inlinable_receiver); auto sender = ex::just(42) | test_adaptor{}; using normal_state = ex::connect_result_t; using inlinable_state_t = ex::connect_result_t; - static_assert(ex::operation_state); - static_assert(ex::operation_state); + STATIC_REQUIRE(ex::operation_state); + STATIC_REQUIRE(ex::operation_state); auto nested_sender = sender | test_adaptor{}; using nested_normal_state = ex::connect_result_t; using nested_inlinable_state = ex::connect_result_t; - static_assert(sizeof(normal_state) == sizeof(nested_normal_state)); - static_assert(sizeof(inlinable_state_t) == sizeof(nested_inlinable_state)); - - auto [result] = ex::sync_wait(nested_sender).value(); - REQUIRE(result == 42); + STATIC_REQUIRE(sizeof(normal_state) == sizeof(nested_normal_state)); + STATIC_REQUIRE(sizeof(inlinable_state_t) == sizeof(nested_inlinable_state)); auto nested_4_sender = ex::just(67) | test_adaptor{} | test_adaptor{} | test_adaptor{} | test_adaptor{}; using nested_4_normal_state = ex::connect_result_t; using nested_4_inlinable_state = ex::connect_result_t; - static_assert(sizeof(normal_state) == sizeof(nested_4_normal_state)); - static_assert(sizeof(inlinable_state_t) == sizeof(nested_4_inlinable_state)); - - auto [result1] = ex::sync_wait(nested_4_sender).value(); - REQUIRE(result1 == 67); + STATIC_REQUIRE(sizeof(normal_state) == sizeof(nested_4_normal_state)); + STATIC_REQUIRE(sizeof(inlinable_state_t) == sizeof(nested_4_inlinable_state)); }