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 {...@@ -264,6 +264,8 @@ pub fn populateFile(comp: *Compilation, mod: *Module, file: *File) !void {
264 assert(!file.zir.hasCompileErrors()); // builtin.zig must not have astgen errors264 assert(!file.zir.hasCompileErrors()); // builtin.zig must not have astgen errors
265 file.zir_loaded = true;265 file.zir_loaded = true;
266 file.status = .success_zir;266 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`.
267}269}
268270
269fn writeFile(file: *File, mod: *Module) !void {271fn 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 {...@@ -381,8 +381,25 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
381381
382 const new_file = try arena.create(File);382 const new_file = try arena.create(File);
383383
384 const digest = Cache.HashHelper.oneShot(generated_builtin_source);384 const bin_digest, const hex_digest = digest: {
385 const builtin_sub_path = try arena.dupe(u8, "b" ++ std.fs.path.sep_str ++ 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
386 new.* = .{403 new.* = .{
387 .root = .{404 .root = .{
388 .root_dir = options.global_cache_directory,405 .root_dir = options.global_cache_directory,
...@@ -429,6 +446,9 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {...@@ -429,6 +446,9 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
429 .status = .never_loaded,446 .status = .never_loaded,
430 .mod = new,447 .mod = new,
431 .root_decl = .none,448 .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,
432 };452 };
433 break :b new;453 break :b new;
434 };454 };