Skip to content

Commit 3416452

Browse files
committed
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.
1 parent ef92c15 commit 3416452

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/Compilation.zig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,17 @@ pub const Path = struct {
352352
gpa.free(p.sub_path);
353353
}
354354

355-
/// The returned digest is relocatable across any compiler process using the same lib and cache
355+
/// The added data is relocatable across any compiler process using the same lib and cache
356356
/// directories; it does not depend on cwd.
357-
pub fn digest(p: Path) Cache.BinDigest {
358-
var h = Cache.hasher_init;
357+
pub fn addToHasher(p: Path, h: *Cache.Hasher) void {
359358
h.update(&.{@intFromEnum(p.root)});
360359
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);
361366
return h.finalResult();
362367
}
363368

src/Zcu.zig

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4239,13 +4239,6 @@ pub fn setFileRootType(zcu: *Zcu, file_index: File.Index, root_type: InternPool.
42394239
files.view().items(.root_type)[file_index_unwrapped.index] = root_type;
42404240
}
42414241

4242-
pub 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-
42494242
pub fn navSrcLoc(zcu: *const Zcu, nav_index: InternPool.Nav.Index) LazySrcLoc {
42504243
const ip = &zcu.intern_pool;
42514244
return .{

src/Zcu/PerThread.zig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,15 @@ pub fn updateFile(
101101
.global_cache, .zig_lib => false,
102102
};
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+
105113
const cache_directory = if (want_local_cache) zcu.local_zir_cache else zcu.global_zir_cache;
106114
const zir_dir = cache_directory.handle;
107115

0 commit comments

Comments
 (0)