authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-06 15:11:06-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-06 15:11:06-08:00
log6f18aca09e8ba3a3e4987cc17f6b92b6b433537d
treeafad06cce4380094b8b6c008211fd6136237fb54
parentb24b0479f6be4e29d9ac4b9c6d2886aa21c412ab

main: fix cleanup of forks


1 files changed, 51 insertions(+), 42 deletions(-)

src/main.zig+51-42
...@@ -5006,6 +5006,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,...@@ -5006,6 +5006,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
5006 .manifest_ast = undefined,5006 .manifest_ast = undefined,
5007 .manifest = undefined,5007 .manifest = undefined,
5008 .error_bundle = undefined,5008 .error_bundle = undefined,
5009 .arena_allocator = undefined,
5009 .path = .{5010 .path = .{
5010 .root_dir = .cwd(),5011 .root_dir = .cwd(),
5011 .sub_path = sub_arg,5012 .sub_path = sub_arg,
...@@ -5203,7 +5204,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,...@@ -5203,7 +5204,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
5203 defer group.cancel(io);5204 defer group.cancel(io);
52045205
5205 for (forks.items) |*fork|5206 for (forks.items) |*fork|
5206 group.async(io, loadFork, .{ io, gpa, fork, color });5207 group.async(io, Fork.load, .{ io, gpa, fork, color });
52075208
5208 try group.await(io);5209 try group.await(io);
52095210
...@@ -5217,6 +5218,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,...@@ -5217,6 +5218,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
5217 }, {});5218 }, {});
5218 }5219 }
5219 }5220 }
5221 defer Fork.deinitList(forks.items);
52205222
5221 // This loop is re-evaluated when the build script exits with an indication that it5223 // This loop is re-evaluated when the build script exits with an indication that it
5222 // could not continue due to missing lazy dependencies.5224 // could not continue due to missing lazy dependencies.
...@@ -5270,6 +5272,9 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,...@@ -5270,6 +5272,9 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
5270 const fetch_prog_node = root_prog_node.start("Fetch Packages", 0);5272 const fetch_prog_node = root_prog_node.start("Fetch Packages", 0);
5271 defer fetch_prog_node.end();5273 defer fetch_prog_node.end();
52725274
5275 // Reset fork match counts.
5276 for (fork_set.keys()) |*fork| fork.uses = 0;
5277
5273 var job_queue: Package.Fetch.JobQueue = .{5278 var job_queue: Package.Fetch.JobQueue = .{
5274 .io = io,5279 .io = io,
5275 .http_client = &http_client,5280 .http_client = &http_client,
...@@ -5582,52 +5587,56 @@ const Fork = struct {...@@ -5582,52 +5587,56 @@ const Fork = struct {
5582 manifest: Package.Manifest,5587 manifest: Package.Manifest,
5583 error_bundle: std.zig.ErrorBundle.Wip,5588 error_bundle: std.zig.ErrorBundle.Wip,
5584 failed: bool,5589 failed: bool,
5585};5590 arena_allocator: std.heap.ArenaAllocator,
55865591
5587fn loadFork(io: Io, gpa: Allocator, fork: *Fork, color: Color) Io.Cancelable!void {5592 fn load(io: Io, gpa: Allocator, fork: *Fork, color: Color) Io.Cancelable!void {
5588 loadForkFallible(io, gpa, fork, color) catch |err| switch (err) {5593 loadFallible(io, gpa, fork, color) catch |err| switch (err) {
5589 error.Canceled => |e| return e,5594 error.Canceled => |e| return e,
5590 error.AlreadyReported => fork.failed = true,5595 error.AlreadyReported => fork.failed = true,
5591 else => |e| {5596 else => |e| {
5592 std.log.err("failed to load fork at {f}: {t}", .{ fork.path, e });5597 std.log.err("failed to load fork at {f}: {t}", .{ fork.path, e });
5593 fork.failed = true;5598 fork.failed = true;
5594 },5599 },
5595 };5600 };
5596}5601 }
55975602
5598fn loadForkFallible(io: Io, gpa: Allocator, fork: *Fork, color: Color) !void {5603 fn loadFallible(io: Io, gpa: Allocator, fork: *Fork, color: Color) !void {
5599 var arena_instance = std.heap.ArenaAllocator.init(gpa);5604 fork.arena_allocator = .init(gpa);
5600 defer arena_instance.deinit();5605 const arena = fork.arena_allocator.allocator();
5601 const arena = arena_instance.allocator();
56025606
5603 var error_bundle: std.zig.ErrorBundle.Wip = undefined;5607 var error_bundle: std.zig.ErrorBundle.Wip = undefined;
5604 try error_bundle.init(gpa);5608 try error_bundle.init(gpa);
5605 defer error_bundle.deinit();5609 defer error_bundle.deinit();
56065610
5607 const manifest_path = try fork.path.join(arena, Package.Manifest.basename);5611 const manifest_path = try fork.path.join(arena, Package.Manifest.basename);
56085612
5609 Package.Manifest.load(5613 Package.Manifest.load(
5610 io,5614 io,
5611 arena,5615 arena,
5612 manifest_path,5616 manifest_path,
5613 &fork.manifest_ast,5617 &fork.manifest_ast,
5614 &error_bundle,5618 &error_bundle,
5615 &fork.manifest,5619 &fork.manifest,
5616 true,5620 true,
5617 ) catch |err| switch (err) {5621 ) catch |err| switch (err) {
5618 error.Canceled => |e| return e,5622 error.Canceled => |e| return e,
5619 error.ErrorsBundled => {5623 error.ErrorsBundled => {
5620 assert(error_bundle.root_list.items.len > 0);5624 assert(error_bundle.root_list.items.len > 0);
5621 var errors = try error_bundle.toOwnedBundle("");5625 var errors = try error_bundle.toOwnedBundle("");
5622 errors.renderToStderr(io, .{}, color) catch {};5626 errors.renderToStderr(io, .{}, color) catch {};
5623 return error.AlreadyReported;5627 return error.AlreadyReported;
5624 },5628 },
5625 else => |e| {5629 else => |e| {
5626 std.log.err("failed to load package manifest {f}: {t}", .{ manifest_path, e });5630 std.log.err("failed to load package manifest {f}: {t}", .{ manifest_path, e });
5627 return error.AlreadyReported;5631 return error.AlreadyReported;
5628 },5632 },
5629 };5633 };
5630}5634 }
5635
5636 fn deinitList(forks: []Fork) void {
5637 for (forks) |*fork| fork.arena_allocator.deinit();
5638 }
5639};
56315640
5632const JitCmdOptions = struct {5641const JitCmdOptions = struct {
5633 cmd_name: []const u8,5642 cmd_name: []const u8,