-
Notifications
You must be signed in to change notification settings - Fork 778
[2025-06 LWG 19] P3481R5 std::execution::bulk() issues #8020
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
burblebee
wants to merge
2
commits into
main
Choose a base branch
from
motions-2025-06-lwg-19
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -629,6 +629,8 @@ | |
struct @\libglobal{let_error_t}@ { @\unspec@ }; | ||
struct @\libglobal{let_stopped_t}@ { @\unspec@ }; | ||
struct @\libglobal{bulk_t}@ { @\unspec@ }; | ||
struct @\libglobal{bulk_chunked_t}@ { @\unspec@ }; | ||
struct @\libglobal{bulk_unchunked_t}@ { @\unspec@ }; | ||
struct @\libglobal{split_t}@ { @\unspec@ }; | ||
struct @\libglobal{when_all_t}@ { @\unspec@ }; | ||
struct @\libglobal{when_all_with_variant_t}@ { @\unspec@ }; | ||
|
@@ -647,6 +649,8 @@ | |
inline constexpr let_error_t @\libglobal{let_error}@{}; | ||
inline constexpr let_stopped_t @\libglobal{let_stopped}@{}; | ||
inline constexpr bulk_t @\libglobal{bulk}@{}; | ||
inline constexpr bulk_chunked_t @\libglobal{bulk_chunked}@{}; | ||
inline constexpr bulk_unchunked_t @\libglobal{bulk_unchunked}@{}; | ||
inline constexpr split_t @\libglobal{split}@{}; | ||
inline constexpr when_all_t @\libglobal{when_all}@{}; | ||
inline constexpr when_all_with_variant_t @\libglobal{when_all_with_variant}@{}; | ||
|
@@ -3608,52 +3612,133 @@ | |
propagates the other completion operations sent by \tcode{sndr}. | ||
\end{itemize} | ||
|
||
\rSec3[exec.bulk]{\tcode{execution::bulk}} | ||
\rSec3[exec.bulk]{\tcode{execution::bulk}, \tcode{execution::bulk_chunked}, and \tcode{execution::bulk_unchunked}} | ||
|
||
\pnum | ||
\tcode{bulk} runs a task repeatedly for every index in an index space. | ||
\tcode{bulk}, \tcode{bulk_chunked}, and \tcode{bulk_unchunked} | ||
run a task repeatedly for every index in an index space. | ||
|
||
The name \tcode{bulk} denotes a pipeable sender adaptor object. | ||
For subexpressions \tcode{sndr}, \tcode{shape}, and \tcode{f}, | ||
let \tcode{Shape} be \tcode{decltype(auto(shape))}. | ||
\pnum | ||
The names \tcode{bulk}, \tcode{bulk_chunked}, and \tcode{bulk_unchunked} | ||
denote pipeable sender adaptor objects. | ||
Let \tcode{\placeholder{bulk-algo}} be either | ||
\tcode{bulk}, \tcode{bulk_chunked}, or \tcode{bulk_unchunked}. | ||
For subexpressions \tcode{sndr}, \tcode{policy}, \tcode{shape}, and \tcode{f}, | ||
let | ||
\tcode{Policy} be \tcode{remove_cvref_t<decltype(policy)>}, | ||
\tcode{Shape} be \tcode{decltype(auto(shape))}, and | ||
\tcode{Func} be \tcode{decay_t<decltype((f))>}. | ||
If | ||
\begin{itemize} | ||
\item | ||
\tcode{decltype((sndr))} does not satisfy \libconcept{sender}, or | ||
\item | ||
\tcode{is_execution_policy_v<Policy>} is \tcode{false}, or | ||
\item | ||
\tcode{Shape} does not satisfy \libconcept{integral}, or | ||
\item | ||
\tcode{decltype((f))} does not satisfy \exposconcept{movable-value}, | ||
\tcode{Func} does not model \libconcept{copy_constructible}, | ||
\end{itemize} | ||
\tcode{bulk(sndr, shape, f)} is ill-formed. | ||
\tcode{\placeholder{bulk-algo}(sndr, policy, shape, f)} is ill-formed. | ||
burblebee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
\pnum | ||
Otherwise, | ||
the expression \tcode{bulk(sndr, shape, f)} is expression-equivalent to: | ||
the expression \tcode{\placeholder{bulk-algo}(sndr, policy, shape, f)} | ||
burblebee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
is expression-equivalent to: | ||
|
||
\begin{codeblock} | ||
transform_sender(@\exposid{get-domain-early}@(sndr), @\exposid{make-sender}@(bulk, @\exposid{product-type}@{shape, f}, sndr)) | ||
transform_sender(@\exposid{get-domain-early}@(sndr), | ||
@\exposid{make-sender}@(@\placeholder{bulk-algo}@, | ||
burblebee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@\exposid{product-type}@<@\seebelow@, Shape, Func>{policy, shape, f}, | ||
sndr)) | ||
\end{codeblock} | ||
except that \tcode{sndr} is evaluated only once. | ||
|
||
\par | ||
The first template argument of \exposid{product-type} is \tcode{Policy} | ||
if \tcode{Policy} models \libconcept{copy_constructible}, and | ||
\tcode{const Policy\&} otherwise. | ||
|
||
\pnum | ||
Let \tcode{sndr} and \tcode{env} be subexpressions such that | ||
\tcode{Sndr} is \tcode{decltype((sndr))}. | ||
If \tcode{\exposconcept{sender-for}<Sndr, bulk_t>} is \tcode{false}, then | ||
the expression \tcode{bulk.transform_sender(sndr, env)} is ill-formed; | ||
otherwise, it is equivalent to: | ||
\begin{codeblock} | ||
auto [_, data, child] = sndr; | ||
auto& [policy, shape, f] = data; | ||
auto new_f = [func=std::move(f)](Shape begin, Shape end, auto&&... vs) | ||
noexcept(noexcept(f(begin, vs...))) { | ||
while (begin != end) func(begin++, vs...); | ||
} | ||
return bulk_chunked(std::move(child), policy, shape, std::move(new_f)); | ||
\end{codeblock} | ||
|
||
\begin{note} | ||
This causes the \tcode{bulk(sndr, policy, shape, f)} sender to be | ||
expressed in terms of \tcode{bulk_chunked(sndr, policy, shape, f)} when | ||
it is connected to a receiver whose | ||
execution domain does not customize \tcode{bulk}. | ||
\end{note} | ||
|
||
\pnum | ||
The exposition-only class template \exposid{impls-for}\iref{exec.snd.general} | ||
is specialized for \tcode{bulk_t} as follows: | ||
is specialized for \tcode{bulk_chunked_t} as follows: | ||
\begin{codeblock} | ||
namespace std::execution { | ||
template<> | ||
struct @\exposid{impls-for}@<bulk_t> : @\exposid{default-impls}@ { | ||
struct @\exposid{impls-for}@<bulk_chunked_t> : @\exposid{default-impls}@ { | ||
Eisenwave marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static constexpr auto @\exposid{complete}@ = @\seebelow@; | ||
}; | ||
} | ||
\end{codeblock} | ||
|
||
\par | ||
The member \tcode{\exposid{impls-for}<bulk_chunked_t>::\exposid{complete}} | ||
is initialized with a callable object equivalent to the following lambda: | ||
\begin{codeblock} | ||
[]<class Index, class State, class Rcvr, class Tag, class... Args> | ||
(Index, State& state, Rcvr& rcvr, Tag, Args&&... args) noexcept | ||
-> void requires @\seebelow@ { | ||
if constexpr (@\libconcept{same_as}@<Tag, set_value_t>) { | ||
auto& [policy, shape, f] = state; | ||
constexpr bool nothrow = noexcept(f(auto(shape), auto(shape), args...)); | ||
@\exposid{TRY-EVAL}@(rcvr, [&]() noexcept(nothrow) { | ||
f(static_cast<decltype(auto(shape))>(0), auto(shape), args...); | ||
Tag()(std::move(rcvr), std::forward<Args>(args)...); | ||
}()); | ||
} else { | ||
Tag()(std::move(rcvr), std::forward<Args>(args)...); | ||
} | ||
} | ||
\end{codeblock} | ||
|
||
\par | ||
The expression in the \grammarterm{requires-clause} of the lambda above is | ||
\tcode{true} if and only | ||
if \tcode{Tag} denotes a type other than \tcode{set_value_t} or | ||
if the expression \tcode{f(auto(shape), auto(shape), args...)} is well-formed. | ||
|
||
\pnum | ||
The member \tcode{\exposid{impls-for}<bulk_t>::\exposid{complete}} | ||
The exposition-only class template \exposid{impls-for}\iref{exec.snd.general} | ||
is specialized for \tcode{bulk_unchunked_t} as follows: | ||
\begin{codeblock} | ||
namespace std::execution { | ||
template<> | ||
struct @\exposid{impls-for}@<bulk_unchunked_t> : @\exposid{default-impls}@ { | ||
static constexpr auto @\exposid{complete}@ = @\seebelow@; | ||
}; | ||
} | ||
\end{codeblock} | ||
|
||
\par | ||
The member \tcode{\exposid{impls-for}<bulk_unchunked_t>::\exposid{complete}} | ||
is initialized with a callable object equivalent to the following lambda: | ||
\begin{codeblock} | ||
[]<class Index, class State, class Rcvr, class Tag, class... Args> | ||
(Index, State& state, Rcvr& rcvr, Tag, Args&&... args) noexcept -> void requires @\seebelow@ { | ||
(Index, State& state, Rcvr& rcvr, Tag, Args&&... args) noexcept | ||
-> void requires @\seebelow@ { | ||
if constexpr (@\libconcept{same_as}@<Tag, set_value_t>) { | ||
auto& [shape, f] = state; | ||
constexpr bool nothrow = noexcept(f(auto(shape), args...)); | ||
|
@@ -3669,32 +3754,110 @@ | |
} | ||
\end{codeblock} | ||
|
||
\pnum | ||
\par | ||
The expression in the \grammarterm{requires-clause} of the lambda above | ||
is \tcode{true} if and only | ||
if \tcode{Tag} denotes a type other than \tcode{set_value_t} or | ||
if the expression \tcode{f(auto(shape), args...)} is well-formed. | ||
|
||
\pnum | ||
Let the subexpression \tcode{out_sndr} denote | ||
the result of the invocation \tcode{bulk(sndr, shape, f)} or | ||
the result of the invocation | ||
\tcode{\placeholder{bulk-algo}(sndr, policy, shape, f)} or | ||
burblebee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
an object equal to such, and | ||
let the subexpression \tcode{rcvr} denote a receiver | ||
such that the expression \tcode{connect(out_sndr, rcvr)} is well-formed. | ||
The expression \tcode{connect(out_sndr, rcvr)} has undefined behavior | ||
unless it creates an asynchronous operation\iref{exec.async.ops} that, | ||
when started, | ||
when started: | ||
|
||
\begin{itemize} | ||
\item | ||
on a value completion operation, | ||
invokes \tcode{f(i, args...)} | ||
for every \tcode{i} of type \tcode{Shape} in \range{\tcode{0}}{\tcode{shape}}, | ||
where \tcode{args} is a pack of lvalue subexpressions | ||
referring to the value completion result datums of the input sender, and | ||
If \tcode{sndr} has a successful completion, where | ||
\tcode{args} is a pack of lvalue subexpressions | ||
referring to the value completion result datums of \tcode{sndr}, or | ||
decayed copies of those values if they model \libconcept{copy_constructible}, | ||
then: | ||
|
||
\begin{itemize} | ||
burblebee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
\item | ||
If \tcode{out_sndr} also completes successfully, then: | ||
|
||
\begin{itemize} | ||
\item | ||
for \tcode{bulk}, | ||
invokes \tcode{f($i$, args...)} for every $i$ of type \tcode{Shape} | ||
from \tcode{0} to \tcode{shape}; | ||
|
||
\item | ||
for \tcode{bulk_unchunked}, | ||
invokes \tcode{f($i$, args...)} for every $i$ of type \tcode{Shape} | ||
from \tcode{0} to \tcode{shape}; | ||
|
||
\recommended | ||
The underlying scheduler should execute each iteration | ||
on a distinct execution agent. | ||
Comment on lines
+3797
to
+3799
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. The paper indicates that this should be a single nested bullet inside of the previous bullet, but ... not sure what to make of that. @jensmaurer or @tkoeppe probably know what to do about this. Maybe this is correct? |
||
|
||
\item | ||
for \tcode{bulk_chunked}, | ||
invokes \tcode{f($b$, $e$, args...)} zero or more times | ||
with pairs of $b$ and $e$ of type \tcode{Shape} | ||
in range \crange{\tcode{0}}{\tcode{shape}}, | ||
such that $b < e$ and | ||
for every $i$ of type \tcode{Shape} from \tcode{0} to \tcode{shape}, | ||
there is exactly one invocation with a pair $b$ and $e$, | ||
such that $i$ is in the range \range{$b$}{$e$}. | ||
\end{itemize} | ||
|
||
\item | ||
If \tcode{out_sndr} completes with \tcode{set_error(rcvr, eptr)}, then | ||
the asynchronous operation may invoke a subset of | ||
the invocations of \tcode{f} | ||
before the error completion handler is called, and | ||
\tcode{eptr} is an \tcode{exception_ptr} containing either: | ||
\begin{itemize} | ||
\item | ||
an exception thrown by an invocation of \tcode{f}, or | ||
\item | ||
a \tcode{bad_alloc} exception if | ||
the implementation fails to allocate required resources, or | ||
\item | ||
an exception derived from \tcode{runtime_error}. | ||
\end{itemize} | ||
burblebee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
\item | ||
If \tcode{out_sndr} completes with \tcode{set_stopped(rcvr)}, then | ||
the asynchronous operation may invoke a subset of | ||
the invocations of \tcode{f} | ||
before the stopped completion handler. | ||
\end{itemize} | ||
|
||
\item | ||
propagates all completion operations sent by \tcode{sndr}. | ||
If \tcode{sndr} does not complete with \tcode{set_value}, then | ||
the completion is forwarded to \tcode{recv}. | ||
|
||
\item | ||
For \tcode{\placeholder{bulk-algo}}, | ||
the parameter \tcode{policy} describes | ||
the manner in which | ||
the execution of the asynchronous operations corresponding to these algorithms | ||
may be parallelized and | ||
the manner in which | ||
%%FIXME: Should this be "apply to f"? | ||
they apply \tcode{f}. | ||
Eisenwave marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Permissions and requirements | ||
on parallel algorithm element access functions\iref{algorithms.parallel.exec} | ||
apply to \tcode{f}. | ||
\end{itemize} | ||
|
||
\pnum | ||
\begin{note} | ||
The asynchronous operation corresponding to | ||
\tcode{\placeholder{bulk-algo}(sndr, policy, shape, f)} | ||
burblebee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
can complete with \tcode{set_stopped} if cancellation is requested or | ||
ignore cancellation requests. | ||
\end{note} | ||
|
||
\rSec3[exec.split]{\tcode{execution::split}} | ||
|
||
\pnum | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.