authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-03-07 06:26:25+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-03-07 06:26:25+00:00
log38331b1cabf86586bdf70c80ed98f74c60305160
tree875824cf56e06fd8b4b38eb6d203ba829a35da6d
parentb41a0b4768d368d81d0d33c779f919d8f315e622
signaturelock-open Commit is signed but in an unrecognized format.

Package.Module: actually set File.path_digest for builtin modules


2 files changed, 24 insertions(+), 2 deletions(-)

src/Builtin.zig+2
......@@ -264,6 +264,8 @@ pub fn populateFile(comp: *Compilation, mod: *Module, file: *File) !void {
264264 assert(!file.zir.hasCompileErrors()); // builtin.zig must not have astgen errors
265265 file.zir_loaded = true;
266266 file.status = .success_zir;
267 // Note that whilst we set `zir_loaded` here, we populated `path_digest`
268 // all the way back in `Package.Module.create`.
267269}
268270
269271fn writeFile(file: *File, mod: *Module) !void {
src/Package/Module.zig+22-2
......@@ -381,8 +381,25 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
381381
382382 const new_file = try arena.create(File);
383383
384 const digest = Cache.HashHelper.oneShot(generated_builtin_source);
385 const builtin_sub_path = try arena.dupe(u8, "b" ++ std.fs.path.sep_str ++ digest);
384 const bin_digest, const hex_digest = digest: {
385 var hasher: Cache.Hasher = Cache.hasher_init;
386 hasher.update(generated_builtin_source);
387
388 var bin_digest: Cache.BinDigest = undefined;
389 hasher.final(&bin_digest);
390
391 var hex_digest: Cache.HexDigest = undefined;
392 _ = std.fmt.bufPrint(
393 &hex_digest,
394 "{s}",
395 .{std.fmt.fmtSliceHexLower(&bin_digest)},
396 ) catch unreachable;
397
398 break :digest .{ bin_digest, hex_digest };
399 };
400
401 const builtin_sub_path = try arena.dupe(u8, "b" ++ std.fs.path.sep_str ++ hex_digest);
402
386403 new.* = .{
387404 .root = .{
388405 .root_dir = options.global_cache_directory,
......@@ -429,6 +446,9 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
429446 .status = .never_loaded,
430447 .mod = new,
431448 .root_decl = .none,
449 // We might as well use this digest for the File `path digest`, since there's a
450 // one-to-one correspondence here between distinct paths and distinct contents.
451 .path_digest = bin_digest,
432452 };
433453 break :b new;
434454 };