Repository navigation
move subscribe's customization point into stdexec as __subscribe #2443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alwaysprince05
wants to merge
2
commits into
NVIDIA:main
Choose a base branch
from
alwaysprince05:refactor/subscribe-cpo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+140
−36
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /* | ||
| * Copyright (c) 2026 NVIDIA Corporation | ||
| * | ||
| * Licensed under the Apache License Version 2.0 with LLVM Exceptions | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * https://llvm.org/LICENSE.txt | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include "__config.hpp" | ||
|
|
||
| #if STDEXEC_USE_MODULES() && !defined(STDEXEC_IN_MODULE_PURVIEW) | ||
|
|
||
| import stdexec; | ||
|
|
||
| #else | ||
|
|
||
| # include "__execution_fwd.hpp" | ||
|
|
||
| # include "__concepts.hpp" | ||
| # include "__type_traits.hpp" | ||
| # include "__utility.hpp" | ||
|
|
||
| # include "__prologue.hpp" | ||
|
|
||
| // NOLINTNEXTLINE(bugprone-std-namespace-modification, modernize-concat-nested-namespaces) | ||
| namespace STDEXEC | ||
| { | ||
| namespace __subscribe_ | ||
| { | ||
| template <class _Sender, class _Receiver> | ||
| concept __has_static_memfn = requires(_Sender && (*__sndr)(), _Receiver && (*__rcvr)()) { | ||
| STDEXEC_REMOVE_REFERENCE(_Sender)::__static_subscribe(__sndr(), __rcvr()); | ||
| }; | ||
|
|
||
| template <class _Sender, class _Receiver> | ||
| concept __has_memfn = requires(_Sender && (*__sndr)(), _Receiver && (*__rcvr)()) { | ||
| __sndr().subscribe(__rcvr()); | ||
| }; | ||
|
|
||
| // The customization point behind exec::subscribe. A sender hooks it with a | ||
| // static __static_subscribe(sndr, rcvr) member or a subscribe(rcvr) member | ||
| // function, the static one taking precedence. Senders defined in stdexec can | ||
| // use this to behave as sequence senders without depending on exec. | ||
| struct __subscribe_t | ||
| { | ||
| template <class _Sender, class _Receiver> | ||
| requires __has_static_memfn<_Sender, _Receiver> | ||
| STDEXEC_ATTRIBUTE(always_inline) | ||
| constexpr auto operator()(_Sender&& __sndr, _Receiver __rcvr) const | ||
| noexcept(noexcept(__sndr.__static_subscribe(__declval<_Sender>(), __declval<_Receiver>()))) | ||
| -> decltype(__sndr.__static_subscribe(__declval<_Sender>(), __declval<_Receiver>())) | ||
| { | ||
| return __sndr.__static_subscribe(static_cast<_Sender&&>(__sndr), | ||
| static_cast<_Receiver&&>(__rcvr)); | ||
| } | ||
|
|
||
| template <class _Sender, class _Receiver> | ||
| requires(!__has_static_memfn<_Sender, _Receiver>) && __has_memfn<_Sender, _Receiver> | ||
| STDEXEC_ATTRIBUTE(always_inline) | ||
| constexpr auto operator()(_Sender&& __sndr, _Receiver __rcvr) const | ||
| noexcept(noexcept(__declval<_Sender>().subscribe(__declval<_Receiver>()))) | ||
| -> decltype(__declval<_Sender>().subscribe(__declval<_Receiver>())) | ||
| { | ||
| return static_cast<_Sender&&>(__sndr).subscribe(static_cast<_Receiver&&>(__rcvr)); | ||
| } | ||
| }; | ||
| } // namespace __subscribe_ | ||
|
|
||
| STDEXEC_MODULE_EXPORT_AUTHORING | ||
| inline constexpr __subscribe_::__subscribe_t __subscribe{}; | ||
|
|
||
| STDEXEC_MODULE_EXPORT_AUTHORING | ||
| template <class _Sender, class _Receiver> | ||
| using __subscribe_result_t = __call_result_t<__subscribe_::__subscribe_t, _Sender, _Receiver>; | ||
|
|
||
| STDEXEC_MODULE_EXPORT_AUTHORING | ||
| template <class _Sender, class _Receiver> | ||
| concept __subscribable = __callable<__subscribe_::__subscribe_t, _Sender, _Receiver>; | ||
| } // namespace STDEXEC | ||
|
|
||
| # include "__epilogue.hpp" | ||
| #endif // !STDEXEC_USE_MODULES() || defined(STDEXEC_IN_MODULE_PURVIEW) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would expect this to become a simple alias for
STDEXEC::__subscribe_::__subscribe_t. why not?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the rest of subscribe_t uses set_next / next_sender_of_t, __stopped_means_break, item_types / sequence_sender_in and the adaptor bits from #2294, and those all live in exec right now. so making it an alias means moving most of the sequence sender basics into stdexec/__detail too. i kept this PR to just the hook lookup to keep it small, but happy to move all of that here if that's what you'd like. or would you rather have that as its own PR first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's fine, i'm just making sure i'm understanding the PR correctly.