4 ms·
Are you saying that you think that Zig does not produce identical outcomes for comptime code regardless of when the code runs? What do you mean?
by chaz72 13d ago
Are you saying that you think that Zig does not produce identical outcomes for comptime code regardless of when the code runs? What do you mean?
- bruckie 13d agoI assumed that it meant that if you ran code at compile time or at runtime, the results should be exactly the same given the same inputs.
- chaz72 13d agoAnd they believe Zig comptime wouldn’t do that? For the same inputs? I’d love an example.
- weinzierl 13d agosin(x) can produce different results at comptime and runtime. In Rust there is no sin(x) at comptime for precisely this reason.
- chaz72 13d agoInteresting, I hadn’t run across that but that’s probably just my problem domain. I did find this bug that looks like it was resolved a year ago https://github.com/ziglang/zig/issues/24184 https://github.com/ziglang/zig/issues/24184 and I have also read they are doing some other work on floating point that will hopefully address other cross-platform inconsistencies.
- deleted 13d ago[deleted]
- vlovich123 13d agoTraditional stuff in this space are: * floating point differences between the build machine and the target. By far the most common * endiannes - code assumes little median runs on big endian There’s other more subtle issues that can crop up but those are the big two. Not saying I agree though - those can happen anyway when you run on two different machines anyway.
- chaz72 13d agoI get it now. Important things but not things that I use often - hopefully addressed by 1.0.
- weinzierl 13d agoI'm not sure there is something to be addressed. Zig has just a different approach and Zig people different expectations. In Rust we can expand what is possible at compile time without breaking existing code because we took a very careful approach only stabilizing what we are sure about. Some things will probably never be possible at compile time in Rust. Zig is much more powerful but that also means they cannot take stuff away without breaking existing code and making comptime more restricted. So it is unlikely Zig will ever become like Rust in that regard, but that is ok - just different approaches.
- chaz72 13d agoI hear you but I’m not sure it’s as dramatic as that, it’s also been quite predictable in my use over the last few years since I haven’t happened to use floating point or different endianness.
- vlovich123 13d agoI think the Rust approach is incorrect - if the runtime behavior can change based on the machine that the code gets run on, why is it so important the build time behavior has such a restrictive definition? Especially considering build.rs can be used to bypass that definition anyway. It feels like a weird cut to make that I can’t figure out the understanding for. It feels like it inherited the const philosophy of c++11 without reexamining if it’s actually a good idea.
- tcfhgj 13d agoreproducible builds
- 13d ago
- weinzierl 13d agoYes. For example in Rust it took a long time for floating point operations to be available at compile time and even now only a subset is. The reason is that a lot of energy and thought went into the issue of producing identical output (and what identical precisely means ) even when compilation is on a different processor than where the target runs. As far as I know this is not a concern for Zig comptime.
- chaz72 13d agoNow I see this response, I responded to the other comment.
- nvme0n1p1 13d agoWhat's your source for this? Comptime Zig code can do pointer casts and whatnot, all emulated as if run on the target bitness/endianness/etc. And any operations that are undefined on the target platform result in a compile error. I've never had an issue cross-compiling.
- weinzierl 13d agoEndianness and pointer casts are the mechanical part and I would expect Zig to emulate them correctly. Other parts, like floats are harder. This is where a difference shows. Rust is like: "Sorry, since we cannot uphold our guarantees, no transcendentals for you at comptime ", whereas Zig is chill about that and let you have your transcendentals even if results may differ between comptime and runtime. Different mindsets.