Date: Wed, 20 Nov 2024 23:06:39 +0100
On 20/11/2024 21.22, Yuxuan Chen via Std-Proposals wrote:
> Coroutines as of today, requires its parameters to be copied into the coroutine through a move constructor as stated in https://eel.is/c++draft/dcl.fct.def.coroutine#13.
>
> The exact wording is "When a coroutine is invoked, after initializing its parameters ([expr.call] <https://eel.is/c++draft/expr.call>), a copy is created for each coroutine parameter. <https://eel.is/c++draft/dcl.fct.def.coroutine#13.sentence-1>
> For a parameter of type cv T, the copy is a variable of type cv T with automatic storage duration that is direct-initialized from an xvalue of type T referring to the parameter. <https://eel.is/c++draft/dcl.fct.def.coroutine#13.sentence-2>"
>
> However, I believe that the current standard wording is too strict and sometimes prevent valid optimizations.
>
> 1.
> In the elision case, sometimes an implementation can prove that a coroutine never suspends, never resumes, or coroutines whose handle never escapes. Hence, the lifetime of the moved parameter won't exceed the original ones as parameters to the ramp function. Such elision should be safe and helps reduce the size of a coroutine frame.
Already allowed; see [class.copy.elision] p1.3
Jens
> Coroutines as of today, requires its parameters to be copied into the coroutine through a move constructor as stated in https://eel.is/c++draft/dcl.fct.def.coroutine#13.
>
> The exact wording is "When a coroutine is invoked, after initializing its parameters ([expr.call] <https://eel.is/c++draft/expr.call>), a copy is created for each coroutine parameter. <https://eel.is/c++draft/dcl.fct.def.coroutine#13.sentence-1>
> For a parameter of type cv T, the copy is a variable of type cv T with automatic storage duration that is direct-initialized from an xvalue of type T referring to the parameter. <https://eel.is/c++draft/dcl.fct.def.coroutine#13.sentence-2>"
>
> However, I believe that the current standard wording is too strict and sometimes prevent valid optimizations.
>
> 1.
> In the elision case, sometimes an implementation can prove that a coroutine never suspends, never resumes, or coroutines whose handle never escapes. Hence, the lifetime of the moved parameter won't exceed the original ones as parameters to the ramp function. Such elision should be safe and helps reduce the size of a coroutine frame.
Already allowed; see [class.copy.elision] p1.3
Jens
Received on 2024-11-20 22:06:47