From 885cf6c80c36acef8ea431527fb1ad9e4d3c3b72 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 27 Nov 2026 16:20:26 -0800 Subject: [PATCH 1/4] don't instantiate the operations below starts_on's walk state starts_on's state holds its child's operation, connected to the facade's receiver for the child. When the state's receiver is an archetype, as in the facade's walk, that receiver is __nested_receiver_archetype, so the walk instantiated the child's operations a second time, and, through __start_nested, their start functions. (Only a sequence sender's item source got a placeholder.) Now starts_on declares its state's type with __state_type (see #2562), and a state whose receiver is an archetype holds a placeholder (__walk_op) for the child's operation, and connects nothing. Whether connecting the child can throw is still asked of the real operation, which a new test checks. on(sch, sndr) is lowered to continues_on(starts_on(sch, sndr), ...), so it gains too. MAINTAINERS.md now says what a state whose receiver is an archetype does. A pipeline of a dozen algorithms (let_value, when_all, continues_on, bulk), 8.78 s alone (clang 22 -O3), in starts_on: 9.10 s / 527 MB -> 8.95 s / 507 MB, and with extra type checking 11.14 s -> 10.75 s; in on: 9.61 s -> 9.40 s. test_starts_on.cpp: 9.60 s -> 9.40 s, test_on.cpp: 11.71 s -> 11.54 s. Their GCC 15 Debug objects are 1.4% and 0.9% smaller. Co-Authored-By: Claude Opus 5.5 --- MAINTAINERS.md | 2 +- include/stdexec/__detail/__starts_on.hpp | 39 +++++++++++++++++-- .../stdexec/algos/adaptors/test_starts_on.cpp | 33 ++++++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 4e6dd390e..da4a64f4e 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -449,7 +449,7 @@ algorithms need only `__complete`, and perhaps `__start`. | `__start(state, children)` | starts every child with `children.__start_all()` | the algorithm completes from `start`, starts only some of its children, or starts a nested operation | `just`, `let_value`, `repeat_n` | | `__get_state(sndr, rcvr)` | a `__basic_state` that holds the receiver and the sender's data | the state holds more than the data (nested operations, saved results, a stop source), or the algorithm rejects its inputs by returning an `__mexception` | `when_all`, `continues_on`, `let_value` | | `__get_state(sndr, rcvr, __subscribing_t)` | the same as the above | the state of a subscribed (sequence) sender differs from that of a connected one | | -| `__state_type` (opt-in) | the type that `__get_state` returns | the state holds nested operations. The walk then gets the state's type without asking whether making the state can throw, which would instantiate the operations below it. It must name the type that `__get_state` returns, or its `__mexception` | `let_value`, `__sequence`, `exec::ignore_all_values` | +| `__state_type` (opt-in) | the type that `__get_state` returns | the state holds nested operations. The walk then gets the state's type without asking whether making the state can throw, which would instantiate the operations below it. It must name the type that `__get_state` returns, or its `__mexception`. A state whose receiver is an archetype (see `__facade::__walking_receiver`) is for the walk, or for asking whether connecting can throw: it holds placeholders for its operations (see `__facade::__state_op_t`) and does not connect them, but whether connecting them can throw is still asked of the real operations | `let_value`, `__sequence`, `exec::ignore_all_values` | | `__connects_children` | `true` | the algorithm connects a child itself, in its state: to connect it later, to start it from a nested operation, or to destroy its operation early | `__sequence`, `starts_on`, `let_value` | | `__connect(key, state, sndr, rcvr)` | `STDEXEC::connect(sndr, rcvr)` | a child or nested operation must be connected to a different kind of receiver, as when a domain adapts a child whose operation completes from a kernel | nvexec | | `__receiver_base` | an empty struct | a domain's algorithm needs the facade's receivers to have a base class, so that its senders complete them in the way they expect | nvexec | diff --git a/include/stdexec/__detail/__starts_on.hpp b/include/stdexec/__detail/__starts_on.hpp index 0f4a8ec83..e1b8410db 100644 --- a/include/stdexec/__detail/__starts_on.hpp +++ b/include/stdexec/__detail/__starts_on.hpp @@ -47,6 +47,27 @@ namespace STDEXEC struct __algo; + // The type of the child's operation: the one that the state attaches, or, if the state is + // for a walk (its receiver is an archetype), a placeholder, since the walk needs only the + // state's type. Naming the operation there would instantiate the operations below it, + // connected to archetypes. (A class keyed by a bool only, so that the debug information, + // which names the class when it names the operation's type, does not repeat the sender's + // and the receiver's types.) + template + struct __child_op_of + { + template + using __f = + __facade::__child_op_t<__algo, _Sender, 0, _State, _Child, _Rcvr, _Subscribing...>; + }; + + template <> + struct __child_op_of + { + template + using __f = __facade::__walk_op; + }; + // The state of a starts_on. If the starts_on is subscribed (_Subscribing is // __facade::__subscribing_t), so is its child, when that is a sequence sender (see // __facade::__attaches_child). @@ -63,8 +84,9 @@ namespace STDEXEC __facade::__receiver_t<__algo, __sched_op, __state, _Sender, _Receiver>; using __child_rcvr_t = __facade::__receiver_t<__algo, __facade::__child<0>, __state, _Sender, _Receiver>; - using __child_op_t = __facade:: - __child_op_t<__algo, _Sender, 0, __state, __child_t, __child_rcvr_t, _Subscribing...>; + using __child_op_of_t = __child_op_of<__facade::__walking_receiver<_Receiver>>; + using __child_op_t = + __child_op_of_t::template __f<_Sender, __state, __child_t, __child_rcvr_t, _Subscribing...>; static constexpr bool __nothrow_v = __nothrow_callable && __nothrow_connectable<__sched_sndr_t, __sched_rcvr_t> @@ -94,11 +116,16 @@ namespace STDEXEC __child_op_t __child_op_; private: - // Connects the child, or attaches it (see __facade::__attaches_child) + // Connects the child, or attaches it (see __facade::__attaches_child), unless the state + // is for a walk: then __child_op_ is a placeholder. STDEXEC_ATTRIBUTE(always_inline) constexpr auto __attach_child(__child_t&& __child) noexcept(__nothrow_v) -> __child_op_t { - if constexpr (__facade::__attaches_child<__algo, _Sender, 0>) + if constexpr (__facade::__walking_receiver<_Receiver>) + { + return {}; + } + else if constexpr (__facade::__attaches_child<__algo, _Sender, 0>) { using __attach_t = __facade::__attach_child_t<__algo, _Sender, 0, __child_rcvr_t, _Subscribing...>; @@ -181,6 +208,10 @@ namespace STDEXEC __facade::__get_data(__sndr)}; } + // (See __facade::__state_type_t.) + template + using __state_type = __state<_Sender, _Receiver, _Subscribing...>; + // (The state of a subscribed starts_on takes __facade::__subscribing_t.) template STDEXEC_ATTRIBUTE(host, device) diff --git a/test/stdexec/algos/adaptors/test_starts_on.cpp b/test/stdexec/algos/adaptors/test_starts_on.cpp index 4d3bce363..30acd1259 100644 --- a/test/stdexec/algos/adaptors/test_starts_on.cpp +++ b/test/stdexec/algos/adaptors/test_starts_on.cpp @@ -29,6 +29,8 @@ import std; #else # include // IWYU pragma: keep for std::chrono_literals +# include +# include #endif namespace ex = STDEXEC; @@ -524,6 +526,37 @@ namespace auto domain = ex::get_env(error).query(ex::get_completion_domain); static_assert(std::same_as); } + +#if !STDEXEC_NO_STDCPP_EXCEPTIONS() + struct throws_on_connect + { + using sender_concept = ex::sender_tag; + using completion_signatures = ex::completion_signatures; + + template + auto connect(Receiver) const -> ex::connect_result_t + { + throw std::logic_error("connect"); + } + }; + + TEST_CASE("starts_on - connecting can throw if connecting the child can", "[adaptors][starts_on]") + { + // (The function is noexcept, so the exception can come only from connecting.) + auto fn = []() noexcept + { + return ex::starts_on(inline_scheduler{}, throws_on_connect{}); + }; + using Sender = decltype(fn()); + STATIC_REQUIRE(!ex::__nothrow_connectable>>); + + // So an algorithm that connects it when another sender completes reports the exception. + using Let = decltype(ex::let_value(ex::just(), fn)); + STATIC_REQUIRE(ex::__mapply, + ex::completion_signatures_of_t>>::value); + CHECK_THROWS_AS(ex::sync_wait(ex::let_value(ex::just(), fn)), std::logic_error); + } +#endif // !STDEXEC_NO_STDCPP_EXCEPTIONS() } // namespace STDEXEC_PRAGMA_POP() From 82104335d4f26050681a2eaba0f4cb95bd8136c0 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 27 Nov 2026 16:20:26 -0800 Subject: [PATCH 2/4] don't instantiate the operations below finally's walk state __finally_'s state holds the operations of both of its children, connected to the facade's receivers for them, which are receiver archetypes in the facade's walk. So the walk instantiated both children's operations a second time, and, through __start_nested, their start functions. affine lowers to __finally_(sndr, unstoppable(schedule(sch))) when sndr is not already affine, and task awaits every sender through affine, so each co_await of such a sender paid for this. Now __finally_ declares its state's type with __state_type, and a state whose receiver is an archetype holds placeholders for the operations, and connects nothing. Whether connecting either child can throw is still asked of the real operations, which a new test checks. The same pipeline in finally (clang 22 -O3): 9.39 s / 541 MB -> 9.19 s / 535 MB, and with extra type checking 11.41 s -> 11.02 s. test_finally.cpp: 9.16 s / 554 MB -> 8.92 s / 531 MB. Its GCC 15 Debug object is 3.3% smaller. Co-Authored-By: Claude Opus 5.5 --- include/stdexec/__detail/__finally.hpp | 40 ++++++++++++++++---- test/stdexec/algos/adaptors/test_finally.cpp | 35 +++++++++++++++++ 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/include/stdexec/__detail/__finally.hpp b/include/stdexec/__detail/__finally.hpp index 97da27d07..75f158b08 100644 --- a/include/stdexec/__detail/__finally.hpp +++ b/include/stdexec/__detail/__finally.hpp @@ -113,8 +113,11 @@ namespace STDEXEC __facade::__receiver_t<__algo, __facade::__child<0>, __state, _Sender, _Receiver>; using __final_rcvr_t = __facade::__receiver_t<__algo, __facade::__child<1>, __state, _Sender, _Receiver>; - using __initial_op_t = connect_result_t<__initial_t, __initial_rcvr_t>; - using __final_op_t = connect_result_t<__final_t, __final_rcvr_t>; + // (A walk's state holds placeholders for the operations: see __facade::__state_op_t.) + using __initial_op_t = + __facade::__state_op_t<_Receiver, connect_result_t, __initial_t, __initial_rcvr_t>; + using __final_op_t = + __facade::__state_op_t<_Receiver, connect_result_t, __final_t, __final_rcvr_t>; static constexpr bool __saves_results = __facade::__completions_of_t<__algo, __facade::__child<1>, _Sender, _Receiver>::__count( @@ -131,12 +134,14 @@ namespace STDEXEC && __nothrow_connectable<__initial_t, __initial_rcvr_t>) : __rcvr_(static_cast<_Receiver&&>(__rcvr)) , __env2_(__trnsfr::__mk_env2(__facade::__get_child<0>(__sndr), STDEXEC::get_env(__rcvr_))) - , __final_op_(STDEXEC::connect(__facade::__get_child<1>(static_cast<_Sender&&>(__sndr)), - __final_rcvr_t{this})) + , __final_op_(__state::__connect_final(static_cast<_Sender&&>(__sndr), this)) { - __initial_op_.__emplace_from(STDEXEC::connect, - __facade::__get_child<0>(static_cast<_Sender&&>(__sndr)), - __initial_rcvr_t{this}); + if constexpr (!__facade::__walking_receiver<_Receiver>) + { + __initial_op_.__emplace_from(STDEXEC::connect, + __facade::__get_child<0>(static_cast<_Sender&&>(__sndr)), + __initial_rcvr_t{this}); + } } STDEXEC_IMMOVABLE(__state); @@ -146,6 +151,23 @@ namespace STDEXEC __storage_t __storage_{}; __final_op_t __final_op_; __optional<__initial_op_t> __initial_op_{}; + + private: + // Connects the final sender, unless the state is for a walk: then __final_op_ is a + // placeholder. + static constexpr auto __connect_final(_Sender&& __sndr, __state* __self) + noexcept(__nothrow_connectable<__final_t, __final_rcvr_t>) -> __final_op_t + { + if constexpr (__facade::__walking_receiver<_Receiver>) + { + return {}; + } + else + { + return STDEXEC::connect(__facade::__get_child<1>(static_cast<_Sender&&>(__sndr)), + __final_rcvr_t{__self}); + } + } }; // __finally_(initial, final): when the initial sender completes, its results are saved, @@ -187,6 +209,10 @@ namespace STDEXEC __hide_scheduler{STDEXEC::get_env(__state.__rcvr_)}); } + // (See __facade::__state_type_t.) + template + using __state_type = __state<_Sender, _Receiver>; + template STDEXEC_ATTRIBUTE(host, device) static constexpr auto __get_state(_Sender&& __sndr, _Receiver __rcvr) diff --git a/test/stdexec/algos/adaptors/test_finally.cpp b/test/stdexec/algos/adaptors/test_finally.cpp index ad4109930..da46c8b9d 100644 --- a/test/stdexec/algos/adaptors/test_finally.cpp +++ b/test/stdexec/algos/adaptors/test_finally.cpp @@ -105,6 +105,41 @@ namespace CHECK_THROWS_AS(sync_wait(std::move(s)), int); CHECK(called); } + + struct throws_on_connect + { + using sender_concept = sender_tag; + using completion_signatures = STDEXEC::completion_signatures; + + template + auto connect(Receiver) const -> connect_result_t + { + throw 42; + } + }; + + TEST_CASE("finally - connecting can throw if connecting either sender can", "[adaptors][finally]") + { + // (The functions are noexcept, so the exception can come only from connecting.) + auto initial_throws = []() noexcept + { + return exec::finally(throws_on_connect{}, just()); + }; + auto final_throws = []() noexcept + { + return exec::finally(just(), throws_on_connect{}); + }; + using Rcvr = __receiver_archetype>; + STATIC_REQUIRE(!__nothrow_connectable); + STATIC_REQUIRE(!__nothrow_connectable); + + // So an algorithm that connects it when another sender completes reports the exception. + using Let = decltype(let_value(just(), final_throws)); + STATIC_REQUIRE(__mapply<__mcontains, + completion_signatures_of_t>>::value); + CHECK_THROWS_AS(sync_wait(let_value(just(), initial_throws)), int); + CHECK_THROWS_AS(sync_wait(let_value(just(), final_throws)), int); + } #endif // !STDEXEC_NO_STDCPP_EXCEPTIONS() TEST_CASE("finally completes where the final action completes", "[adaptors][finally]") From 1115b16662d69b0dd9c93be0c0c69592838a07fe Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 27 Nov 2026 16:20:26 -0800 Subject: [PATCH 3/4] don't connect the body in the walk state of the repeating algorithms The state of repeat_n, repeat_until and repeat holds the operation of the current iteration's body. Its __get_state's return type was deduced, so naming the state's type instantiated __get_state's body, and with it the state's constructor, which connects the first iteration's body. And the handlers connect the body of each next iteration. So the walk instantiated the body's connect and start functions, connected to a receiver archetype. Now __get_state names its return type, __state_type: the state, or the type error that it reports. And a state whose receiver is an archetype holds a placeholder for the body's operation, and connects nothing. The walk still asks whether connecting the body can throw, which decides whether the operation can complete with set_error_t(std::exception_ptr) (test_repeat_n.cpp checks that), so it still instantiates the type of the body's operation, but none of its functions. The trampoline's operation is the same in every walk, so it stays. The same pipeline in repeat_n (clang 22 -O3): 9.91 s / 561 MB -> 9.53 s / 546 MB, and with extra type checking 13.48 s / 695 MB -> 12.06 s / 647 MB. test_repeat_n.cpp: 11.95 s -> 11.62 s, test_repeat_until.cpp: 12.25 s -> 11.93 s. Their GCC 15 Debug objects are 1.4% and 1.6% smaller. Co-Authored-By: Claude Opus 5.5 --- include/exec/detail/repeat.hpp | 80 ++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 19 deletions(-) diff --git a/include/exec/detail/repeat.hpp b/include/exec/detail/repeat.hpp index 1a4a8afa7..36459ddcf 100644 --- a/include/exec/detail/repeat.hpp +++ b/include/exec/detail/repeat.hpp @@ -92,8 +92,11 @@ namespace experimental::execution::__repeat using __child_t = __repeat::__child_t<_Sender>; using __body_rcvr_t = __body_receiver_t<_Algo, _Sender, _Receiver>; using __bounce_rcvr_t = __facade::__receiver_t<_Algo, __bounce, __state, _Sender, _Receiver>; - using __body_op_t = connect_result_t<__child_t, __body_rcvr_t>; - using __bounce_op_t = connect_result_t<__bounce_sender_t, __bounce_rcvr_t>; + // (A walk's state holds a placeholder for the body's operation: see + // __facade::__state_op_t. The trampoline's operation is the same in every walk.) + using __body_op_t = + __facade::__state_op_t<_Receiver, connect_result_t, __child_t, __body_rcvr_t>; + using __bounce_op_t = connect_result_t<__bounce_sender_t, __bounce_rcvr_t>; static constexpr bool __nothrow_connect = __nothrow_constructible_from<__child_t, __child_t &> && __nothrow_connectable<__child_t, __body_rcvr_t>; @@ -118,10 +121,19 @@ namespace experimental::execution::__repeat // Connects the body of the next iteration, destroying the operation of the last one. // (This happens in the last one's completion. Operations that complete must not touch - // themselves afterward.) + // themselves afterward.) If the state is for a walk, __body_op_ is a placeholder. constexpr auto __connect_body() noexcept(__nothrow_connect) -> __body_op_t & { - return __body_op_.__emplace_from(STDEXEC::connect, __child_t(__child_), __body_rcvr_t{this}); + if constexpr (__facade::__walking_receiver<_Receiver>) + { + return __body_op_.emplace(); + } + else + { + return __body_op_.__emplace_from(STDEXEC::connect, + __child_t(__child_), + __body_rcvr_t{this}); + } } // Destroys the operations, before the operation completes @@ -147,6 +159,41 @@ namespace experimental::execution::__repeat return true; } + // The type that __get_state returns: the state, or the type error that it reports. + // (Classes keyed by bools only, so that the debug information, which names a class when + // it names the state's type, does not repeat the sender's and the receiver's types.) + template + struct __state_or_error + { + template + using __f = __state<_Algo, _Sender, _Receiver>; + }; + + template + struct __state_or_error + { + template + using __f = __mexception<_WHAT_(_INVALID_ARGUMENT_), + _WHERE_(_IN_ALGORITHM_, typename __decay_t<_Sender>::__tag_t), + _WHY_(_THE_INPUT_SENDER_MUST_BE_COPYABLE_), + _WITH_SENDER_<__child_t<_Sender>>>; + }; + + template <> + struct __state_or_error + { + template + using __f = __mexception<_WHAT_(_INVALID_ARGUMENT_), + _WHERE_(_IN_ALGORITHM_, typename __decay_t<_Sender>::__tag_t), + _WHY_(_THE_SENDER_CANNOT_BE_CONNECTED_), + _WITH_SENDER_<__child_t<_Sender>>>; + }; + + template + using __state_type_t = __state_or_error< + __std::copy_constructible<__child_t<_Sender>>, + __connectable<_Algo, _Sender, _Receiver>>::template __f<_Algo, _Sender, _Receiver>; + // The base of the repeating algorithms. _Derived is the algorithm, which says what the // body's value completions mean (with a __complete(__body, ...) handler), and how the // operation starts (with __start, which calls __start_iteration). Its static member @@ -202,29 +249,24 @@ namespace experimental::execution::__repeat return STDEXEC::schedule(trampoline_scheduler{}); } + // (See __facade::__state_type_t.) + template + using __state_type = __repeat::__state_type_t<_Derived, _Sender, _Receiver>; + + // The state, or the type error that it reports (see __state_or_error) template static constexpr auto __get_state(_Sender &&__sndr, _Receiver __rcvr) noexcept(__repeat::__nothrow_state<_Derived, _Sender, _Receiver>()) + -> __state_type<_Sender, _Receiver> { - using __tag_t = __decay_t<_Sender>::__tag_t; - if constexpr (!__std::copy_constructible<__child_t<_Sender>>) + if constexpr (__connectable<_Derived, _Sender, _Receiver>) { - return __mexception<_WHAT_(_INVALID_ARGUMENT_), - _WHERE_(_IN_ALGORITHM_, __tag_t), - _WHY_(_THE_INPUT_SENDER_MUST_BE_COPYABLE_), - _WITH_SENDER_<__child_t<_Sender>>>(); - } - else if constexpr (!__connectable<_Derived, _Sender, _Receiver>) - { - return __mexception<_WHAT_(_INVALID_ARGUMENT_), - _WHERE_(_IN_ALGORITHM_, __tag_t), - _WHY_(_THE_SENDER_CANNOT_BE_CONNECTED_), - _WITH_SENDER_<__child_t<_Sender>>>(); + return __state<_Derived, _Sender, _Receiver>(static_cast<_Sender &&>(__sndr), + static_cast<_Receiver &&>(__rcvr)); } else { - return __state<_Derived, _Sender, _Receiver>(static_cast<_Sender &&>(__sndr), - static_cast<_Receiver &&>(__rcvr)); + return __state_type<_Sender, _Receiver>(); } } From c3725acd9f4f6fd12db09644931f406dbaf150b9 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 27 Nov 2026 16:20:26 -0800 Subject: [PATCH 4/4] don't instantiate the operations below associate's walk state associate's state holds the operation of the sender that it wraps, connected to the facade's receiver for it, which is a receiver archetype in the facade's walk. So the walk instantiated the wrapped sender's operations a second time, and, through __start_nested, their start functions. Now associate declares its state's type with __state_type, and a state whose receiver is an archetype holds a placeholder for the operation, and connects nothing. Whether connecting the wrapped sender can throw is still asked of the real operation, which a new test checks. The same pipeline in associate, with a simple_counting_scope (clang 22 -O3): 9.92 s / 559 MB -> 9.10 s / 517 MB, and with extra type checking 11.73 s -> 10.67 s. test_associate.cpp: 10.36 s -> 10.24 s. Co-Authored-By: Claude Opus 5.5 --- include/stdexec/__detail/__associate.hpp | 22 ++++++++---- .../stdexec/algos/adaptors/test_associate.cpp | 34 +++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/include/stdexec/__detail/__associate.hpp b/include/stdexec/__detail/__associate.hpp index a053e5a21..fef951811 100644 --- a/include/stdexec/__detail/__associate.hpp +++ b/include/stdexec/__detail/__associate.hpp @@ -196,18 +196,24 @@ namespace STDEXEC using __wrap_sender_t = __associate_data_t::__wrap_sender_t; using __wrapped_rcvr_t = __facade::__receiver_t<__algo, __wrapped_op, __state, _Sender, _Receiver>; - using __op_t = connect_result_t<__wrap_sender_t, __wrapped_rcvr_t>; + // (A walk's state holds a placeholder for the operation: see __facade::__state_op_t.) + using __op_t = + __facade::__state_op_t<_Receiver, connect_result_t, __wrap_sender_t, __wrapped_rcvr_t>; - // The wrapped sender's operation is connected only if the association succeeded. + // The wrapped sender's operation is connected only if the association succeeded, and + // the state is not for a walk. explicit __state(std::pair<__assoc_t, __sender_ref_t> __parts, _Receiver&& __rcvr) : __rcvr_(static_cast<_Receiver&&>(__rcvr)) , __assoc_(STDEXEC::__allocator_aware_forward(std::move(__parts.first), __rcvr_)) { - if (__assoc_) + if constexpr (!__facade::__walking_receiver<_Receiver>) { - __op_.__emplace_from(STDEXEC::connect, - std::move(*__parts.second), - __wrapped_rcvr_t{this}); + if (__assoc_) + { + __op_.__emplace_from(STDEXEC::connect, + std::move(*__parts.second), + __wrapped_rcvr_t{this}); + } } } @@ -244,6 +250,10 @@ namespace STDEXEC return {}; } + // (See __facade::__state_type_t.) + template + using __state_type = __state<_Sender, _Receiver>; + template static constexpr auto __get_state(_Sender&& __sndr, _Receiver __rcvr) noexcept((!std::is_lvalue_reference_v<_Sender> diff --git a/test/stdexec/algos/adaptors/test_associate.cpp b/test/stdexec/algos/adaptors/test_associate.cpp index 70f0d005a..1aa4e9854 100644 --- a/test/stdexec/algos/adaptors/test_associate.cpp +++ b/test/stdexec/algos/adaptors/test_associate.cpp @@ -25,7 +25,9 @@ import std; #else # include +# include # include +# include #endif namespace ex = STDEXEC; @@ -305,6 +307,38 @@ namespace (void) snd; } +#if !STDEXEC_NO_STDCPP_EXCEPTIONS() + struct throws_on_connect + { + using sender_concept = ex::sender_tag; + using completion_signatures = ex::completion_signatures; + + template + auto connect(Receiver) const -> ex::connect_result_t + { + throw std::logic_error("connect"); + } + }; + + TEST_CASE("associate - connecting can throw if connecting the wrapped sender can", + "[adaptors][associate]") + { + // (The function is noexcept, so the exception can come only from connecting.) + auto fn = []() noexcept + { + return ex::associate(throws_on_connect{}, null_token{}); + }; + using Sender = decltype(fn()); + STATIC_REQUIRE(!ex::__nothrow_connectable>>); + + // So an algorithm that connects it when another sender completes reports the exception. + using Let = decltype(ex::let_value(ex::just(), fn)); + STATIC_REQUIRE(ex::__mapply, + ex::completion_signatures_of_t>>::value); + CHECK_THROWS_AS(ex::sync_wait(ex::let_value(ex::just(), fn)), std::logic_error); + } +#endif // !STDEXEC_NO_STDCPP_EXCEPTIONS() + // TODO: check the pass-through nature of __sync_attrs // TODO: check the pass-through stop request behaviour // TODO: confirm timing of destruction of opstate relative to release of