| ... | @@ -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 | }; |
| 401 | | 401 | |
| | 402 | fn 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 | |
| 402 | pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | 446 | pub 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(); |
| 2705 | | 2754 | |
| 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()); |