From 55a2e535fdb663793b84769cb6c3a261bda3fc66 Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 4 Feb 2025 14:03:40 +0000 Subject: compiler: integrate ZON with the ZIR caching system This came with a big cleanup to `Zcu.PerThread.updateFile` (formerly `astGenFile`). Also, change how the cache manifest works for files in the import table. Instead of being added to the manifest when we call `semaFile` on them, we iterate the import table after running the AstGen workers and add all the files to the cache manifest then. The downside is that this is a bit more eager to include files in the manifest; in particular, files which are imported but not actually referenced are now included in analysis. So, for instance, modifying any standard library file will invalidate all Zig compilations using that standard library, even if they don't use that file. The original motivation here was simply that the old logic in `semaFile` didn't translate nicely to ZON. However, it turns out to actually be necessary for correctness. Because `@import("foo.zig")` is an AstGen-level error if `foo.zig` does not exist, we need to invalidate the cache when an imported but unreferenced file is removed to make sure this error is triggered when it needs to be. Resolves: #22746 --- lib/std/zig/Zoir.zig | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/std') diff --git a/lib/std/zig/Zoir.zig b/lib/std/zig/Zoir.zig index af93d03261..700bf6ea32 100644 --- a/lib/std/zig/Zoir.zig +++ b/lib/std/zig/Zoir.zig @@ -10,6 +10,31 @@ string_bytes: []u8, compile_errors: []Zoir.CompileError, error_notes: []Zoir.CompileError.Note, +/// The data stored at byte offset 0 when ZOIR is stored in a file. +pub const Header = extern struct { + nodes_len: u32, + extra_len: u32, + limbs_len: u32, + string_bytes_len: u32, + compile_errors_len: u32, + error_notes_len: u32, + + /// We could leave this as padding, however it triggers a Valgrind warning because + /// we read and write undefined bytes to the file system. This is harmless, but + /// it's essentially free to have a zero field here and makes the warning go away, + /// making it more likely that following Valgrind warnings will be taken seriously. + unused: u64 = 0, + + stat_inode: std.fs.File.INode, + stat_size: u64, + stat_mtime: i128, + + comptime { + // Check that `unused` is working as expected + assert(std.meta.hasUniqueRepresentation(Header)); + } +}; + pub fn hasCompileErrors(zoir: Zoir) bool { if (zoir.compile_errors.len > 0) { assert(zoir.nodes.len == 0); -- cgit v1.2.3