diff --git a/.clang-format b/.clang-format index b9da1c3f6..155a97315 100644 --- a/.clang-format +++ b/.clang-format @@ -28,7 +28,7 @@ AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: Yes AttributeMacros: [ - STDEXEC_PARALLEL_SCHEDULER_INLINE + STDEXEC_PARALLEL_SCHEDULER_INLINE, STDEXEC_IMMOVABLE_NO_UNIQUE_ADDRESS ] BinPackArguments: false diff --git a/.github/workflows/ci.cpu.yml b/.github/workflows/ci.cpu.yml index 0bd1d2ffa..a90ff85f6 100644 --- a/.github/workflows/ci.cpu.yml +++ b/.github/workflows/ci.cpu.yml @@ -31,9 +31,9 @@ jobs: # is cached by commit, so only bumping llvm_sha (or the image tag) # triggers a rebuild. This is the only modules row: move it to a # released Clang's image once one contains the fix. - - { name: "CPU (clang trunk, Debug, modules)", build: "Debug", tag: llvm22-cuda13.2, cxxstd: "23", cxxflags: "-stdlib=libc++", llvm_sha: f970f59a9d4e6b8738547d01bc33e8a12df5244b } - - { name: "CPU (clang 22, Release)", build: "Release", tag: llvm22-cuda13.2, cxxstd: "23", cxxflags: "-stdlib=libc++" } - - { name: "CPU (clang 22, Release, noexcept)", build: "Release", tag: llvm22-cuda13.2, cxxstd: "23", cxxflags: "-stdlib=libc++ -fno-exceptions" } + - { name: "CPU (clang trunk, Debug, modules)", build: "Debug", tag: llvm22-cuda13.2, cxxstd: "23", cxxflags: "-stdlib=libc++", llvm_sha: f970f59a9d4e6b8738547d01bc33e8a12df5244b } + - { name: "CPU (clang 22, Release)", build: "Release", tag: llvm22-cuda13.2, cxxstd: "23", cxxflags: "-stdlib=libc++ -DSTDEXEC_ENABLE_EXTRA_TYPE_CHECKING" } + - { name: "CPU (clang 22, Release, noexcept)", build: "Release", tag: llvm22-cuda13.2, cxxstd: "23", cxxflags: "-stdlib=libc++ -fno-exceptions" } # TSan in Clang < 18 and GCC < 15 aborts at startup ("unexpected # memory mapping") when high-entropy ASLR places the executable # outside its fixed shadow layout; newer runtimes re-exec without diff --git a/include/exec/detail/xorshift.hpp b/include/exec/detail/xorshift.hpp index 28a91405d..611acc389 100644 --- a/include/exec/detail/xorshift.hpp +++ b/include/exec/detail/xorshift.hpp @@ -35,7 +35,6 @@ import stdexec; STDEXEC_MODULE_EXPORT namespace experimental::execution { - class xorshift { public: diff --git a/include/exec/fork_join.hpp b/include/exec/fork_join.hpp index c83024ad4..35fecf1fd 100644 --- a/include/exec/fork_join.hpp +++ b/include/exec/fork_join.hpp @@ -73,7 +73,7 @@ namespace experimental::execution {}; template - using _cref_sig_t = Tag(Args const &...); + using _cref_sig_t = Tag(STDEXEC::__decay_t const &...); // Given a set of async results, each of the form `tuple`, // compute the corresponding completion signatures, where each signature is @@ -135,7 +135,7 @@ namespace experimental::execution { using operation_state_concept = STDEXEC::operation_state_tag; using _env_t = STDEXEC::__fwd_env_t>; - using _child_completions_t = STDEXEC::__completion_signatures_of_t; + using _child_completions_t = STDEXEC::completion_signatures_of_t; using _domain_t = STDEXEC::__completion_domain_of_t; using _when_all_sndr_t = _fork_join::_when_all_sndr_t<_child_completions_t, Closures, _domain_t>; @@ -247,26 +247,28 @@ namespace experimental::execution if constexpr (__minvocable_q<__completion_domain_of_t, set_value_t, _child_sndr_t, Env...>) { - using _domain_t = __completion_domain_of_t; - using _child_t = __copy_cvref_t; - using _child_completions_t = __completion_signatures_of_t<_child_t, __fwd_env_t...>; - using __decay_copyable_results_t = __decay_copyable_results_t<_child_completions_t>; + using _domain_t = __completion_domain_of_t; + using _child_t = __copy_cvref_t; + auto _child_completions = + STDEXEC::get_completion_signatures<_child_t, __fwd_env_t...>(); - if constexpr (!__valid_completion_signatures<_child_completions_t>) + STDEXEC_IF_OK(_child_completions) { - return _child_completions_t{}; - } - else if constexpr (!__decay_copyable_results_t::value) - { - return STDEXEC::__throw_compile_time_error< // - _WHAT_(_PREDECESSOR_RESULTS_ARE_NOT_DECAY_COPYABLE_), - _IN_ALGORITHM_(exec::fork_join_t)>(); - } - else - { - using _sndr_t = - _fork_join::_when_all_sndr_t<_child_completions_t, _closures_t, _domain_t>; - return STDEXEC::get_completion_signatures<_sndr_t, __fwd_env_t...>(); + using _child_completions_t = decltype(_child_completions); + using __decay_copyable_results_t = __decay_copyable_results_t<_child_completions_t>; + + if constexpr (!__decay_copyable_results_t::value) + { + return STDEXEC::__throw_compile_time_error< // + _WHAT_(_PREDECESSOR_RESULTS_ARE_NOT_DECAY_COPYABLE_), + _IN_ALGORITHM_(exec::fork_join_t)>(); + } + else + { + using _sndr_t = + _fork_join::_when_all_sndr_t<_child_completions_t, _closures_t, _domain_t>; + return STDEXEC::get_completion_signatures<_sndr_t, __fwd_env_t...>(); + } } } else if constexpr (sizeof...(Env) == 0) diff --git a/include/exec/repeat_until.hpp b/include/exec/repeat_until.hpp index a4e28a04c..6874bb65c 100644 --- a/include/exec/repeat_until.hpp +++ b/include/exec/repeat_until.hpp @@ -302,8 +302,10 @@ namespace experimental::execution } else { + // The child is connected as an lvalue (see __opstate), so copying it + // can throw even when moving it cannot. using __has_nothrow_connect_t = - __mbool<(__nothrow_connectable<__child_t, __receiver_archetype<_Env>> || ...)>; + __mbool<(__nothrow_connectable<__child_t &, __receiver_archetype<_Env>> || ...)>; constexpr auto __eptr_sigs = __eptr_completion_unless_t<__has_nothrow_connect_t>(); constexpr auto __bouncer_sigs = exec::transform_completion_signatures( get_completion_signatures<__bouncer_t, _Env...>(), diff --git a/include/exec/reschedule.hpp b/include/exec/reschedule.hpp index 7c9a82538..42e5a634f 100644 --- a/include/exec/reschedule.hpp +++ b/include/exec/reschedule.hpp @@ -16,6 +16,7 @@ #pragma once #include "../stdexec/execution.hpp" +#include "exec/completion_signatures.hpp" namespace experimental::execution { @@ -28,24 +29,10 @@ namespace experimental::execution using namespace STDEXEC; struct reschedule_t; - template - using __no_scheduler_error = - __mexception<_WHAT_(_CANNOT_RESCHEDULE_), - _WHY_(_THE_CURRENT_EXECUTION_ENVIRONMENT_DOES_NOT_HAVE_A_START_SCHEDULER_), - _WHERE_(_IN_ALGORITHM_, reschedule_t), - _WITH_ENVIRONMENT_(_Env)>; template using __schedule_sender_t = schedule_result_t<__call_result_t>; - template - using __try_schedule_sender_t = - __minvoke<__mtry_catch_q<__schedule_sender_t, __q<__no_scheduler_error>>, _Env>; - - template - using __completions = - __minvoke_q<__completion_signatures_of_t, __try_schedule_sender_t<_Env>, _Env>; - struct __scheduler { using scheduler_concept = scheduler_tag; @@ -64,13 +51,19 @@ namespace experimental::execution using sender_concept = sender_tag; template - static consteval auto get_completion_signatures() -> __completions<_Env> + static consteval auto get_completion_signatures() { - return {}; + if constexpr (!__callable) + return exec::throw_compile_time_error< + _WHAT_(_CANNOT_RESCHEDULE_), + _WHY_(_THE_CURRENT_EXECUTION_ENVIRONMENT_DOES_NOT_HAVE_A_START_SCHEDULER_), + _WHERE_(_IN_ALGORITHM_, reschedule_t), + _WITH_ENVIRONMENT_(_Env)>(); + else + return STDEXEC::get_completion_signatures<__schedule_sender_t<_Env>, _Env>(); } template - requires receiver_of<_Receiver, __completions>> auto connect(_Receiver __rcvr) const -> connect_result_t<__schedule_sender_t>, _Receiver> { diff --git a/include/exec/sequence/merge_each.hpp b/include/exec/sequence/merge_each.hpp index 27500a798..4315fd3ee 100644 --- a/include/exec/sequence/merge_each.hpp +++ b/include/exec/sequence/merge_each.hpp @@ -1269,11 +1269,16 @@ namespace experimental::execution struct __completions_fn { template - using __f = - __minvoke_q<__concat_completion_signatures_t, - completion_signatures, - __sequence_aware_completion_signatures_of_t<__child_of<_Self>, _Env...>, - __sequence_aware_completion_signatures_of_t<_Sequences, _Env...>...>; + using __f = __minvoke_q< + __concat_completion_signatures_t, + // merge_each can always complete with set_value() (when + // all the nested sequences complete normally), with + // set_stopped(), and with an exception_ptr (errors from + // the sequence of sequences and failures to connect or + // start the error item are stored as one). + completion_signatures, + __sequence_aware_completion_signatures_of_t<__child_of<_Self>, _Env...>, + __sequence_aware_completion_signatures_of_t<_Sequences, _Env...>...>; }; template diff --git a/include/exec/sequence_senders.hpp b/include/exec/sequence_senders.hpp index 68671f1aa..1a3c817cd 100644 --- a/include/exec/sequence_senders.hpp +++ b/include/exec/sequence_senders.hpp @@ -691,7 +691,7 @@ namespace experimental::execution } template - requires sequence_sender<_Sequence, _Env...> + requires sequence_sender_in<_Sequence, _Env...> using item_types_of_t = decltype(exec::__checked_item_types(STDEXEC::__declval<_Sequence>(), STDEXEC::__declval<_Env>()...)); # else diff --git a/include/exec/when_any.hpp b/include/exec/when_any.hpp index fc86b394a..fed172e61 100644 --- a/include/exec/when_any.hpp +++ b/include/exec/when_any.hpp @@ -49,10 +49,23 @@ namespace experimental::execution exec::decay_arguments())...); } + // The results storage is computed from the children's *undecayed* + // completions: whether storing a result can throw (and so needs an + // exception_ptr alternative) depends on the actual argument types, e.g., + // copying an lvalue reference can be nothrow where moving the decayed + // value is not. + template + consteval auto __mk_storage_completions(__mlist_ptr<_CvSenders...>) + { + return exec::concat_completion_signatures( + STDEXEC::completion_signatures(), + STDEXEC::get_completion_signatures<_CvSenders, __env_t<_Env>...>()...); + } + template - using __results_storage_t = - __mapply_q<__results_storage, - decltype(__when_any::__mk_completions<_Env>(__mlist_ptr<_CvSenders...>()))>; + using __results_storage_t = __mapply_q<__results_storage, + decltype(__when_any::__mk_storage_completions<_Env>( + __mlist_ptr<_CvSenders...>()))>; // Forwards stop requests on the receiver's token to __stop_source_. template diff --git a/include/stdexec/__detail/__continues_on.hpp b/include/stdexec/__detail/__continues_on.hpp index c79a93989..80d85b5f7 100644 --- a/include/stdexec/__detail/__continues_on.hpp +++ b/include/stdexec/__detail/__continues_on.hpp @@ -122,9 +122,15 @@ namespace STDEXEC template using __state_t = __state<_Scheduler, __secondary_env_t<_Sender, env_of_t<_Receiver>, set_value_t>, - __storage_for_t<_Sender, env_of_t<_Receiver>>, + __storage_for_t<_Sender, __fwd_env_t>>, _Receiver>; + //! The environment of the receiver to which the scheduler's sender is + //! connected. This must match @c __receiver2::get_env(). + template + using __sch_sndr_env_t = + __join_env_t<__secondary_env_t<_Child, _Env, set_value_t> const &, _Env>; + //! @brief The @c continues_on sender's attributes. template struct __attrs @@ -134,6 +140,10 @@ namespace STDEXEC using __env2_t = __secondary_env_t<_Sender, _Env, set_value_t>; template using __sch_env_t = __join_env_t<__env2_t<_Env>, _Env>; + // The environment of the receiver to which the schedule sender is + // connected; see __receiver2. + template + using __sch_sndr_env_t = __trnsfr::__sch_sndr_env_t<_Sender, _Env>; template constexpr auto __mk_sch_env(_Env&& __env) const noexcept -> __sch_env_t<_Env> @@ -156,9 +166,9 @@ namespace STDEXEC { if constexpr (__sends...>) { - return !__cmplsigs::__partitions_of_t...>>::__nothrow_decay_copyable::__values::value; + using __completions_t = completion_signatures_of_t<_Sender, __fwd_env_t<_Env>...>; + return !__cmplsigs::__partitions_of_t< + __completions_t>::__nothrow_decay_copyable::__values::value; } } return false; @@ -182,27 +192,27 @@ namespace STDEXEC // `void`) that the query would reject. Bail out before touching anything // that could hard-error. if constexpr (!__one_of<_SetTag, set_error_t, set_stopped_t>) - { + { // NOLINT(bugprone-branch-clone) return indeterminate_domain<>(); } else if constexpr (__forwards_completion<_SetTag, _Env...>()) { - constexpr bool __own = __sends<_SetTag, _SchSndr, __env2_t<_Env>...>; - using _Fwd = __completion_domain_of_t...>; + constexpr bool __own = __sends<_SetTag, _SchSndr, __sch_sndr_env_t<_Env>...>; + using _Fwd = __completion_domain_of_t...>; if constexpr (__own) { return __common_domain_t< _Fwd, - __completion_domain_of_t<_SetTag, _SchSndr, __env2_t<_Env>...>>(); + __completion_domain_of_t<_SetTag, _SchSndr, __sch_sndr_env_t<_Env>...>>(); } else { return _Fwd(); } } - else if constexpr (__sends<_SetTag, _SchSndr, __env2_t<_Env>...>) + else if constexpr (__sends<_SetTag, _SchSndr, __sch_sndr_env_t<_Env>...>) { - return __completion_domain_of_t<_SetTag, _SchSndr, __env2_t<_Env>...>(); + return __completion_domain_of_t<_SetTag, _SchSndr, __sch_sndr_env_t<_Env>...>(); } else { @@ -215,7 +225,7 @@ namespace STDEXEC template static consteval bool __sch_sends() noexcept { - return __sends<_SetTag, schedule_result_t<_Scheduler>, __env2_t<_Env>...>; + return __sends<_SetTag, schedule_result_t<_Scheduler>, __sch_sndr_env_t<_Env>...>; } _Scheduler __sch_; @@ -284,8 +294,9 @@ namespace STDEXEC template <__same_as _SetTag, class... _Env> [[nodiscard]] constexpr auto query(get_completion_domain_t<_SetTag>, _Env const &...) const noexcept - -> __ensure_valid_domain_t< - __completion_domain_of_t<_SetTag, schedule_result_t<_Scheduler>, __env2_t<_Env>...>> + -> __ensure_valid_domain_t<__completion_domain_of_t<_SetTag, + schedule_result_t<_Scheduler>, + __sch_sndr_env_t<_Env>...>> { return {}; } @@ -298,7 +309,7 @@ namespace STDEXEC //! domain contributes too. template <__one_of _SetTag, class... _Env> requires(__forwards_completion<_SetTag, _Env...>() - || __sends<_SetTag, schedule_result_t<_Scheduler>, __env2_t<_Env>...>) + || __sends<_SetTag, schedule_result_t<_Scheduler>, __sch_sndr_env_t<_Env>...>) [[nodiscard]] constexpr auto query(get_completion_domain_t<_SetTag>, _Env const &...) const noexcept -> __ensure_valid_domain_t())> @@ -317,7 +328,7 @@ namespace STDEXEC { using _SchSender = schedule_result_t<_Scheduler>; constexpr auto cb_sched = - STDEXEC::__get_completion_behavior<_Tag, _SchSender, __env2_t<_Env>...>(); + STDEXEC::__get_completion_behavior<_Tag, _SchSender, __sch_sndr_env_t<_Env>...>(); constexpr auto cb_sndr = STDEXEC::__get_completion_behavior<_Tag, _Sender, __fwd_env_t<_Env>...>(); return cb_sched | cb_sndr; @@ -353,13 +364,15 @@ namespace STDEXEC __decay_arguments()); } - template + template static consteval auto __get_scheduler_completions() { // The scheduler contributes only error and stopped completions; we - // ignore value completions here + // ignore value completions here. The schedule sender is connected to a + // receiver whose environment is __sch_sndr_env_t, not __fwd_env_t<_Env>. return STDEXEC::__transform_completion_signatures( - STDEXEC::get_completion_signatures, __fwd_env_t<_Env>...>(), + STDEXEC::get_completion_signatures, + __sch_sndr_env_t<_Child, _Env>...>(), __ignore_completion()); } @@ -385,11 +398,19 @@ namespace STDEXEC auto __child_completions = __get_child_completions<__child_t, _Env...>(); return STDEXEC::__concat_completion_signatures( __child_completions, - __get_scheduler_completions<__scheduler_t, _Env...>(), + __get_scheduler_completions<__child_t, __scheduler_t, _Env...>(), __eptr_completion_unless_t< __nothrow_decay_copyable_results_t>()); } + // The child's completions are computed with __fwd_env_t<_Env>, so the child + // must be connected to a receiver whose environment is likewise forwarded. + static constexpr auto __get_env = [](__ignore, _State const & __state) noexcept + -> __fwd_env_t> + { + return __fwd_env(STDEXEC::get_env(__state.__rcvr_)); + }; + static constexpr auto __get_state = [](_Sender&& __sndr, _Receiver&& __rcvr) noexcept( __nothrow_constructible_from<__state_for_t<_Sender, _Receiver>, diff --git a/include/stdexec/__detail/__execution_fwd.hpp b/include/stdexec/__detail/__execution_fwd.hpp index 8963434f8..af34091a2 100644 --- a/include/stdexec/__detail/__execution_fwd.hpp +++ b/include/stdexec/__detail/__execution_fwd.hpp @@ -224,10 +224,14 @@ namespace STDEXEC struct receiver_tag; // concept tag aliases for backwards compatibility: - STDEXEC_MODULE_EXPORT using sender_t = sender_tag; - STDEXEC_MODULE_EXPORT using operation_state_t = operation_state_tag; - STDEXEC_MODULE_EXPORT using scheduler_t = scheduler_tag; - STDEXEC_MODULE_EXPORT using receiver_t = receiver_tag; + STDEXEC_MODULE_EXPORT + using sender_t = sender_tag; + STDEXEC_MODULE_EXPORT + using operation_state_t = operation_state_tag; + STDEXEC_MODULE_EXPORT + using scheduler_t = scheduler_tag; + STDEXEC_MODULE_EXPORT + using receiver_t = receiver_tag; template STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) diff --git a/include/stdexec/__detail/__inline_scheduler.hpp b/include/stdexec/__detail/__inline_scheduler.hpp index 44f84ab46..2395a50a5 100644 --- a/include/stdexec/__detail/__inline_scheduler.hpp +++ b/include/stdexec/__detail/__inline_scheduler.hpp @@ -44,7 +44,8 @@ namespace STDEXEC constexpr auto operator==(__inline_attrs const &) const noexcept -> bool = default; }; - STDEXEC_MODULE_EXPORT struct inline_scheduler : __inline_attrs + STDEXEC_MODULE_EXPORT + struct inline_scheduler : __inline_attrs { private: template diff --git a/include/stdexec/__detail/__let.hpp b/include/stdexec/__detail/__let.hpp index 54aa70eff..43be846b5 100644 --- a/include/stdexec/__detail/__let.hpp +++ b/include/stdexec/__detail/__let.hpp @@ -401,7 +401,7 @@ namespace STDEXEC return __minvoke_or_q<__gather_completion_signatures_t, indeterminate_domain<>, __t<_LetTag>, - __completion_signatures_of_t<_Sndr, _Env...>, + completion_signatures_of_t<_Sndr, _Env...>, __domain_transform_fn, __qq<__common_domain_t>>(); } @@ -462,7 +462,7 @@ namespace STDEXEC __minvoke_or_q<__gather_completion_signatures_t, __secondary_summary, // unknown => conservative _SetTag, - __completion_signatures_of_t<_Sender, _Env...>, + completion_signatures_of_t<_Sender, _Env...>, __secondary_summary_fn<_Tag, _SetTag, _Fun, _Sender, _Env...>, __qq<__combine_summaries>>; @@ -675,7 +675,7 @@ namespace STDEXEC __result_completion_behavior_fn<__set_tag_t, _Fun, __result_env_t<__set_tag_t, _Sndr, _Env>...>; - using __completions_t = __completion_signatures_of_t<_Sndr, __fwd_env_t<_Env>...>; + using __completions_t = completion_signatures_of_t<_Sndr, __fwd_env_t<_Env>...>; STDEXEC_CONSTEXPR_LOCAL auto __pred_behavior = STDEXEC::__get_completion_behavior<__set_tag_t, _Sndr, __fwd_env_t<_Env>...>(); diff --git a/include/stdexec/__detail/__operation_states.hpp b/include/stdexec/__detail/__operation_states.hpp index 1c898da4d..cc7853268 100644 --- a/include/stdexec/__detail/__operation_states.hpp +++ b/include/stdexec/__detail/__operation_states.hpp @@ -200,7 +200,8 @@ namespace STDEXEC //! depends on //! @see stdexec::operation_state_tag — the tag type that opts a class into //! this concept - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template concept operation_state = __std::destructible<_Op> && std::is_object_v<_Op> && requires(_Op &__op) { STDEXEC::start(__op); }; } // namespace STDEXEC diff --git a/include/stdexec/__detail/__parallel_scheduler.hpp b/include/stdexec/__detail/__parallel_scheduler.hpp index c3d012380..f64ef2528 100644 --- a/include/stdexec/__detail/__parallel_scheduler.hpp +++ b/include/stdexec/__detail/__parallel_scheduler.hpp @@ -802,7 +802,11 @@ namespace STDEXEC { using __cv_previous_t = __copy_cvref_t<_Self, _Previous>; auto __completions = STDEXEC::get_completion_signatures<__cv_previous_t, _Env...>(); - return STDEXEC::__concat_completion_signatures(__completions, __eptr_completion_t()); + // The intermediate receiver completes with set_stopped if the connected + // receiver's stop token has a stop request when the input completes. + return STDEXEC::__concat_completion_signatures(__completions, + completion_signatures(), + __eptr_completion_t()); } private: diff --git a/include/stdexec/__detail/__parallel_scheduler_default_impl_entry.hpp b/include/stdexec/__detail/__parallel_scheduler_default_impl_entry.hpp index 1c69b8c13..a974d1fd4 100644 --- a/include/stdexec/__detail/__parallel_scheduler_default_impl_entry.hpp +++ b/include/stdexec/__detail/__parallel_scheduler_default_impl_entry.hpp @@ -55,8 +55,8 @@ namespace STDEXEC::parallel_scheduler_replacement //! Can be used to replace the parallel scheduler at runtime. //! NOT TO SPEC extern STDEXEC_PARALLEL_SCHEDULER_INLINE // - auto set_parallel_scheduler_backend(__parallel_scheduler_backend_factory_t __new_factory) - -> __parallel_scheduler_backend_factory_t + auto set_parallel_scheduler_backend(__parallel_scheduler_backend_factory_t __new_factory) + -> __parallel_scheduler_backend_factory_t { return STDEXEC::__parallel_scheduler_default_impl::__parallel_scheduler_backend_singleton .__set_backend_factory(__new_factory); diff --git a/include/stdexec/__detail/__parallel_scheduler_replacement_api.hpp b/include/stdexec/__detail/__parallel_scheduler_replacement_api.hpp index 498acc711..028cf0291 100644 --- a/include/stdexec/__detail/__parallel_scheduler_replacement_api.hpp +++ b/include/stdexec/__detail/__parallel_scheduler_replacement_api.hpp @@ -48,8 +48,10 @@ namespace STDEXEC::parallel_scheduler_replacement //! Can be used to replace the parallel scheduler at runtime. //! NOT TO SPEC STDEXEC_MODULE_EXPORT - [[deprecated("Replacing the parallel scheduler backend at runtime is not recommended and may " - "lead to unexpected behavior. Use weak linking to replace the parallel scheduler at " + [[deprecated("Replacing the parallel scheduler backend at runtime is not " + "recommended and may " + "lead to unexpected behavior. Use weak linking to replace the " + "parallel scheduler at " "compile time instead.")]] auto set_parallel_scheduler_backend(__parallel_scheduler_backend_factory_t __new_factory) -> __parallel_scheduler_backend_factory_t; diff --git a/include/stdexec/__detail/__query.hpp b/include/stdexec/__detail/__query.hpp index 4fe92223e..2b2c388e8 100644 --- a/include/stdexec/__detail/__query.hpp +++ b/include/stdexec/__detail/__query.hpp @@ -72,7 +72,9 @@ namespace STDEXEC concept __has_validation = requires { _Query::template __validate<_Env, _Args...>(); }; STDEXEC_MODULE_EXPORT_AUTHORING - template > + template > struct __query // NOLINT(bugprone-crtp-constructor-accessibility) : __query<_Query, __no_default, _Transform> { diff --git a/include/stdexec/__detail/__receivers.hpp b/include/stdexec/__detail/__receivers.hpp index 9551ba623..7ba99c7c0 100644 --- a/include/stdexec/__detail/__receivers.hpp +++ b/include/stdexec/__detail/__receivers.hpp @@ -357,7 +357,8 @@ namespace STDEXEC //! @see stdexec::set_value //! @see stdexec::set_error //! @see stdexec::set_stopped - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template concept receiver = __detail::__enable_receiver<__decay_t<_Receiver>> && __environment_provider<__cref_t<_Receiver>> && __nothrow_move_constructible<__decay_t<_Receiver>> @@ -453,7 +454,8 @@ namespace STDEXEC //! concept //! @see stdexec::completion_signatures — the signature pack this concept //! consumes - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template concept receiver_of = receiver<_Receiver> && requires(_Completions *__completions) { { __detail::__try_completions<_Receiver>(__completions) } -> __ok; }; diff --git a/include/stdexec/__detail/__schedulers.hpp b/include/stdexec/__detail/__schedulers.hpp index ef7d57f55..331d7de76 100644 --- a/include/stdexec/__detail/__schedulers.hpp +++ b/include/stdexec/__detail/__schedulers.hpp @@ -740,9 +740,9 @@ namespace STDEXEC "get_delegation_scheduler_t")]] = get_delegation_scheduler_t; STDEXEC_MODULE_EXPORT_AUTHORING - inline constexpr auto &get_delegatee_scheduler [[deprecated("get_delegatee_scheduler has been " - "renamed get_delegation_scheduler")]] - = get_delegation_scheduler; + inline constexpr auto &get_delegatee_scheduler // + [[deprecated("get_delegatee_scheduler has been renamed get_delegation_scheduler")]] + = get_delegation_scheduler; } // namespace STDEXEC # include "__epilogue.hpp" diff --git a/include/stdexec/__detail/__sender_concepts.hpp b/include/stdexec/__detail/__sender_concepts.hpp index 5d1d0b23f..08764cf28 100644 --- a/include/stdexec/__detail/__sender_concepts.hpp +++ b/include/stdexec/__detail/__sender_concepts.hpp @@ -132,7 +132,8 @@ namespace STDEXEC //! @see stdexec::sender_tag — the tag type that opts a class into this //! concept //! @see stdexec::enable_sender — alternative opt-in path - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template concept sender = enable_sender<__decay_t<_Sender>> // && __environment_provider<__cref_t<_Sender>> // && __std::move_constructible<__decay_t<_Sender>> @@ -179,7 +180,9 @@ namespace STDEXEC //! @see stdexec::sender_to — adds a specific receiver //! @see stdexec::get_completion_signatures — the customization point this //! concept depends on - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + // + template concept sender_in = (sizeof...(_Env) <= 1) // && sender<_Sender> // @@ -213,7 +216,8 @@ namespace STDEXEC //! @see stdexec::sender_in — without the receiver-compatibility check //! @see stdexec::receiver_of — the receiver-side mirror of this concept //! @see stdexec::connect — the operation @c sender_to validates - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template concept sender_to = __sender_to<_Sender, _Receiver> // && requires(_Sender &&__sndr, _Receiver &&__rcvr) { connect(static_cast<_Sender &&>(__sndr), static_cast<_Receiver &&>(__rcvr)); @@ -262,23 +266,28 @@ namespace STDEXEC //! See @c single-sender-value-type in [exec.snd.concepts] in the C++26 //! working draft. + STDEXEC_MODULE_EXPORT_AUTHORING template using __single_sender_value_t = // __value_types_t<__completion_signatures_of_t<_Sender, _Env...>, __as_single_value, __qq<__msingle>>; + STDEXEC_MODULE_EXPORT_AUTHORING template concept __sends = sender_in<_Sender, _Env...> // && __count_of<_Tag, _Sender, _Env...>::value != 0; + STDEXEC_MODULE_EXPORT_AUTHORING template concept __never_sends = sender_in<_Sender, _Env...> // && __count_of<_Tag, _Sender, _Env...>::value == 0; + STDEXEC_MODULE_EXPORT_AUTHORING template using __never_sends_t = __mbool<__never_sends<_Tag, _Sender, _Env...>>; + STDEXEC_MODULE_EXPORT_AUTHORING template using __is_eptr_t = __mbool<__decays_to<_Error, std::exception_ptr>>; diff --git a/include/stdexec/__detail/__senders.hpp b/include/stdexec/__detail/__senders.hpp index a66657349..a036b4f11 100644 --- a/include/stdexec/__detail/__senders.hpp +++ b/include/stdexec/__detail/__senders.hpp @@ -58,7 +58,8 @@ namespace STDEXEC template using __signature_tag_t = decltype(__detail::__signature_tag_v<_Sig>); - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template concept sender_of = sender_in<_Sender, _Env...> && __same_as< diff --git a/include/stdexec/__detail/__sequence.hpp b/include/stdexec/__detail/__sequence.hpp index ddde220cb..63ff36bc1 100644 --- a/include/stdexec/__detail/__sequence.hpp +++ b/include/stdexec/__detail/__sequence.hpp @@ -303,6 +303,22 @@ namespace STDEXEC } constexpr void __start_next() noexcept + { + // __start_next is virtual, so it is instantiated even when _CvSender1 never + // completes with set_value. In that case the successor is never started, and + // the completions of _Sender2 are not among the declared completions. + if constexpr (!__sends>>) + { + __std::unreachable(); + } + else + { + __start_next_impl(); + } + } + + private: + constexpr void __start_next_impl() noexcept { STDEXEC_TRY { @@ -319,7 +335,6 @@ namespace STDEXEC } } - private: using __env2_t = __seq::__env2_t<_CvSender1, env_of_t<_Receiver>>; using __rcvr1_t = __rcvr1<_Receiver, __env2_t>; using __rcvr2_t = __rcvr2<_Receiver, __env2_t>; diff --git a/include/stdexec/__detail/__stop_token.hpp b/include/stdexec/__detail/__stop_token.hpp index 2ce0d3398..55b27a9cf 100644 --- a/include/stdexec/__detail/__stop_token.hpp +++ b/include/stdexec/__detail/__stop_token.hpp @@ -76,7 +76,8 @@ STDEXEC_P2300_NAMESPACE_BEGIN() }; # endif - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template using stop_callback_for_t = STDEXEC::__mcall1<__stop_callback_for<_Token>, _Callback>; template @@ -133,18 +134,21 @@ STDEXEC_P2300_NAMESPACE_BEGIN() void deregister_stoppable() noexcept {} }; - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template struct __stoppable_base_for { template using __f = __stoppable_base_impl<_Token, _Stoppable, _Tag>; }; - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template using __stoppable_base_for_t = typename __stoppable_base_for<_Token>::template __f<_Stoppable, _Tag>; - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template concept stoppable_token = requires(_Token const __token) { requires __has_stop_callback_v<_Token>; @@ -154,7 +158,8 @@ STDEXEC_P2300_NAMESPACE_BEGIN() } && STDEXEC::__std::copyable<_Token> // && STDEXEC::__std::equality_comparable<_Token>; - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template concept unstoppable_token = stoppable_token<_Token> // && requires { @@ -170,7 +175,8 @@ STDEXEC_P2300_NAMESPACE_BEGIN() }; // [stoptoken.never], class never_stop_token - STDEXEC_MODULE_EXPORT struct never_stop_token + STDEXEC_MODULE_EXPORT + struct never_stop_token { private: struct __callback_type diff --git a/include/stdexec/__detail/__transform_sender.hpp b/include/stdexec/__detail/__transform_sender.hpp index ceb312709..406bd77b4 100644 --- a/include/stdexec/__detail/__transform_sender.hpp +++ b/include/stdexec/__detail/__transform_sender.hpp @@ -267,7 +267,8 @@ namespace STDEXEC ////////////////////////////////////////////////////////////////////////////// // [exec.snd.apply] - STDEXEC_MODULE_EXPORT inline constexpr struct apply_sender_t + STDEXEC_MODULE_EXPORT + inline constexpr struct apply_sender_t { template requires __has_implementation_for<_Tag, _Domain, _Sender, _Args...> @@ -290,7 +291,8 @@ namespace STDEXEC } } apply_sender{}; - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template using apply_sender_result_t = __call_result_t; ////////////////////////////////////////////////////////////////////////////// diff --git a/include/stdexec/__detail/__with_awaitable_senders.hpp b/include/stdexec/__detail/__with_awaitable_senders.hpp index 3733b3efd..9d3d64102 100644 --- a/include/stdexec/__detail/__with_awaitable_senders.hpp +++ b/include/stdexec/__detail/__with_awaitable_senders.hpp @@ -35,7 +35,8 @@ import stdexec; namespace STDEXEC { # if !STDEXEC_NO_STDCPP_COROUTINES() - STDEXEC_MODULE_EXPORT template + STDEXEC_MODULE_EXPORT + template struct with_awaitable_senders; namespace __detail diff --git a/include/stdexec/__detail/__write_env.hpp b/include/stdexec/__detail/__write_env.hpp index 44f3762e2..85c66b12f 100644 --- a/include/stdexec/__detail/__write_env.hpp +++ b/include/stdexec/__detail/__write_env.hpp @@ -180,7 +180,8 @@ namespace STDEXEC //! @see stdexec::get_env — the CPO that exposes the merged environment //! //! @hideinitializer - STDEXEC_MODULE_EXPORT inline constexpr __write_env_t write_env{}; + STDEXEC_MODULE_EXPORT + inline constexpr __write_env_t write_env{}; template <> struct __sexpr_impl<__write_env_t> : __write::__write_env_impl diff --git a/test/stdexec/algos/adaptors/test_continues_on.cpp b/test/stdexec/algos/adaptors/test_continues_on.cpp index b5d43335b..93d1b4d3e 100644 --- a/test/stdexec/algos/adaptors/test_continues_on.cpp +++ b/test/stdexec/algos/adaptors/test_continues_on.cpp @@ -79,6 +79,54 @@ namespace operator==(potentially_throwing_connect_scheduler const &) const noexcept -> bool = default; }; + // A scheduler whose schedule sender's completion signatures depend on the + // environment: it can additionally fail with `int` iff the environment it is + // connected to has a start scheduler. + struct env_sensitive_scheduler + { + using scheduler_concept = ex::scheduler_tag; + + struct sender + { + using sender_concept = ex::sender_tag; + + template + struct opstate + { + void start() & noexcept + { + ex::set_value(static_cast(receiver_)); + } + + Receiver receiver_; + }; + + template + static consteval auto get_completion_signatures() + { + if constexpr (ex::__callable) + return ex::completion_signatures(); + else + return ex::completion_signatures(); + } + + template + [[nodiscard, maybe_unused]] + auto connect(Receiver receiver) const noexcept -> opstate + { + return {static_cast(receiver)}; + } + }; + + [[nodiscard]] + auto schedule() const noexcept -> sender + { + return {}; + } + + auto operator==(env_sensitive_scheduler const &) const noexcept -> bool = default; + }; + struct value_type { int val_; @@ -556,4 +604,22 @@ namespace ex::start(op); REQUIRE(res == "goodbye"); } + TEST_CASE("continues_on computes the scheduler's completions with the environment the schedule " + "sender is actually connected to", + "[adaptors][continues_on]") + { + // The predecessor completes on inline_scheduler, so the schedule sender is + // connected to a receiver whose environment has a start scheduler, even + // though the receiver passed to continues_on's connect does not. + auto snd = ex::continues_on(ex::continues_on(ex::just(), inline_scheduler{}), + env_sensitive_scheduler{}); + using snd_t = decltype(snd); + STATIC_REQUIRE(ex::__sends>); + + // With STDEXEC_ENABLE_EXTRA_TYPE_CHECKING=ON, connecting also verifies that + // the declared and actual completions agree. + auto op = ex::connect(std::move(snd), expect_void_receiver{}); + ex::start(op); + } + } // namespace diff --git a/test/stdexec/algos/adaptors/test_on3.cpp b/test/stdexec/algos/adaptors/test_on3.cpp index 0cdb85575..3c369c907 100644 --- a/test/stdexec/algos/adaptors/test_on3.cpp +++ b/test/stdexec/algos/adaptors/test_on3.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -75,11 +76,12 @@ namespace template Self, class Env> static consteval auto get_completion_signatures() { - return ex::__transform_completion_signatures_of_t< - ex::__copy_cvref_t, - Env, - ex::completion_signatures, - ex::__mconst>::__f>{}; + return exec::transform_completion_signatures( + ex::get_completion_signatures, Env>(), + exec::ignore_completion(), + {}, + {}, + ex::completion_signatures()); } };