Second Draft: Coroutines
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Thu Jan 23 09:49:54 UTC 2025
On 23/01/2025 10:00 PM, Sebastiaan Koppe wrote:
> On Thursday, 12 December 2024 at 10:36:50 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> Stackless coroutines, is a way to enable asynchronous programming, for
>> lesser skilled and less knowledgable people whilst offering efficient
>> processing of events, safely.
>>
>> This version of the proposal has been rewritten to account for a lack
>> of understanding on the separation of library code versus what the
>> language is offering.
>>
>> And a few changes related to yielding. Yielding is no longer
>> guaranteed to be implicit. You may explicitly yield using an ``await``
>> statement should you wish to. The library type must support implicit
>> yielding if you wish to use it. Both may be used on the same type, it
>> is entirely dependent upon the called methods attributes.
>>
>> Lastly, the changes have been made to simplify the descriptor to make
>> the implementation within the compiler a little bit easier. It does
>> mean that you as a library author have no way to know about the
>> functions in the state machine (not that you could have done much with
>> them).
>>
>> Current: https://gist.github.com/rikkimax/
>> fe2578e1dfbf66346201fd191db4bdd4/649a5a6cc68c4bfe9f5a62f746a3a90f6b4beaf4
>>
>> Latest: https://gist.github.com/rikkimax/fe2578e1dfbf66346201fd191db4bdd4
>
> The design as presented isn't focused enough IMO. It lacks detail in
> core areas and adds in too many (questionable) nice-to-have or day-two
> features.
>
> I believe the challenge with coroutines is twofold: 1) the code
> transformations and 2) how/when to resume suspended coroutines. Then
> there are secondary goals like extensibility/flexibility and eliding
> allocations.
>
> Additionally, the DIP has no reference to C++'s coroutine feature. I am
> sure there is a ton written on the subject by users, implementors,
> designers, etc.
>
> A good starting point would be the official reference https://
> en.cppreference.com/w/cpp/language/coroutines
I didn't seen anything worth adding. So I haven't.
> as well as Lewis Baker's
> blog: https://lewissbaker.github.io/2022/08/27/understanding-the-
> compiler-transform (part 5 of 5), who is knee-deep in this stuff.
That article by Lewis Baker is pretty good at laying out how C++ does
it, although it does hand waive some details away that I would be
interested in.
It also confirms a couple of things for me.
1. Tieing the language to a specific library does not inherently make it
simpler.
2. C++ has a more complex design, that does not offer anything above
that of my proposal.
I'll add it to the references section, but not the prior work. This is
not a copy C++ situation.
More information about the dip.development
mailing list