3 ms·
I may be totally wrong with this assumption, but the way I understoog Zig's color-less async support is that the compiler either creates a "red" or "blue" funct
by flohofwoe 5y ago
I may be totally wrong with this assumption, but the way I understoog Zig's color-less async support is that the compiler either creates a "red" or "blue" function body from the same source code based on how the function is called (so on the language level, function coloring doesn't matter, but it does in compiler output).
The compiler still needs to stamp out colored function bodies because the generated code for a function with async support needs to look different - the compiler needs to turn the code into a state machine instead of a simple sequence).
It's a bit unfortunate that red and blue functions appear to have a different "ABI signature", but I guess that's needed to pass an additional context pointer into a function with async support (which would otherwise be the implicit stack pointer).
- anonymoushn 5y agoThis is all correct. I don't think it needs to be this way though. It could plausibly work in a way that doesn't make async functions special other than that the compiler must calculate the size of the deepest stack they can use, and then TFA's code would work rather than not working. (Well, other than the thing where the author wanted to make a function that suspends only once, then call it, then resume it, the await it, which will never work by design)
- dundarious 5y agoPretty sure stack growth knowledge like this is on the Zig roadmap. Stack memory is a free-for-all in most languages, but in many domains, it's as crucial to manage as the heap.
- anonymoushn 5y agoA similar type of information is already recorded by the compiler for async functions to figure out how large their frames must be. So the proposed change would change the size of some frames but otherwise do nothing to most code.
- dundarious 5y agoCheers. I must admit I've completely ignored the async aspect of Zig for the time being, so I know nothing about how close or far it is from already doing enough of this work. Thanks for the info.
- kristoff_it 5y agoThat's exactly it. It just enables code reuse. You still have to think about how your application will behave, but you won't have to use an async-flavored reimplementaion of another library. Case in point: zig-okredis works in both sync and async applicatons, and I don't have to maintain two codebases. https://github.com/kristoff-it/zig-okredis https://github.com/kristoff-it/zig-okredis I thought using "colorblind" in the title of my original blogpost would be a clear enough hint to the reader that the colors still exist, but I guess you can never be too explicit.