authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-17 19:18:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-19 12:39:37-07:00
log297774ed7c2f337e1528a99abf0e089718363768
treef24ce6d45b1e3ecfcb07494fb3d3cd76f933bd39
parent5b8bee462a63538083e7b2e16f1dae7b39c8529b

Compilation: still hash the module table names and relative paths

otherwise if you did nothing except swap the import names of two modules, you would get a false positive cache hit

1 files changed, 7 insertions(+), 22 deletions(-)

src/Compilation.zig+7-22
......@@ -1678,15 +1678,7 @@ pub const CreateOptions = struct {
16781678 };
16791679};
16801680
1681fn addModuleTableToCacheHash(
1682 zcu: *Zcu,
1683 arena: Allocator,
1684 hash: *Cache.HashHelper,
1685 hash_type: union(enum) { path_bytes, files: *Cache.Manifest },
1686) error{
1687 OutOfMemory,
1688 Unexpected,
1689}!void {
1681fn addModuleTableToCacheHash(zcu: *Zcu, hash: *Cache.HashHelper) error{ OutOfMemory, Unexpected }!void {
16901682 assert(zcu.module_roots.count() != 0); // module_roots is populated
16911683
16921684 for (zcu.module_roots.keys(), zcu.module_roots.values()) |mod, opt_mod_root_file| {
......@@ -1695,17 +1687,9 @@ fn addModuleTableToCacheHash(
16951687 if (zcu.fileByIndex(mod_root_file).is_builtin) continue; // redundant
16961688 }
16971689 cache_helpers.addModule(hash, mod);
1698 switch (hash_type) {
1699 .path_bytes => {
1700 hash.add(mod.root.root);
1701 hash.addBytes(mod.root.sub_path);
1702 hash.addBytes(mod.root_src_path);
1703 },
1704 .files => |man| if (mod.root_src_path.len != 0) {
1705 const root_src_path = try mod.root.toCachePath(zcu.comp.dirs).join(arena, mod.root_src_path);
1706 _ = try man.addFilePath(root_src_path, null);
1707 },
1708 }
1690 hash.add(mod.root.root);
1691 hash.addBytes(mod.root.sub_path);
1692 hash.addBytes(mod.root_src_path);
17091693 hash.addListOfBytes(mod.deps.keys());
17101694 }
17111695}
......@@ -2336,7 +2320,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
23362320 // likely different compilations and therefore this would be likely to
23372321 // cause cache hits.
23382322 if (comp.zcu) |zcu| {
2339 try addModuleTableToCacheHash(zcu, arena, &hash, .path_bytes);
2323 try addModuleTableToCacheHash(zcu, &hash);
23402324 } else {
23412325 cache_helpers.addModule(&hash, options.root_mod);
23422326 }
......@@ -3392,10 +3376,11 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
33923376 comptime assert(link_hash_implementation_version == 14);
33933377
33943378 if (comp.zcu) |zcu| {
3395 // No need to call `addModuleTableToCacheHash` here because it is
3379 // No need to hash the actual file contents here because it is
33963380 // redundant with the logic in `PerThread.update` which iterates over
33973381 // `zcu.alive_files` and adds those files discovered via `@import` to
33983382 // the whole cache manifest.
3383 try addModuleTableToCacheHash(zcu, &man.hash);
33993384
34003385 // Synchronize with other matching comments: ZigOnlyHashStuff
34013386 man.hash.addListOfBytes(comp.test_filters);