authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-05-20 19:34:27+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-05-21 11:11:28+01:00
log3416452d567e6725ef887252237e553f7d7be242
treed715aa160d1ec67502ca61502a6b46607eaf83e9
parentef92c156b5ce1fade3106fc0d79af36bb4409246

compiler: fix ZIR hash not including compiler version

This was an unintentional regression in 23c8175 which meant that backwards-incompatible ZIR changes would have caused compiler crashes if old caches were present.

3 files changed, 17 insertions(+), 11 deletions(-)

src/Compilation.zig+8-3
...@@ -352,12 +352,17 @@ pub const Path = struct {...@@ -352,12 +352,17 @@ pub const Path = struct {
352 gpa.free(p.sub_path);352 gpa.free(p.sub_path);
353 }353 }
354354
355 /// The returned digest is relocatable across any compiler process using the same lib and cache355 /// The added data is relocatable across any compiler process using the same lib and cache
356 /// directories; it does not depend on cwd.356 /// directories; it does not depend on cwd.
357 pub fn digest(p: Path) Cache.BinDigest {357 pub fn addToHasher(p: Path, h: *Cache.Hasher) void {
358 var h = Cache.hasher_init;
359 h.update(&.{@intFromEnum(p.root)});358 h.update(&.{@intFromEnum(p.root)});
360 h.update(p.sub_path);359 h.update(p.sub_path);
360 }
361
362 /// Small convenience wrapper around `addToHasher`.
363 pub fn digest(p: Path) Cache.BinDigest {
364 var h = Cache.hasher_init;
365 p.addToHasher(&h);
361 return h.finalResult();366 return h.finalResult();
362 }367 }
363368
src/Zcu.zig-7
...@@ -4239,13 +4239,6 @@ pub fn setFileRootType(zcu: *Zcu, file_index: File.Index, root_type: InternPool....@@ -4239,13 +4239,6 @@ pub fn setFileRootType(zcu: *Zcu, file_index: File.Index, root_type: InternPool.
4239 files.view().items(.root_type)[file_index_unwrapped.index] = root_type;4239 files.view().items(.root_type)[file_index_unwrapped.index] = root_type;
4240}4240}
42414241
4242pub fn filePathDigest(zcu: *const Zcu, file_index: File.Index) Cache.BinDigest {
4243 const ip = &zcu.intern_pool;
4244 const file_index_unwrapped = file_index.unwrap(ip);
4245 const files = ip.getLocalShared(file_index_unwrapped.tid).files.acquire();
4246 return files.view().items(.bin_digest)[file_index_unwrapped.index];
4247}
4248
4249pub fn navSrcLoc(zcu: *const Zcu, nav_index: InternPool.Nav.Index) LazySrcLoc {4242pub fn navSrcLoc(zcu: *const Zcu, nav_index: InternPool.Nav.Index) LazySrcLoc {
4250 const ip = &zcu.intern_pool;4243 const ip = &zcu.intern_pool;
4251 return .{4244 return .{
src/Zcu/PerThread.zig+9-1
...@@ -101,7 +101,15 @@ pub fn updateFile(...@@ -101,7 +101,15 @@ pub fn updateFile(
101 .global_cache, .zig_lib => false,101 .global_cache, .zig_lib => false,
102 };102 };
103103
104 const hex_digest = Cache.binToHex(file.path.digest());104 const hex_digest: Cache.HexDigest = d: {
105 var h: Cache.HashHelper = .{};
106 // As well as the file path, we also include the compiler version in case of backwards-incompatible ZIR changes.
107 file.path.addToHasher(&h.hasher);
108 h.addBytes(build_options.version);
109 h.add(builtin.zig_backend);
110 break :d h.final();
111 };
112
105 const cache_directory = if (want_local_cache) zcu.local_zir_cache else zcu.global_zir_cache;113 const cache_directory = if (want_local_cache) zcu.local_zir_cache else zcu.global_zir_cache;
106 const zir_dir = cache_directory.handle;114 const zir_dir = cache_directory.handle;
107115