Skip to content

Commit

Permalink
Publish: Merge pull request #161 from cplusplus/port-transfer-to-basi…
Browse files Browse the repository at this point in the history
…c-sender

port the `transfer` algorithm to `basic-sender` 37b940f
  • Loading branch information
ericniebler committed Dec 13, 2023
1 parent f9d0323 commit ac044cb
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions execution.html
Original file line number Diff line number Diff line change
Expand Up @@ -2246,7 +2246,7 @@
<div class="head">
<p data-fill-with="logo"></p>
<h1 class="p-name no-ref" id="title">D2300R8<br><code class="highlight"><c- n>std</c-><c- o>::</c-><c- n>execution</c-></code></h1>
<h2 class="no-num no-toc no-ref heading settled" id="profile-and-date"><span class="content">Draft Proposal, <time class="dt-updated" datetime="2023-12-12">2023-12-12</time></span></h2>
<h2 class="no-num no-toc no-ref heading settled" id="profile-and-date"><span class="content">Draft Proposal, <time class="dt-updated" datetime="2023-12-13">2023-12-13</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt class="editor">Authors:
Expand Down Expand Up @@ -6962,6 +6962,12 @@ <h4 class="heading settled" data-level="11.9.1" id="spec-execution.senders.gener
<li data-md>
<p>otherwise, <code class="highlight"><c- n>tag_invoke</c-><c- p>(</c-><c- n>q</c-><c- p>,</c-> <c- n>e3</c-><c- p>,</c-> <c- n>as</c-><c- p>...)</c-></code> is ill-formed.</p>
</ul>
<li data-md>
<p>For a scheduler <code class="highlight"><c- n>sch</c-></code>, let <code class="highlight"><i><c- n>SCHED</c-><c- o>-</c-><c- n>ATTRS</c-></i><c- p>(</c-><c- n>sch</c-><c- p>)</c-></code> be a
queryable object <code class="highlight"><c- n>o1</c-></code> such that <code class="highlight"><c- n>tag_invoke</c-><c- p>(</c-><c- n>get_completion_scheduler</c-><c- o>&lt;</c-><i><c- n>Tag</c-></i><c- o>></c-><c- p>,</c-> <c- n>o1</c-><c- p>)</c-></code> is a
prvalue with the same type and value as <code class="highlight"><c- n>sch</c-></code> where <i><code class="highlight"><c- n>Tag</c-></code></i> is one
of <code class="highlight"><c- n>set_value_t</c-></code> or <code class="highlight"><c- n>set_stopped_t</c-></code>; and let <code class="highlight"><c- n>tag_invoke</c-><c- p>(</c-><c- n>get_domain</c-><c- p>,</c-> <c- n>o1</c-><c- p>)</c-></code> be expression-equivalent to <code class="highlight"><c- n>tag_invoke</c-><c- p>(</c-><c- n>get_domain</c-><c- p>,</c-> <c- n>sch</c-><c- p>)</c-></code>. Let <code class="highlight"><i><c- n>SCHED</c-><c- o>-</c-><c- n>ENV</c-></i><c- p>(</c-><c- n>sch</c-><c- p>)</c-></code> be a queryable object <code class="highlight"><c- n>o2</c-></code> such that <code class="highlight"><c- n>tag_invoke</c-><c- p>(</c-><c- n>get_scheduler</c-><c- p>,</c-> <c- n>o2</c-><c- p>)</c-></code> is a prvalue with the same
type and value as <code class="highlight"><c- n>sch</c-></code>, and let <code class="highlight"><c- n>tag_invoke</c-><c- p>(</c-><c- n>get_domain</c-><c- p>,</c-> <c- n>o2</c-><c- p>)</c-></code> be expression-equivalent to <code class="highlight"><c- n>tag_invoke</c-><c- p>(</c-><c- n>get_domain</c-><c- p>,</c-> <c- n>sch</c-><c- p>)</c-></code>.</p>
<li data-md>
<p>For two subexpressions <code class="highlight"><c- n>r</c-></code> and <code class="highlight"><c- n>e</c-></code>, let <code class="highlight"><i><c- n>SET</c-><c- o>-</c-><c- n>VALUE</c-></i><c- p>(</c-><c- n>r</c-><c- p>,</c-> <c- n>e</c-><c- p>)</c-></code> be <code class="highlight"><c- p>(</c-><c- n>e</c-><c- p>,</c-> <c- n>set_value</c-><c- p>(</c-><c- n>r</c-><c- p>))</c-></code> if the type of <code class="highlight"><c- n>e</c-></code> is <code class="highlight"><c- b>void</c-></code>;
otherwise, it is <code class="highlight"><c- n>set_value</c-><c- p>(</c-><c- n>r</c-><c- p>,</c-> <c- n>e</c-><c- p>)</c-></code>. Let <code class="highlight"><i><c- n>TRY</c-><c- o>-</c-><c- n>SET</c-><c- o>-</c-><c- n>VALUE</c-></i><c- p>(</c-><c- n>r</c-><c- p>,</c-> <c- n>e</c-><c- p>)</c-></code> be:</p>
Expand Down Expand Up @@ -7873,9 +7879,6 @@ <h5 class="heading settled" data-level="11.9.10.3" id="spec-execution.senders.ad
<li data-md>
<p><code class="highlight"><c- n>on</c-></code> adapts an input sender into a sender that will start on an execution
agent belonging to a particular scheduler’s associated execution resource.</p>
<li data-md>
<p>Let <code class="highlight"><i><c- n>replace</c-><c- o>-</c-><c- n>scheduler</c-></i><c- p>(</c-><c- n>e</c-><c- p>,</c-> <c- n>sch</c-><c- p>)</c-></code> be an expression denoting
an object <code class="highlight"><c- n>e2</c-></code> such that <code class="highlight"><c- n>get_scheduler</c-><c- p>(</c-><c- n>e2</c-><c- p>)</c-></code> returns a copy of <code class="highlight"><c- n>sch</c-></code>, <code class="highlight"><c- n>get_domain</c-><c- p>(</c-><c- n>e2</c-><c- p>)</c-></code> is expression-equivalent to <code class="highlight"><c- n>get_domain</c-><c- p>(</c-><c- n>sch</c-><c- p>)</c-></code>, and <code class="highlight"><c- n>tag_invoke</c-><c- p>(</c-><c- n>tag</c-><c- p>,</c-> <c- n>e2</c-><c- p>,</c-> <c- n>args</c-><c- p>...)</c-></code> is expression-equivalent to <code class="highlight"><c- n>tag</c-><c- p>(</c-><c- n>e</c-><c- p>,</c-> <c- n>args</c-><c- p>...)</c-></code> for all arguments <code class="highlight"><c- n>args</c-><c- p>...</c-></code> and for all <code class="highlight"><c- n>tag</c-></code> whose type satisfies <code class="highlight"><i><c- n>forwarding</c-><c- o>-</c-><c- n>query</c-></i></code> and is not <code class="highlight"><c- n>get_scheduler_t</c-></code> or <code class="highlight"><c- n>get_domain_t</c-></code>.</p>
<li data-md>
<p>The name <code class="highlight"><c- n>on</c-></code> denotes a customization point object. For some subexpressions <code class="highlight"><c- n>sch</c-></code> and <code class="highlight"><c- n>s</c-></code>, let <code class="highlight"><c- n>Sch</c-></code> be <code class="highlight"><c- k>decltype</c-><c- p>((</c-><c- n>sch</c-><c- p>))</c-></code> and <code class="highlight"><c- n>S</c-></code> be <code class="highlight"><c- k>decltype</c-><c- p>((</c-><c- n>s</c-><c- p>))</c-></code>. If <code class="highlight"><c- n>Sch</c-></code> does not satisfy <code class="highlight"><c- n>scheduler</c-></code>, or <code class="highlight"><c- n>S</c-></code> does not satisfy <code class="highlight"><c- n>sender</c-></code>, <code class="highlight"><c- n>on</c-><c- p>(</c-><c- n>sch</c-><c- p>,</c-> <c- n>s</c-><c- p>)</c-></code> is ill-formed. Otherwise, the expression <code class="highlight"><c- n>on</c-><c- p>(</c-><c- n>sch</c-><c- p>,</c-> <c- n>s</c-><c- p>)</c-></code> is
expression-equivalent to:</p>
Expand All @@ -7890,7 +7893,7 @@ <h5 class="heading settled" data-level="11.9.10.3" id="spec-execution.senders.ad
<li data-md>
<p><code class="highlight"><c- n>on_t</c-><c- p>().</c-><c- n>transform_env</c-><c- p>(</c-><c- n>out_s</c-><c- p>,</c-> <c- n>e</c-><c- p>)</c-></code> is equivalent to:</p>
<pre class="highlight"><c- k>auto</c-><c- o>&amp;&amp;</c-> <c- p>[</c-><c- n>ign1</c-><c- p>,</c-> <c- n>sch</c-><c- p>,</c-> <c- n>ign2</c-><c- p>]</c-> <c- o>=</c-> <c- n>out_s</c-><c- p>;</c->
<c- k>return</c-> <i><c- n>replace</c-><c- o>-</c-><c- n>scheduler</c-></i><c- p>(</c-><c- n>e</c-><c- p>,</c-> <c- n>sch</c-><c- p>);</c->
<c- k>return</c-> <i><c- n>JOIN</c-><c- o>-</c-><c- n>ENV</c-></i><c- p>(</c-><i><c- n>SCHED</c-><c- o>-</c-><c- n>ENV</c-></i><c- p>(</c-><c- n>sch</c-><c- p>),</c-> <i><c- n>FWD</c-><c- o>-</c-><c- n>ENV</c-></i><c- p>(</c-><c- n>e</c-><c- p>));</c->
</pre>
<li data-md>
<p><code class="highlight"><c- n>on_t</c-><c- p>().</c-><c- n>transform_sender</c-><c- p>(</c-><c- n>out_s</c-><c- p>,</c-> <c- n>e</c-><c- p>)</c-></code> is equivalent to:</p>
Expand All @@ -7905,8 +7908,9 @@ <h5 class="heading settled" data-level="11.9.10.3" id="spec-execution.senders.ad
<li data-md>
<p>Let <code class="highlight"><c- n>out_s</c-></code> be a subexpression denoting a sender returned from <code class="highlight"><c- n>on</c-><c- p>(</c-><c- n>sch</c-><c- p>,</c-> <c- n>s</c-><c- p>)</c-></code> or one equal to such, and let <code class="highlight"><c- n>OutS</c-></code> be the type <code class="highlight"><c- k>decltype</c-><c- p>((</c-><c- n>out_s</c-><c- p>))</c-></code>. Let <code class="highlight"><c- n>out_r</c-></code> be a subexpression denoting a receiver that has an environment of
type <code class="highlight"><c- n>E</c-></code> such that <code class="highlight"><c- n>sender_in</c-><c- o>&lt;</c-><c- n>OutS</c-><c- p>,</c-> <c- n>E</c-><c- o>></c-></code> is <code class="highlight">true</code>. Let <code class="highlight"><c- n>op</c-></code> be an lvalue
referring to the operation state that results from connecting <code class="highlight"><c- n>out_s</c-></code> with <code class="highlight"><c- n>out_r</c-></code>. Calling <code class="highlight"><c- n>start</c-><c- p>(</c-><c- n>op</c-><c- p>)</c-></code> shall start <code class="highlight"><c- n>s</c-></code> on an execution agent of
the associated execution resource of <code class="highlight"><c- n>sch</c-></code>.</p>
referring to the operation state that results from connecting <code class="highlight"><c- n>out_s</c-></code> with <code class="highlight"><c- n>out_r</c-></code>. Calling <code class="highlight"><c- n>start</c-><c- p>(</c-><c- n>op</c-><c- p>)</c-></code> shall start <code class="highlight"><c- n>s</c-></code> on an execution agent of the
associated execution resource of <code class="highlight"><c- n>sch</c-></code>, or failing that, shall execute an
error completion on <code class="highlight"><c- n>out_r</c-></code>.</p>
</ol>
<h5 class="heading settled" data-level="11.9.10.4" id="spec-execution.senders.adapt.transfer"><span class="secno">11.9.10.4. </span><span class="content"><code class="highlight"><c- n>execution</c-><c- o>::</c-><c- n>transfer</c-></code> <b>[exec.transfer]</b></span><a class="self-link" href="#spec-execution.senders.adapt.transfer"></a></h5>
<ol>
Expand All @@ -7922,26 +7926,32 @@ <h5 class="heading settled" data-level="11.9.10.4" id="spec-execution.senders.ad
<i><c- n>get</c-><c- o>-</c-><c- n>domain</c-><c- o>-</c-><c- n>early</c-></i><c- p>(</c-><c- n>s</c-><c- p>),</c->
<i><c- n>make</c-><c- o>-</c-><c- n>sender</c-></i><c- p>(</c-><c- n>transfer</c-><c- p>,</c-> <c- n>sch</c-><c- p>,</c-> <c- n>s</c-><c- p>));</c->
</pre>
<p>If a sender <code class="highlight"><c- n>S</c-></code> returned from <code class="highlight"><c- n>transfer</c-><c- p>(</c-><c- n>s</c-><c- p>,</c-> <c- n>sch</c-><c- p>)</c-></code> is connected with a
receiver <code class="highlight"><c- n>R</c-></code> with environment <code class="highlight"><c- n>E</c-></code> such that <code class="highlight"><c- n>transform_sender</c-><c- p>(</c-><i><c- n>get</c-><c- o>-</c-><c- n>domain</c-><c- o>-</c-><c- n>late</c-></i><c- p>(</c-><c- n>S</c-><c- p>,</c-> <c- n>E</c-><c- p>),</c-> <c- n>S</c-><c- p>,</c-> <c- n>E</c-><c- p>)</c-></code> does not
return a sender that is a result of a call to <code class="highlight"><c- n>transform_sender</c-><c- p>(</c-><i><c- n>get</c-><c- o>-</c-><c- n>domain</c-><c- o>-</c-><c- n>late</c-></i><c- p>(</c-><c- n>S</c-><c- p>,</c-> <c- n>E</c-><c- p>),</c-> <c- n>schedule_from</c-><c- p>(</c-><c- n>sch</c-><c- p>,</c-> <c- n>s2</c-><c- p>),</c-> <c- n>E</c-><c- p>)</c-></code>,
where <code class="highlight"><c- n>s2</c-></code> is a sender that sends values equal to those sent by <code class="highlight"><c- n>s</c-></code>,
the behavior of calling <code class="highlight"><c- n>connect</c-><c- p>(</c-><c- n>S</c-><c- p>,</c-> <c- n>R</c-><c- p>)</c-></code> is undefined.</p>
<li data-md>
<p>For a sender <code class="highlight"><c- n>t</c-></code> returned from <code class="highlight"><c- n>transfer</c-><c- p>(</c-><c- n>s</c-><c- p>,</c-> <c- n>sch</c-><c- p>)</c-></code>, <code class="highlight"><c- n>get_env</c-><c- p>(</c-><c- n>t</c-><c- p>)</c-></code> shall return
a queryable object <code class="highlight"><c- n>q</c-></code> such that <code class="highlight"><c- n>get_domain</c-><c- p>(</c-><c- n>q</c-><c- p>)</c-></code> is expression-equivalent to <code class="highlight"><c- n>get_domain</c-><c- p>(</c-><c- n>sch</c-><c- p>)</c-></code> and <code class="highlight"><c- n>get_completion_scheduler</c-><c- o>&lt;</c-><c- n>CPO</c-><c- o>></c-><c- p>(</c-><c- n>q</c-><c- p>)</c-></code> returns a copy of <code class="highlight"><c- n>sch</c-></code>, where <code class="highlight"><c- n>CPO</c-></code> is either <code class="highlight"><c- n>set_value_t</c-></code> or <code class="highlight"><c- n>set_stopped_t</c-></code>. <span class="wg21note">The <code class="highlight"><c- n>get_completion_scheduler</c-><c- o>&lt;</c-><c- n>set_error_t</c-><c- o>></c-></code> query is not
implemented, as the scheduler cannot be guaranteed in case an error is
thrown while trying to schedule work on the given scheduler object.</span> For all other query objects <code class="highlight"><i><c- n>Q</c-></i></code> whose type satisfies <code class="highlight"><i><c- n>forwarding</c-><c- o>-</c-><c- n>query</c-></i></code>, the expression <code class="highlight"><i><c- n>Q</c-></i><c- p>(</c-><c- n>q</c-><c- p>,</c-> <c- n>args</c-><c- p>...)</c-></code> shall be equivalent to <code class="highlight"><i><c- n>Q</c-></i><c- p>(</c-><c- n>get_env</c-><c- p>(</c-><c- n>s</c-><c- p>),</c-> <c- n>args</c-><c- p>...)</c-></code>.</p>
<p>The exposition-only class template <code class="highlight"><i><c- n>impls</c-><c- o>-</c-><c- k>for</c-></i></code> is specialized
for <code class="highlight"><c- n>transform_t</c-></code> as follows:</p>
<pre class="highlight"><c- k>template</c-><c- o>&lt;></c->
<c- k>struct</c-> <i><c- nc>impls</c-><c- o>-</c-><c- k>for</c-></i><c- o>&lt;</c-><c- n>transform_t</c-><c- o>></c-> <c- o>:</c-> <i><c- k>default</c-><c- o>-</c-><c- n>impls</c-></i> <c- p>{</c->
<c- k>static</c-> <c- k>constexpr</c-> <c- k>auto</c-> <c- n>get_attrs</c-> <c- o>=</c->
<c- p>[](</c-><c- k>const</c-> <c- k>auto</c-><c- o>&amp;</c-> <c- n>data</c-><c- p>,</c-> <c- k>const</c-> <c- k>auto</c-><c- o>&amp;</c-> <c- n>child</c-><c- p>)</c-> <c- k>noexcept</c-> <c- o>-></c-> <c- k>decltype</c-><c- p>(</c-><c- k>auto</c-><c- p>)</c-> <c- p>{</c->
<c- k>return</c-> <i><c- n>JOIN</c-><c- o>-</c-><c- n>ENV</c-></i><c- p>(</c-><i><c- n>SCHED</c-><c- o>-</c-><c- n>ATTRS</c-></i><c- p>(</c-><c- n>data</c-><c- p>),</c-> <i><c- n>FWD</c-><c- o>-</c-><c- n>ENV</c-></i><c- p>(</c-><c- n>get_env</c-><c- p>(</c-><c- n>child</c-><c- p>)));</c->
<c- p>};</c->
<c- p>};</c->
</pre>
<li data-md>
<p>Let <code class="highlight"><c- n>s</c-></code> and <code class="highlight"><c- n>e</c-></code> be subexpressions such that <code class="highlight"><c- n>S</c-></code> is <code class="highlight"><c- k>decltype</c-><c- p>((</c-><c- n>s</c-><c- p>))</c-></code>. If <code class="highlight"><i><c- n>sender</c-><c- o>-</c-><c- k>for</c-></i><c- o>&lt;</c-><c- n>S</c-><c- p>,</c-> <c- n>transfer_t</c-><c- o>></c-></code> is <code class="highlight">false</code>, then the expression <code class="highlight"><c- n>transfer_t</c-><c- p>().</c-><c- n>transform_sender</c-><c- p>(</c-><c- n>s</c-><c- p>,</c-> <c- n>e</c-><c- p>)</c-></code> is ill-formed; otherwise, it
is equal to:</p>
<pre class="highlight"><c- k>const</c-> <c- k>auto</c-><c- o>&amp;</c-> <c- n>env</c-> <c- o>=</c-> <c- n>e</c-><c- p>;</c->
<c- k>auto</c-> <c- n>domain</c-> <c- o>=</c-> <i><c- n>get</c-><c- o>-</c-><c- n>domain</c-><c- o>-</c-><c- n>late</c-></i><c- p>(</c-><c- n>s</c-><c- p>,</c-> <c- n>env</c-><c- p>);</c->
<c- k>auto</c-> <c- p>[</c-><c- n>tag</c-><c- p>,</c-> <c- n>data</c-><c- p>,</c-> <c- n>child</c-><c- p>]</c-> <c- o>=</c-> <c- n>s</c-><c- p>;</c->
<pre class="highlight"><c- k>auto</c-> <c- p>[</c-><c- n>tag</c-><c- p>,</c-> <c- n>data</c-><c- p>,</c-> <c- n>child</c-><c- p>]</c-> <c- o>=</c-> <c- n>s</c-><c- p>;</c->
<c- k>return</c-> <c- n>schedule_from</c-><c- p>(</c-><c- n>std</c-><c- o>::</c-><c- n>move</c-><c- p>(</c-><c- n>data</c-><c- p>),</c-> <c- n>std</c-><c- o>::</c-><c- n>move</c-><c- p>(</c-><c- n>child</c-><c- p>));</c->
</pre>
<p><span class="wg21note">This causes the <code class="highlight"><c- n>transfer</c-><c- p>(</c-><c- n>s</c-><c- p>,</c-> <c- n>sch</c-><c- p>)</c-></code> sender to become <code class="highlight"><c- n>schedule_from</c-><c- p>(</c-><c- n>sch</c-><c- p>,</c-> <c- n>s</c-><c- p>)</c-></code> when it is connected with a receiver with an
execution domain that does not customize <code class="highlight"><c- n>transfer</c-></code>.</span></p>
<li data-md>
<p>Let <code class="highlight"><c- n>out_s</c-></code> be a subexpression denoting a sender returned from <code class="highlight"><c- n>transfer</c-><c- p>(</c-><c- n>s</c-><c- p>,</c-> <c- n>sch</c-><c- p>)</c-></code> or one equal to such, and let <code class="highlight"><c- n>OutS</c-></code> be the type <code class="highlight"><c- k>decltype</c-><c- p>((</c-><c- n>out_s</c-><c- p>))</c-></code>. Let <code class="highlight"><c- n>out_r</c-></code> be a subexpression denoting a receiver that has an environment of
type <code class="highlight"><c- n>E</c-></code> such that <code class="highlight"><c- n>sender_in</c-><c- o>&lt;</c-><c- n>OutS</c-><c- p>,</c-> <c- n>E</c-><c- o>></c-></code> is <code class="highlight">true</code>. Let <code class="highlight"><c- n>op</c-></code> be an lvalue
referring to the operation state that results from connecting <code class="highlight"><c- n>out_s</c-></code> with <code class="highlight"><c- n>out_r</c-></code>. Calling <code class="highlight"><c- n>start</c-><c- p>(</c-><c- n>op</c-><c- p>)</c-></code> shall start <code class="highlight"><c- n>s</c-></code> on the current execution agent
and execute completion operations on <code class="highlight"><c- n>out_r</c-></code> on an execution agent of the
associated execution resource of <code class="highlight"><c- n>sch</c-></code>; or failing that, execute an error
completion on <code class="highlight"><c- n>out_r</c-></code>.</p>
</ol>
<h5 class="heading settled" data-level="11.9.10.5" id="spec-execution.senders.adaptors.schedule_from"><span class="secno">11.9.10.5. </span><span class="content"><code class="highlight"><c- n>execution</c-><c- o>::</c-><c- n>schedule_from</c-></code> <b>[exec.schedule.from]</b></span><a class="self-link" href="#spec-execution.senders.adaptors.schedule_from"></a></h5>
<ol>
Expand Down

0 comments on commit ac044cb

Please sign in to comment.