|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4356" status="New"> |
| 5 | +<title>`connect()` should use `get_allocator(get_env(rcvr))` to allocate the coroutine-state for a |
| 6 | +<tt><i>connect-awaitable</i></tt> coroutine</title> |
| 7 | +<section> |
| 8 | +<sref ref="[exec.connect]"/> |
| 9 | +</section> |
| 10 | +<submitter>Lewis Baker</submitter> |
| 11 | +<date>27 Aug 2025</date> |
| 12 | +<priority>99</priority> |
| 13 | + |
| 14 | +<discussion> |
| 15 | +<p> |
| 16 | +The wording for `connect()` (<sref ref="[exec.connect]"/>) handles passing awaitable types as the sender argument |
| 17 | +by calling the <tt><i>connect-awaitable</i></tt>() coroutine and having it execute a `co_await` expression. |
| 18 | +<p/> |
| 19 | +The <tt><i>connect-awaitable</i></tt>() coroutine will typically need to dynamically allocate storage for |
| 20 | +the coroutine state and, as specified, this currently just always uses the global default allocator. |
| 21 | +This is because the <tt><i>connect-awaitable-promise</i></tt> type does not define any member operator |
| 22 | +`new/delete` overloads. |
| 23 | +<p/> |
| 24 | +It seems desirable for this facility to use the allocator obtained from the receiver, by calling |
| 25 | +`get_allocator(get_env(rcvr))`, in order to allocate storage for the coroutine-state instead of always |
| 26 | +using global operator `new`. This would give the user at least some level of control over how this |
| 27 | +allocation is performed. |
| 28 | +</p> |
| 29 | +</discussion> |
| 30 | + |
| 31 | +<resolution> |
| 32 | +<p> |
| 33 | +This wording is relative to <paper num="N5014"/>. |
| 34 | +</p> |
| 35 | + |
| 36 | +<ol> |
| 37 | + |
| 38 | +<li><p>Modify <sref ref="[exec.connect]"/> as indicated:</p> |
| 39 | + |
| 40 | +<blockquote class="note"> |
| 41 | +<p> |
| 42 | +[<i>Drafting note: </i> This should cover the design intent, although we may want to spell this out |
| 43 | +more explicitly in terms of the exact semantics in a similar way to <sref ref="[coro.generator.promise]"/> p17, |
| 44 | +which lists overloads of operator `new()` and describes the rebound allocator type which allocates storage |
| 45 | +in chunks of size `__STDCPP_DEFAULT_NEW_ALIGNMENT__`.] |
| 46 | +</p> |
| 47 | +</blockquote> |
| 48 | + |
| 49 | +<blockquote> |
| 50 | +<p> |
| 51 | +-5- Let `V` name the type <tt><i>await-result-type</i><DS, <i>connect-awaitable-promise</i>></tt>, |
| 52 | +let `Sigs` name the type |
| 53 | +</p> |
| 54 | +<blockquote><pre> |
| 55 | +[…] |
| 56 | +</pre></blockquote> |
| 57 | +<p> |
| 58 | +and let <tt><i>connect-awaitable</i></tt> be an exposition-only coroutine defined as follows: |
| 59 | +</p> |
| 60 | +<blockquote><pre> |
| 61 | +namespace std::execution { |
| 62 | + […] |
| 63 | +} |
| 64 | +</pre></blockquote> |
| 65 | +<p> |
| 66 | +<ins>Any dynamically allocated storage required for the coroutine state allocated by an invocation |
| 67 | +of the form <tt><i>connect-awaitable</i>(sndr, rcvr)</tt> is allocated using the allocator obtained |
| 68 | +from `get_allocator(get_env(rcvr))`.</ins> |
| 69 | +<p/> |
| 70 | +-6- […] |
| 71 | +</p> |
| 72 | +</blockquote> |
| 73 | + |
| 74 | +</li> |
| 75 | + |
| 76 | +</ol> |
| 77 | +</resolution> |
| 78 | + |
| 79 | +</issue> |
0 commit comments