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?
…/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.
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.
--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.
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:
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)).*);
(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!
Also use mise, and that command uses the last downloaded version of master that is cached locally. You have to mise uninstall zig@master and then mise install zig@master to get mise to download a more recent version.