aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorTimon Kruiper <timonkruiper@gmail.com>2021-04-05 20:53:46 +0200
committerTimon Kruiper <timonkruiper@gmail.com>2021-04-08 14:23:18 +0200
commita97efbd1850cbf12dbf9332f7da2652385a38cd6 (patch)
treed8aeed5eaa1f8bc13c7f047bb51497ae855c5eb4 /src/Compilation.zig
parentfb16cb9183bfdf5db9448666803943127802317a (diff)
downloadzig-a97efbd1850cbf12dbf9332f7da2652385a38cd6.tar.gz
zig-a97efbd1850cbf12dbf9332f7da2652385a38cd6.zip
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.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 95db5e78c6..c0409fcb3b 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -510,11 +510,11 @@ pub const InitOptions = struct {
fn addPackageTableToCacheHash(
hash: *Cache.HashHelper,
arena: *std.heap.ArenaAllocator,
- pkg_table: Package.Table,
+ package: *Package,
hash_type: union(enum) { path_bytes, files: *Cache.Manifest },
) (error{OutOfMemory} || std.os.GetCwdError)!void {
const allocator = &arena.allocator;
-
+ const pkg_table = package.table;
const packages = try allocator.alloc(Package.Table.Entry, pkg_table.count());
{
// Copy over the hashmap entries to our slice
@@ -547,7 +547,8 @@ fn addPackageTableToCacheHash(
},
}
// Recurse to handle the package's dependencies
- try addPackageTableToCacheHash(hash, arena, pkg.value.table, hash_type);
+ if (package != pkg.value)
+ try addPackageTableToCacheHash(hash, arena, pkg.value, hash_type);
}
}
@@ -885,7 +886,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
{
var local_arena = std.heap.ArenaAllocator.init(gpa);
defer local_arena.deinit();
- try addPackageTableToCacheHash(&hash, &local_arena, root_pkg.table, .path_bytes);
+ try addPackageTableToCacheHash(&hash, &local_arena, root_pkg, .path_bytes);
}
hash.add(valgrind);
hash.add(single_threaded);
@@ -908,6 +909,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
const builtin_pkg = try Package.create(gpa, zig_cache_artifact_directory.path.?, "builtin2.zig");
try root_pkg.add(gpa, "builtin", builtin_pkg);
+ try root_pkg.add(gpa, "root", root_pkg);
// TODO when we implement serialization and deserialization of incremental compilation metadata,
// 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
{
var local_arena = std.heap.ArenaAllocator.init(comp.gpa);
defer local_arena.deinit();
- try addPackageTableToCacheHash(&man.hash, &local_arena, mod.root_pkg.table, .{ .files = &man });
+ try addPackageTableToCacheHash(&man.hash, &local_arena, mod.root_pkg, .{ .files = &man });
}
man.hash.add(comp.bin_file.options.valgrind);
man.hash.add(comp.bin_file.options.single_threaded);