C++ Logo

std-proposals

Advanced search

[std-proposals] Permit Elision or Trivial Elision for Coroutine Parameter Moves?

From: Yuxuan Chen <yuxuanchen1997_at_[hidden]>
Date: Wed, 20 Nov 2024 20:22:45 +0000
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.
  2.
It should also be possible to trivially relocate all parameters to the coroutine frame if elision in (1) cannot happen. This part is of course dependent on the trivial relocation paper.

I have a feeling that the current standard wording can be relaxed a little bit. I am open to write a paper to address this. I am wondering if such ideas have been discussed.


Yuxuan Chen

Received on 2024-11-20 20:22:51