4 ms·
Very nice, but how does it support separate compilation? Does the compiler always compile two versions of each function or zig only support whole program compil
by gpderetta 5y ago
Very nice, but how does it support separate compilation? Does the compiler always compile two versions of each function or zig only support whole program compilation ( by JITing for example)?
Or is it just stackful coroutines and there is really no difference between async and sync functions?
- aeldidi 5y agoI believe it's up to the programmer to implement this. Here's some code from the zig github[1] page that illustrates how it might look once zig is stable (this is from an issue). pub fn write(file: *File, bytes: []const u8) usize { // Note that this is an if with comptime-known condition. if (std.event.loop.instance) |event_loop| { // non blocking version } else { // blocking call } } So I guess functions that don't support async could just do something like: if (!std.event.loop.instance) @compileError("X function only supports async"); [1]: https://github.com/ziglang/zig/issues/1778 https://github.com/ziglang/zig/issues/1778
- gpderetta 5y agoThanks, but how is a waiter suspended? The typical await implementation will do a CPS conversion of the waiter function, but to trigger the conversion it needs to see an await call, or pessimistically generate two versions of each functions. But from your example it seems that Zig just do context switching (not knocking it, I'm a big fan of it over await), but then why would it need an await/async keyword at all?
- gpderetta 5y agoTo answer myself. Zig doesn't really do separate compilation: https://github.com/ziglang/zig/issues/233 https://github.com/ziglang/zig/issues/233