From b10c753a299c4e4f737b63bf85857899a9e574e6 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 26 Nov 2026 15:55:35 -0800 Subject: [PATCH 1/3] skip `transform_sender`'s steps when neither transforms the sender `transform_sender(sndr, env)` composes two steps, one for the domain where the sender completes and one for the domain where its operation starts, and each step computes its result with consteval functions and variables of its own, for each sender and environment. For most senders neither step does anything: neither domain has a transformation for the sender, and its tag has none either. In that case `transform_sender` now returns the sender as it is, without composing the steps (`__leaves_alone`, from each step's own test). The result is the same as before: a reference to the sender. The composition was named in a default template argument of the other overload, and default template arguments are substituted before constraints are checked, so it is now named in that overload's return type instead. Clang 22, frontend only, on test_merge_each_threaded.cpp: with STDEXEC_ENABLE_EXTRA_TYPE_CHECKING, peak memory goes from 5.9 GB to 5.3 GB (-11%), with 10% fewer types; without it, from 2.6 GB to 2.4 GB (-9%). Co-Authored-By: Claude Opus 5.5 --- .../stdexec/__detail/__transform_sender.hpp | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/include/stdexec/__detail/__transform_sender.hpp b/include/stdexec/__detail/__transform_sender.hpp index 406bd77b4..09a212b6c 100644 --- a/include/stdexec/__detail/__transform_sender.hpp +++ b/include/stdexec/__detail/__transform_sender.hpp @@ -237,6 +237,15 @@ namespace STDEXEC __detail::__transform_sender<__detail::__completing_domain_t, set_value_t>>; + // Does neither step transform the sender? Then transform_sender returns it as it is, + // without composing the steps. + template + static constexpr bool __leaves_alone = + __detail::__transform_sender<__detail::__starting_domain_t<_Env>, + start_t>::template __leaves_alone<_Sndr, _Env> + && __detail::__transform_sender<__detail::__completing_domain_t, + set_value_t>::template __leaves_alone<_Sndr, _Env>; + public: // NOT TO SPEC: template @@ -247,13 +256,24 @@ namespace STDEXEC return static_cast<_Sndr&&>(__sndr); } - template > + template + requires __leaves_alone<_Sndr, _Env> + STDEXEC_ATTRIBUTE(nodiscard, host, device, always_inline) + constexpr auto operator()(_Sndr&& __sndr, _Env const &) const noexcept -> _Sndr&& + { + return static_cast<_Sndr&&>(__sndr); + } + + // (__impl_fn_t is named in the return type, not in a default template argument, which + // would be substituted before the constraint is checked.) + template + requires(!__leaves_alone<_Sndr, _Env>) STDEXEC_ATTRIBUTE(nodiscard, host, device, always_inline) constexpr auto operator()(_Sndr&& __sndr, _Env const & __env) const - noexcept(__nothrow_callable<_ImplFn, _Sndr, _Env const &>) - -> __call_result_t<_ImplFn, _Sndr, _Env const &> + noexcept(__nothrow_callable<__impl_fn_t<_Sndr, _Env>, _Sndr, _Env const &>) + -> __call_result_t<__impl_fn_t<_Sndr, _Env>, _Sndr, _Env const &> { - return _ImplFn()(static_cast<_Sndr&&>(__sndr), __env); + return __impl_fn_t<_Sndr, _Env>()(static_cast<_Sndr&&>(__sndr), __env); } }; From 3f1ae919676be8911b6b03e6664540b0993c4136 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 26 Nov 2026 20:25:27 -0800 Subject: [PATCH 2/3] check a tag's transformation only when the domain's isn't taken `__leaves_alone` named `__has_tag_transform_sender` in an `&&`, but a concept-id is checked when the initializer is instantiated, even where `&&` skips it. For a sender that a domain transforms, such as exec::ensure_started under nvexec's stream_domain, that checked the tag's default transformation, whose deduced return type instantiates exec's generic, host-only shared receiver. Clang CUDA then reported it referenced from the device. Before, the check ran only on senders that a transformation had returned. `__leaves_alone` is now a consteval function that names the concept only when the domain's transformation isn't taken. Co-Authored-By: Claude Sonnet 5.5 --- .../stdexec/__detail/__transform_sender.hpp | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/include/stdexec/__detail/__transform_sender.hpp b/include/stdexec/__detail/__transform_sender.hpp index 09a212b6c..91086bf3f 100644 --- a/include/stdexec/__detail/__transform_sender.hpp +++ b/include/stdexec/__detail/__transform_sender.hpp @@ -88,9 +88,25 @@ namespace STDEXEC // is. A caller holding a new sender an earlier step returned by value // skips such a step, so that the sender can be returned without being // moved. + // + // (The tag's transformation is checked only when the domain's isn't: naming the concept + // would check it even where `&&` skips it, and checking it can instantiate the tag's + // default transformation, which a domain that transforms the sender replaces.) template - static constexpr bool __leaves_alone = __same_as<__domain_for_t<_Sndr, _Env>, default_domain> - && !__has_tag_transform_sender<_OpTag, _Sndr, _Env>; + static consteval auto __is_leaves_alone() noexcept -> bool + { + if constexpr (__same_as<__domain_for_t<_Sndr, _Env>, default_domain>) + { + return !__has_tag_transform_sender<_OpTag, _Sndr, _Env>; + } + else + { + return false; + } + } + + template + static constexpr bool __leaves_alone = __is_leaves_alone<_Sndr, _Env>(); template STDEXEC_ATTRIBUTE(nodiscard, host, device) From 7ede206ccc623b26ff728ec3cae155c7bf60bfc6 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 26 Nov 2026 20:27:40 -0800 Subject: [PATCH 3/3] silence GCC 12's use-after-free false positive on std::stop_token in a test With the transform_sender fast path inlined into connect, GCC 12 at -O3 warns that connect's copy of the receiver's std::stop_token (in the environment it passes to transform_sender) can free the shared stop state before the receiver is moved. The receiver's own reference keeps the state alive, so it is a false positive. Scope the suppression to the two std::stop_token tests. Co-Authored-By: Claude Sonnet 5.5 --- test/exec/test_timed_thread_scheduler.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/exec/test_timed_thread_scheduler.cpp b/test/exec/test_timed_thread_scheduler.cpp index 751647b3c..699622425 100644 --- a/test/exec/test_timed_thread_scheduler.cpp +++ b/test/exec/test_timed_thread_scheduler.cpp @@ -414,6 +414,12 @@ namespace } # if defined(__cpp_lib_jthread) && __cpp_lib_jthread >= 201911L + // GCC 12 wrongly warns that connect's copy of the receiver's std::stop_token (in the + // environment it passes to transform_sender) can free the shared stop state before the + // receiver is moved. The receiver's own reference keeps the state alive. + STDEXEC_PRAGMA_PUSH() + STDEXEC_PRAGMA_IGNORE_GNU("-Wuse-after-free") + enum class completion { value, @@ -472,6 +478,8 @@ namespace REQUIRE(future.wait_for(std::chrono::seconds(10)) == std::future_status::ready); CHECK(future.get() == completion::stopped); } + + STDEXEC_PRAGMA_POP() # endif } // namespace #endif