authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-11-16 11:21:28+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-01 14:57:27-07:00
log7099dff7ea6ec4467d426e0955020b20f964e6e5
tree07c4fccc83378a49c0fee03d3626c288fb1d8343
parent6bf19e32e7c51d3c3274151327af7ca3dc231510

Add package names and paths to the zig root module cache hash.

Add package names to the stage1 cache hash and package files to the stage1 manifest file.

1 files changed, 54 insertions(+), 0 deletions(-)

src/Compilation.zig+54
...@@ -399,6 +399,50 @@ pub const InitOptions = struct {...@@ -399,6 +399,50 @@ pub const InitOptions = struct {
399 subsystem: ?std.Target.SubSystem = null,399 subsystem: ?std.Target.SubSystem = null,
400};400};
401401
402fn addPackageTableToCacheHash(
403 hash: *Cache.HashHelper,
404 arena: *std.heap.ArenaAllocator,
405 pkg_table: Package.Table,
406 hash_type: union(enum) { path_bytes, files: *Cache.Manifest },
407) (error{OutOfMemory} || std.os.GetCwdError)!void {
408 const allocator = &arena.allocator;
409
410 const packages = try allocator.alloc(Package.Table.Entry, pkg_table.count());
411 {
412 // Copy over the hashmap entries to our slice
413 var table_it = pkg_table.iterator();
414 var idx: usize = 0;
415 while (table_it.next()) |entry| : (idx += 1) {
416 packages[idx] = entry.*;
417 }
418 }
419 // Sort the slice by package name
420 std.sort.sort(Package.Table.Entry, packages, {}, struct {
421 fn lessThan(_: void, lhs: Package.Table.Entry, rhs: Package.Table.Entry) bool {
422 return std.mem.lessThan(u8, lhs.key, rhs.key);
423 }
424 }.lessThan);
425
426 for (packages) |pkg| {
427 // Finally insert the package name and path to the cache hash.
428 hash.addBytes(pkg.key);
429 switch (hash_type) {
430 .path_bytes => {
431 hash.addBytes(pkg.value.root_src_path);
432 hash.addOptionalBytes(pkg.value.root_src_directory.path);
433 },
434 .files => |man| {
435 const pkg_zig_file = try pkg.value.root_src_directory.join(allocator, &[_][]const u8{
436 pkg.value.root_src_path,
437 });
438 _ = try man.addFile(pkg_zig_file, null);
439 },
440 }
441 // Recurse to handle the package's dependencies
442 try addPackageTableToCacheHash(hash, arena, pkg.value.table, hash_type);
443 }
444}
445
402pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {446pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
403 const is_dyn_lib = switch (options.output_mode) {447 const is_dyn_lib = switch (options.output_mode) {
404 .Obj, .Exe => false,448 .Obj, .Exe => false,
...@@ -662,6 +706,11 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -662,6 +706,11 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
662 // would be likely to cause cache hits.706 // would be likely to cause cache hits.
663 hash.addBytes(root_pkg.root_src_path);707 hash.addBytes(root_pkg.root_src_path);
664 hash.addOptionalBytes(root_pkg.root_src_directory.path);708 hash.addOptionalBytes(root_pkg.root_src_directory.path);
709 {
710 var local_arena = std.heap.ArenaAllocator.init(gpa);
711 defer local_arena.deinit();
712 try addPackageTableToCacheHash(&hash, &local_arena, root_pkg.table, .path_bytes);
713 }
665 hash.add(valgrind);714 hash.add(valgrind);
666 hash.add(single_threaded);715 hash.add(single_threaded);
667 hash.add(dll_export_fns);716 hash.add(dll_export_fns);
...@@ -2704,6 +2753,11 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node...@@ -2704,6 +2753,11 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
2704 defer man.deinit();2753 defer man.deinit();
27052754
2706 _ = try man.addFile(main_zig_file, null);2755 _ = try man.addFile(main_zig_file, null);
2756 {
2757 var local_arena = std.heap.ArenaAllocator.init(comp.gpa);
2758 defer local_arena.deinit();
2759 try addPackageTableToCacheHash(&man.hash, &local_arena, mod.root_pkg.table, .{ .files = &man });
2760 }
2707 man.hash.add(comp.bin_file.options.valgrind);2761 man.hash.add(comp.bin_file.options.valgrind);
2708 man.hash.add(comp.bin_file.options.single_threaded);2762 man.hash.add(comp.bin_file.options.single_threaded);
2709 man.hash.add(target.os.getVersionRange());2763 man.hash.add(target.os.getVersionRange());