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,
50065006 .manifest_ast = undefined,
50075007 .manifest = undefined,
50085008 .error_bundle = undefined,
5009 .arena_allocator = undefined,
50095010 .path = .{
50105011 .root_dir = .cwd(),
50115012 .sub_path = sub_arg,
......@@ -5203,7 +5204,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
52035204 defer group.cancel(io);
52045205
52055206 for (forks.items) |*fork|
5206 group.async(io, loadFork, .{ io, gpa, fork, color });
5207 group.async(io, Fork.load, .{ io, gpa, fork, color });
52075208
52085209 try group.await(io);
52095210
......@@ -5217,6 +5218,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
52175218 }, {});
52185219 }
52195220 }
5221 defer Fork.deinitList(forks.items);
52205222
52215223 // This loop is re-evaluated when the build script exits with an indication that it
52225224 // could not continue due to missing lazy dependencies.
......@@ -5270,6 +5272,9 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
52705272 const fetch_prog_node = root_prog_node.start("Fetch Packages", 0);
52715273 defer fetch_prog_node.end();
52725274
5275 // Reset fork match counts.
5276 for (fork_set.keys()) |*fork| fork.uses = 0;
5277
52735278 var job_queue: Package.Fetch.JobQueue = .{
52745279 .io = io,
52755280 .http_client = &http_client,
......@@ -5582,52 +5587,56 @@ const Fork = struct {
55825587 manifest: Package.Manifest,
55835588 error_bundle: std.zig.ErrorBundle.Wip,
55845589 failed: bool,
5585};
5590 arena_allocator: std.heap.ArenaAllocator,
55865591
5587fn loadFork(io: Io, gpa: Allocator, fork: *Fork, color: Color) Io.Cancelable!void {
5588 loadForkFallible(io, gpa, fork, color) catch |err| switch (err) {
5589 error.Canceled => |e| return e,
5590 error.AlreadyReported => fork.failed = true,
5591 else => |e| {
5592 std.log.err("failed to load fork at {f}: {t}", .{ fork.path, e });
5593 fork.failed = true;
5594 },
5595 };
5596}
5592 fn load(io: Io, gpa: Allocator, fork: *Fork, color: Color) Io.Cancelable!void {
5593 loadFallible(io, gpa, fork, color) catch |err| switch (err) {
5594 error.Canceled => |e| return e,
5595 error.AlreadyReported => fork.failed = true,
5596 else => |e| {
5597 std.log.err("failed to load fork at {f}: {t}", .{ fork.path, e });
5598 fork.failed = true;
5599 },
5600 };
5601 }
55975602
5598fn loadForkFallible(io: Io, gpa: Allocator, fork: *Fork, color: Color) !void {
5599 var arena_instance = std.heap.ArenaAllocator.init(gpa);
5600 defer arena_instance.deinit();
5601 const arena = arena_instance.allocator();
5603 fn loadFallible(io: Io, gpa: Allocator, fork: *Fork, color: Color) !void {
5604 fork.arena_allocator = .init(gpa);
5605 const arena = fork.arena_allocator.allocator();
56025606
5603 var error_bundle: std.zig.ErrorBundle.Wip = undefined;
5604 try error_bundle.init(gpa);
5605 defer error_bundle.deinit();
5607 var error_bundle: std.zig.ErrorBundle.Wip = undefined;
5608 try error_bundle.init(gpa);
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(
5610 io,
5611 arena,
5612 manifest_path,
5613 &fork.manifest_ast,
5614 &error_bundle,
5615 &fork.manifest,
5616 true,
5617 ) catch |err| switch (err) {
5618 error.Canceled => |e| return e,
5619 error.ErrorsBundled => {
5620 assert(error_bundle.root_list.items.len > 0);
5621 var errors = try error_bundle.toOwnedBundle("");
5622 errors.renderToStderr(io, .{}, color) catch {};
5623 return error.AlreadyReported;
5624 },
5625 else => |e| {
5626 std.log.err("failed to load package manifest {f}: {t}", .{ manifest_path, e });
5627 return error.AlreadyReported;
5628 },
5629 };
5630}
5613 Package.Manifest.load(
5614 io,
5615 arena,
5616 manifest_path,
5617 &fork.manifest_ast,
5618 &error_bundle,
5619 &fork.manifest,
5620 true,
5621 ) catch |err| switch (err) {
5622 error.Canceled => |e| return e,
5623 error.ErrorsBundled => {
5624 assert(error_bundle.root_list.items.len > 0);
5625 var errors = try error_bundle.toOwnedBundle("");
5626 errors.renderToStderr(io, .{}, color) catch {};
5627 return error.AlreadyReported;
5628 },
5629 else => |e| {
5630 std.log.err("failed to load package manifest {f}: {t}", .{ manifest_path, e });
5631 return error.AlreadyReported;
5632 },
5633 };
5634 }
5635
5636 fn deinitList(forks: []Fork) void {
5637 for (forks) |*fork| fork.arena_allocator.deinit();
5638 }
5639};
56315640
56325641const JitCmdOptions = struct {
56335642 cmd_name: []const u8,