|
|
Log in / Subscribe / Register

One and a half colors

One and a half colors

Posted Dec 3, 2025 9:17 UTC (Wed) by pbonzini (subscriber, #60935)
In reply to: One and a half colors by khim
Parent article: Zig's new plan for asynchronous programs

> That's much better solution that what Rust did. Of course Zig has the benefits of hindsight.

I would like to understand how IO functions are compiled. If they are stackful coroutines, Zig's solution is very clever but that's a very different design space than the stackless coroutines you have in Rust or, for that matter, in Zig's previous attempt at asynchronous I/O. Stackless coroutines need compiler support but are more efficient (a couple years back I had a (IMO) really nice design for C stackless coroutines, but no time to implement it...).

Or does the compiler effectively treat the IO argument as a request to turn the function into a state machine and pass it to the threaded or evented run-time?


to post comments

One and a half colors

Posted Dec 3, 2025 10:17 UTC (Wed) by spiffyk (subscriber, #173891) [Link]

As I understand it, the way the function will ultimately be compiled is entirely up to the chosen implementation of the Io interface. May be stackful, may be stackless – the point is that to the function taking the Io parameter, this is just a transparent implementation detail.

What is important to note is that the language provides no special treatment to the Io parameter, it is entirely an API convention to pass it. Io is an extension of the standard library, which in and of itself does not change how the language works. The only point at which the compiler itself will need to provide special functionality is when an implementation of the Io interface uses the (as of yet not finalized, afaik) constructs for stackless coroutines. But those are planned to be a separate feature of the language, and, from the perspective of the Io, will only be used by specific Io implementations.

One and a half colors

Posted Dec 3, 2025 12:40 UTC (Wed) by lukasl (guest, #180745) [Link]

There is no compiler support for this. It's either threads or stackful coroutines, depending on the implementation. The current dev versions of Zig only support threaded version of this. There are work-in-progress implementations of event loops in the zig std. I also created one alternative stackful coroutine runtime, outside of the zig std, that also implements the interface.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds