authorgravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2021-04-05 20:53:46+02:00
committergravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2021-04-08 14:23:18+02:00
loga97efbd1850cbf12dbf9332f7da2652385a38cd6
treed8aeed5eaa1f8bc13c7f047bb51497ae855c5eb4
parentfb16cb9183bfdf5db9448666803943127802317a

stage2: add support for root pkg

Fix some infinite recursions, because the code assumed that packages cannot point to each other. But this assumption does not hold anymore.

2 files changed, 10 insertions(+), 6 deletions(-)

src/Compilation.zig+7-5
......@@ -510,11 +510,11 @@ pub const InitOptions = struct {
510510fn addPackageTableToCacheHash(
511511 hash: *Cache.HashHelper,
512512 arena: *std.heap.ArenaAllocator,
513 pkg_table: Package.Table,
513 package: *Package,
514514 hash_type: union(enum) { path_bytes, files: *Cache.Manifest },
515515) (error{OutOfMemory} || std.os.GetCwdError)!void {
516516 const allocator = &arena.allocator;
517
517 const pkg_table = package.table;
518518 const packages = try allocator.alloc(Package.Table.Entry, pkg_table.count());
519519 {
520520 // Copy over the hashmap entries to our slice
......@@ -547,7 +547,8 @@ fn addPackageTableToCacheHash(
547547 },
548548 }
549549 // Recurse to handle the package's dependencies
550 try addPackageTableToCacheHash(hash, arena, pkg.value.table, hash_type);
550 if (package != pkg.value)
551 try addPackageTableToCacheHash(hash, arena, pkg.value, hash_type);
551552 }
552553}
553554
......@@ -885,7 +886,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
885886 {
886887 var local_arena = std.heap.ArenaAllocator.init(gpa);
887888 defer local_arena.deinit();
888 try addPackageTableToCacheHash(&hash, &local_arena, root_pkg.table, .path_bytes);
889 try addPackageTableToCacheHash(&hash, &local_arena, root_pkg, .path_bytes);
889890 }
890891 hash.add(valgrind);
891892 hash.add(single_threaded);
......@@ -908,6 +909,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
908909
909910 const builtin_pkg = try Package.create(gpa, zig_cache_artifact_directory.path.?, "builtin2.zig");
910911 try root_pkg.add(gpa, "builtin", builtin_pkg);
912 try root_pkg.add(gpa, "root", root_pkg);
911913
912914 // TODO when we implement serialization and deserialization of incremental compilation metadata,
913915 // this is where we would load it. We have open a handle to the directory where
......@@ -3203,7 +3205,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
32033205 {
32043206 var local_arena = std.heap.ArenaAllocator.init(comp.gpa);
32053207 defer local_arena.deinit();
3206 try addPackageTableToCacheHash(&man.hash, &local_arena, mod.root_pkg.table, .{ .files = &man });
3208 try addPackageTableToCacheHash(&man.hash, &local_arena, mod.root_pkg, .{ .files = &man });
32073209 }
32083210 man.hash.add(comp.bin_file.options.valgrind);
32093211 man.hash.add(comp.bin_file.options.single_threaded);
src/Package.zig+3-1
......@@ -58,7 +58,9 @@ pub fn destroy(pkg: *Package, gpa: *Allocator) void {
5858 {
5959 var it = pkg.table.iterator();
6060 while (it.next()) |kv| {
61 kv.value.destroy(gpa);
61 if (pkg != kv.value) {
62 kv.value.destroy(gpa);
63 }
6264 gpa.free(kv.key);
6365 }
6466 }