update the codebase for the new std.Progress API

This commit is contained in:
Andrew Kelley
2024-05-24 08:22:47 -07:00
parent f6873c6b00
commit f97c2f28fd
49 changed files with 226 additions and 355 deletions
+38 -63
View File
@@ -1273,8 +1273,8 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
if (options.verbose_llvm_cpu_features) {
if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: {
const target = options.root_mod.resolved_target.result;
std.debug.getStderrMutex().lock();
defer std.debug.getStderrMutex().unlock();
std.debug.lockStdErr();
defer std.debug.unlockStdErr();
const stderr = std.io.getStdErr().writer();
nosuspend {
stderr.print("compilation: {s}\n", .{options.root_name}) catch break :print;
@@ -1934,7 +1934,7 @@ pub fn getTarget(self: Compilation) Target {
/// Only legal to call when cache mode is incremental and a link file is present.
pub fn hotCodeSwap(
comp: *Compilation,
prog_node: *std.Progress.Node,
prog_node: std.Progress.Node,
pid: std.process.Child.Id,
) !void {
const lf = comp.bin_file.?;
@@ -1966,7 +1966,7 @@ fn cleanupAfterUpdate(comp: *Compilation) void {
}
/// Detect changes to source files, perform semantic analysis, and update the output files.
pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void {
pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
const tracy_trace = trace(@src());
defer tracy_trace.end();
@@ -2256,7 +2256,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
}
}
fn flush(comp: *Compilation, arena: Allocator, prog_node: *std.Progress.Node) !void {
fn flush(comp: *Compilation, arena: Allocator, prog_node: std.Progress.Node) !void {
if (comp.bin_file) |lf| {
// This is needed before reading the error flags.
lf.flush(arena, prog_node) catch |err| switch (err) {
@@ -2566,13 +2566,11 @@ pub fn emitLlvmObject(
default_emit: Emit,
bin_emit_loc: ?EmitLoc,
llvm_object: *LlvmObject,
prog_node: *std.Progress.Node,
prog_node: std.Progress.Node,
) !void {
if (build_options.only_c) @compileError("unreachable");
var sub_prog_node = prog_node.start("LLVM Emit Object", 0);
sub_prog_node.activate();
sub_prog_node.context.refresh();
const sub_prog_node = prog_node.start("LLVM Emit Object", 0);
defer sub_prog_node.end();
try llvm_object.emit(.{
@@ -3249,23 +3247,23 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {
pub fn performAllTheWork(
comp: *Compilation,
main_progress_node: *std.Progress.Node,
main_progress_node: std.Progress.Node,
) error{ TimerUnsupported, OutOfMemory }!void {
// Here we queue up all the AstGen tasks first, followed by C object compilation.
// We wait until the AstGen tasks are all completed before proceeding to the
// (at least for now) single-threaded main work queue. However, C object compilation
// only needs to be finished by the end of this function.
var zir_prog_node = main_progress_node.start("AST Lowering", 0);
const zir_prog_node = main_progress_node.start("AST Lowering", 0);
defer zir_prog_node.end();
var wasm_prog_node = main_progress_node.start("Compile Autodocs", 0);
const wasm_prog_node = main_progress_node.start("Compile Autodocs", 0);
defer wasm_prog_node.end();
var c_obj_prog_node = main_progress_node.start("Compile C Objects", comp.c_source_files.len);
const c_obj_prog_node = main_progress_node.start("Compile C Objects", comp.c_source_files.len);
defer c_obj_prog_node.end();
var win32_resource_prog_node = main_progress_node.start("Compile Win32 Resources", comp.rc_source_files.len);
const win32_resource_prog_node = main_progress_node.start("Compile Win32 Resources", comp.rc_source_files.len);
defer win32_resource_prog_node.end();
comp.work_queue_wait_group.reset();
@@ -3274,7 +3272,7 @@ pub fn performAllTheWork(
if (!build_options.only_c and !build_options.only_core_functionality) {
if (comp.docs_emit != null) {
comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerDocsCopy, .{comp});
comp.work_queue_wait_group.spawnManager(workerDocsWasm, .{ comp, &wasm_prog_node });
comp.work_queue_wait_group.spawnManager(workerDocsWasm, .{ comp, wasm_prog_node });
}
}
@@ -3313,7 +3311,7 @@ pub fn performAllTheWork(
while (comp.astgen_work_queue.readItem()) |file| {
comp.thread_pool.spawnWg(&comp.astgen_wait_group, workerAstGenFile, .{
comp, file, &zir_prog_node, &comp.astgen_wait_group, .root,
comp, file, zir_prog_node, &comp.astgen_wait_group, .root,
});
}
@@ -3325,14 +3323,14 @@ pub fn performAllTheWork(
while (comp.c_object_work_queue.readItem()) |c_object| {
comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerUpdateCObject, .{
comp, c_object, &c_obj_prog_node,
comp, c_object, c_obj_prog_node,
});
}
if (!build_options.only_core_functionality) {
while (comp.win32_resource_work_queue.readItem()) |win32_resource| {
comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerUpdateWin32Resource, .{
comp, win32_resource, &win32_resource_prog_node,
comp, win32_resource, win32_resource_prog_node,
});
}
}
@@ -3342,7 +3340,6 @@ pub fn performAllTheWork(
try reportMultiModuleErrors(mod);
try mod.flushRetryableFailures();
mod.sema_prog_node = main_progress_node.start("Semantic Analysis", 0);
mod.sema_prog_node.activate();
}
defer if (comp.module) |mod| {
mod.sema_prog_node.end();
@@ -3379,7 +3376,7 @@ pub fn performAllTheWork(
}
}
fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !void {
fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !void {
switch (job) {
.codegen_decl => |decl_index| {
const module = comp.module.?;
@@ -3803,7 +3800,7 @@ fn docsCopyModule(comp: *Compilation, module: *Package.Module, name: []const u8,
}
}
fn workerDocsWasm(comp: *Compilation, prog_node: *std.Progress.Node) void {
fn workerDocsWasm(comp: *Compilation, prog_node: std.Progress.Node) void {
workerDocsWasmFallible(comp, prog_node) catch |err| {
comp.lockAndSetMiscFailure(.docs_wasm, "unable to build autodocs: {s}", .{
@errorName(err),
@@ -3811,7 +3808,7 @@ fn workerDocsWasm(comp: *Compilation, prog_node: *std.Progress.Node) void {
};
}
fn workerDocsWasmFallible(comp: *Compilation, prog_node: *std.Progress.Node) anyerror!void {
fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anyerror!void {
const gpa = comp.gpa;
var arena_allocator = std.heap.ArenaAllocator.init(gpa);
@@ -3952,12 +3949,11 @@ const AstGenSrc = union(enum) {
fn workerAstGenFile(
comp: *Compilation,
file: *Module.File,
prog_node: *std.Progress.Node,
prog_node: std.Progress.Node,
wg: *WaitGroup,
src: AstGenSrc,
) void {
var child_prog_node = prog_node.start(file.sub_file_path, 0);
child_prog_node.activate();
const child_prog_node = prog_node.start(file.sub_file_path, 0);
defer child_prog_node.end();
const mod = comp.module.?;
@@ -4265,7 +4261,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8, owner_mod: *Package.Module
fn workerUpdateCObject(
comp: *Compilation,
c_object: *CObject,
progress_node: *std.Progress.Node,
progress_node: std.Progress.Node,
) void {
comp.updateCObject(c_object, progress_node) catch |err| switch (err) {
error.AnalysisFail => return,
@@ -4282,7 +4278,7 @@ fn workerUpdateCObject(
fn workerUpdateWin32Resource(
comp: *Compilation,
win32_resource: *Win32Resource,
progress_node: *std.Progress.Node,
progress_node: std.Progress.Node,
) void {
comp.updateWin32Resource(win32_resource, progress_node) catch |err| switch (err) {
error.AnalysisFail => return,
@@ -4300,7 +4296,7 @@ fn buildCompilerRtOneShot(
comp: *Compilation,
output_mode: std.builtin.OutputMode,
out: *?CRTFile,
prog_node: *std.Progress.Node,
prog_node: std.Progress.Node,
) void {
comp.buildOutputFromZig(
"compiler_rt.zig",
@@ -4427,7 +4423,7 @@ fn reportRetryableEmbedFileError(
}
}
fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.Progress.Node) !void {
fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Progress.Node) !void {
if (comp.config.c_frontend == .aro) {
return comp.failCObj(c_object, "aro does not support compiling C objects yet", .{});
}
@@ -4467,9 +4463,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
const c_source_basename = std.fs.path.basename(c_object.src.src_path);
c_obj_prog_node.activate();
var child_progress_node = c_obj_prog_node.start(c_source_basename, 0);
child_progress_node.activate();
const child_progress_node = c_obj_prog_node.start(c_source_basename, 0);
defer child_progress_node.end();
// 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
};
}
fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32_resource_prog_node: *std.Progress.Node) !void {
fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32_resource_prog_node: std.Progress.Node) !void {
if (!std.process.can_spawn) {
return comp.failWin32Resource(win32_resource, "{s} does not support spawning a child process", .{@tagName(builtin.os.tag)});
}
@@ -4763,9 +4757,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
_ = comp.failed_win32_resources.swapRemove(win32_resource);
}
win32_resource_prog_node.activate();
var child_progress_node = win32_resource_prog_node.start(src_basename, 0);
child_progress_node.activate();
const child_progress_node = win32_resource_prog_node.start(src_basename, 0);
defer child_progress_node.end();
var man = comp.obtainWin32ResourceCacheManifest();
@@ -4833,7 +4825,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
});
try argv.appendSlice(&.{ "--", in_rc_path, out_res_path });
try spawnZigRc(comp, win32_resource, src_basename, arena, argv.items, &child_progress_node);
try spawnZigRc(comp, win32_resource, arena, argv.items, child_progress_node);
break :blk digest;
};
@@ -4901,7 +4893,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
try argv.appendSlice(rc_src.extra_flags);
try argv.appendSlice(&.{ "--", rc_src.src_path, out_res_path });
try spawnZigRc(comp, win32_resource, src_basename, arena, argv.items, &child_progress_node);
try spawnZigRc(comp, win32_resource, arena, argv.items, child_progress_node);
// Read depfile and update cache manifest
{
@@ -4966,10 +4958,9 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
fn spawnZigRc(
comp: *Compilation,
win32_resource: *Win32Resource,
src_basename: []const u8,
arena: Allocator,
argv: []const []const u8,
child_progress_node: *std.Progress.Node,
child_progress_node: std.Progress.Node,
) !void {
var node_name: std.ArrayListUnmanaged(u8) = .{};
defer node_name.deinit(arena);
@@ -4978,6 +4969,7 @@ fn spawnZigRc(
child.stdin_behavior = .Ignore;
child.stdout_behavior = .Pipe;
child.stderr_behavior = .Pipe;
child.progress_node = child_progress_node;
child.spawn() catch |err| {
return comp.failWin32Resource(win32_resource, "unable to spawn {s} rc: {s}", .{ argv[0], @errorName(err) });
@@ -5019,22 +5011,6 @@ fn spawnZigRc(
};
return comp.failWin32ResourceWithOwnedBundle(win32_resource, error_bundle);
},
.progress => {
node_name.clearRetainingCapacity();
// <resinator> is a special string that indicates that the child
// process has reached resinator's main function
if (std.mem.eql(u8, body, "<resinator>")) {
child_progress_node.setName(src_basename);
}
// Ignore 0-length strings since if multiple zig rc commands
// are executed at the same time, only one will send progress strings
// while the other(s) will send empty strings.
else if (body.len > 0) {
try node_name.appendSlice(arena, "build 'zig rc'... ");
try node_name.appendSlice(arena, body);
child_progress_node.setName(node_name.items);
}
},
else => {}, // ignore other messages
}
@@ -5937,8 +5913,8 @@ pub fn lockAndParseLldStderr(comp: *Compilation, prefix: []const u8, stderr: []c
}
pub fn dump_argv(argv: []const []const u8) void {
std.debug.getStderrMutex().lock();
defer std.debug.getStderrMutex().unlock();
std.debug.lockStdErr();
defer std.debug.unlockStdErr();
const stderr = std.io.getStdErr().writer();
for (argv[0 .. argv.len - 1]) |arg| {
nosuspend stderr.print("{s} ", .{arg}) catch return;
@@ -5989,11 +5965,10 @@ pub fn updateSubCompilation(
parent_comp: *Compilation,
sub_comp: *Compilation,
misc_task: MiscTask,
prog_node: *std.Progress.Node,
prog_node: std.Progress.Node,
) !void {
{
var sub_node = prog_node.start(@tagName(misc_task), 0);
sub_node.activate();
const sub_node = prog_node.start(@tagName(misc_task), 0);
defer sub_node.end();
try sub_comp.update(prog_node);
@@ -6024,7 +5999,7 @@ fn buildOutputFromZig(
output_mode: std.builtin.OutputMode,
out: *?CRTFile,
misc_task_tag: MiscTask,
prog_node: *std.Progress.Node,
prog_node: std.Progress.Node,
) !void {
const tracy_trace = trace(@src());
defer tracy_trace.end();
@@ -6131,7 +6106,7 @@ pub fn build_crt_file(
root_name: []const u8,
output_mode: std.builtin.OutputMode,
misc_task_tag: MiscTask,
prog_node: *std.Progress.Node,
prog_node: std.Progress.Node,
/// These elements have to get mutated to add the owner module after it is
/// created within this function.
c_source_files: []CSourceFile,
+2 -4
View File
@@ -2991,8 +2991,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
try mod.deleteDeclExports(decl_index);
}
var decl_prog_node = mod.sema_prog_node.start("", 0);
decl_prog_node.activate();
const decl_prog_node = mod.sema_prog_node.start("", 0);
defer decl_prog_node.end();
const sema_result: SemaDeclResult = blk: {
@@ -5316,7 +5315,7 @@ fn handleUpdateExports(
pub fn populateTestFunctions(
mod: *Module,
main_progress_node: *std.Progress.Node,
main_progress_node: std.Progress.Node,
) !void {
const gpa = mod.gpa;
const ip = &mod.intern_pool;
@@ -5333,7 +5332,6 @@ pub fn populateTestFunctions(
// We have to call `ensureDeclAnalyzed` here in case `builtin.test_functions`
// was not referenced by start code.
mod.sema_prog_node = main_progress_node.start("Semantic Analysis", 0);
mod.sema_prog_node.activate();
defer {
mod.sema_prog_node.end();
mod.sema_prog_node = undefined;
+5 -9
View File
@@ -35,7 +35,7 @@ name_tok: std.zig.Ast.TokenIndex,
lazy_status: LazyStatus,
parent_package_root: Cache.Path,
parent_manifest_ast: ?*const std.zig.Ast,
prog_node: *std.Progress.Node,
prog_node: std.Progress.Node,
job_queue: *JobQueue,
/// If true, don't add an error for a missing hash. This flag is not passed
/// down to recursive dependencies. It's intended to be used only be the CLI.
@@ -720,8 +720,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
};
}
// job_queue mutex is locked so this is OK.
f.prog_node.unprotected_estimated_total_items += new_fetch_index;
f.prog_node.increaseEstimatedTotalItems(new_fetch_index);
break :nf .{ new_fetches[0..new_fetch_index], prog_names[0..new_fetch_index] };
};
@@ -751,9 +750,8 @@ pub fn relativePathDigest(
}
pub fn workerRun(f: *Fetch, prog_name: []const u8) void {
var prog_node = f.prog_node.start(prog_name, 0);
const prog_node = f.prog_node.start(prog_name, 0);
defer prog_node.end();
prog_node.activate();
run(f) catch |err| switch (err) {
error.OutOfMemory => f.oom_flag = true,
@@ -1311,9 +1309,8 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource) anyerror!Unpac
var index_file = try pack_dir.createFile("pkg.idx", .{ .read = true });
defer index_file.close();
{
var index_prog_node = f.prog_node.start("Index pack", 0);
const index_prog_node = f.prog_node.start("Index pack", 0);
defer index_prog_node.end();
index_prog_node.activate();
var index_buffered_writer = std.io.bufferedWriter(index_file.writer());
try git.indexPack(gpa, pack_file, index_buffered_writer.writer());
try index_buffered_writer.flush();
@@ -1321,9 +1318,8 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource) anyerror!Unpac
}
{
var checkout_prog_node = f.prog_node.start("Checkout", 0);
const checkout_prog_node = f.prog_node.start("Checkout", 0);
defer checkout_prog_node.end();
checkout_prog_node.activate();
var repository = try git.Repository.init(gpa, pack_file, index_file);
defer repository.deinit();
var diagnostics: git.Diagnostics = .{ .allocator = arena };
+3 -3
View File
@@ -160,7 +160,7 @@ pub const CRTFile = enum {
libc_nonshared_a,
};
pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progress.Node) !void {
pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: std.Progress.Node) !void {
if (!build_options.have_llvm) {
return error.ZigCompilerNotBuiltWithLLVMExtensions;
}
@@ -658,7 +658,7 @@ pub const BuiltSharedObjects = struct {
const all_map_basename = "all.map";
pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !void {
pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !void {
const tracy = trace(@src());
defer tracy.end();
@@ -1065,7 +1065,7 @@ fn buildSharedLib(
bin_directory: Compilation.Directory,
asm_file_basename: []const u8,
lib: Lib,
prog_node: *std.Progress.Node,
prog_node: std.Progress.Node,
) !void {
const tracy = trace(@src());
defer tracy.end();
+2 -2
View File
@@ -113,7 +113,7 @@ pub const BuildError = error{
ZigCompilerNotBuiltWithLLVMExtensions,
};
pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
pub fn buildLibCXX(comp: *Compilation, prog_node: std.Progress.Node) BuildError!void {
if (!build_options.have_llvm) {
return error.ZigCompilerNotBuiltWithLLVMExtensions;
}
@@ -357,7 +357,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) BuildError
comp.libcxx_static_lib = try sub_compilation.toCrtFile();
}
pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
pub fn buildLibCXXABI(comp: *Compilation, prog_node: std.Progress.Node) BuildError!void {
if (!build_options.have_llvm) {
return error.ZigCompilerNotBuiltWithLLVMExtensions;
}
+1 -1
View File
@@ -13,7 +13,7 @@ pub const BuildError = error{
TSANUnsupportedCPUArchitecture,
};
pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!void {
if (!build_options.have_llvm) {
return error.ZigCompilerNotBuiltWithLLVMExtensions;
}
+1 -1
View File
@@ -14,7 +14,7 @@ pub const BuildError = error{
ZigCompilerNotBuiltWithLLVMExtensions,
};
pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildError!void {
if (!build_options.have_llvm) {
return error.ZigCompilerNotBuiltWithLLVMExtensions;
}
+4 -4
View File
@@ -535,7 +535,7 @@ pub const File = struct {
/// Commit pending changes and write headers. Takes into account final output mode
/// and `use_lld`, not only `effectiveOutputMode`.
/// `arena` has the lifetime of the call to `Compilation.update`.
pub fn flush(base: *File, arena: Allocator, prog_node: *std.Progress.Node) FlushError!void {
pub fn flush(base: *File, arena: Allocator, prog_node: std.Progress.Node) FlushError!void {
if (build_options.only_c) {
assert(base.tag == .c);
return @as(*C, @fieldParentPtr("base", base)).flush(arena, prog_node);
@@ -572,7 +572,7 @@ pub const File = struct {
/// Commit pending changes and write headers. Works based on `effectiveOutputMode`
/// rather than final output mode.
pub fn flushModule(base: *File, arena: Allocator, prog_node: *std.Progress.Node) FlushError!void {
pub fn flushModule(base: *File, arena: Allocator, prog_node: std.Progress.Node) FlushError!void {
switch (base.tag) {
inline else => |tag| {
if (tag != .c and build_options.only_c) unreachable;
@@ -688,7 +688,7 @@ pub const File = struct {
}
}
pub fn linkAsArchive(base: *File, arena: Allocator, prog_node: *std.Progress.Node) FlushError!void {
pub fn linkAsArchive(base: *File, arena: Allocator, prog_node: std.Progress.Node) FlushError!void {
const tracy = trace(@src());
defer tracy.end();
@@ -966,7 +966,7 @@ pub const File = struct {
base: File,
arena: Allocator,
llvm_object: *LlvmObject,
prog_node: *std.Progress.Node,
prog_node: std.Progress.Node,
) !void {
return base.comp.emitLlvmObject(arena, base.emit, .{
.directory = null,
+3 -4
View File
@@ -370,7 +370,7 @@ pub fn updateDeclLineNumber(self: *C, zcu: *Zcu, decl_index: InternPool.DeclInde
_ = decl_index;
}
pub fn flush(self: *C, arena: Allocator, prog_node: *std.Progress.Node) !void {
pub fn flush(self: *C, arena: Allocator, prog_node: std.Progress.Node) !void {
return self.flushModule(arena, prog_node);
}
@@ -389,14 +389,13 @@ fn abiDefines(self: *C, target: std.Target) !std.ArrayList(u8) {
return defines;
}
pub fn flushModule(self: *C, arena: Allocator, prog_node: *std.Progress.Node) !void {
pub fn flushModule(self: *C, arena: Allocator, prog_node: std.Progress.Node) !void {
_ = arena; // Has the same lifetime as the call to Compilation.update.
const tracy = trace(@src());
defer tracy.end();
var sub_prog_node = prog_node.start("Flush Module", 0);
sub_prog_node.activate();
const sub_prog_node = prog_node.start("Flush Module", 0);
defer sub_prog_node.end();
const comp = self.base.comp;
+3 -4
View File
@@ -1702,7 +1702,7 @@ fn resolveGlobalSymbol(self: *Coff, current: SymbolWithLoc) !void {
gop.value_ptr.* = current;
}
pub fn flush(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flush(self: *Coff, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
const comp = self.base.comp;
const use_lld = build_options.have_llvm and comp.config.use_lld;
if (use_lld) {
@@ -1714,7 +1714,7 @@ pub fn flush(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node) link.
}
}
pub fn flushModule(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flushModule(self: *Coff, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
const tracy = trace(@src());
defer tracy.end();
@@ -1726,8 +1726,7 @@ pub fn flushModule(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node)
return;
}
var sub_prog_node = prog_node.start("COFF Flush", 0);
sub_prog_node.activate();
const sub_prog_node = prog_node.start("COFF Flush", 0);
defer sub_prog_node.end();
const module = comp.module orelse return error.LinkingWithoutZigSourceUnimplemented;
+2 -4
View File
@@ -16,7 +16,7 @@ const Allocator = mem.Allocator;
const Coff = @import("../Coff.zig");
const Compilation = @import("../../Compilation.zig");
pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node) !void {
pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: std.Progress.Node) !void {
const tracy = trace(@src());
defer tracy.end();
@@ -38,9 +38,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node)
}
} else null;
var sub_prog_node = prog_node.start("LLD Link", 0);
sub_prog_node.activate();
sub_prog_node.context.refresh();
const sub_prog_node = prog_node.start("LLD Link", 0);
defer sub_prog_node.end();
const is_lib = comp.config.output_mode == .Lib;
+5 -8
View File
@@ -1064,7 +1064,7 @@ pub fn markDirty(self: *Elf, shdr_index: u32) void {
}
}
pub fn flush(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flush(self: *Elf, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
const use_lld = build_options.have_llvm and self.base.comp.config.use_lld;
if (use_lld) {
return self.linkWithLLD(arena, prog_node);
@@ -1072,7 +1072,7 @@ pub fn flush(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) link.F
try self.flushModule(arena, prog_node);
}
pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flushModule(self: *Elf, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
const tracy = trace(@src());
defer tracy.end();
@@ -1085,8 +1085,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node)
if (use_lld) return;
}
var sub_prog_node = prog_node.start("ELF Flush", 0);
sub_prog_node.activate();
const sub_prog_node = prog_node.start("ELF Flush", 0);
defer sub_prog_node.end();
const target = comp.root_mod.resolved_target.result;
@@ -2147,7 +2146,7 @@ fn scanRelocs(self: *Elf) !void {
}
}
fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !void {
fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: std.Progress.Node) !void {
const tracy = trace(@src());
defer tracy.end();
@@ -2169,9 +2168,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
}
} else null;
var sub_prog_node = prog_node.start("LLD Link", 0);
sub_prog_node.activate();
sub_prog_node.context.refresh();
const sub_prog_node = prog_node.start("LLD Link", 0);
defer sub_prog_node.end();
const output_mode = comp.config.output_mode;
+3 -4
View File
@@ -360,11 +360,11 @@ pub fn deinit(self: *MachO) void {
self.unwind_records.deinit(gpa);
}
pub fn flush(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flush(self: *MachO, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
try self.flushModule(arena, prog_node);
}
pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flushModule(self: *MachO, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
const tracy = trace(@src());
defer tracy.end();
@@ -375,8 +375,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node
try self.base.emitLlvmObject(arena, llvm_object, prog_node);
}
var sub_prog_node = prog_node.start("MachO Flush", 0);
sub_prog_node.activate();
const sub_prog_node = prog_node.start("MachO Flush", 0);
defer sub_prog_node.end();
const directory = self.base.emit.directory;
+2 -2
View File
@@ -106,11 +106,11 @@ pub fn freeDecl(self: *NvPtx, decl_index: InternPool.DeclIndex) void {
return self.llvm_object.freeDecl(decl_index);
}
pub fn flush(self: *NvPtx, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flush(self: *NvPtx, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
return self.flushModule(arena, prog_node);
}
pub fn flushModule(self: *NvPtx, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flushModule(self: *NvPtx, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
if (build_options.skip_non_native)
@panic("Attempted to compile for architecture that was disabled by build configuration");
+3 -4
View File
@@ -604,7 +604,7 @@ fn allocateGotIndex(self: *Plan9) usize {
}
}
pub fn flush(self: *Plan9, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flush(self: *Plan9, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
const comp = self.base.comp;
const use_lld = build_options.have_llvm and comp.config.use_lld;
assert(!use_lld);
@@ -663,7 +663,7 @@ fn atomCount(self: *Plan9) usize {
return data_decl_count + fn_decl_count + unnamed_const_count + lazy_atom_count + extern_atom_count + anon_atom_count;
}
pub fn flushModule(self: *Plan9, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flushModule(self: *Plan9, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
if (build_options.skip_non_native and builtin.object_format != .plan9) {
@panic("Attempted to compile for object format that was disabled by build configuration");
}
@@ -677,8 +677,7 @@ pub fn flushModule(self: *Plan9, arena: Allocator, prog_node: *std.Progress.Node
const tracy = trace(@src());
defer tracy.end();
var sub_prog_node = prog_node.start("Flush Module", 0);
sub_prog_node.activate();
const sub_prog_node = prog_node.start("Flush Module", 0);
defer sub_prog_node.end();
log.debug("flushModule", .{});
+5 -6
View File
@@ -193,11 +193,11 @@ pub fn freeDecl(self: *SpirV, decl_index: InternPool.DeclIndex) void {
_ = decl_index;
}
pub fn flush(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flush(self: *SpirV, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
return self.flushModule(arena, prog_node);
}
pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
if (build_options.skip_non_native) {
@panic("Attempted to compile for architecture that was disabled by build configuration");
}
@@ -205,8 +205,7 @@ pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node
const tracy = trace(@src());
defer tracy.end();
var sub_prog_node = prog_node.start("Flush Module", 0);
sub_prog_node.activate();
const sub_prog_node = prog_node.start("Flush Module", 0);
defer sub_prog_node.end();
const spv = &self.object.spv;
@@ -253,7 +252,7 @@ pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node
const module = try spv.finalize(arena, target);
errdefer arena.free(module);
const linked_module = self.linkModule(arena, module, &sub_prog_node) catch |err| switch (err) {
const linked_module = self.linkModule(arena, module, sub_prog_node) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
else => |other| {
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
try self.base.file.?.writeAll(std.mem.sliceAsBytes(linked_module));
}
fn linkModule(self: *SpirV, a: Allocator, module: []Word, progress: *std.Progress.Node) ![]Word {
fn linkModule(self: *SpirV, a: Allocator, module: []Word, progress: std.Progress.Node) ![]Word {
_ = self;
const lower_invocation_globals = @import("SpirV/lower_invocation_globals.zig");
+2 -3
View File
@@ -418,9 +418,8 @@ const EntityHashContext = struct {
}
};
pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: *std.Progress.Node) !void {
var sub_node = progress.start("deduplicate", 0);
sub_node.activate();
pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: std.Progress.Node) !void {
const sub_node = progress.start("deduplicate", 0);
defer sub_node.end();
var arena = std.heap.ArenaAllocator.init(parser.a);
+2 -3
View File
@@ -682,9 +682,8 @@ const ModuleBuilder = struct {
}
};
pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: *std.Progress.Node) !void {
var sub_node = progress.start("Lower invocation globals", 6);
sub_node.activate();
pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: std.Progress.Node) !void {
const sub_node = progress.start("Lower invocation globals", 6);
defer sub_node.end();
var arena = std.heap.ArenaAllocator.init(parser.a);
+2 -3
View File
@@ -255,9 +255,8 @@ fn removeIdsFromMap(a: Allocator, map: anytype, info: ModuleInfo, alive_marker:
}
}
pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: *std.Progress.Node) !void {
var sub_node = progress.start("Prune unused IDs", 0);
sub_node.activate();
pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: std.Progress.Node) !void {
const sub_node = progress.start("Prune unused IDs", 0);
defer sub_node.end();
var arena = std.heap.ArenaAllocator.init(parser.a);
+5 -8
View File
@@ -2464,7 +2464,7 @@ fn appendDummySegment(wasm: *Wasm) !void {
});
}
pub fn flush(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flush(wasm: *Wasm, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
const comp = wasm.base.comp;
const use_lld = build_options.have_llvm and comp.config.use_lld;
@@ -2475,7 +2475,7 @@ pub fn flush(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) link.
}
/// Uses the in-house linker to link one or multiple object -and archive files into a WebAssembly binary.
pub fn flushModule(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void {
pub fn flushModule(wasm: *Wasm, arena: Allocator, prog_node: std.Progress.Node) link.File.FlushError!void {
const tracy = trace(@src());
defer tracy.end();
@@ -2486,8 +2486,7 @@ pub fn flushModule(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node)
if (use_lld) return;
}
var sub_prog_node = prog_node.start("Wasm Flush", 0);
sub_prog_node.activate();
const sub_prog_node = prog_node.start("Wasm Flush", 0);
defer sub_prog_node.end();
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 {
}
}
fn linkWithLLD(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) !void {
fn linkWithLLD(wasm: *Wasm, arena: Allocator, prog_node: std.Progress.Node) !void {
const tracy = trace(@src());
defer tracy.end();
@@ -3350,9 +3349,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) !vo
}
} else null;
var sub_prog_node = prog_node.start("LLD Link", 0);
sub_prog_node.activate();
sub_prog_node.context.refresh();
const sub_prog_node = prog_node.start("LLD Link", 0);
defer sub_prog_node.end();
const is_obj = comp.config.output_mode == .Obj;
+15 -135
View File
@@ -4028,22 +4028,7 @@ fn serve(
var child_pid: ?std.process.Child.Id = null;
var progress: std.Progress = .{
.terminal = null,
.root = .{
.context = undefined,
.parent = null,
.name = "",
.unprotected_estimated_total_items = 0,
.unprotected_completed_items = 0,
},
.columns_written = 0,
.prev_refresh_timestamp = 0,
.timer = null,
.done = false,
};
const main_progress_node = &progress.root;
main_progress_node.context = &progress;
const main_progress_node = std.Progress.start(.{});
while (true) {
const hdr = try server.receiveMessage();
@@ -4051,7 +4036,6 @@ fn serve(
switch (hdr.tag) {
.exit => return cleanExit(),
.update => {
assert(main_progress_node.recently_updated_child == null);
tracy.frameMark();
if (arg_mode == .translate_c) {
@@ -4075,21 +4059,7 @@ fn serve(
try comp.makeBinFileWritable();
}
if (builtin.single_threaded) {
try comp.update(main_progress_node);
} else {
var reset: std.Thread.ResetEvent = .{};
var progress_thread = try std.Thread.spawn(.{}, progressThread, .{
&progress, &server, &reset,
});
defer {
reset.set();
progress_thread.join();
}
try comp.update(main_progress_node);
}
try comp.update(main_progress_node);
try comp.makeBinFileExecutable();
try serveUpdateResults(&server, comp);
@@ -4116,7 +4086,6 @@ fn serve(
},
.hot_update => {
tracy.frameMark();
assert(main_progress_node.recently_updated_child == null);
if (child_pid) |pid| {
try comp.hotCodeSwap(main_progress_node, pid);
try serveUpdateResults(&server, comp);
@@ -4146,63 +4115,6 @@ fn serve(
}
}
fn progressThread(progress: *std.Progress, server: *const Server, reset: *std.Thread.ResetEvent) void {
while (true) {
if (reset.timedWait(500 * std.time.ns_per_ms)) |_| {
// The Compilation update has completed.
return;
} else |err| switch (err) {
error.Timeout => {},
}
var buf: std.BoundedArray(u8, 160) = .{};
{
progress.update_mutex.lock();
defer progress.update_mutex.unlock();
var need_ellipse = false;
var maybe_node: ?*std.Progress.Node = &progress.root;
while (maybe_node) |node| {
if (need_ellipse) {
buf.appendSlice("... ") catch {};
}
need_ellipse = false;
const eti = @atomicLoad(usize, &node.unprotected_estimated_total_items, .monotonic);
const completed_items = @atomicLoad(usize, &node.unprotected_completed_items, .monotonic);
const current_item = completed_items + 1;
if (node.name.len != 0 or eti > 0) {
if (node.name.len != 0) {
buf.appendSlice(node.name) catch {};
need_ellipse = true;
}
if (eti > 0) {
if (need_ellipse) buf.appendSlice(" ") catch {};
buf.writer().print("[{d}/{d}] ", .{ current_item, eti }) catch {};
need_ellipse = false;
} else if (completed_items != 0) {
if (need_ellipse) buf.appendSlice(" ") catch {};
buf.writer().print("[{d}] ", .{current_item}) catch {};
need_ellipse = false;
}
}
maybe_node = @atomicLoad(?*std.Progress.Node, &node.recently_updated_child, .acquire);
}
}
const progress_string = buf.slice();
server.serveMessage(.{
.tag = .progress,
.bytes_len = @as(u32, @intCast(progress_string.len)),
}, &.{
progress_string,
}) catch |err| {
fatal("unable to write to client: {s}", .{@errorName(err)});
};
}
}
fn serveUpdateResults(s: *Server, comp: *Compilation) !void {
const gpa = comp.gpa;
var error_bundle = try comp.getAllErrorsAlloc();
@@ -4472,19 +4384,10 @@ fn runOrTestHotSwap(
fn updateModule(comp: *Compilation, color: Color) !void {
{
// If the terminal is dumb, we dont want to show the user all the output.
var progress: std.Progress = .{ .dont_print_on_dumb = true };
const main_progress_node = progress.start("", 0);
const main_progress_node = std.Progress.start(.{
.disable_printing = color == .off,
});
defer main_progress_node.end();
switch (color) {
.off => {
progress.terminal = null;
},
.on => {
progress.terminal = std.io.getStdErr();
progress.supports_ansi_escape_codes = true;
},
.auto => {},
}
try comp.update(main_progress_node);
}
@@ -4736,8 +4639,6 @@ const usage_build =
;
fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
var progress: std.Progress = .{ .dont_print_on_dumb = true };
var build_file: ?[]const u8 = null;
var override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena);
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 {
config,
);
} else {
const root_prog_node = progress.start("Fetch Packages", 0);
const root_prog_node = std.Progress.start(.{
.root_name = "Fetch Packages",
});
defer root_prog_node.end();
var job_queue: Package.Fetch.JobQueue = .{
@@ -5473,38 +5376,14 @@ fn jitCmd(
};
defer comp.destroy();
if (options.server and !builtin.single_threaded) {
var reset: std.Thread.ResetEvent = .{};
var progress: std.Progress = .{
.terminal = null,
.root = .{
.context = undefined,
.parent = null,
.name = "",
.unprotected_estimated_total_items = 0,
.unprotected_completed_items = 0,
},
.columns_written = 0,
.prev_refresh_timestamp = 0,
.timer = null,
.done = false,
};
const main_progress_node = &progress.root;
main_progress_node.context = &progress;
if (options.server) {
const main_progress_node = std.Progress.start(.{});
var server = std.zig.Server{
.out = std.io.getStdOut(),
.in = undefined, // won't be receiving messages
.receive_fifo = undefined, // won't be receiving messages
};
var progress_thread = try std.Thread.spawn(.{}, progressThread, .{
&progress, &server, &reset,
});
defer {
reset.set();
progress_thread.join();
}
try comp.update(main_progress_node);
var error_bundle = try comp.getAllErrorsAlloc();
@@ -6963,8 +6842,9 @@ fn cmdFetch(
try http_client.initDefaultProxies(arena);
var progress: std.Progress = .{ .dont_print_on_dumb = true };
const root_prog_node = progress.start("Fetch", 0);
var root_prog_node = std.Progress.start(.{
.root_name = "Fetch",
});
defer root_prog_node.end();
var global_cache_directory: Compilation.Directory = l: {
@@ -7028,8 +6908,8 @@ fn cmdFetch(
const hex_digest = Package.Manifest.hexDigest(fetch.actual_hash);
progress.done = true;
progress.refresh();
root_prog_node.end();
root_prog_node = .{ .index = .none };
const name = switch (save) {
.no => {
+3 -3
View File
@@ -16,7 +16,7 @@ pub const CRTFile = enum {
mingw32_lib,
};
pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progress.Node) !void {
pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: std.Progress.Node) !void {
if (!build_options.have_llvm) {
return error.ZigCompilerNotBuiltWithLLVMExtensions;
}
@@ -234,8 +234,8 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
const include_dir = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", "def-include" });
if (comp.verbose_cc) print: {
std.debug.getStderrMutex().lock();
defer std.debug.getStderrMutex().unlock();
std.debug.lockStdErr();
defer std.debug.unlockStdErr();
const stderr = std.io.getStdErr().writer();
nosuspend stderr.print("def file: {s}\n", .{def_file_path}) catch break :print;
nosuspend stderr.print("include dir: {s}\n", .{include_dir}) catch break :print;
+1 -1
View File
@@ -19,7 +19,7 @@ pub const CRTFile = enum {
libc_so,
};
pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progress.Node) !void {
pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: std.Progress.Node) !void {
if (!build_options.have_llvm) {
return error.ZigCompilerNotBuiltWithLLVMExtensions;
}
+1 -1
View File
@@ -57,7 +57,7 @@ pub fn execModelCrtFileFullName(wasi_exec_model: std.builtin.WasiExecModel) []co
};
}
pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progress.Node) !void {
pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: std.Progress.Node) !void {
if (!build_options.have_llvm) {
return error.ZigCompilerNotBuiltWithLLVMExtensions;
}