authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-24 08:22:47-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-27 20:56:48-07:00
logf97c2f28fdc3061bc7e30ccfcafaccbee77993b6
treea2c4165829d84b35df23346b1808a43e0cccec41
parentf6873c6b00544923d5699737651f2bc4fe29fd06

update the codebase for the new std.Progress API


49 files changed, 226 insertions(+), 355 deletions(-)

lib/compiler/aro/aro/Diagnostics.zig+2-2
......@@ -528,7 +528,7 @@ const MsgWriter = struct {
528528 config: std.io.tty.Config,
529529
530530 fn init(config: std.io.tty.Config) MsgWriter {
531 std.debug.getStderrMutex().lock();
531 std.debug.lockStdErr();
532532 return .{
533533 .w = std.io.bufferedWriter(std.io.getStdErr().writer()),
534534 .config = config,
......@@ -537,7 +537,7 @@ const MsgWriter = struct {
537537
538538 pub fn deinit(m: *MsgWriter) void {
539539 m.w.flush() catch {};
540 std.debug.getStderrMutex().unlock();
540 std.debug.unlockStdErr();
541541 }
542542
543543 pub fn print(m: *MsgWriter, comptime fmt: []const u8, args: anytype) void {
lib/compiler/build_runner.zig+9-11
......@@ -289,8 +289,7 @@ pub fn main() !void {
289289 .windows_api => {},
290290 }
291291
292 var progress: std.Progress = .{ .dont_print_on_dumb = true };
293 const main_progress_node = progress.start("", 0);
292 const main_progress_node = std.Progress.start(.{});
294293
295294 builder.debug_log_scopes = debug_log_scopes.items;
296295 builder.resolveInstallPrefix(install_prefix, dir_list);
......@@ -385,7 +384,7 @@ fn runStepNames(
385384 arena: std.mem.Allocator,
386385 b: *std.Build,
387386 step_names: []const []const u8,
388 parent_prog_node: *std.Progress.Node,
387 parent_prog_node: std.Progress.Node,
389388 thread_pool_options: std.Thread.Pool.Options,
390389 run: *Run,
391390 seed: u32,
......@@ -452,7 +451,7 @@ fn runStepNames(
452451 {
453452 defer parent_prog_node.end();
454453
455 var step_prog = parent_prog_node.start("steps", step_stack.count());
454 const step_prog = parent_prog_node.start("steps", step_stack.count());
456455 defer step_prog.end();
457456
458457 var wait_group: std.Thread.WaitGroup = .{};
......@@ -467,7 +466,7 @@ fn runStepNames(
467466 if (step.state == .skipped_oom) continue;
468467
469468 thread_pool.spawnWg(&wait_group, workerMakeOneStep, .{
470 &wait_group, &thread_pool, b, step, &step_prog, run,
469 &wait_group, &thread_pool, b, step, step_prog, run,
471470 });
472471 }
473472 }
......@@ -891,7 +890,7 @@ fn workerMakeOneStep(
891890 thread_pool: *std.Thread.Pool,
892891 b: *std.Build,
893892 s: *Step,
894 prog_node: *std.Progress.Node,
893 prog_node: std.Progress.Node,
895894 run: *Run,
896895) void {
897896 // First, check the conditions for running this step. If they are not met,
......@@ -941,11 +940,10 @@ fn workerMakeOneStep(
941940 }
942941 }
943942
944 var sub_prog_node = prog_node.start(s.name, 0);
945 sub_prog_node.activate();
943 const sub_prog_node = prog_node.start(s.name, 0);
946944 defer sub_prog_node.end();
947945
948 const make_result = s.make(&sub_prog_node);
946 const make_result = s.make(sub_prog_node);
949947
950948 // No matter the result, we want to display error/warning messages.
951949 const show_compile_errors = !run.prominent_compile_errors and
......@@ -954,8 +952,8 @@ fn workerMakeOneStep(
954952 const show_stderr = s.result_stderr.len > 0;
955953
956954 if (show_error_msgs or show_compile_errors or show_stderr) {
957 sub_prog_node.context.lock_stderr();
958 defer sub_prog_node.context.unlock_stderr();
955 std.debug.lockStdErr();
956 defer std.debug.unlockStdErr();
959957
960958 printErrorMessages(b, s, run) catch {};
961959 }
lib/std/Build.zig+5-5
......@@ -1059,7 +1059,7 @@ pub fn getUninstallStep(b: *Build) *Step {
10591059 return &b.uninstall_tls.step;
10601060}
10611061
1062fn makeUninstall(uninstall_step: *Step, prog_node: *std.Progress.Node) anyerror!void {
1062fn makeUninstall(uninstall_step: *Step, prog_node: std.Progress.Node) anyerror!void {
10631063 _ = prog_node;
10641064 const uninstall_tls: *TopLevelStep = @fieldParentPtr("step", uninstall_step);
10651065 const b: *Build = @fieldParentPtr("uninstall_tls", uninstall_tls);
......@@ -2281,10 +2281,10 @@ pub const LazyPath = union(enum) {
22812281 .cwd_relative => |p| return src_builder.pathFromCwd(p),
22822282 .generated => |gen| {
22832283 var file_path: []const u8 = gen.file.step.owner.pathFromRoot(gen.file.path orelse {
2284 std.debug.getStderrMutex().lock();
2284 std.debug.lockStdErr();
22852285 const stderr = std.io.getStdErr();
22862286 dumpBadGetPathHelp(gen.file.step, stderr, src_builder, asking_step) catch {};
2287 std.debug.getStderrMutex().unlock();
2287 std.debug.unlockStdErr();
22882288 @panic("misconfigured build script");
22892289 });
22902290
......@@ -2351,8 +2351,8 @@ fn dumpBadDirnameHelp(
23512351 comptime msg: []const u8,
23522352 args: anytype,
23532353) anyerror!void {
2354 debug.getStderrMutex().lock();
2355 defer debug.getStderrMutex().unlock();
2354 debug.lockStdErr();
2355 defer debug.unlockStdErr();
23562356
23572357 const stderr = io.getStdErr();
23582358 const w = stderr.writer();
lib/std/Build/Step.zig+8-14
......@@ -58,7 +58,7 @@ pub const TestResults = struct {
5858 }
5959};
6060
61pub const MakeFn = *const fn (step: *Step, prog_node: *std.Progress.Node) anyerror!void;
61pub const MakeFn = *const fn (step: *Step, prog_node: std.Progress.Node) anyerror!void;
6262
6363pub const State = enum {
6464 precheck_unstarted,
......@@ -176,7 +176,7 @@ pub fn init(options: StepOptions) Step {
176176/// If the Step's `make` function reports `error.MakeFailed`, it indicates they
177177/// have already reported the error. Otherwise, we add a simple error report
178178/// here.
179pub fn make(s: *Step, prog_node: *std.Progress.Node) error{ MakeFailed, MakeSkipped }!void {
179pub fn make(s: *Step, prog_node: std.Progress.Node) error{ MakeFailed, MakeSkipped }!void {
180180 const arena = s.owner.allocator;
181181
182182 s.makeFn(s, prog_node) catch |err| switch (err) {
......@@ -217,7 +217,7 @@ pub fn getStackTrace(s: *Step) ?std.builtin.StackTrace {
217217 };
218218}
219219
220fn makeNoOp(step: *Step, prog_node: *std.Progress.Node) anyerror!void {
220fn makeNoOp(step: *Step, prog_node: std.Progress.Node) anyerror!void {
221221 _ = prog_node;
222222
223223 var all_cached = true;
......@@ -303,7 +303,7 @@ pub fn addError(step: *Step, comptime fmt: []const u8, args: anytype) error{OutO
303303pub fn evalZigProcess(
304304 s: *Step,
305305 argv: []const []const u8,
306 prog_node: *std.Progress.Node,
306 prog_node: std.Progress.Node,
307307) !?[]const u8 {
308308 assert(argv.len != 0);
309309 const b = s.owner;
......@@ -313,12 +313,16 @@ pub fn evalZigProcess(
313313 try handleChildProcUnsupported(s, null, argv);
314314 try handleVerbose(s.owner, null, argv);
315315
316 const sub_prog_node = prog_node.start("", 0);
317 defer sub_prog_node.end();
318
316319 var child = std.process.Child.init(argv, arena);
317320 child.env_map = &b.graph.env_map;
318321 child.stdin_behavior = .Pipe;
319322 child.stdout_behavior = .Pipe;
320323 child.stderr_behavior = .Pipe;
321324 child.request_resource_usage_statistics = true;
325 child.progress_node = sub_prog_node;
322326
323327 child.spawn() catch |err| return s.fail("unable to spawn {s}: {s}", .{
324328 argv[0], @errorName(err),
......@@ -337,11 +341,6 @@ pub fn evalZigProcess(
337341 const Header = std.zig.Server.Message.Header;
338342 var result: ?[]const u8 = null;
339343
340 var node_name: std.ArrayListUnmanaged(u8) = .{};
341 defer node_name.deinit(gpa);
342 var sub_prog_node = prog_node.start("", 0);
343 defer sub_prog_node.end();
344
345344 const stdout = poller.fifo(.stdout);
346345
347346 poll: while (true) {
......@@ -379,11 +378,6 @@ pub fn evalZigProcess(
379378 .extra = extra_array,
380379 };
381380 },
382 .progress => {
383 node_name.clearRetainingCapacity();
384 try node_name.appendSlice(gpa, body);
385 sub_prog_node.setName(node_name.items);
386 },
387381 .emit_bin_path => {
388382 const EbpHdr = std.zig.Server.Message.EmitBinPath;
389383 const ebp_hdr = @as(*align(1) const EbpHdr, @ptrCast(body));
lib/std/Build/Step/CheckFile.zig+1-1
......@@ -46,7 +46,7 @@ pub fn setName(check_file: *CheckFile, name: []const u8) void {
4646 check_file.step.name = name;
4747}
4848
49fn make(step: *Step, prog_node: *std.Progress.Node) !void {
49fn make(step: *Step, prog_node: std.Progress.Node) !void {
5050 _ = prog_node;
5151 const b = step.owner;
5252 const check_file: *CheckFile = @fieldParentPtr("step", step);
lib/std/Build/Step/CheckObject.zig+1-1
......@@ -550,7 +550,7 @@ pub fn checkComputeCompare(
550550 check_object.checks.append(check) catch @panic("OOM");
551551}
552552
553fn make(step: *Step, prog_node: *std.Progress.Node) !void {
553fn make(step: *Step, prog_node: std.Progress.Node) !void {
554554 _ = prog_node;
555555 const b = step.owner;
556556 const gpa = b.allocator;
lib/std/Build/Step/Compile.zig+3-3
......@@ -967,7 +967,7 @@ fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking
967967 const maybe_path: ?*GeneratedFile = @field(compile, tag_name);
968968
969969 const generated_file = maybe_path orelse {
970 std.debug.getStderrMutex().lock();
970 std.debug.lockStdErr();
971971 const stderr = std.io.getStdErr();
972972
973973 std.Build.dumpBadGetPathHelp(&compile.step, stderr, compile.step.owner, asking_step) catch {};
......@@ -976,7 +976,7 @@ fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking
976976 };
977977
978978 const path = generated_file.path orelse {
979 std.debug.getStderrMutex().lock();
979 std.debug.lockStdErr();
980980 const stderr = std.io.getStdErr();
981981
982982 std.Build.dumpBadGetPathHelp(&compile.step, stderr, compile.step.owner, asking_step) catch {};
......@@ -987,7 +987,7 @@ fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking
987987 return path;
988988}
989989
990fn make(step: *Step, prog_node: *std.Progress.Node) !void {
990fn make(step: *Step, prog_node: std.Progress.Node) !void {
991991 const b = step.owner;
992992 const arena = b.allocator;
993993 const compile: *Compile = @fieldParentPtr("step", step);
lib/std/Build/Step/ConfigHeader.zig+1-1
......@@ -164,7 +164,7 @@ fn putValue(config_header: *ConfigHeader, field_name: []const u8, comptime T: ty
164164 }
165165}
166166
167fn make(step: *Step, prog_node: *std.Progress.Node) !void {
167fn make(step: *Step, prog_node: std.Progress.Node) !void {
168168 _ = prog_node;
169169 const b = step.owner;
170170 const config_header: *ConfigHeader = @fieldParentPtr("step", step);
lib/std/Build/Step/Fmt.zig+1-1
......@@ -36,7 +36,7 @@ pub fn create(owner: *std.Build, options: Options) *Fmt {
3636 return fmt;
3737}
3838
39fn make(step: *Step, prog_node: *std.Progress.Node) !void {
39fn make(step: *Step, prog_node: std.Progress.Node) !void {
4040 // zig fmt is fast enough that no progress is needed.
4141 _ = prog_node;
4242
lib/std/Build/Step/InstallArtifact.zig+1-1
......@@ -115,7 +115,7 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins
115115 return install_artifact;
116116}
117117
118fn make(step: *Step, prog_node: *std.Progress.Node) !void {
118fn make(step: *Step, prog_node: std.Progress.Node) !void {
119119 _ = prog_node;
120120 const install_artifact: *InstallArtifact = @fieldParentPtr("step", step);
121121 const b = step.owner;
lib/std/Build/Step/InstallDir.zig+1-1
......@@ -56,7 +56,7 @@ pub fn create(owner: *std.Build, options: Options) *InstallDir {
5656 return install_dir;
5757}
5858
59fn make(step: *Step, prog_node: *std.Progress.Node) !void {
59fn make(step: *Step, prog_node: std.Progress.Node) !void {
6060 _ = prog_node;
6161 const b = step.owner;
6262 const install_dir: *InstallDir = @fieldParentPtr("step", step);
lib/std/Build/Step/InstallFile.zig+1-1
......@@ -36,7 +36,7 @@ pub fn create(
3636 return install_file;
3737}
3838
39fn make(step: *Step, prog_node: *std.Progress.Node) !void {
39fn make(step: *Step, prog_node: std.Progress.Node) !void {
4040 _ = prog_node;
4141 const b = step.owner;
4242 const install_file: *InstallFile = @fieldParentPtr("step", step);
lib/std/Build/Step/ObjCopy.zig+1-1
......@@ -90,7 +90,7 @@ pub fn getOutputSeparatedDebug(objcopy: *const ObjCopy) ?std.Build.LazyPath {
9090 return if (objcopy.output_file_debug) |*file| .{ .generated = .{ .file = file } } else null;
9191}
9292
93fn make(step: *Step, prog_node: *std.Progress.Node) !void {
93fn make(step: *Step, prog_node: std.Progress.Node) !void {
9494 const b = step.owner;
9595 const objcopy: *ObjCopy = @fieldParentPtr("step", step);
9696
lib/std/Build/Step/Options.zig+1-1
......@@ -410,7 +410,7 @@ pub fn getOutput(options: *Options) LazyPath {
410410 return .{ .generated = .{ .file = &options.generated_file } };
411411}
412412
413fn make(step: *Step, prog_node: *std.Progress.Node) !void {
413fn make(step: *Step, prog_node: std.Progress.Node) !void {
414414 // This step completes so quickly that no progress is necessary.
415415 _ = prog_node;
416416
lib/std/Build/Step/RemoveDir.zig+1-1
......@@ -22,7 +22,7 @@ pub fn create(owner: *std.Build, dir_path: []const u8) *RemoveDir {
2222 return remove_dir;
2323}
2424
25fn make(step: *Step, prog_node: *std.Progress.Node) !void {
25fn make(step: *Step, prog_node: std.Progress.Node) !void {
2626 // TODO update progress node while walking file system.
2727 // Should the standard library support this use case??
2828 _ = prog_node;
lib/std/Build/Step/Run.zig+11-7
......@@ -574,7 +574,7 @@ const IndexedOutput = struct {
574574 tag: @typeInfo(Arg).Union.tag_type.?,
575575 output: *Output,
576576};
577fn make(step: *Step, prog_node: *std.Progress.Node) !void {
577fn make(step: *Step, prog_node: std.Progress.Node) !void {
578578 const b = step.owner;
579579 const arena = b.allocator;
580580 const run: *Run = @fieldParentPtr("step", step);
......@@ -878,7 +878,7 @@ fn runCommand(
878878 argv: []const []const u8,
879879 has_side_effects: bool,
880880 output_dir_path: []const u8,
881 prog_node: *std.Progress.Node,
881 prog_node: std.Progress.Node,
882882) !void {
883883 const step = &run.step;
884884 const b = step.owner;
......@@ -1195,7 +1195,7 @@ fn spawnChildAndCollect(
11951195 run: *Run,
11961196 argv: []const []const u8,
11971197 has_side_effects: bool,
1198 prog_node: *std.Progress.Node,
1198 prog_node: std.Progress.Node,
11991199) !ChildProcResult {
12001200 const b = run.step.owner;
12011201 const arena = b.allocator;
......@@ -1235,6 +1235,10 @@ fn spawnChildAndCollect(
12351235 child.stdin_behavior = .Pipe;
12361236 }
12371237
1238 if (run.stdio != .zig_test) {
1239 child.progress_node = prog_node.start("", 0);
1240 }
1241
12381242 try child.spawn();
12391243 var timer = try std.time.Timer.start();
12401244
......@@ -1264,7 +1268,7 @@ const StdIoResult = struct {
12641268fn evalZigTest(
12651269 run: *Run,
12661270 child: *std.process.Child,
1267 prog_node: *std.Progress.Node,
1271 prog_node: std.Progress.Node,
12681272) !StdIoResult {
12691273 const gpa = run.step.owner.allocator;
12701274 const arena = run.step.owner.allocator;
......@@ -1291,7 +1295,7 @@ fn evalZigTest(
12911295 var metadata: ?TestMetadata = null;
12921296
12931297 var sub_prog_node: ?std.Progress.Node = null;
1294 defer if (sub_prog_node) |*n| n.end();
1298 defer if (sub_prog_node) |n| n.end();
12951299
12961300 poll: while (true) {
12971301 while (stdout.readableLength() < @sizeOf(Header)) {
......@@ -1406,7 +1410,7 @@ const TestMetadata = struct {
14061410 expected_panic_msgs: []const u32,
14071411 string_bytes: []const u8,
14081412 next_index: u32,
1409 prog_node: *std.Progress.Node,
1413 prog_node: std.Progress.Node,
14101414
14111415 fn testName(tm: TestMetadata, index: u32) []const u8 {
14121416 return std.mem.sliceTo(tm.string_bytes[tm.names[index]..], 0);
......@@ -1421,7 +1425,7 @@ fn requestNextTest(in: fs.File, metadata: *TestMetadata, sub_prog_node: *?std.Pr
14211425 if (metadata.expected_panic_msgs[i] != 0) continue;
14221426
14231427 const name = metadata.testName(i);
1424 if (sub_prog_node.*) |*n| n.end();
1428 if (sub_prog_node.*) |n| n.end();
14251429 sub_prog_node.* = metadata.prog_node.start(name, 0);
14261430
14271431 try sendRunTestMessage(in, i);
lib/std/Build/Step/TranslateC.zig+1-1
......@@ -116,7 +116,7 @@ pub fn defineCMacroRaw(translate_c: *TranslateC, name_and_value: []const u8) voi
116116 translate_c.c_macros.append(translate_c.step.owner.dupe(name_and_value)) catch @panic("OOM");
117117}
118118
119fn make(step: *Step, prog_node: *std.Progress.Node) !void {
119fn make(step: *Step, prog_node: std.Progress.Node) !void {
120120 const b = step.owner;
121121 const translate_c: *TranslateC = @fieldParentPtr("step", step);
122122
lib/std/Build/Step/WriteFile.zig+1-1
......@@ -198,7 +198,7 @@ fn maybeUpdateName(write_file: *WriteFile) void {
198198 }
199199}
200200
201fn make(step: *Step, prog_node: *std.Progress.Node) !void {
201fn make(step: *Step, prog_node: std.Progress.Node) !void {
202202 _ = prog_node;
203203 const b = step.owner;
204204 const write_file: *WriteFile = @fieldParentPtr("step", step);
lib/std/Progress.zig+39-4
......@@ -58,7 +58,7 @@ pub const Options = struct {
5858 /// cannot fit into this buffer which will look bad but not cause any malfunctions.
5959 ///
6060 /// Must be at least 200 bytes.
61 draw_buffer: []u8,
61 draw_buffer: []u8 = &default_draw_buffer,
6262 /// How many nanoseconds between writing updates to the terminal.
6363 refresh_rate_ns: u64 = 60 * std.time.ns_per_ms,
6464 /// How many nanoseconds to keep the output hidden
......@@ -67,6 +67,7 @@ pub const Options = struct {
6767 /// 0 means unknown.
6868 estimated_total_items: usize = 0,
6969 root_name: []const u8 = "",
70 disable_printing: bool = false,
7071};
7172
7273/// Represents one unit of progress. Each node can have children nodes, or
......@@ -203,6 +204,13 @@ pub const Node = struct {
203204 @atomicStore(u32, &storage.estimated_total_count, std.math.lossyCast(u32, count), .monotonic);
204205 }
205206
207 /// Thread-safe.
208 pub fn increaseEstimatedTotalItems(n: Node, count: usize) void {
209 const index = n.index.unwrap() orelse return;
210 const storage = storageByIndex(index);
211 _ = @atomicRmw(u32, &storage.estimated_total_count, .Add, std.math.lossyCast(u32, count), .monotonic);
212 }
213
206214 /// Finish a started `Node`. Thread-safe.
207215 pub fn end(n: Node) void {
208216 const index = n.index.unwrap() orelse return;
......@@ -290,6 +298,8 @@ var node_parents_buffer: [default_node_storage_buffer_len]Node.Parent = undefine
290298var node_storage_buffer: [default_node_storage_buffer_len]Node.Storage = undefined;
291299var node_freelist_buffer: [default_node_storage_buffer_len]Node.OptionalIndex = undefined;
292300
301var default_draw_buffer: [2000]u8 = undefined;
302
293303/// Initializes a global Progress instance.
294304///
295305/// Asserts there is only one global Progress instance.
......@@ -318,6 +328,9 @@ pub fn start(options: Options) Node {
318328 }
319329 } else |env_err| switch (env_err) {
320330 error.EnvironmentVariableNotFound => {
331 if (options.disable_printing) {
332 return .{ .index = .none };
333 }
321334 const stderr = std.io.getStdErr();
322335 if (stderr.supportsAnsiEscapeCodes()) {
323336 global_progress.terminal = stderr;
......@@ -330,7 +343,7 @@ pub fn start(options: Options) Node {
330343 global_progress.terminal = stderr;
331344 }
332345
333 if (global_progress.terminal == null) {
346 if (global_progress.terminal == null or !global_progress.supports_ansi_escape_codes) {
334347 return .{ .index = .none };
335348 }
336349
......@@ -379,7 +392,10 @@ fn updateThreadRun() void {
379392 return clearTerminal();
380393
381394 const buffer = computeRedraw();
382 write(buffer);
395 if (stderr_mutex.tryLock()) {
396 defer stderr_mutex.unlock();
397 write(buffer);
398 }
383399 }
384400
385401 while (true) {
......@@ -390,10 +406,25 @@ fn updateThreadRun() void {
390406 return clearTerminal();
391407
392408 const buffer = computeRedraw();
393 write(buffer);
409 if (stderr_mutex.tryLock()) {
410 defer stderr_mutex.unlock();
411 write(buffer);
412 }
394413 }
395414}
396415
416/// Allows the caller to freely write to stderr until `unlockStdErr` is called.
417///
418/// During the lock, any `std.Progress` information is cleared from the terminal.
419pub fn lockStdErr() void {
420 stderr_mutex.lock();
421 clearTerminal();
422}
423
424pub fn unlockStdErr() void {
425 stderr_mutex.unlock();
426}
427
397428fn ipcThreadRun(fd: posix.fd_t) anyerror!void {
398429 {
399430 _ = wait(global_progress.initial_delay_ns);
......@@ -432,6 +463,8 @@ const tree_line = "\x1B\x28\x30\x78\x1B\x28\x42 "; // │
432463const tree_langle = "\x1B\x28\x30\x6d\x71\x1B\x28\x42 "; // └─
433464
434465fn clearTerminal() void {
466 if (global_progress.newline_count == 0) return;
467
435468 var i: usize = 0;
436469 const buf = global_progress.draw_buffer;
437470
......@@ -876,3 +909,5 @@ fn handleSigWinch(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque)
876909 assert(sig == posix.SIG.WINCH);
877910 global_progress.redraw_event.set();
878911}
912
913var stderr_mutex: std.Thread.Mutex = .{};
lib/std/debug.zig+15-6
......@@ -77,19 +77,28 @@ const PdbOrDwarf = union(enum) {
7777 }
7878};
7979
80var stderr_mutex = std.Thread.Mutex{};
80/// Allows the caller to freely write to stderr until `unlockStdErr` is called.
81///
82/// During the lock, any `std.Progress` information is cleared from the terminal.
83pub fn lockStdErr() void {
84 std.Progress.lockStdErr();
85}
86
87pub fn unlockStdErr() void {
88 std.Progress.unlockStdErr();
89}
8190
8291/// Print to stderr, unbuffered, and silently returning on failure. Intended
8392/// for use in "printf debugging." Use `std.log` functions for proper logging.
8493pub fn print(comptime fmt: []const u8, args: anytype) void {
85 stderr_mutex.lock();
86 defer stderr_mutex.unlock();
94 lockStdErr();
95 defer unlockStdErr();
8796 const stderr = io.getStdErr().writer();
8897 nosuspend stderr.print(fmt, args) catch return;
8998}
9099
91100pub fn getStderrMutex() *std.Thread.Mutex {
92 return &stderr_mutex;
101 @compileError("deprecated. call std.debug.lockStdErr() and std.debug.unlockStdErr() instead which will integrate properly with std.Progress");
93102}
94103
95104/// TODO multithreaded awareness
......@@ -107,8 +116,8 @@ pub fn getSelfDebugInfo() !*DebugInfo {
107116/// Tries to print a hexadecimal view of the bytes, unbuffered, and ignores any error returned.
108117/// Obtains the stderr mutex while dumping.
109118pub fn dump_hex(bytes: []const u8) void {
110 stderr_mutex.lock();
111 defer stderr_mutex.unlock();
119 lockStdErr();
120 defer unlockStdErr();
112121 dump_hex_fallible(bytes) catch {};
113122}
114123
lib/std/json/dynamic.zig+2-2
......@@ -52,8 +52,8 @@ pub const Value = union(enum) {
5252 }
5353
5454 pub fn dump(self: Value) void {
55 std.debug.getStderrMutex().lock();
56 defer std.debug.getStderrMutex().unlock();
55 std.debug.lockStdErr();
56 defer std.debug.unlockStdErr();
5757
5858 const stderr = std.io.getStdErr().writer();
5959 stringify(self, .{}, stderr) catch return;
lib/std/log.zig+4-4
......@@ -45,8 +45,8 @@
4545//! const prefix = "[" ++ comptime level.asText() ++ "] " ++ scope_prefix;
4646//!
4747//! // Print the message to stderr, silently ignoring any errors
48//! std.debug.getStderrMutex().lock();
49//! defer std.debug.getStderrMutex().unlock();
48//! std.debug.lockStdErr();
49//! defer std.debug.unlockStdErr();
5050//! const stderr = std.io.getStdErr().writer();
5151//! nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return;
5252//! }
......@@ -152,8 +152,8 @@ pub fn defaultLog(
152152 var bw = std.io.bufferedWriter(stderr);
153153 const writer = bw.writer();
154154
155 std.debug.getStderrMutex().lock();
156 defer std.debug.getStderrMutex().unlock();
155 std.debug.lockStdErr();
156 defer std.debug.unlockStdErr();
157157 nosuspend {
158158 writer.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;
159159 bw.flush() catch return;
lib/std/zig/ErrorBundle.zig+2-2
......@@ -155,8 +155,8 @@ pub const RenderOptions = struct {
155155};
156156
157157pub fn renderToStdErr(eb: ErrorBundle, options: RenderOptions) void {
158 std.debug.getStderrMutex().lock();
159 defer std.debug.getStderrMutex().unlock();
158 std.debug.lockStdErr();
159 defer std.debug.unlockStdErr();
160160 const stderr = std.io.getStdErr();
161161 return renderToWriter(eb, options, stderr.writer()) catch return;
162162}
lib/std/zig/Server.zig-2
......@@ -14,8 +14,6 @@ pub const Message = struct {
1414 zig_version,
1515 /// Body is an ErrorBundle.
1616 error_bundle,
17 /// Body is a UTF-8 string.
18 progress,
1917 /// Body is a EmitBinPath.
2018 emit_bin_path,
2119 /// Body is a TestMetadata
src/Compilation.zig+38-63
......@@ -1273,8 +1273,8 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
12731273 if (options.verbose_llvm_cpu_features) {
12741274 if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: {
12751275 const target = options.root_mod.resolved_target.result;
1276 std.debug.getStderrMutex().lock();
1277 defer std.debug.getStderrMutex().unlock();
1276 std.debug.lockStdErr();
1277 defer std.debug.unlockStdErr();
12781278 const stderr = std.io.getStdErr().writer();
12791279 nosuspend {
12801280 stderr.print("compilation: {s}\n", .{options.root_name}) catch break :print;
......@@ -1934,7 +1934,7 @@ pub fn getTarget(self: Compilation) Target {
19341934/// Only legal to call when cache mode is incremental and a link file is present.
19351935pub fn hotCodeSwap(
19361936 comp: *Compilation,
1937 prog_node: *std.Progress.Node,
1937 prog_node: std.Progress.Node,
19381938 pid: std.process.Child.Id,
19391939) !void {
19401940 const lf = comp.bin_file.?;
......@@ -1966,7 +1966,7 @@ fn cleanupAfterUpdate(comp: *Compilation) void {
19661966}
19671967
19681968/// Detect changes to source files, perform semantic analysis, and update the output files.
1969pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void {
1969pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
19701970 const tracy_trace = trace(@src());
19711971 defer tracy_trace.end();
19721972
......@@ -2256,7 +2256,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
22562256 }
22572257}
22582258
2259fn flush(comp: *Compilation, arena: Allocator, prog_node: *std.Progress.Node) !void {
2259fn flush(comp: *Compilation, arena: Allocator, prog_node: std.Progress.Node) !void {
22602260 if (comp.bin_file) |lf| {
22612261 // This is needed before reading the error flags.
22622262 lf.flush(arena, prog_node) catch |err| switch (err) {
......@@ -2566,13 +2566,11 @@ pub fn emitLlvmObject(
25662566 default_emit: Emit,
25672567 bin_emit_loc: ?EmitLoc,
25682568 llvm_object: *LlvmObject,
2569 prog_node: *std.Progress.Node,
2569 prog_node: std.Progress.Node,
25702570) !void {
25712571 if (build_options.only_c) @compileError("unreachable");
25722572
2573 var sub_prog_node = prog_node.start("LLVM Emit Object", 0);
2574 sub_prog_node.activate();
2575 sub_prog_node.context.refresh();
2573 const sub_prog_node = prog_node.start("LLVM Emit Object", 0);
25762574 defer sub_prog_node.end();
25772575
25782576 try llvm_object.emit(.{
......@@ -3249,23 +3247,23 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {
32493247
32503248pub fn performAllTheWork(
32513249 comp: *Compilation,
3252 main_progress_node: *std.Progress.Node,
3250 main_progress_node: std.Progress.Node,
32533251) error{ TimerUnsupported, OutOfMemory }!void {
32543252 // Here we queue up all the AstGen tasks first, followed by C object compilation.
32553253 // We wait until the AstGen tasks are all completed before proceeding to the
32563254 // (at least for now) single-threaded main work queue. However, C object compilation
32573255 // only needs to be finished by the end of this function.
32583256
3259 var zir_prog_node = main_progress_node.start("AST Lowering", 0);
3257 const zir_prog_node = main_progress_node.start("AST Lowering", 0);
32603258 defer zir_prog_node.end();
32613259
3262 var wasm_prog_node = main_progress_node.start("Compile Autodocs", 0);
3260 const wasm_prog_node = main_progress_node.start("Compile Autodocs", 0);
32633261 defer wasm_prog_node.end();
32643262
3265 var c_obj_prog_node = main_progress_node.start("Compile C Objects", comp.c_source_files.len);
3263 const c_obj_prog_node = main_progress_node.start("Compile C Objects", comp.c_source_files.len);
32663264 defer c_obj_prog_node.end();
32673265
3268 var win32_resource_prog_node = main_progress_node.start("Compile Win32 Resources", comp.rc_source_files.len);
3266 const win32_resource_prog_node = main_progress_node.start("Compile Win32 Resources", comp.rc_source_files.len);
32693267 defer win32_resource_prog_node.end();
32703268
32713269 comp.work_queue_wait_group.reset();
......@@ -3274,7 +3272,7 @@ pub fn performAllTheWork(
32743272 if (!build_options.only_c and !build_options.only_core_functionality) {
32753273 if (comp.docs_emit != null) {
32763274 comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerDocsCopy, .{comp});
3277 comp.work_queue_wait_group.spawnManager(workerDocsWasm, .{ comp, &wasm_prog_node });
3275 comp.work_queue_wait_group.spawnManager(workerDocsWasm, .{ comp, wasm_prog_node });
32783276 }
32793277 }
32803278
......@@ -3313,7 +3311,7 @@ pub fn performAllTheWork(
33133311
33143312 while (comp.astgen_work_queue.readItem()) |file| {
33153313 comp.thread_pool.spawnWg(&comp.astgen_wait_group, workerAstGenFile, .{
3316 comp, file, &zir_prog_node, &comp.astgen_wait_group, .root,
3314 comp, file, zir_prog_node, &comp.astgen_wait_group, .root,
33173315 });
33183316 }
33193317
......@@ -3325,14 +3323,14 @@ pub fn performAllTheWork(
33253323
33263324 while (comp.c_object_work_queue.readItem()) |c_object| {
33273325 comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerUpdateCObject, .{
3328 comp, c_object, &c_obj_prog_node,
3326 comp, c_object, c_obj_prog_node,
33293327 });
33303328 }
33313329
33323330 if (!build_options.only_core_functionality) {
33333331 while (comp.win32_resource_work_queue.readItem()) |win32_resource| {
33343332 comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerUpdateWin32Resource, .{
3335 comp, win32_resource, &win32_resource_prog_node,
3333 comp, win32_resource, win32_resource_prog_node,
33363334 });
33373335 }
33383336 }
......@@ -3342,7 +3340,6 @@ pub fn performAllTheWork(
33423340 try reportMultiModuleErrors(mod);
33433341 try mod.flushRetryableFailures();
33443342 mod.sema_prog_node = main_progress_node.start("Semantic Analysis", 0);
3345 mod.sema_prog_node.activate();
33463343 }
33473344 defer if (comp.module) |mod| {
33483345 mod.sema_prog_node.end();
......@@ -3379,7 +3376,7 @@ pub fn performAllTheWork(
33793376 }
33803377}
33813378
3382fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !void {
3379fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !void {
33833380 switch (job) {
33843381 .codegen_decl => |decl_index| {
33853382 const module = comp.module.?;
......@@ -3803,7 +3800,7 @@ fn docsCopyModule(comp: *Compilation, module: *Package.Module, name: []const u8,
38033800 }
38043801}
38053802
3806fn workerDocsWasm(comp: *Compilation, prog_node: *std.Progress.Node) void {
3803fn workerDocsWasm(comp: *Compilation, prog_node: std.Progress.Node) void {
38073804 workerDocsWasmFallible(comp, prog_node) catch |err| {
38083805 comp.lockAndSetMiscFailure(.docs_wasm, "unable to build autodocs: {s}", .{
38093806 @errorName(err),
......@@ -3811,7 +3808,7 @@ fn workerDocsWasm(comp: *Compilation, prog_node: *std.Progress.Node) void {
38113808 };
38123809}
38133810
3814fn workerDocsWasmFallible(comp: *Compilation, prog_node: *std.Progress.Node) anyerror!void {
3811fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anyerror!void {
38153812 const gpa = comp.gpa;
38163813
38173814 var arena_allocator = std.heap.ArenaAllocator.init(gpa);
......@@ -3952,12 +3949,11 @@ const AstGenSrc = union(enum) {
39523949fn workerAstGenFile(
39533950 comp: *Compilation,
39543951 file: *Module.File,
3955 prog_node: *std.Progress.Node,
3952 prog_node: std.Progress.Node,
39563953 wg: *WaitGroup,
39573954 src: AstGenSrc,
39583955) void {
3959 var child_prog_node = prog_node.start(file.sub_file_path, 0);
3960 child_prog_node.activate();
3956 const child_prog_node = prog_node.start(file.sub_file_path, 0);
39613957 defer child_prog_node.end();
39623958
39633959 const mod = comp.module.?;
......@@ -4265,7 +4261,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8, owner_mod: *Package.Module
42654261fn workerUpdateCObject(
42664262 comp: *Compilation,
42674263 c_object: *CObject,
4268 progress_node: *std.Progress.Node,
4264 progress_node: std.Progress.Node,
42694265) void {
42704266 comp.updateCObject(c_object, progress_node) catch |err| switch (err) {
42714267 error.AnalysisFail => return,
......@@ -4282,7 +4278,7 @@ fn workerUpdateCObject(
42824278fn workerUpdateWin32Resource(
42834279 comp: *Compilation,
42844280 win32_resource: *Win32Resource,
4285 progress_node: *std.Progress.Node,
4281 progress_node: std.Progress.Node,
42864282) void {
42874283 comp.updateWin32Resource(win32_resource, progress_node) catch |err| switch (err) {
42884284 error.AnalysisFail => return,
......@@ -4300,7 +4296,7 @@ fn buildCompilerRtOneShot(
43004296 comp: *Compilation,
43014297 output_mode: std.builtin.OutputMode,
43024298 out: *?CRTFile,
4303 prog_node: *std.Progress.Node,
4299 prog_node: std.Progress.Node,
43044300) void {
43054301 comp.buildOutputFromZig(
43064302 "compiler_rt.zig",
......@@ -4427,7 +4423,7 @@ fn reportRetryableEmbedFileError(
44274423 }
44284424}
44294425
4430fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.Progress.Node) !void {
4426fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Progress.Node) !void {
44314427 if (comp.config.c_frontend == .aro) {
44324428 return comp.failCObj(c_object, "aro does not support compiling C objects yet", .{});
44334429 }
......@@ -4467,9 +4463,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
44674463
44684464 const c_source_basename = std.fs.path.basename(c_object.src.src_path);
44694465
4470 c_obj_prog_node.activate();
4471 var child_progress_node = c_obj_prog_node.start(c_source_basename, 0);
4472 child_progress_node.activate();
4466 const child_progress_node = c_obj_prog_node.start(c_source_basename, 0);
44734467 defer child_progress_node.end();
44744468
44754469 // Special case when doing build-obj for just one C file. When there are more than one object
......@@ -4731,7 +4725,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
47314725 };
47324726}
47334727
4734fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32_resource_prog_node: *std.Progress.Node) !void {
4728fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32_resource_prog_node: std.Progress.Node) !void {
47354729 if (!std.process.can_spawn) {
47364730 return comp.failWin32Resource(win32_resource, "{s} does not support spawning a child process", .{@tagName(builtin.os.tag)});
47374731 }
......@@ -4763,9 +4757,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
47634757 _ = comp.failed_win32_resources.swapRemove(win32_resource);
47644758 }
47654759
4766 win32_resource_prog_node.activate();
4767 var child_progress_node = win32_resource_prog_node.start(src_basename, 0);
4768 child_progress_node.activate();
4760 const child_progress_node = win32_resource_prog_node.start(src_basename, 0);
47694761 defer child_progress_node.end();
47704762
47714763 var man = comp.obtainWin32ResourceCacheManifest();
......@@ -4833,7 +4825,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
48334825 });
48344826 try argv.appendSlice(&.{ "--", in_rc_path, out_res_path });
48354827
4836 try spawnZigRc(comp, win32_resource, src_basename, arena, argv.items, &child_progress_node);
4828 try spawnZigRc(comp, win32_resource, arena, argv.items, child_progress_node);
48374829
48384830 break :blk digest;
48394831 };
......@@ -4901,7 +4893,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
49014893 try argv.appendSlice(rc_src.extra_flags);
49024894 try argv.appendSlice(&.{ "--", rc_src.src_path, out_res_path });
49034895
4904 try spawnZigRc(comp, win32_resource, src_basename, arena, argv.items, &child_progress_node);
4896 try spawnZigRc(comp, win32_resource, arena, argv.items, child_progress_node);
49054897
49064898 // Read depfile and update cache manifest
49074899 {
......@@ -4966,10 +4958,9 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
49664958fn spawnZigRc(
49674959 comp: *Compilation,
49684960 win32_resource: *Win32Resource,
4969 src_basename: []const u8,
49704961 arena: Allocator,
49714962 argv: []const []const u8,
4972 child_progress_node: *std.Progress.Node,
4963 child_progress_node: std.Progress.Node,
49734964) !void {
49744965 var node_name: std.ArrayListUnmanaged(u8) = .{};
49754966 defer node_name.deinit(arena);
......@@ -4978,6 +4969,7 @@ fn spawnZigRc(
49784969 child.stdin_behavior = .Ignore;
49794970 child.stdout_behavior = .Pipe;
49804971 child.stderr_behavior = .Pipe;
4972 child.progress_node = child_progress_node;
49814973
49824974 child.spawn() catch |err| {
49834975 return comp.failWin32Resource(win32_resource, "unable to spawn {s} rc: {s}", .{ argv[0], @errorName(err) });
......@@ -5019,22 +5011,6 @@ fn spawnZigRc(
50195011 };
50205012 return comp.failWin32ResourceWithOwnedBundle(win32_resource, error_bundle);
50215013 },
5022 .progress => {
5023 node_name.clearRetainingCapacity();
5024 // <resinator> is a special string that indicates that the child
5025 // process has reached resinator's main function
5026 if (std.mem.eql(u8, body, "<resinator>")) {
5027 child_progress_node.setName(src_basename);
5028 }
5029 // Ignore 0-length strings since if multiple zig rc commands
5030 // are executed at the same time, only one will send progress strings
5031 // while the other(s) will send empty strings.
5032 else if (body.len > 0) {
5033 try node_name.appendSlice(arena, "build 'zig rc'... ");
5034 try node_name.appendSlice(arena, body);
5035 child_progress_node.setName(node_name.items);
5036 }
5037 },
50385014 else => {}, // ignore other messages
50395015 }
50405016
......@@ -5937,8 +5913,8 @@ pub fn lockAndParseLldStderr(comp: *Compilation, prefix: []const u8, stderr: []c
59375913}
59385914
59395915pub fn dump_argv(argv: []const []const u8) void {
5940 std.debug.getStderrMutex().lock();
5941 defer std.debug.getStderrMutex().unlock();
5916 std.debug.lockStdErr();
5917 defer std.debug.unlockStdErr();
59425918 const stderr = std.io.getStdErr().writer();
59435919 for (argv[0 .. argv.len - 1]) |arg| {
59445920 nosuspend stderr.print("{s} ", .{arg}) catch return;
......@@ -5989,11 +5965,10 @@ pub fn updateSubCompilation(
59895965 parent_comp: *Compilation,
59905966 sub_comp: *Compilation,
59915967 misc_task: MiscTask,
5992 prog_node: *std.Progress.Node,
5968 prog_node: std.Progress.Node,
59935969) !void {
59945970 {
5995 var sub_node = prog_node.start(@tagName(misc_task), 0);
5996 sub_node.activate();
5971 const sub_node = prog_node.start(@tagName(misc_task), 0);
59975972 defer sub_node.end();
59985973
59995974 try sub_comp.update(prog_node);
......@@ -6024,7 +5999,7 @@ fn buildOutputFromZig(
60245999 output_mode: std.builtin.OutputMode,
60256000 out: *?CRTFile,
60266001 misc_task_tag: MiscTask,
6027 prog_node: *std.Progress.Node,
6002 prog_node: std.Progress.Node,
60286003) !void {
60296004 const tracy_trace = trace(@src());
60306005 defer tracy_trace.end();
......@@ -6131,7 +6106,7 @@ pub fn build_crt_file(
61316106 root_name: []const u8,
61326107 output_mode: std.builtin.OutputMode,
61336108 misc_task_tag: MiscTask,
6134 prog_node: *std.Progress.Node,
6109 prog_node: std.Progress.Node,
61356110 /// These elements have to get mutated to add the owner module after it is
61366111 /// created within this function.
61376112 c_source_files: []CSourceFile,
src/Module.zig+2-4
......@@ -2991,8 +2991,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
29912991 try mod.deleteDeclExports(decl_index);
29922992 }
29932993
2994 var decl_prog_node = mod.sema_prog_node.start("", 0);
2995 decl_prog_node.activate();
2994 const decl_prog_node = mod.sema_prog_node.start("", 0);
29962995 defer decl_prog_node.end();
29972996
29982997 const sema_result: SemaDeclResult = blk: {
......@@ -5316,7 +5315,7 @@ fn handleUpdateExports(
53165315
53175316pub fn populateTestFunctions(
53185317 mod: *Module,
5319 main_progress_node: *std.Progress.Node,
5318 main_progress_node: std.Progress.Node,
53205319) !void {
53215320 const gpa = mod.gpa;
53225321 const ip = &mod.intern_pool;
......@@ -5333,7 +5332,6 @@ pub fn populateTestFunctions(
53335332 // We have to call `ensureDeclAnalyzed` here in case `builtin.test_functions`
53345333 // was not referenced by start code.
53355334 mod.sema_prog_node = main_progress_node.start("Semantic Analysis", 0);
5336 mod.sema_prog_node.activate();
53375335 defer {
53385336 mod.sema_prog_node.end();
53395337 mod.sema_prog_node = undefined;
src/Package/Fetch.zig+5-9
......@@ -35,7 +35,7 @@ name_tok: std.zig.Ast.TokenIndex,
3535lazy_status: LazyStatus,
3636parent_package_root: Cache.Path,
3737parent_manifest_ast: ?*const std.zig.Ast,
38prog_node: *std.Progress.Node,
38prog_node: std.Progress.Node,
3939job_queue: *JobQueue,
4040/// If true, don't add an error for a missing hash. This flag is not passed
4141/// down to recursive dependencies. It's intended to be used only be the CLI.
......@@ -720,8 +720,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
720720 };
721721 }
722722
723 // job_queue mutex is locked so this is OK.
724 f.prog_node.unprotected_estimated_total_items += new_fetch_index;
723 f.prog_node.increaseEstimatedTotalItems(new_fetch_index);
725724
726725 break :nf .{ new_fetches[0..new_fetch_index], prog_names[0..new_fetch_index] };
727726 };
......@@ -751,9 +750,8 @@ pub fn relativePathDigest(
751750}
752751
753752pub fn workerRun(f: *Fetch, prog_name: []const u8) void {
754 var prog_node = f.prog_node.start(prog_name, 0);
753 const prog_node = f.prog_node.start(prog_name, 0);
755754 defer prog_node.end();
756 prog_node.activate();
757755
758756 run(f) catch |err| switch (err) {
759757 error.OutOfMemory => f.oom_flag = true,
......@@ -1311,9 +1309,8 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource) anyerror!Unpac
13111309 var index_file = try pack_dir.createFile("pkg.idx", .{ .read = true });
13121310 defer index_file.close();
13131311 {
1314 var index_prog_node = f.prog_node.start("Index pack", 0);
1312 const index_prog_node = f.prog_node.start("Index pack", 0);
13151313 defer index_prog_node.end();
1316 index_prog_node.activate();
13171314 var index_buffered_writer = std.io.bufferedWriter(index_file.writer());
13181315 try git.indexPack(gpa, pack_file, index_buffered_writer.writer());
13191316 try index_buffered_writer.flush();
......@@ -1321,9 +1318,8 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource) anyerror!Unpac
13211318 }
13221319
13231320 {
1324 var checkout_prog_node = f.prog_node.start("Checkout", 0);
1321 const checkout_prog_node = f.prog_node.start("Checkout", 0);
13251322 defer checkout_prog_node.end();
1326 checkout_prog_node.activate();
13271323 var repository = try git.Repository.init(gpa, pack_file, index_file);
13281324 defer repository.deinit();
13291325 var diagnostics: git.Diagnostics = .{ .allocator = arena };
src/glibc.zig+3-3
......@@ -160,7 +160,7 @@ pub const CRTFile = enum {
160160 libc_nonshared_a,
161161};
162162
163pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progress.Node) !void {
163pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: std.Progress.Node) !void {
164164 if (!build_options.have_llvm) {
165165 return error.ZigCompilerNotBuiltWithLLVMExtensions;
166166 }
......@@ -658,7 +658,7 @@ pub const BuiltSharedObjects = struct {
658658
659659const all_map_basename = "all.map";
660660
661pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !void {
661pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !void {
662662 const tracy = trace(@src());
663663 defer tracy.end();
664664
......@@ -1065,7 +1065,7 @@ fn buildSharedLib(
10651065 bin_directory: Compilation.Directory,
10661066 asm_file_basename: []const u8,
10671067 lib: Lib,
1068 prog_node: *std.Progress.Node,
1068 prog_node: std.Progress.Node,
10691069) !void {
10701070 const tracy = trace(@src());
10711071 defer tracy.end();
src/libcxx.zig+2-2
......@@ -113,7 +113,7 @@ pub const BuildError = error{
113113 ZigCompilerNotBuiltWithLLVMExtensions,
114114};
115115
116pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
116pub fn buildLibCXX(comp: *Compilation, prog_node: std.Progress.Node) BuildError!void {
117117 if (!build_options.have_llvm) {
118118 return error.ZigCompilerNotBuiltWithLLVMExtensions;
119119 }
......@@ -357,7 +357,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) BuildError
357357 comp.libcxx_static_lib = try sub_compilation.toCrtFile();
358358}
359359
360pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
360pub fn buildLibCXXABI(comp: *Compilation, prog_node: std.Progress.Node) BuildError!void {
361361 if (!build_options.have_llvm) {
362362 return error.ZigCompilerNotBuiltWithLLVMExtensions;
363363 }
src/libtsan.zig+1-1
......@@ -13,7 +13,7 @@ pub const BuildError = error{
1313 TSANUnsupportedCPUArchitecture,
1414};
1515
16pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
16pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!void {
1717 if (!build_options.have_llvm) {
1818 return error.ZigCompilerNotBuiltWithLLVMExtensions;
1919 }
src/libunwind.zig+1-1
......@@ -14,7 +14,7 @@ pub const BuildError = error{
1414 ZigCompilerNotBuiltWithLLVMExtensions,
1515};
1616
17pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
17pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildError!void {
1818 if (!build_options.have_llvm) {
1919 return error.ZigCompilerNotBuiltWithLLVMExtensions;
2020 }
src/link.zig+4-4
......@@ -535,7 +535,7 @@ pub const File = struct {
535535 /// Commit pending changes and write headers. Takes into account final output mode
536536 /// and `use_lld`, not only `effectiveOutputMode`.
537537 /// `arena` has the lifetime of the call to `Compilation.update`.
538 pub fn flush(base: *File, arena: Allocator, prog_node: *std.Progress.Node) FlushError!void {
538 pub fn flush(base: *File, arena: Allocator, prog_node: std.Progress.Node) FlushError!void {
539539 if (build_options.only_c) {
540540 assert(base.tag == .c);
541541 return @as(*C, @fieldParentPtr("base", base)).flush(arena, prog_node);
......@@ -572,7 +572,7 @@ pub const File = struct {
572572
573573 /// Commit pending changes and write headers. Works based on `effectiveOutputMode`
574574 /// rather than final output mode.
575 pub fn flushModule(base: *File, arena: Allocator, prog_node: *std.Progress.Node) FlushError!void {
575 pub fn flushModule(base: *File, arena: Allocator, prog_node: std.Progress.Node) FlushError!void {
576576 switch (base.tag) {
577577 inline else => |tag| {
578578 if (tag != .c and build_options.only_c) unreachable;
......@@ -688,7 +688,7 @@ pub const File = struct {
688688 }
689689 }
690690
691 pub fn linkAsArchive(base: *File, arena: Allocator, prog_node: *std.Progress.Node) FlushError!void {
691 pub fn linkAsArchive(base: *File, arena: Allocator, prog_node: std.Progress.Node) FlushError!void {
692692 const tracy = trace(@src());
693693 defer tracy.end();
694694
......@@ -966,7 +966,7 @@ pub const File = struct {
966966 base: File,
967967 arena: Allocator,
968968 llvm_object: *LlvmObject,
969 prog_node: *std.Progress.Node,
969 prog_node: std.Progress.Node,
970970 ) !void {
971971 return base.comp.emitLlvmObject(arena, base.emit, .{
972972 .directory = null,
src/link/C.zig+3-4
......@@ -370,7 +370,7 @@ pub fn updateDeclLineNumber(self: *C, zcu: *Zcu, decl_index: InternPool.DeclInde
370370 _ = decl_index;
371371}
372372
373pub fn flush(self: *C, arena: Allocator, prog_node: *std.Progress.Node) !void {
373pub fn flush(self: *C, arena: Allocator, prog_node: std.Progress.Node) !void {
374374 return self.flushModule(arena, prog_node);
375375}
376376
......@@ -389,14 +389,13 @@ fn abiDefines(self: *C, target: std.Target) !std.ArrayList(u8) {
389389 return defines;
390390}
391391
392pub fn flushModule(self: *C, arena: Allocator, prog_node: *std.Progress.Node) !void {
392pub fn flushModule(self: *C, arena: Allocator, prog_node: std.Progress.Node) !void {
393393 _ = arena; // Has the same lifetime as the call to Compilation.update.
394394
395395 const tracy = trace(@src());
396396 defer tracy.end();
397397
398 var sub_prog_node = prog_node.start("Flush Module", 0);
399 sub_prog_node.activate();
398 const sub_prog_node = prog_node.start("Flush Module", 0);
400399 defer sub_prog_node.end();
401400
402401 const comp = self.base.comp;
src/link/Coff.zig+3-4
......@@ -1702,7 +1702,7 @@ fn resolveGlobalSymbol(self: *Coff, current: SymbolWithLoc) !void {
17021702 gop.value_ptr.* = current;
17031703}
17041704
1705pub fn flush(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
1705pub fn flush(self: *Coff, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
17061706 const comp = self.base.comp;
17071707 const use_lld = build_options.have_llvm and comp.config.use_lld;
17081708 if (use_lld) {
......@@ -1714,7 +1714,7 @@ pub fn flush(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node) link.
17141714 }
17151715}
17161716
1717pub fn flushModule(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
1717pub fn flushModule(self: *Coff, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
17181718 const tracy = trace(@src());
17191719 defer tracy.end();
17201720
......@@ -1726,8 +1726,7 @@ pub fn flushModule(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node)
17261726 return;
17271727 }
17281728
1729 var sub_prog_node = prog_node.start("COFF Flush", 0);
1730 sub_prog_node.activate();
1729 const sub_prog_node = prog_node.start("COFF Flush", 0);
17311730 defer sub_prog_node.end();
17321731
17331732 const module = comp.module orelse return error.LinkingWithoutZigSourceUnimplemented;
src/link/Coff/lld.zig+2-4
......@@ -16,7 +16,7 @@ const Allocator = mem.Allocator;
1616const Coff = @import("../Coff.zig");
1717const Compilation = @import("../../Compilation.zig");
1818
19pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node) !void {
19pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: std.Progress.Node) !void {
2020 const tracy = trace(@src());
2121 defer tracy.end();
2222
......@@ -38,9 +38,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node)
3838 }
3939 } else null;
4040
41 var sub_prog_node = prog_node.start("LLD Link", 0);
42 sub_prog_node.activate();
43 sub_prog_node.context.refresh();
41 const sub_prog_node = prog_node.start("LLD Link", 0);
4442 defer sub_prog_node.end();
4543
4644 const is_lib = comp.config.output_mode == .Lib;
src/link/Elf.zig+5-8
......@@ -1064,7 +1064,7 @@ pub fn markDirty(self: *Elf, shdr_index: u32) void {
10641064 }
10651065}
10661066
1067pub fn flush(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
1067pub fn flush(self: *Elf, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
10681068 const use_lld = build_options.have_llvm and self.base.comp.config.use_lld;
10691069 if (use_lld) {
10701070 return self.linkWithLLD(arena, prog_node);
......@@ -1072,7 +1072,7 @@ pub fn flush(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) link.F
10721072 try self.flushModule(arena, prog_node);
10731073}
10741074
1075pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
1075pub fn flushModule(self: *Elf, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
10761076 const tracy = trace(@src());
10771077 defer tracy.end();
10781078
......@@ -1085,8 +1085,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node)
10851085 if (use_lld) return;
10861086 }
10871087
1088 var sub_prog_node = prog_node.start("ELF Flush", 0);
1089 sub_prog_node.activate();
1088 const sub_prog_node = prog_node.start("ELF Flush", 0);
10901089 defer sub_prog_node.end();
10911090
10921091 const target = comp.root_mod.resolved_target.result;
......@@ -2147,7 +2146,7 @@ fn scanRelocs(self: *Elf) !void {
21472146 }
21482147}
21492148
2150fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !void {
2149fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: std.Progress.Node) !void {
21512150 const tracy = trace(@src());
21522151 defer tracy.end();
21532152
......@@ -2169,9 +2168,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
21692168 }
21702169 } else null;
21712170
2172 var sub_prog_node = prog_node.start("LLD Link", 0);
2173 sub_prog_node.activate();
2174 sub_prog_node.context.refresh();
2171 const sub_prog_node = prog_node.start("LLD Link", 0);
21752172 defer sub_prog_node.end();
21762173
21772174 const output_mode = comp.config.output_mode;
src/link/MachO.zig+3-4
......@@ -360,11 +360,11 @@ pub fn deinit(self: *MachO) void {
360360 self.unwind_records.deinit(gpa);
361361}
362362
363pub fn flush(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
363pub fn flush(self: *MachO, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
364364 try self.flushModule(arena, prog_node);
365365}
366366
367pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
367pub fn flushModule(self: *MachO, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
368368 const tracy = trace(@src());
369369 defer tracy.end();
370370
......@@ -375,8 +375,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node
375375 try self.base.emitLlvmObject(arena, llvm_object, prog_node);
376376 }
377377
378 var sub_prog_node = prog_node.start("MachO Flush", 0);
379 sub_prog_node.activate();
378 const sub_prog_node = prog_node.start("MachO Flush", 0);
380379 defer sub_prog_node.end();
381380
382381 const directory = self.base.emit.directory;
src/link/NvPtx.zig+2-2
......@@ -106,11 +106,11 @@ pub fn freeDecl(self: *NvPtx, decl_index: InternPool.DeclIndex) void {
106106 return self.llvm_object.freeDecl(decl_index);
107107}
108108
109pub fn flush(self: *NvPtx, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
109pub fn flush(self: *NvPtx, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
110110 return self.flushModule(arena, prog_node);
111111}
112112
113pub fn flushModule(self: *NvPtx, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
113pub fn flushModule(self: *NvPtx, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
114114 if (build_options.skip_non_native)
115115 @panic("Attempted to compile for architecture that was disabled by build configuration");
116116
src/link/Plan9.zig+3-4
......@@ -604,7 +604,7 @@ fn allocateGotIndex(self: *Plan9) usize {
604604 }
605605}
606606
607pub fn flush(self: *Plan9, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
607pub fn flush(self: *Plan9, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
608608 const comp = self.base.comp;
609609 const use_lld = build_options.have_llvm and comp.config.use_lld;
610610 assert(!use_lld);
......@@ -663,7 +663,7 @@ fn atomCount(self: *Plan9) usize {
663663 return data_decl_count + fn_decl_count + unnamed_const_count + lazy_atom_count + extern_atom_count + anon_atom_count;
664664}
665665
666pub fn flushModule(self: *Plan9, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
666pub fn flushModule(self: *Plan9, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
667667 if (build_options.skip_non_native and builtin.object_format != .plan9) {
668668 @panic("Attempted to compile for object format that was disabled by build configuration");
669669 }
......@@ -677,8 +677,7 @@ pub fn flushModule(self: *Plan9, arena: Allocator, prog_node: *std.Progress.Node
677677 const tracy = trace(@src());
678678 defer tracy.end();
679679
680 var sub_prog_node = prog_node.start("Flush Module", 0);
681 sub_prog_node.activate();
680 const sub_prog_node = prog_node.start("Flush Module", 0);
682681 defer sub_prog_node.end();
683682
684683 log.debug("flushModule", .{});
src/link/SpirV.zig+5-6
......@@ -193,11 +193,11 @@ pub fn freeDecl(self: *SpirV, decl_index: InternPool.DeclIndex) void {
193193 _ = decl_index;
194194}
195195
196pub fn flush(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
196pub fn flush(self: *SpirV, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
197197 return self.flushModule(arena, prog_node);
198198}
199199
200pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
200pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
201201 if (build_options.skip_non_native) {
202202 @panic("Attempted to compile for architecture that was disabled by build configuration");
203203 }
......@@ -205,8 +205,7 @@ pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node
205205 const tracy = trace(@src());
206206 defer tracy.end();
207207
208 var sub_prog_node = prog_node.start("Flush Module", 0);
209 sub_prog_node.activate();
208 const sub_prog_node = prog_node.start("Flush Module", 0);
210209 defer sub_prog_node.end();
211210
212211 const spv = &self.object.spv;
......@@ -253,7 +252,7 @@ pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node
253252 const module = try spv.finalize(arena, target);
254253 errdefer arena.free(module);
255254
256 const linked_module = self.linkModule(arena, module, &sub_prog_node) catch |err| switch (err) {
255 const linked_module = self.linkModule(arena, module, sub_prog_node) catch |err| switch (err) {
257256 error.OutOfMemory => return error.OutOfMemory,
258257 else => |other| {
259258 log.err("error while linking: {s}\n", .{@errorName(other)});
......@@ -264,7 +263,7 @@ pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node
264263 try self.base.file.?.writeAll(std.mem.sliceAsBytes(linked_module));
265264}
266265
267fn linkModule(self: *SpirV, a: Allocator, module: []Word, progress: *std.Progress.Node) ![]Word {
266fn linkModule(self: *SpirV, a: Allocator, module: []Word, progress: std.Progress.Node) ![]Word {
268267 _ = self;
269268
270269 const lower_invocation_globals = @import("SpirV/lower_invocation_globals.zig");
src/link/SpirV/deduplicate.zig+2-3
......@@ -418,9 +418,8 @@ const EntityHashContext = struct {
418418 }
419419};
420420
421pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: *std.Progress.Node) !void {
422 var sub_node = progress.start("deduplicate", 0);
423 sub_node.activate();
421pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: std.Progress.Node) !void {
422 const sub_node = progress.start("deduplicate", 0);
424423 defer sub_node.end();
425424
426425 var arena = std.heap.ArenaAllocator.init(parser.a);
src/link/SpirV/lower_invocation_globals.zig+2-3
......@@ -682,9 +682,8 @@ const ModuleBuilder = struct {
682682 }
683683};
684684
685pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: *std.Progress.Node) !void {
686 var sub_node = progress.start("Lower invocation globals", 6);
687 sub_node.activate();
685pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: std.Progress.Node) !void {
686 const sub_node = progress.start("Lower invocation globals", 6);
688687 defer sub_node.end();
689688
690689 var arena = std.heap.ArenaAllocator.init(parser.a);
src/link/SpirV/prune_unused.zig+2-3
......@@ -255,9 +255,8 @@ fn removeIdsFromMap(a: Allocator, map: anytype, info: ModuleInfo, alive_marker:
255255 }
256256}
257257
258pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: *std.Progress.Node) !void {
259 var sub_node = progress.start("Prune unused IDs", 0);
260 sub_node.activate();
258pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: std.Progress.Node) !void {
259 const sub_node = progress.start("Prune unused IDs", 0);
261260 defer sub_node.end();
262261
263262 var arena = std.heap.ArenaAllocator.init(parser.a);
src/link/Wasm.zig+5-8
......@@ -2464,7 +2464,7 @@ fn appendDummySegment(wasm: *Wasm) !void {
24642464 });
24652465}
24662466
2467pub fn flush(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
2467pub fn flush(wasm: *Wasm, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
24682468 const comp = wasm.base.comp;
24692469 const use_lld = build_options.have_llvm and comp.config.use_lld;
24702470
......@@ -2475,7 +2475,7 @@ pub fn flush(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) link.
24752475}
24762476
24772477/// Uses the in-house linker to link one or multiple object -and archive files into a WebAssembly binary.
2478pub fn flushModule(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
2478pub fn flushModule(wasm: *Wasm, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
24792479 const tracy = trace(@src());
24802480 defer tracy.end();
24812481
......@@ -2486,8 +2486,7 @@ pub fn flushModule(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node)
24862486 if (use_lld) return;
24872487 }
24882488
2489 var sub_prog_node = prog_node.start("Wasm Flush", 0);
2490 sub_prog_node.activate();
2489 const sub_prog_node = prog_node.start("Wasm Flush", 0);
24912490 defer sub_prog_node.end();
24922491
24932492 const directory = wasm.base.emit.directory; // Just an alias to make it shorter to type.
......@@ -3323,7 +3322,7 @@ fn emitImport(wasm: *Wasm, writer: anytype, import: types.Import) !void {
33233322 }
33243323}
33253324
3326fn linkWithLLD(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) !void {
3325fn linkWithLLD(wasm: *Wasm, arena: Allocator, prog_node: std.Progress.Node) !void {
33273326 const tracy = trace(@src());
33283327 defer tracy.end();
33293328
......@@ -3350,9 +3349,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) !vo
33503349 }
33513350 } else null;
33523351
3353 var sub_prog_node = prog_node.start("LLD Link", 0);
3354 sub_prog_node.activate();
3355 sub_prog_node.context.refresh();
3352 const sub_prog_node = prog_node.start("LLD Link", 0);
33563353 defer sub_prog_node.end();
33573354
33583355 const is_obj = comp.config.output_mode == .Obj;
src/main.zig+15-135
......@@ -4028,22 +4028,7 @@ fn serve(
40284028
40294029 var child_pid: ?std.process.Child.Id = null;
40304030
4031 var progress: std.Progress = .{
4032 .terminal = null,
4033 .root = .{
4034 .context = undefined,
4035 .parent = null,
4036 .name = "",
4037 .unprotected_estimated_total_items = 0,
4038 .unprotected_completed_items = 0,
4039 },
4040 .columns_written = 0,
4041 .prev_refresh_timestamp = 0,
4042 .timer = null,
4043 .done = false,
4044 };
4045 const main_progress_node = &progress.root;
4046 main_progress_node.context = &progress;
4031 const main_progress_node = std.Progress.start(.{});
40474032
40484033 while (true) {
40494034 const hdr = try server.receiveMessage();
......@@ -4051,7 +4036,6 @@ fn serve(
40514036 switch (hdr.tag) {
40524037 .exit => return cleanExit(),
40534038 .update => {
4054 assert(main_progress_node.recently_updated_child == null);
40554039 tracy.frameMark();
40564040
40574041 if (arg_mode == .translate_c) {
......@@ -4075,21 +4059,7 @@ fn serve(
40754059 try comp.makeBinFileWritable();
40764060 }
40774061
4078 if (builtin.single_threaded) {
4079 try comp.update(main_progress_node);
4080 } else {
4081 var reset: std.Thread.ResetEvent = .{};
4082
4083 var progress_thread = try std.Thread.spawn(.{}, progressThread, .{
4084 &progress, &server, &reset,
4085 });
4086 defer {
4087 reset.set();
4088 progress_thread.join();
4089 }
4090
4091 try comp.update(main_progress_node);
4092 }
4062 try comp.update(main_progress_node);
40934063
40944064 try comp.makeBinFileExecutable();
40954065 try serveUpdateResults(&server, comp);
......@@ -4116,7 +4086,6 @@ fn serve(
41164086 },
41174087 .hot_update => {
41184088 tracy.frameMark();
4119 assert(main_progress_node.recently_updated_child == null);
41204089 if (child_pid) |pid| {
41214090 try comp.hotCodeSwap(main_progress_node, pid);
41224091 try serveUpdateResults(&server, comp);
......@@ -4146,63 +4115,6 @@ fn serve(
41464115 }
41474116}
41484117
4149fn progressThread(progress: *std.Progress, server: *const Server, reset: *std.Thread.ResetEvent) void {
4150 while (true) {
4151 if (reset.timedWait(500 * std.time.ns_per_ms)) |_| {
4152 // The Compilation update has completed.
4153 return;
4154 } else |err| switch (err) {
4155 error.Timeout => {},
4156 }
4157
4158 var buf: std.BoundedArray(u8, 160) = .{};
4159
4160 {
4161 progress.update_mutex.lock();
4162 defer progress.update_mutex.unlock();
4163
4164 var need_ellipse = false;
4165 var maybe_node: ?*std.Progress.Node = &progress.root;
4166 while (maybe_node) |node| {
4167 if (need_ellipse) {
4168 buf.appendSlice("... ") catch {};
4169 }
4170 need_ellipse = false;
4171 const eti = @atomicLoad(usize, &node.unprotected_estimated_total_items, .monotonic);
4172 const completed_items = @atomicLoad(usize, &node.unprotected_completed_items, .monotonic);
4173 const current_item = completed_items + 1;
4174 if (node.name.len != 0 or eti > 0) {
4175 if (node.name.len != 0) {
4176 buf.appendSlice(node.name) catch {};
4177 need_ellipse = true;
4178 }
4179 if (eti > 0) {
4180 if (need_ellipse) buf.appendSlice(" ") catch {};
4181 buf.writer().print("[{d}/{d}] ", .{ current_item, eti }) catch {};
4182 need_ellipse = false;
4183 } else if (completed_items != 0) {
4184 if (need_ellipse) buf.appendSlice(" ") catch {};
4185 buf.writer().print("[{d}] ", .{current_item}) catch {};
4186 need_ellipse = false;
4187 }
4188 }
4189 maybe_node = @atomicLoad(?*std.Progress.Node, &node.recently_updated_child, .acquire);
4190 }
4191 }
4192
4193 const progress_string = buf.slice();
4194
4195 server.serveMessage(.{
4196 .tag = .progress,
4197 .bytes_len = @as(u32, @intCast(progress_string.len)),
4198 }, &.{
4199 progress_string,
4200 }) catch |err| {
4201 fatal("unable to write to client: {s}", .{@errorName(err)});
4202 };
4203 }
4204}
4205
42064118fn serveUpdateResults(s: *Server, comp: *Compilation) !void {
42074119 const gpa = comp.gpa;
42084120 var error_bundle = try comp.getAllErrorsAlloc();
......@@ -4472,19 +4384,10 @@ fn runOrTestHotSwap(
44724384fn updateModule(comp: *Compilation, color: Color) !void {
44734385 {
44744386 // If the terminal is dumb, we dont want to show the user all the output.
4475 var progress: std.Progress = .{ .dont_print_on_dumb = true };
4476 const main_progress_node = progress.start("", 0);
4387 const main_progress_node = std.Progress.start(.{
4388 .disable_printing = color == .off,
4389 });
44774390 defer main_progress_node.end();
4478 switch (color) {
4479 .off => {
4480 progress.terminal = null;
4481 },
4482 .on => {
4483 progress.terminal = std.io.getStdErr();
4484 progress.supports_ansi_escape_codes = true;
4485 },
4486 .auto => {},
4487 }
44884391
44894392 try comp.update(main_progress_node);
44904393 }
......@@ -4736,8 +4639,6 @@ const usage_build =
47364639;
47374640
47384641fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
4739 var progress: std.Progress = .{ .dont_print_on_dumb = true };
4740
47414642 var build_file: ?[]const u8 = null;
47424643 var override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena);
47434644 var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);
......@@ -5051,7 +4952,9 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
50514952 config,
50524953 );
50534954 } else {
5054 const root_prog_node = progress.start("Fetch Packages", 0);
4955 const root_prog_node = std.Progress.start(.{
4956 .root_name = "Fetch Packages",
4957 });
50554958 defer root_prog_node.end();
50564959
50574960 var job_queue: Package.Fetch.JobQueue = .{
......@@ -5473,38 +5376,14 @@ fn jitCmd(
54735376 };
54745377 defer comp.destroy();
54755378
5476 if (options.server and !builtin.single_threaded) {
5477 var reset: std.Thread.ResetEvent = .{};
5478 var progress: std.Progress = .{
5479 .terminal = null,
5480 .root = .{
5481 .context = undefined,
5482 .parent = null,
5483 .name = "",
5484 .unprotected_estimated_total_items = 0,
5485 .unprotected_completed_items = 0,
5486 },
5487 .columns_written = 0,
5488 .prev_refresh_timestamp = 0,
5489 .timer = null,
5490 .done = false,
5491 };
5492 const main_progress_node = &progress.root;
5493 main_progress_node.context = &progress;
5379 if (options.server) {
5380 const main_progress_node = std.Progress.start(.{});
54945381 var server = std.zig.Server{
54955382 .out = std.io.getStdOut(),
54965383 .in = undefined, // won't be receiving messages
54975384 .receive_fifo = undefined, // won't be receiving messages
54985385 };
54995386
5500 var progress_thread = try std.Thread.spawn(.{}, progressThread, .{
5501 &progress, &server, &reset,
5502 });
5503 defer {
5504 reset.set();
5505 progress_thread.join();
5506 }
5507
55085387 try comp.update(main_progress_node);
55095388
55105389 var error_bundle = try comp.getAllErrorsAlloc();
......@@ -6963,8 +6842,9 @@ fn cmdFetch(
69636842
69646843 try http_client.initDefaultProxies(arena);
69656844
6966 var progress: std.Progress = .{ .dont_print_on_dumb = true };
6967 const root_prog_node = progress.start("Fetch", 0);
6845 var root_prog_node = std.Progress.start(.{
6846 .root_name = "Fetch",
6847 });
69686848 defer root_prog_node.end();
69696849
69706850 var global_cache_directory: Compilation.Directory = l: {
......@@ -7028,8 +6908,8 @@ fn cmdFetch(
70286908
70296909 const hex_digest = Package.Manifest.hexDigest(fetch.actual_hash);
70306910
7031 progress.done = true;
7032 progress.refresh();
6911 root_prog_node.end();
6912 root_prog_node = .{ .index = .none };
70336913
70346914 const name = switch (save) {
70356915 .no => {
src/mingw.zig+3-3
......@@ -16,7 +16,7 @@ pub const CRTFile = enum {
1616 mingw32_lib,
1717};
1818
19pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progress.Node) !void {
19pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: std.Progress.Node) !void {
2020 if (!build_options.have_llvm) {
2121 return error.ZigCompilerNotBuiltWithLLVMExtensions;
2222 }
......@@ -234,8 +234,8 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
234234 const include_dir = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", "def-include" });
235235
236236 if (comp.verbose_cc) print: {
237 std.debug.getStderrMutex().lock();
238 defer std.debug.getStderrMutex().unlock();
237 std.debug.lockStdErr();
238 defer std.debug.unlockStdErr();
239239 const stderr = std.io.getStdErr().writer();
240240 nosuspend stderr.print("def file: {s}\n", .{def_file_path}) catch break :print;
241241 nosuspend stderr.print("include dir: {s}\n", .{include_dir}) catch break :print;
src/musl.zig+1-1
......@@ -19,7 +19,7 @@ pub const CRTFile = enum {
1919 libc_so,
2020};
2121
22pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progress.Node) !void {
22pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: std.Progress.Node) !void {
2323 if (!build_options.have_llvm) {
2424 return error.ZigCompilerNotBuiltWithLLVMExtensions;
2525 }
src/wasi_libc.zig+1-1
......@@ -57,7 +57,7 @@ pub fn execModelCrtFileFullName(wasi_exec_model: std.builtin.WasiExecModel) []co
5757 };
5858}
5959
60pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progress.Node) !void {
60pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: std.Progress.Node) !void {
6161 if (!build_options.have_llvm) {
6262 return error.ZigCompilerNotBuiltWithLLVMExtensions;
6363 }
test/standalone/cmakedefine/build.zig+1-1
......@@ -80,7 +80,7 @@ pub fn build(b: *std.Build) void {
8080 test_step.dependOn(&wrapper_header.step);
8181}
8282
83fn compare_headers(step: *std.Build.Step, prog_node: *std.Progress.Node) !void {
83fn compare_headers(step: *std.Build.Step, prog_node: std.Progress.Node) !void {
8484 _ = prog_node;
8585 const allocator = step.owner.allocator;
8686 const expected_fmt = "expected_{s}";