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 {...@@ -510,11 +510,11 @@ pub const InitOptions = struct {
510fn addPackageTableToCacheHash(510fn addPackageTableToCacheHash(
511 hash: *Cache.HashHelper,511 hash: *Cache.HashHelper,
512 arena: *std.heap.ArenaAllocator,512 arena: *std.heap.ArenaAllocator,
513 pkg_table: Package.Table,513 package: *Package,
514 hash_type: union(enum) { path_bytes, files: *Cache.Manifest },514 hash_type: union(enum) { path_bytes, files: *Cache.Manifest },
515) (error{OutOfMemory} || std.os.GetCwdError)!void {515) (error{OutOfMemory} || std.os.GetCwdError)!void {
516 const allocator = &arena.allocator;516 const allocator = &arena.allocator;
517517 const pkg_table = package.table;
518 const packages = try allocator.alloc(Package.Table.Entry, pkg_table.count());518 const packages = try allocator.alloc(Package.Table.Entry, pkg_table.count());
519 {519 {
520 // Copy over the hashmap entries to our slice520 // Copy over the hashmap entries to our slice
...@@ -547,7 +547,8 @@ fn addPackageTableToCacheHash(...@@ -547,7 +547,8 @@ fn addPackageTableToCacheHash(
547 },547 },
548 }548 }
549 // Recurse to handle the package's dependencies549 // 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);
551 }552 }
552}553}
553554
...@@ -885,7 +886,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -885,7 +886,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
885 {886 {
886 var local_arena = std.heap.ArenaAllocator.init(gpa);887 var local_arena = std.heap.ArenaAllocator.init(gpa);
887 defer local_arena.deinit();888 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);
889 }890 }
890 hash.add(valgrind);891 hash.add(valgrind);
891 hash.add(single_threaded);892 hash.add(single_threaded);
...@@ -908,6 +909,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -908,6 +909,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
908909
909 const builtin_pkg = try Package.create(gpa, zig_cache_artifact_directory.path.?, "builtin2.zig");910 const builtin_pkg = try Package.create(gpa, zig_cache_artifact_directory.path.?, "builtin2.zig");
910 try root_pkg.add(gpa, "builtin", builtin_pkg);911 try root_pkg.add(gpa, "builtin", builtin_pkg);
912 try root_pkg.add(gpa, "root", root_pkg);
911913
912 // TODO when we implement serialization and deserialization of incremental compilation metadata,914 // TODO when we implement serialization and deserialization of incremental compilation metadata,
913 // this is where we would load it. We have open a handle to the directory where915 // 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...@@ -3203,7 +3205,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
3203 {3205 {
3204 var local_arena = std.heap.ArenaAllocator.init(comp.gpa);3206 var local_arena = std.heap.ArenaAllocator.init(comp.gpa);
3205 defer local_arena.deinit();3207 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 });
3207 }3209 }
3208 man.hash.add(comp.bin_file.options.valgrind);3210 man.hash.add(comp.bin_file.options.valgrind);
3209 man.hash.add(comp.bin_file.options.single_threaded);3211 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 {...@@ -58,7 +58,9 @@ pub fn destroy(pkg: *Package, gpa: *Allocator) void {
58 {58 {
59 var it = pkg.table.iterator();59 var it = pkg.table.iterator();
60 while (it.next()) |kv| {60 while (it.next()) |kv| {
61 kv.value.destroy(gpa);61 if (pkg != kv.value) {
62 kv.value.destroy(gpa);
63 }
62 gpa.free(kv.key);64 gpa.free(kv.key);
63 }65 }
64 }66 }