-
Notifications
You must be signed in to change notification settings - Fork 227
Move associate's opstate into the get_state function #1831
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
Closed
Closed
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,59 +147,6 @@ namespace STDEXEC { | |
| } | ||
| }; | ||
|
|
||
| // NOTE: the spec declares this class template inside the get_state function | ||
| // but I couldn't get that to build with Clang 21 so I moved it out to | ||
| // this namespace-scoped template and __uglified all the symbols | ||
| template <class _Sender, class _Receiver> | ||
| struct __op_state { | ||
| using __associate_data_t = std::remove_cvref_t<__data_of<_Sender>>; | ||
| using __assoc_t = __associate_data_t::__assoc_t; | ||
| using __sender_ref_t = __associate_data_t::__sender_ref; | ||
|
|
||
| using __op_t = connect_result_t<typename __sender_ref_t::element_type, _Receiver>; | ||
|
|
||
| __assoc_t __assoc_; | ||
| union { | ||
| _Receiver __rcvr_; | ||
| __op_t __op_; | ||
| }; | ||
|
|
||
| explicit __op_state(std::pair<__assoc_t, __sender_ref_t> __parts, _Receiver&& __rcvr) | ||
| : __assoc_(std::move(__parts.first)) { | ||
| if (__assoc_) { | ||
| ::new ((void*) std::addressof(__op_)) | ||
| __op_t(connect(std::move(*__parts.second), std::move(__rcvr))); | ||
| } else { | ||
| std::construct_at(std::addressof(__rcvr_), std::move(__rcvr)); | ||
| } | ||
| } | ||
|
|
||
| explicit __op_state(__associate_data_t&& __ad, _Receiver&& __rcvr) | ||
| : __op_state(std::move(__ad).release(), std::move(__rcvr)) { | ||
| } | ||
|
|
||
| explicit __op_state(const __associate_data_t& __ad, _Receiver&& __rcvr) | ||
| requires __std::copy_constructible<__associate_data_t> | ||
| : __op_state(__associate_data_t(__ad).release(), std::move(__rcvr)) { | ||
| } | ||
|
|
||
| ~__op_state() { | ||
| if (__assoc_) { | ||
| std::destroy_at(std::addressof(__op_)); | ||
| } else { | ||
| std::destroy_at(std::addressof(__rcvr_)); | ||
| } | ||
| } | ||
|
|
||
| void __run() noexcept { | ||
| if (__assoc_) { | ||
| STDEXEC::start(__op_); | ||
| } else { | ||
| STDEXEC::set_stopped(std::move(__rcvr_)); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| struct __associate_impl : __sexpr_defaults { | ||
| #if 0 // TODO: I don't know how to implement this correctly | ||
| static constexpr auto get_attrs = []<class _Child>(__ignore, const _Child& __child) noexcept { | ||
|
|
@@ -231,8 +178,56 @@ namespace STDEXEC { | |
| >) { | ||
| auto& [__tag, __data] = __self; | ||
|
|
||
| using op_state_t = __op_state<std::remove_cvref_t<_Self>, _Receiver>; | ||
| return op_state_t{__forward_like<_Self>(__data), std::move(__rcvr)}; | ||
| using __associate_data_t = std::remove_cvref_t<decltype(__data)>; | ||
| using __assoc_t = __associate_data_t::__assoc_t; | ||
| using __sender_ref_t = __associate_data_t::__sender_ref; | ||
|
|
||
| using __op_t = connect_result_t<typename __sender_ref_t::element_type, _Receiver>; | ||
|
|
||
| struct __op_state { | ||
| __assoc_t __assoc_; | ||
| union { | ||
| _Receiver* __rcvr_; | ||
| __op_t __op_; | ||
| }; | ||
|
|
||
| explicit __op_state(std::pair<__assoc_t, __sender_ref_t> __parts, _Receiver& __rcvr) | ||
| : __assoc_(std::move(__parts.first)) { | ||
| if (__assoc_) { | ||
| ::new ((void*) std::addressof(__op_)) | ||
| __op_t(STDEXEC::connect(std::move(*__parts.second), std::move(__rcvr))); | ||
| } else { | ||
| __rcvr_ = std::addressof(__rcvr); | ||
| } | ||
| } | ||
|
|
||
| explicit __op_state(__associate_data_t&& __ad, _Receiver& __rcvr) | ||
| : __op_state(std::move(__ad).release(), __rcvr) { | ||
| } | ||
|
|
||
| explicit __op_state(const __associate_data_t& __ad, _Receiver& __rcvr) | ||
| requires __std::copy_constructible<__associate_data_t> | ||
| : __op_state(__associate_data_t(__ad).release(), __rcvr) { | ||
| } | ||
|
|
||
| __op_state(__op_state&&) = delete; | ||
|
|
||
| ~__op_state() { | ||
| if (__assoc_) { | ||
| std::destroy_at(std::addressof(__op_)); | ||
| } | ||
| } | ||
|
|
||
| void __run() noexcept { | ||
| if (__assoc_) { | ||
| STDEXEC::start(__op_); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This call to |
||
| } else { | ||
| set_stopped(std::move(*__rcvr_)); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| return __op_state{__forward_like<_Self>(__data), __rcvr}; | ||
| }; | ||
|
|
||
| static constexpr auto start = [](auto& __state) noexcept -> void { | ||
|
|
||
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.
The spec doesn't fully-qualify this call to
connect; it's required in stdexec to avoid an ambiguity with (I think) a memberconnectthat's in scope here. I'm wondering ifbasic-senderhas the same ambiguity as__sexpr_defaults.