Storing Data in Control Flow
What&#x27;s really unfortunate is that compilers <i>already</i> perform this &quot;control flow -&gt; state machine&quot; transformation, but almost none of them expose it to the user for direct manipulation - instead, they tightly couple it to a bunch of unrelated abstractions like event loop runtimes, async executors, managed stacks, etc. I&#x27;d kill for a compiler that can properly:<p>* Parse a coroutine that produces and consumes values<p>* Perform all the normal function-level optimizations to minimize frame space (stack slot reuse via liveness analysis of local variables, re-computing temporaries across yield points, etc.)<p>* Expose that coroutine frame as a fixed-size struct that I can explicitly resume and query<p>Zig is <i>almost</i> there, but suspend&#x2F;resume cannot return values&#x2F;take arguments, which requires some unergonomic workarounds. Rust is making some promising progress on unified coroutines (<a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rfcs&#x2F;pull&#x2F;2781">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rfcs&#x2F;pull&#x2F;2781</a>), but the generator types are opaque so you can&#x27;t encapsulate them in a Sized struct or allocate an array of them. Not to mention that it&#x27;s still extra-unstable, and last I checked, there were issues with generator size optimizations (<a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;issues&#x2F;59087">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;issues&#x2F;59087</a>). C++20 coroutines are similarly opaque and cannot be allocated as a contiguous array.