I had 2 problems, I wanted to make the post about the first problem but ended up also encountering a bug, so I will mention both. I don’t exactly understand the error in problem 2 so I couldn’t make a bug report.
Problem 1
When I am in watch mode, and I make a change, when the compiler shows me the new error message, it doesn’t clear the previous error messages. The Result is if I try to use it for extended periods of time, the terminal gets filled with error messages from previous failed compilations and I completely lose track.
for example, in the image below, I fix bug1 and save, then it shows bug2, but ideally I would like it if bug1 disappeared from the screen, since it’s now fixed.
Is there a flag I can give to tell it to clear them?
Problem 2 (Bug?)
The project can compile in normal mode, but fails to compile in incremental, I don’t understand the error message.
BTW LLVM backend still works, which is what I used in the first image.
andrewrk August 1, 2026, 9:58pm 2
I’m pretty sure a bunch of incremental bugs were fixed after that commit.
I assumed “mise use zig@master” was enough to use the latest version.
I updated to 0.17.0-dev.1516+8a4b5424d (AFAIK it’s the latest version right)
I hope I am staying in topic here - because I noticed what I think is a different bug, the code below used to work:
const std = @import("std");
const RandomStruct = extern struct {
field: f32 = 0,
};
pub fn main() !void {
const p: RandomStruct = .{};
const arr: [@sizeOf(@TypeOf(p))]u8 = @bitCast(p);
std.debug.print("{any}", .{arr});
}
however now I get the error:
…/zig/test ❯ zig run tmp.zig
tmp.zig:9:51: error: cannot @bitCast from 'tmp.RandomStruct'
const arr: [@sizeOf(@TypeOf(p))]u8 = @bitCast(p);
^
tmp.zig:3:29: note: struct declared here
const RandomStruct = extern struct {
~~~~~~~^~~~~~
referenced by:
callMain [inlined]: /home/plebosaur/.local/share/mise/installs/zig/master/lib/std/start.zig:752:64
callMainWithArgs [inlined]: /home/plebosaur/.local/share/mise/installs/zig/master/lib/std/start.zig:693:20
posixCallMainAndExit: /home/plebosaur/.local/share/mise/installs/zig/master/lib/std/start.zig:645:38
2 reference(s) hidden; use '-freference-trace=5' to see all references
I think this is not intentional with the new bitcast changes, if that’s the case I’ll open a bug report.
Other suspicious thing
This part of the build took ~1 minute, it’s on the LLVM emit object phase so it’s likely LLVM’s fault, but this is not a big project, and it took only a few seconds to compile the project in previous versions.
andrewrk August 1, 2026, 10:22pm 4
Other Suspicious Thing
see:
That has to be done once per different zig version. If you’re doing a lot of switching between zig versions or patching std lib you might benefit from using ZIG_DEBUG_MAKER=1.
mlugg August 1, 2026, 10:23pm 5
--error-style verbose_clear (or --error-style minimal_clear for a more compact view) will make it clear the terminal on every rebuild. You can set the environment variable ZIG_BUILD_ERROR_STYLE to either verbose_clear or minimal_clear to avoid having to pass it every time.
mlugg August 1, 2026, 10:25pm 6
This is working as intended—@bitCast is a primitive which it would very rarely make sense to use on an extern struct, since usually what you actually want with an extern struct is simple memory reinterpretation. In this case, it looks like you did indeed just want the raw bytes of the RandomStruct? If so, you should be able to do this:
const p: RandomStruct = .{};
const bytes: []const u8 = @ptrCast(&p);
std.debug.print("{any}", .{bytes});
Actually the use case here was very weird:
I just wanted to pass the actual struct from build.zig to my program.
However there’s a bug preventing that:
https://codeberg.org/ziglang/zig/issues/35842
So as a workaround I passed just the raw array of bytes
in build.zig
const arrtype = [@sizeOf(zorg.building.MTSDFfontBuilder.FontData)]u8;
// This used to be bitcast, I did this now
fontOptions.addOption(arrtype, "bitCastedMetadata", @as(*const arrtype, @ptrCast(&metadata)).*);
Then in the code
const metadata: zorg.building.MTSDFfontBuilder.FontData = @bitCast(jb.bitCastedMetadata);
Edit: here is what actually worked:
const metadata: zorg.building.MTSDFfontBuilder.FontData =
D: {
var ans: zorg.building.MTSDFfontBuilder.FontData = undefined;
const ptr: *[@sizeOf(zorg.building.MTSDFfontBuilder.FontData)]u8 = @ptrCast(&ans);
ptr.* = jb.bitCastedMetadata;
break :D ans;
};
(If this line doesn’t work then I will probably do the same trick in reverse)
Edit: Apparently 80% of my @bitCast uses are in extern structs, but switching to @ptrCast doesn’t seem like a difficult migration.
Edit: This got resolved - will still leave it here, will have to compiler explorer it though!
I didn’t get to see if it worked, because of a completely different part of the codebase with @Vector in extern unions, the use case for that was simulating indexing into [*]@Vector(32, u8) for an exotic performance optimization, I initially tried using [*][32]u8 but LLVM was confused about the alignment, then I went into an extern union{} that has both, I’ll have to take some time to write a seperate thread for that use case, sorry for rambling a bit.
That should solve #problem 1, I will see if the incremental fails after I update the codebase.
If that happens should I try to come back here on this thread, make a different one or try to copy paste the terminal output into a bug report?
EDIT - I updated, it works.
Anyways, I just want to say that from a user perspective It’s very reassuring And appreciated to get this sort of response from the core team when something in the language is not working!
After migrating the codebase incremental seems to work!!!
0 Comments
Log in to join the conversation.No comments yet. Be the first to share your thoughts.