authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-05-27 09:44:20+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-05-28 09:03:09+01:00
log98165680582b4d592adb0a057ae2e00d74922e61
treed33abfab2654d270b5dad3655fa426c253c61d2c
parent3f1dead2fc5922b588fbfb108f421ca957d6934a
signaturelock-open Commit is signed but in an unrecognized format.

compiler: make Tracy integration more useful


12 files changed, 302 insertions(+), 537 deletions(-)

build.zig+25-26
......@@ -181,10 +181,10 @@ pub fn build(b: *std.Build) !void {
181181 return;
182182
183183 const entitlements = b.option([]const u8, "entitlements", "Path to entitlements file for hot-code swapping without sudo on macOS");
184 const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
185 const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null);
186 const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null);
187 const tracy_callstack_depth: u32 = b.option(u32, "tracy-callstack-depth", "Declare callstack depth for Tracy data. Does nothing if -Dtracy_callstack is not provided") orelse 10;
184 const tracy = b.option(std.Build.LazyPath, "tracy", "Enable Tracy integration. Supply path to Tracy source");
185 const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided. Has a significant performance impact in some cases. Default: false") orelse false;
186 const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided. Default: true") orelse (tracy != null);
187 const tracy_callstack_depth: u32 = b.option(u32, "tracy-callstack-depth", "Declare callstack depth for Tracy data. Does nothing if -Dtracy-callstack is not provided") orelse 6;
188188 const debug_gpa = b.option(bool, "debug-allocator", "Force the compiler to use SafeAllocator") orelse false;
189189 const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse (enable_llvm or only_c);
190190 const sanitize_thread = b.option(bool, "sanitize-thread", "Enable thread-sanitization") orelse false;
......@@ -373,32 +373,31 @@ pub fn build(b: *std.Build) !void {
373373 exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
374374 exe_options.addOption(u32, "tracy_callstack_depth", tracy_callstack_depth);
375375 exe_options.addOption(bool, "value_tracing", value_tracing);
376 if (tracy) |tracy_path| {
377 const client_cpp = b.pathJoin(
378 &[_][]const u8{ tracy_path, "public", "TracyClient.cpp" },
379 );
380
381 const tracy_c_flags: []const []const u8 = &.{
382 "-DTRACY_ENABLE=1",
383 "-fno-sanitize=undefined",
384 "-DTRACY_FIBERS",
385 };
386
387 exe.root_module.addIncludePath(.{ .cwd_relative = tracy_path });
388 exe.root_module.addCSourceFile(.{
389 .file = .{ .cwd_relative = client_cpp },
390 .flags = tracy_c_flags[0..switch (io_mode) {
391 .threaded => 2,
392 .evented => 3,
393 }],
376 if (tracy) |tracy_dir| {
377 const tracy_mod = b.createModule(.{
378 .target = target,
379 // Always build Tracy in ReleaseFast so that it doesn't make Debug compiler builds unusable.
380 .optimize = .ReleaseFast,
381 .root_source_file = null,
382 .link_libc = true,
383 .link_libcpp = true,
394384 });
395 exe.root_module.link_libc = true;
396 exe.root_module.link_libcpp = true;
385
386 tracy_mod.addCMacro("TRACY_ENABLE", "1");
387
388 if (!tracy_callstack) {
389 tracy_mod.addCMacro("TRACY_NO_CALLSTACK", "1");
390 }
391
392 tracy_mod.addIncludePath(tracy_dir);
393 tracy_mod.addCSourceFile(.{ .file = tracy_dir.path(b, "public/TracyClient.cpp") });
397394
398395 if (target.result.os.tag == .windows) {
399 exe.root_module.linkSystemLibrary("dbghelp", .{});
400 exe.root_module.linkSystemLibrary("ws2_32", .{});
396 tracy_mod.linkSystemLibrary("dbghelp", .{});
397 tracy_mod.linkSystemLibrary("ws2_32", .{});
401398 }
399
400 exe.root_module.addImport("tracy", tracy_mod);
402401 }
403402
404403 const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match any filter") orelse &[0][]const u8{};
src/Air/Liveness.zig+2-2
......@@ -13,7 +13,7 @@ const Log2Int = std.math.Log2Int;
1313const Writer = std.Io.Writer;
1414
1515const Liveness = @This();
16const trace = @import("../tracy.zig").trace;
16const traceNamed = @import("../tracy.zig").traceNamed;
1717const Air = @import("../Air.zig");
1818const InternPool = @import("../InternPool.zig");
1919const Zcu = @import("../Zcu.zig");
......@@ -140,7 +140,7 @@ fn LivenessPassData(comptime pass: LivenessPass) type {
140140}
141141
142142pub fn analyze(zcu: *Zcu, air: Air, intern_pool: *InternPool) Allocator.Error!Liveness {
143 const tracy = trace(@src());
143 const tracy = traceNamed(@src(), "analyze_liveness");
144144 defer tracy.end();
145145
146146 const gpa = zcu.gpa;
src/Compilation.zig+2-2
......@@ -2870,8 +2870,8 @@ pub const UpdateError = error{
28702870
28712871/// Detect changes to source files, perform semantic analysis, and update the output files.
28722872pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateError!void {
2873 const tracy_trace = trace(@src());
2874 defer tracy_trace.end();
2873 const tracy_frame = tracy.namedFrame(comp.root_name);
2874 defer tracy_frame.end();
28752875
28762876 const gpa = comp.gpa;
28772877 const io = comp.io;
src/Sema.zig-287
......@@ -19,7 +19,6 @@ const Type = @import("Type.zig");
1919const Air = @import("Air.zig");
2020const Zir = std.zig.Zir;
2121const Zcu = @import("Zcu.zig");
22const trace = @import("tracy.zig").trace;
2322const Namespace = Zcu.Namespace;
2423const CompileError = Zcu.CompileError;
2524const SemaError = Zcu.SemaError;
......@@ -1127,8 +1126,6 @@ fn analyzeBodyInner(
11271126 block: *Block,
11281127 body: []const Zir.Inst.Index,
11291128) CompileError!void {
1130 // No tracy calls here, to avoid interfering with the tail call mechanism.
1131
11321129 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, body);
11331130
11341131 const pt = sema.pt;
......@@ -3002,9 +2999,6 @@ fn zirErrorSetDecl(
30022999 sema: *Sema,
30033000 inst: Zir.Inst.Index,
30043001) CompileError!Air.Inst.Ref {
3005 const tracy = trace(@src());
3006 defer tracy.end();
3007
30083002 const pt = sema.pt;
30093003 const zcu = pt.zcu;
30103004 const comp = zcu.comp;
......@@ -3032,9 +3026,6 @@ fn zirErrorSetDecl(
30323026}
30333027
30343028fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3035 const tracy = trace(@src());
3036 defer tracy.end();
3037
30383029 const pt = sema.pt;
30393030 const zcu = pt.zcu;
30403031
......@@ -3061,18 +3052,12 @@ fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
30613052}
30623053
30633054fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3064 const tracy = trace(@src());
3065 defer tracy.end();
3066
30673055 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
30683056 const operand = sema.resolveInst(inst_data.operand);
30693057 return sema.analyzeRef(block, block.tokenOffset(inst_data.src_tok), operand, .none);
30703058}
30713059
30723060fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
3073 const tracy = trace(@src());
3074 defer tracy.end();
3075
30763061 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
30773062 const operand = sema.resolveInst(inst_data.operand);
30783063 const src = block.nodeOffset(inst_data.src_node);
......@@ -3114,9 +3099,6 @@ fn ensureResultUsed(
31143099}
31153100
31163101fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
3117 const tracy = trace(@src());
3118 defer tracy.end();
3119
31203102 const pt = sema.pt;
31213103 const zcu = pt.zcu;
31223104 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
......@@ -3139,9 +3121,6 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
31393121}
31403122
31413123fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
3142 const tracy = trace(@src());
3143 defer tracy.end();
3144
31453124 const pt = sema.pt;
31463125 const zcu = pt.zcu;
31473126 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
......@@ -3166,9 +3145,6 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
31663145}
31673146
31683147fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3169 const tracy = trace(@src());
3170 defer tracy.end();
3171
31723148 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
31733149 const src = block.nodeOffset(inst_data.src_node);
31743150 const object = sema.resolveInst(inst_data.operand);
......@@ -3302,9 +3278,6 @@ fn zirAllocExtended(
33023278}
33033279
33043280fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3305 const tracy = trace(@src());
3306 defer tracy.end();
3307
33083281 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
33093282 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
33103283 const var_src = block.nodeOffset(inst_data.src_node);
......@@ -3732,9 +3705,6 @@ fn zirAllocInferredComptime(
37323705}
37333706
37343707fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3735 const tracy = trace(@src());
3736 defer tracy.end();
3737
37383708 const pt = sema.pt;
37393709 const zcu = pt.zcu;
37403710
......@@ -3764,9 +3734,6 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
37643734}
37653735
37663736fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3767 const tracy = trace(@src());
3768 defer tracy.end();
3769
37703737 const pt = sema.pt;
37713738 const zcu = pt.zcu;
37723739
......@@ -3797,9 +3764,6 @@ fn zirAllocInferred(
37973764 block: *Block,
37983765 is_const: bool,
37993766) CompileError!Air.Inst.Ref {
3800 const tracy = trace(@src());
3801 defer tracy.end();
3802
38033767 const gpa = sema.gpa;
38043768
38053769 if (block.isComptime()) {
......@@ -3830,9 +3794,6 @@ fn zirAllocInferred(
38303794}
38313795
38323796fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3833 const tracy = trace(@src());
3834 defer tracy.end();
3835
38363797 const pt = sema.pt;
38373798 const zcu = pt.zcu;
38383799 const gpa = sema.gpa;
......@@ -4391,9 +4352,6 @@ fn zirValidatePtrStructInit(
43914352 block: *Block,
43924353 inst: Zir.Inst.Index,
43934354) CompileError!void {
4394 const tracy = trace(@src());
4395 defer tracy.end();
4396
43974355 const pt = sema.pt;
43984356 const zcu = pt.zcu;
43994357 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -4776,9 +4734,6 @@ pub fn addDeclaredHereNote(sema: *Sema, parent: *Zcu.ErrorMsg, decl_ty: Type) !v
47764734}
47774735
47784736fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
4779 const tracy = trace(@src());
4780 defer tracy.end();
4781
47824737 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
47834738 const src = block.nodeOffset(pl_node.src_node);
47844739 const bin = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
......@@ -4870,9 +4825,6 @@ fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
48704825}
48714826
48724827fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
4873 const tracy = trace(@src());
4874 defer tracy.end();
4875
48764828 const zir_tags = sema.code.instructions.items(.tag);
48774829 const zir_datas = sema.code.instructions.items(.data);
48784830 const inst_data = zir_datas[@intFromEnum(inst)].pl_node;
......@@ -4935,8 +4887,6 @@ fn uavRef(sema: *Sema, val: Value) CompileError!Air.Inst.Ref {
49354887
49364888fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
49374889 _ = block;
4938 const tracy = trace(@src());
4939 defer tracy.end();
49404890
49414891 const int = sema.code.instructions.items(.data)[@intFromEnum(inst)].int;
49424892 return sema.pt.intRef(.comptime_int, int);
......@@ -4944,8 +4894,6 @@ fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
49444894
49454895fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
49464896 _ = block;
4947 const tracy = trace(@src());
4948 defer tracy.end();
49494897
49504898 const int = sema.code.instructions.items(.data)[@intFromEnum(inst)].str;
49514899 const byte_count = int.len * @sizeOf(std.math.big.Limb);
......@@ -4981,9 +4929,6 @@ fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
49814929}
49824930
49834931fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
4984 const tracy = trace(@src());
4985 defer tracy.end();
4986
49874932 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
49884933 const src = block.nodeOffset(inst_data.src_node);
49894934 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
......@@ -5111,9 +5056,6 @@ fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
51115056}
51125057
51135058fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
5114 const tracy = trace(@src());
5115 defer tracy.end();
5116
51175059 const pt = sema.pt;
51185060 const zcu = pt.zcu;
51195061 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -5202,9 +5144,6 @@ fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) Comp
52025144}
52035145
52045146fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
5205 const tracy = trace(@src());
5206 defer tracy.end();
5207
52085147 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
52095148 const src = parent_block.nodeOffset(pl_node.src_node);
52105149 const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index);
......@@ -5326,9 +5265,6 @@ fn resolveAnalyzedBlock(
53265265 merges: *Block.Merges,
53275266 need_debug_scope: bool,
53285267) CompileError!Air.Inst.Ref {
5329 const tracy = trace(@src());
5330 defer tracy.end();
5331
53325268 const gpa = sema.gpa;
53335269 const pt = sema.pt;
53345270 const zcu = pt.zcu;
......@@ -5540,9 +5476,6 @@ fn resolveAnalyzedBlock(
55405476}
55415477
55425478fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
5543 const tracy = trace(@src());
5544 defer tracy.end();
5545
55465479 const pt = sema.pt;
55475480 const zcu = pt.zcu;
55485481 const ip = &zcu.intern_pool;
......@@ -5713,9 +5646,6 @@ fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
57135646}
57145647
57155648fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError!void {
5716 const tracy = trace(@src());
5717 defer tracy.end();
5718
57195649 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"break";
57205650 const extra = sema.code.extraData(Zir.Inst.Break, inst_data.payload_index).data;
57215651 const operand = sema.resolveInst(inst_data.operand);
......@@ -5746,9 +5676,6 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError
57465676}
57475677
57485678fn zirSwitchContinue(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError!void {
5749 const tracy = trace(@src());
5750 defer tracy.end();
5751
57525679 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"break";
57535680 const extra = sema.code.extraData(Zir.Inst.Break, inst_data.payload_index).data;
57545681 const operand_src = start_block.nodeOffset(extra.operand_src_node.unwrap().?);
......@@ -6139,9 +6066,6 @@ fn zirCall(
61396066 inst: Zir.Inst.Index,
61406067 comptime kind: enum { direct, field },
61416068) CompileError!Air.Inst.Ref {
6142 const tracy = trace(@src());
6143 defer tracy.end();
6144
61456069 const pt = sema.pt;
61466070 const zcu = pt.zcu;
61476071 const comp = zcu.comp;
......@@ -7376,9 +7300,6 @@ fn zirIntType(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
73767300}
73777301
73787302fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7379 const tracy = trace(@src());
7380 defer tracy.end();
7381
73827303 const pt = sema.pt;
73837304 const zcu = pt.zcu;
73847305 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
......@@ -7469,9 +7390,6 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
74697390}
74707391
74717392fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7472 const tracy = trace(@src());
7473 defer tracy.end();
7474
74757393 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
74767394 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
74777395 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
......@@ -7488,9 +7406,6 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
74887406}
74897407
74907408fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7491 const tracy = trace(@src());
7492 defer tracy.end();
7493
74947409 const pt = sema.pt;
74957410 const zcu = pt.zcu;
74967411 const comp = zcu.comp;
......@@ -7534,9 +7449,6 @@ fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src:
75347449}
75357450
75367451fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7537 const tracy = trace(@src());
7538 defer tracy.end();
7539
75407452 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
75417453 if (true) {
75427454 return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node));
......@@ -7550,9 +7462,6 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
75507462}
75517463
75527464fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7553 const tracy = trace(@src());
7554 defer tracy.end();
7555
75567465 const pt = sema.pt;
75577466 const zcu = pt.zcu;
75587467 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -7613,9 +7522,6 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
76137522}
76147523
76157524fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
7616 const tracy = trace(@src());
7617 defer tracy.end();
7618
76197525 const pt = sema.pt;
76207526 const zcu = pt.zcu;
76217527 const ip = &zcu.intern_pool;
......@@ -7655,9 +7561,6 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
76557561}
76567562
76577563fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
7658 const tracy = trace(@src());
7659 defer tracy.end();
7660
76617564 const pt = sema.pt;
76627565 const zcu = pt.zcu;
76637566 const io = zcu.comp.io;
......@@ -7702,9 +7605,6 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
77027605}
77037606
77047607fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7705 const tracy = trace(@src());
7706 defer tracy.end();
7707
77087608 const pt = sema.pt;
77097609 const zcu = pt.zcu;
77107610 const ip = &zcu.intern_pool;
......@@ -7759,8 +7659,6 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
77597659
77607660fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
77617661 _ = block;
7762 const tracy = trace(@src());
7763 defer tracy.end();
77647662
77657663 const pt = sema.pt;
77667664 const zcu = pt.zcu;
......@@ -7776,9 +7674,6 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
77767674}
77777675
77787676fn zirDeclLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index, do_coerce: bool) CompileError!Air.Inst.Ref {
7779 const tracy = trace(@src());
7780 defer tracy.end();
7781
77827677 const pt = sema.pt;
77837678 const zcu = pt.zcu;
77847679 const comp = zcu.comp;
......@@ -7960,9 +7855,6 @@ fn zirOptionalPayloadPtr(
79607855 inst: Zir.Inst.Index,
79617856 safety_check: bool,
79627857) CompileError!Air.Inst.Ref {
7963 const tracy = trace(@src());
7964 defer tracy.end();
7965
79667858 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
79677859 const optional_ptr = sema.resolveInst(inst_data.operand);
79687860 const src = block.nodeOffset(inst_data.src_node);
......@@ -8051,9 +7943,6 @@ fn zirOptionalPayload(
80517943 inst: Zir.Inst.Index,
80527944 safety_check: bool,
80537945) CompileError!Air.Inst.Ref {
8054 const tracy = trace(@src());
8055 defer tracy.end();
8056
80577946 const pt = sema.pt;
80587947 const zcu = pt.zcu;
80597948 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
......@@ -8105,9 +7994,6 @@ fn zirErrUnionPayload(
81057994 block: *Block,
81067995 inst: Zir.Inst.Index,
81077996) CompileError!Air.Inst.Ref {
8108 const tracy = trace(@src());
8109 defer tracy.end();
8110
81117997 const pt = sema.pt;
81127998 const zcu = pt.zcu;
81137999 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
......@@ -8164,9 +8050,6 @@ fn zirErrUnionPayloadPtr(
81648050 block: *Block,
81658051 inst: Zir.Inst.Index,
81668052) CompileError!Air.Inst.Ref {
8167 const tracy = trace(@src());
8168 defer tracy.end();
8169
81708053 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
81718054 const operand = sema.resolveInst(inst_data.operand);
81728055 const src = block.nodeOffset(inst_data.src_node);
......@@ -8256,9 +8139,6 @@ fn analyzeErrUnionPayloadPtr(
82568139
82578140/// Value in, value out
82588141fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8259 const tracy = trace(@src());
8260 defer tracy.end();
8261
82628142 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
82638143 const src = block.nodeOffset(inst_data.src_node);
82648144 const operand = sema.resolveInst(inst_data.operand);
......@@ -8292,9 +8172,6 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air
82928172
82938173/// Pointer in, value out
82948174fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8295 const tracy = trace(@src());
8296 defer tracy.end();
8297
82988175 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
82998176 const src = block.nodeOffset(inst_data.src_node);
83008177 const operand = sema.resolveInst(inst_data.operand);
......@@ -9088,9 +8965,6 @@ fn zirParamAnytype(
90888965}
90898966
90908967fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9091 const tracy = trace(@src());
9092 defer tracy.end();
9093
90948968 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
90958969 const src = block.nodeOffset(inst_data.src_node);
90968970 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
......@@ -9098,9 +8972,6 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
90988972}
90998973
91008974fn zirAsShiftOperand(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9101 const tracy = trace(@src());
9102 defer tracy.end();
9103
91048975 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
91058976 const src = block.nodeOffset(inst_data.src_node);
91068977 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
......@@ -9136,9 +9007,6 @@ fn analyzeAs(
91369007}
91379008
91389009fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9139 const tracy = trace(@src());
9140 defer tracy.end();
9141
91429010 const pt = sema.pt;
91439011 const zcu = pt.zcu;
91449012 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
......@@ -9193,9 +9061,6 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
91939061}
91949062
91959063fn zirFieldPtrLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9196 const tracy = trace(@src());
9197 defer tracy.end();
9198
91999064 const pt = sema.pt;
92009065 const zcu = pt.zcu;
92019066 const comp = zcu.comp;
......@@ -9218,9 +9083,6 @@ fn zirFieldPtrLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
92189083}
92199084
92209085fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9221 const tracy = trace(@src());
9222 defer tracy.end();
9223
92249086 const pt = sema.pt;
92259087 const zcu = pt.zcu;
92269088 const comp = zcu.comp;
......@@ -9243,9 +9105,6 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
92439105}
92449106
92459107fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9246 const tracy = trace(@src());
9247 defer tracy.end();
9248
92499108 const pt = sema.pt;
92509109 const zcu = pt.zcu;
92519110 const comp = zcu.comp;
......@@ -9276,9 +9135,6 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
92769135}
92779136
92789137fn zirFieldPtrNamedLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9279 const tracy = trace(@src());
9280 defer tracy.end();
9281
92829138 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
92839139 const src = block.nodeOffset(inst_data.src_node);
92849140 const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
......@@ -9289,9 +9145,6 @@ fn zirFieldPtrNamedLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
92899145}
92909146
92919147fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9292 const tracy = trace(@src());
9293 defer tracy.end();
9294
92959148 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
92969149 const src = block.nodeOffset(inst_data.src_node);
92979150 const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
......@@ -9302,9 +9155,6 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
93029155}
93039156
93049157fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9305 const tracy = trace(@src());
9306 defer tracy.end();
9307
93089158 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
93099159 const src = block.nodeOffset(inst_data.src_node);
93109160 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
......@@ -9375,9 +9225,6 @@ fn intCast(
93759225}
93769226
93779227fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9378 const tracy = trace(@src());
9379 defer tracy.end();
9380
93819228 const pt = sema.pt;
93829229 const zcu = pt.zcu;
93839230 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -9541,9 +9388,6 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
95419388}
95429389
95439390fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9544 const tracy = trace(@src());
9545 defer tracy.end();
9546
95479391 const pt = sema.pt;
95489392 const zcu = pt.zcu;
95499393 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -9609,9 +9453,6 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
96099453}
96109454
96119455fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9612 const tracy = trace(@src());
9613 defer tracy.end();
9614
96159456 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
96169457 const src = block.nodeOffset(inst_data.src_node);
96179458 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -9621,9 +9462,6 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
96219462}
96229463
96239464fn zirElemPtrLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9624 const tracy = trace(@src());
9625 defer tracy.end();
9626
96279465 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
96289466 const src = block.nodeOffset(inst_data.src_node);
96299467 const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node });
......@@ -9643,9 +9481,6 @@ fn zirElemPtrLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
96439481}
96449482
96459483fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9646 const tracy = trace(@src());
9647 defer tracy.end();
9648
96499484 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
96509485 const array = sema.resolveInst(inst_data.operand);
96519486 const elem_index = try sema.pt.intRef(.usize, inst_data.idx);
......@@ -9653,9 +9488,6 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
96539488}
96549489
96559490fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9656 const tracy = trace(@src());
9657 defer tracy.end();
9658
96599491 const pt = sema.pt;
96609492 const zcu = pt.zcu;
96619493 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -9684,9 +9516,6 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
96849516}
96859517
96869518fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9687 const tracy = trace(@src());
9688 defer tracy.end();
9689
96909519 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
96919520 const src = block.nodeOffset(inst_data.src_node);
96929521 const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node });
......@@ -9698,9 +9527,6 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
96989527}
96999528
97009529fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9701 const tracy = trace(@src());
9702 defer tracy.end();
9703
97049530 const pt = sema.pt;
97059531 const zcu = pt.zcu;
97069532 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -9719,9 +9545,6 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
97199545}
97209546
97219547fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9722 const tracy = trace(@src());
9723 defer tracy.end();
9724
97259548 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
97269549 const src = block.nodeOffset(inst_data.src_node);
97279550 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
......@@ -9735,9 +9558,6 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
97359558}
97369559
97379560fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9738 const tracy = trace(@src());
9739 defer tracy.end();
9740
97419561 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
97429562 const src = block.nodeOffset(inst_data.src_node);
97439563 const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
......@@ -9752,9 +9572,6 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
97529572}
97539573
97549574fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9755 const tracy = trace(@src());
9756 defer tracy.end();
9757
97589575 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
97599576 const src = block.nodeOffset(inst_data.src_node);
97609577 const sentinel_src = block.src(.{ .node_offset_slice_sentinel = inst_data.src_node });
......@@ -9771,9 +9588,6 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
97719588}
97729589
97739590fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9774 const tracy = trace(@src());
9775 defer tracy.end();
9776
97779591 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
97789592 const src = block.nodeOffset(inst_data.src_node);
97799593 const extra = sema.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data;
......@@ -9793,9 +9607,6 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
97939607}
97949608
97959609fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9796 const tracy = trace(@src());
9797 defer tracy.end();
9798
97999610 const pt = sema.pt;
98009611 const zcu = pt.zcu;
98019612
......@@ -9833,9 +9644,6 @@ fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
98339644}
98349645
98359646fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9836 const tracy = trace(@src());
9837 defer tracy.end();
9838
98399647 const pt = sema.pt;
98409648 const zcu = pt.zcu;
98419649 const gpa = sema.gpa;
......@@ -9999,8 +9807,6 @@ fn zirSwitchBlock(
99999807 inst: Zir.Inst.Index,
100009808 operand_is_ref: bool,
100019809) CompileError!Air.Inst.Ref {
10002 const tracy = trace(@src());
10003 defer tracy.end();
100049810 const zir_switch = sema.code.getSwitchBlock(inst);
100059811
100069812 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
......@@ -12847,9 +12653,6 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1284712653}
1284812654
1284912655fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
12850 const tracy = trace(@src());
12851 defer tracy.end();
12852
1285312656 const pt = sema.pt;
1285412657 const zcu = pt.zcu;
1285512658 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
......@@ -12898,9 +12701,6 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1289812701}
1289912702
1290012703fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
12901 const tracy = trace(@src());
12902 defer tracy.end();
12903
1290412704 const pt = sema.pt;
1290512705 const zcu = pt.zcu;
1290612706
......@@ -12935,9 +12735,6 @@ fn zirShl(
1293512735 inst: Zir.Inst.Index,
1293612736 air_tag: Air.Inst.Tag,
1293712737) CompileError!Air.Inst.Ref {
12938 const tracy = trace(@src());
12939 defer tracy.end();
12940
1294112738 const pt = sema.pt;
1294212739 const zcu = pt.zcu;
1294312740 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -13125,9 +12922,6 @@ fn zirShr(
1312512922 inst: Zir.Inst.Index,
1312612923 air_tag: Air.Inst.Tag,
1312712924) CompileError!Air.Inst.Ref {
13128 const tracy = trace(@src());
13129 defer tracy.end();
13130
1313112925 const pt = sema.pt;
1313212926 const zcu = pt.zcu;
1313312927 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -13255,9 +13049,6 @@ fn zirBitwise(
1325513049 inst: Zir.Inst.Index,
1325613050 air_tag: Air.Inst.Tag,
1325713051) CompileError!Air.Inst.Ref {
13258 const tracy = trace(@src());
13259 defer tracy.end();
13260
1326113052 const pt = sema.pt;
1326213053 const zcu = pt.zcu;
1326313054 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -13438,9 +13229,6 @@ fn analyzeTupleCat(
1343813229}
1343913230
1344013231fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
13441 const tracy = trace(@src());
13442 defer tracy.end();
13443
1344413232 const pt = sema.pt;
1344513233 const zcu = pt.zcu;
1344613234 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -13933,9 +13721,6 @@ fn zirArithmetic(
1393313721 zir_tag: Zir.Inst.Tag,
1393413722 safety: bool,
1393513723) CompileError!Air.Inst.Ref {
13936 const tracy = trace(@src());
13937 defer tracy.end();
13938
1393913724 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1394013725 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
1394113726 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
......@@ -14663,9 +14448,6 @@ fn zirOverflowArithmetic(
1466314448 extended: Zir.Inst.Extended.InstData,
1466414449 zir_tag: Zir.Inst.Extended,
1466514450) CompileError!Air.Inst.Ref {
14666 const tracy = trace(@src());
14667 defer tracy.end();
14668
1466914451 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
1467014452 const src = block.nodeOffset(extra.node);
1467114453
......@@ -15183,9 +14965,6 @@ fn analyzePtrArithmetic(
1518314965}
1518414966
1518514967fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15186 const tracy = trace(@src());
15187 defer tracy.end();
15188
1518914968 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1519014969 const src = block.nodeOffset(inst_data.src_node);
1519114970 const ptr_src = src; // TODO better source location
......@@ -15199,9 +14978,6 @@ fn zirAsm(
1519914978 extended: Zir.Inst.Extended.InstData,
1520014979 tmpl_is_expr: bool,
1520114980) CompileError!Air.Inst.Ref {
15202 const tracy = trace(@src());
15203 defer tracy.end();
15204
1520514981 const pt = sema.pt;
1520614982 const zcu = pt.zcu;
1520714983 const comp = zcu.comp;
......@@ -15393,9 +15169,6 @@ fn zirCmpEq(
1539315169 op: std.math.CompareOperator,
1539415170 air_tag: Air.Inst.Tag,
1539515171) CompileError!Air.Inst.Ref {
15396 const tracy = trace(@src());
15397 defer tracy.end();
15398
1539915172 const pt = sema.pt;
1540015173 const zcu = pt.zcu;
1540115174 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -15509,9 +15282,6 @@ fn zirCmp(
1550915282 inst: Zir.Inst.Index,
1551015283 op: std.math.CompareOperator,
1551115284) CompileError!Air.Inst.Ref {
15512 const tracy = trace(@src());
15513 defer tracy.end();
15514
1551515285 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1551615286 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1551715287 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
......@@ -15852,9 +15622,6 @@ fn zirBuiltinSrc(
1585215622 block: *Block,
1585315623 extended: Zir.Inst.Extended.InstData,
1585415624) CompileError!Air.Inst.Ref {
15855 const tracy = trace(@src());
15856 defer tracy.end();
15857
1585815625 const pt = sema.pt;
1585915626 const zcu = pt.zcu;
1586015627 const comp = zcu.comp;
......@@ -17181,9 +16948,6 @@ fn zirTypeofPeer(
1718116948 extended: Zir.Inst.Extended.InstData,
1718216949 inst: Zir.Inst.Index,
1718316950) CompileError!Air.Inst.Ref {
17184 const tracy = trace(@src());
17185 defer tracy.end();
17186
1718716951 const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);
1718816952 const src = block.nodeOffset(extra.data.src_node);
1718916953 const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len);
......@@ -17249,9 +17013,6 @@ fn zirBoolBr(
1724917013 inst: Zir.Inst.Index,
1725017014 is_bool_or: bool,
1725117015) CompileError!Air.Inst.Ref {
17252 const tracy = trace(@src());
17253 defer tracy.end();
17254
1725517016 const pt = sema.pt;
1725617017 const zcu = pt.zcu;
1725717018 const gpa = sema.gpa;
......@@ -17418,9 +17179,6 @@ fn zirIsNonNull(
1741817179 block: *Block,
1741917180 inst: Zir.Inst.Index,
1742017181) CompileError!Air.Inst.Ref {
17421 const tracy = trace(@src());
17422 defer tracy.end();
17423
1742417182 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1742517183 const src = block.nodeOffset(inst_data.src_node);
1742617184 const operand = sema.resolveInst(inst_data.operand);
......@@ -17433,9 +17191,6 @@ fn zirIsNonNullPtr(
1743317191 block: *Block,
1743417192 inst: Zir.Inst.Index,
1743517193) CompileError!Air.Inst.Ref {
17436 const tracy = trace(@src());
17437 defer tracy.end();
17438
1743917194 const pt = sema.pt;
1744017195 const zcu = pt.zcu;
1744117196 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
......@@ -17472,9 +17227,6 @@ fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
1747217227}
1747317228
1747417229fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
17475 const tracy = trace(@src());
17476 defer tracy.end();
17477
1747817230 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1747917231 const src = block.nodeOffset(inst_data.src_node);
1748017232 const operand = sema.resolveInst(inst_data.operand);
......@@ -17483,9 +17235,6 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1748317235}
1748417236
1748517237fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
17486 const tracy = trace(@src());
17487 defer tracy.end();
17488
1748917238 const pt = sema.pt;
1749017239 const zcu = pt.zcu;
1749117240 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
......@@ -17500,9 +17249,6 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1750017249}
1750117250
1750217251fn zirRetIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
17503 const tracy = trace(@src());
17504 defer tracy.end();
17505
1750617252 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1750717253 const src = block.nodeOffset(inst_data.src_node);
1750817254 const operand = sema.resolveInst(inst_data.operand);
......@@ -17514,9 +17260,6 @@ fn zirCondbr(
1751417260 parent_block: *Block,
1751517261 inst: Zir.Inst.Index,
1751617262) CompileError!void {
17517 const tracy = trace(@src());
17518 defer tracy.end();
17519
1752017263 const pt = sema.pt;
1752117264 const zcu = pt.zcu;
1752217265 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -17866,9 +17609,6 @@ fn zirRetImplicit(
1786617609 block: *Block,
1786717610 inst: Zir.Inst.Index,
1786817611) CompileError!void {
17869 const tracy = trace(@src());
17870 defer tracy.end();
17871
1787217612 const pt = sema.pt;
1787317613 const zcu = pt.zcu;
1787417614 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
......@@ -17913,9 +17653,6 @@ fn zirRetImplicit(
1791317653}
1791417654
1791517655fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
17916 const tracy = trace(@src());
17917 defer tracy.end();
17918
1791917656 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1792017657 const operand = sema.resolveInst(inst_data.operand);
1792117658 const src = block.nodeOffset(inst_data.src_node);
......@@ -17924,9 +17661,6 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
1792417661}
1792517662
1792617663fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
17927 const tracy = trace(@src());
17928 defer tracy.end();
17929
1793017664 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1793117665 const src = block.nodeOffset(inst_data.src_node);
1793217666 const ret_ptr = sema.resolveInst(inst_data.operand);
......@@ -18071,9 +17805,6 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, extended: Zir.Inst.Ex
1807117805/// its state at the point `block` was reached (or, if `block` is `none`, the
1807217806/// point this function began execution).
1807317807fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_block: Zir.Inst.Ref, operand_zir: Zir.Inst.Ref) CompileError!void {
18074 const tracy = trace(@src());
18075 defer tracy.end();
18076
1807717808 const pt = sema.pt;
1807817809 const zcu = pt.zcu;
1807917810
......@@ -18229,9 +17960,6 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool {
1822917960}
1823017961
1823117962fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
18232 const tracy = trace(@src());
18233 defer tracy.end();
18234
1823517963 const pt = sema.pt;
1823617964 const zcu = pt.zcu;
1823717965 const comp = zcu.comp;
......@@ -18361,9 +18089,6 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1836118089}
1836218090
1836318091fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
18364 const tracy = trace(@src());
18365 defer tracy.end();
18366
1836718092 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1836818093 const src = block.nodeOffset(inst_data.src_node);
1836918094 const ty_src = block.src(.{ .node_offset_init_ty = inst_data.src_node });
......@@ -18382,9 +18107,6 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
1838218107}
1838318108
1838418109fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_byref: bool) CompileError!Air.Inst.Ref {
18385 const tracy = trace(@src());
18386 defer tracy.end();
18387
1838818110 const pt = sema.pt;
1838918111 const zcu = pt.zcu;
1839018112 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
......@@ -19622,9 +19344,6 @@ fn zirUnaryMath(
1962219344 air_tag: Air.Inst.Tag,
1962319345 comptime eval: fn (Value, Type, Allocator, Zcu.PerThread) Allocator.Error!Value,
1962419346) CompileError!Air.Inst.Ref {
19625 const tracy = trace(@src());
19626 defer tracy.end();
19627
1962819347 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1962919348 const operand = sema.resolveInst(inst_data.operand);
1963019349 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
......@@ -23441,9 +23160,6 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2344123160}
2344223161
2344323162fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23444 const tracy = trace(@src());
23445 defer tracy.end();
23446
2344723163 const pt = sema.pt;
2344823164 const zcu = pt.zcu;
2344923165 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -24489,9 +24205,6 @@ fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2448924205}
2449024206
2449124207fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
24492 const tracy = trace(@src());
24493 defer tracy.end();
24494
2449524208 const pt = sema.pt;
2449624209 const zcu = pt.zcu;
2449724210 const comp = zcu.comp;
src/Sema/type_resolution.zig+21
......@@ -13,6 +13,7 @@ const LazySrcLoc = Zcu.LazySrcLoc;
1313const InternPool = @import("../InternPool.zig");
1414const Alignment = InternPool.Alignment;
1515const arith = @import("arith.zig");
16const trace = @import("../tracy.zig").trace;
1617
1718pub const LayoutResolveReason = enum {
1819 variable,
......@@ -174,6 +175,11 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
174175 const gpa = comp.gpa;
175176 const ip = &zcu.intern_pool;
176177
178 const tracy = trace(@src());
179 defer tracy.end();
180 tracy.addText(struct_ty.containerTypeName(ip).toSlice(ip));
181 tracy.addTextFmt("ip_index={d}", .{struct_ty.toIntern()});
182
177183 assert(sema.owner.unwrap().type_layout == struct_ty.toIntern());
178184
179185 const struct_obj = ip.loadStructType(struct_ty.toIntern());
......@@ -548,6 +554,11 @@ pub fn resolveStructDefaults(sema: *Sema, struct_ty: Type) CompileError!void {
548554 const gpa = comp.gpa;
549555 const ip = &zcu.intern_pool;
550556
557 const tracy = trace(@src());
558 defer tracy.end();
559 tracy.addText(struct_ty.containerTypeName(ip).toSlice(ip));
560 tracy.addTextFmt("ip_index={d}", .{struct_ty.toIntern()});
561
551562 assert(sema.owner.unwrap().struct_defaults == struct_ty.toIntern());
552563
553564 // We always depend on the layout of `struct_ty`. However, we don't actually need to resolve it
......@@ -655,6 +666,11 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
655666 const gpa = comp.gpa;
656667 const ip = &zcu.intern_pool;
657668
669 const tracy = trace(@src());
670 defer tracy.end();
671 tracy.addText(union_ty.containerTypeName(ip).toSlice(ip));
672 tracy.addTextFmt("ip_index={d}", .{union_ty.toIntern()});
673
658674 assert(sema.owner.unwrap().type_layout == union_ty.toIntern());
659675
660676 const union_obj = ip.loadUnionType(union_ty.toIntern());
......@@ -1134,6 +1150,11 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {
11341150 const gpa = comp.gpa;
11351151 const ip = &zcu.intern_pool;
11361152
1153 const tracy = trace(@src());
1154 defer tracy.end();
1155 tracy.addText(enum_ty.containerTypeName(ip).toSlice(ip));
1156 tracy.addTextFmt("ip_index={d}", .{enum_ty.toIntern()});
1157
11371158 assert(sema.owner.unwrap().type_layout == enum_ty.toIntern());
11381159
11391160 const enum_obj = ip.loadEnumType(enum_ty.toIntern());
src/Zcu.zig+52-3
......@@ -29,7 +29,7 @@ const Package = @import("Package.zig");
2929const link = @import("link.zig");
3030const Air = @import("Air.zig");
3131const Zir = std.zig.Zir;
32const trace = @import("tracy.zig").trace;
32const tracy = @import("tracy.zig");
3333const AstGen = std.zig.AstGen;
3434const Sema = @import("Sema.zig");
3535const target_util = @import("target.zig");
......@@ -2811,6 +2811,7 @@ pub const CompileError = error{
28112811
28122812pub fn init(zcu: *Zcu, gpa: Allocator, io: Io, thread_count: usize) !void {
28132813 try zcu.intern_pool.init(gpa, io, thread_count);
2814 zcu.initTracyPlots();
28142815}
28152816
28162817pub fn deinit(zcu: *Zcu) void {
......@@ -3161,12 +3162,15 @@ pub fn markDependeeOutdated(
31613162 try zcu.markTransitiveDependersPotentiallyOutdated(depender);
31623163 }
31633164 }
3165
3166 zcu.updateTracyOutdatedPlots();
31643167}
31653168
31663169pub fn markPoDependeeUpToDate(zcu: *Zcu, dependee: InternPool.Dependee) !void {
31673170 if (std.debug.runtime_safety) zcu.outdated_lock.lockUncancelable(zcu.comp.io);
31683171 defer if (std.debug.runtime_safety) zcu.outdated_lock.unlock(zcu.comp.io);
3169 return markPoDependeeUpToDateInner(zcu, dependee);
3172 try markPoDependeeUpToDateInner(zcu, dependee);
3173 zcu.updateTracyOutdatedPlots();
31703174}
31713175/// Assumes that `zcu.outdated_lock` is already held exclusively.
31723176fn markPoDependeeUpToDateInner(zcu: *Zcu, dependee: InternPool.Dependee) !void {
......@@ -3304,6 +3308,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?AnalUnit {
33043308 // Everything is up-to-date. There could be lingering entries in `zcu.potentially_outdated`
33053309 // from a dependency loop on a previous update.
33063310 zcu.potentially_outdated.clearRetainingCapacity();
3311 zcu.updateTracyOutdatedPlots();
33073312 log.debug("findOutdatedToAnalyze: all up-to-date", .{});
33083313 return null;
33093314 }
......@@ -3337,6 +3342,7 @@ pub fn flushRetryableFailures(zcu: *Zcu) !void {
33373342 try zcu.markTransitiveDependersPotentiallyOutdated(depender);
33383343 }
33393344 zcu.retryable_failures.clearRetainingCapacity();
3345 zcu.updateTracyOutdatedPlots();
33403346}
33413347
33423348pub fn mapOldZirToNew(
......@@ -3580,6 +3586,7 @@ pub fn ensureFuncBodyAnalysisQueued(zcu: *Zcu, func: InternPool.Index) !void {
35803586 try zcu.outdated_ready.funcs.ensureUnusedCapacity(gpa, 1);
35813587 zcu.outdated.putAssumeCapacityNoClobber(.wrap(.{ .func = func }), 0);
35823588 zcu.outdated_ready.funcs.putAssumeCapacityNoClobber(func, {});
3589 zcu.updateTracyOutdatedPlots();
35833590 }
35843591}
35853592
......@@ -3598,6 +3605,7 @@ pub fn ensureNavValAnalysisQueued(zcu: *Zcu, nav: InternPool.Nav.Index) !void {
35983605 zcu.outdated.putAssumeCapacityNoClobber(.wrap(.{ .nav_ty = nav }), 0);
35993606 zcu.outdated_ready.other.putAssumeCapacityNoClobber(.wrap(.{ .nav_val = nav }), {});
36003607 zcu.outdated_ready.other.putAssumeCapacityNoClobber(.wrap(.{ .nav_ty = nav }), {});
3608 zcu.updateTracyOutdatedPlots();
36013609 }
36023610}
36033611
......@@ -3614,6 +3622,7 @@ pub fn queueComptimeUnitAnalysis(zcu: *Zcu, cu: InternPool.ComptimeUnit.Id) Allo
36143622 try zcu.outdated_ready.other.ensureUnusedCapacity(gpa, 1);
36153623 zcu.outdated.putAssumeCapacityNoClobber(unit, 0);
36163624 zcu.outdated_ready.other.putAssumeCapacityNoClobber(unit, {});
3625 zcu.updateTracyOutdatedPlots();
36173626}
36183627
36193628/// If `unit` was marked as outdated or porentially outdated, clears that status and returns `true`.
......@@ -3632,8 +3641,10 @@ pub fn clearOutdatedState(zcu: *Zcu, unit: AnalUnit) bool {
36323641 } else {
36333642 assert(!was_ready);
36343643 }
3644 zcu.updateTracyOutdatedPlots();
36353645 return true;
36363646 } else if (zcu.potentially_outdated.swapRemove(unit)) {
3647 zcu.updateTracyOutdatedPlots();
36373648 return true;
36383649 } else {
36393650 return false;
......@@ -4164,6 +4175,9 @@ pub fn resolveReferences(zcu: *Zcu) Allocator.Error!*const std.AutoArrayHashMapU
41644175 return &zcu.resolved_references.?;
41654176}
41664177fn resolveReferencesInner(zcu: *Zcu) Allocator.Error!std.AutoArrayHashMapUnmanaged(AnalUnit, ?ResolvedReference) {
4178 const trace = tracy.trace(@src());
4179 defer trace.end();
4180
41674181 const gpa = zcu.gpa;
41684182 const comp = zcu.comp;
41694183 const ip = &zcu.intern_pool;
......@@ -5265,6 +5279,7 @@ pub const CodegenTaskPool = struct {
52655279 mir.deinit(zcu);
52665280 }
52675281 assert(pool.available_air_bytes == max_air_bytes_in_flight);
5282 zcu.updateTracyPlot("air_bytes_in_flight", 0);
52685283 }
52695284
52705285 pub fn start(
......@@ -5298,6 +5313,12 @@ pub const CodegenTaskPool = struct {
52985313 }
52995314
53005315 pool.available_air_bytes -= effective_air_bytes;
5316
5317 zcu.updateTracyPlot("air_bytes_in_flight", @max(
5318 max_air_bytes_in_flight - pool.available_air_bytes,
5319 actual_air_bytes,
5320 ));
5321
53015322 break :index pool.free.pop().?;
53025323 };
53035324
......@@ -5326,8 +5347,9 @@ pub const CodegenTaskPool = struct {
53265347 pub fn wait(
53275348 index: Index,
53285349 pool: *CodegenTaskPool,
5329 io: Io,
5350 zcu: *const Zcu,
53305351 ) PerThread.RunCodegenError!struct { InternPool.Index, codegen.AnyMir } {
5352 const io = zcu.comp.io;
53315353 const func = pool.task_funcs[@intFromEnum(index)];
53325354 assert(func != .none);
53335355 const effective_air_bytes = pool.task_air_bytes[@intFromEnum(index)];
......@@ -5343,6 +5365,7 @@ pub const CodegenTaskPool = struct {
53435365 pool.available_air_bytes += effective_air_bytes;
53445366 pool.free.appendAssumeCapacity(index);
53455367 pool.free_cond.signal(io);
5368 zcu.updateTracyPlot("air_bytes_in_flight", max_air_bytes_in_flight - pool.available_air_bytes);
53465369 }
53475370
53485371 return .{ func, try result };
......@@ -5376,3 +5399,29 @@ pub const CodegenTaskPool = struct {
53765399 return pt.runCodegen(func_index, air);
53775400 }
53785401};
5402
5403fn initTracyPlots(zcu: *const Zcu) void {
5404 if (zcu.comp.skip_linker_dependencies) return;
5405
5406 tracy.plotConfig("air_bytes_in_flight", .{ .format = .memory, .mode = .step });
5407
5408 tracy.plotConfig("outdated + potentially_outdated", .{ .format = .number, .mode = .step, .color = 0xFFFF00 });
5409 tracy.plotConfig("outdated", .{ .format = .number, .mode = .step, .color = 0xFF0000 });
5410 tracy.plotConfig("potentially_outdated", .{ .format = .number, .mode = .step, .color = 0xFF7700 });
5411 tracy.plotConfig("outdated_ready", .{ .format = .number, .mode = .step, .color = 0x00FF00 });
5412}
5413
5414/// Marked `inline` to prevent binary bloat from trivial generic instances, and to ensure there is
5415/// minimal overhead to this call when Tracy is disabled, even in Debug builds.
5416inline fn updateTracyPlot(zcu: *const Zcu, comptime name: [*:0]const u8, val: u64) void {
5417 if (zcu.comp.skip_linker_dependencies) return;
5418 tracy.plotInt(name, @intCast(val));
5419}
5420
5421/// Assumes that `zcu.outdated_lock` is already held.
5422fn updateTracyOutdatedPlots(zcu: *const Zcu) void {
5423 zcu.updateTracyPlot("outdated + potentially_outdated", zcu.outdated.count() + zcu.potentially_outdated.count());
5424 zcu.updateTracyPlot("outdated", zcu.outdated.count());
5425 zcu.updateTracyPlot("potentially_outdated", zcu.potentially_outdated.count());
5426 zcu.updateTracyPlot("outdated_ready", zcu.outdated_ready.funcs.count() + zcu.outdated_ready.other.count());
5427}
src/Zcu/PerThread.zig+52-36
......@@ -313,18 +313,22 @@ pub fn update(
313313 // `comptime` declarations, any declarations marked `export`, and `test` declarations in the
314314 // main module if this is a test compilation---become referenced, and so will be picked up
315315 // up by the main semantic analysis loop below.
316 for (zcu.analysisRoots()) |analysis_root_mod| {
317 const analysis_root_file = zcu.module_roots.get(analysis_root_mod).?.unwrap().?;
318 try pt.ensureFilePopulated(analysis_root_file);
316 {
317 const tracy_trace = traceNamed(@src(), "populate_sema_roots");
318 defer tracy_trace.end();
319 for (zcu.analysisRoots()) |analysis_root_mod| {
320 const analysis_root_file = zcu.module_roots.get(analysis_root_mod).?.unwrap().?;
321 try pt.ensureFilePopulated(analysis_root_file);
322 }
319323 }
320324
325 const tracy_trace = traceNamed(@src(), "sema_loop");
326 defer tracy_trace.end();
327
321328 // This is the main semantic analysis loop, which is essentially the main loop of the whole
322329 // Zig compilation pipeline. It selects some `AnalUnit` which we know needs to be analyzed,
323330 // and analyzes it, which may in turn discover more `AnalUnit`s which we need to analyze.
324331 while (try zcu.findOutdatedToAnalyze()) |unit| {
325 const tracy_trace = traceNamed(@src(), "analyze_outdated");
326 defer tracy_trace.end();
327
328332 const maybe_err: Zcu.SemaError!void = switch (unit.unwrap()) {
329333 .@"comptime" => |cu| pt.ensureComptimeUnitUpToDate(cu),
330334 .nav_ty => |nav| pt.ensureNavTypeUpToDate(nav, null),
......@@ -823,6 +827,9 @@ fn updateZirRefs(pt: Zcu.PerThread) (Io.Cancelable || Allocator.Error)!void {
823827 const gpa = comp.gpa;
824828 const io = comp.io;
825829
830 const tracy_trace = trace(@src());
831 defer tracy_trace.end();
832
826833 // We need to visit every updated File for every TrackedInst in InternPool.
827834 // This only includes Zig files; ZON files are omitted.
828835 var updated_files: std.AutoArrayHashMapUnmanaged(Zcu.File.Index, UpdatedFile) = .empty;
......@@ -1008,9 +1015,6 @@ fn updateZirRefs(pt: Zcu.PerThread) (Io.Cancelable || Allocator.Error)!void {
10081015pub fn ensureFilePopulated(pt: Zcu.PerThread, file_index: Zcu.File.Index) (Allocator.Error || Io.Cancelable)!void {
10091016 dev.check(.sema);
10101017
1011 const tracy_trace = trace(@src());
1012 defer tracy_trace.end();
1013
10141018 const zcu = pt.zcu;
10151019 const comp = zcu.comp;
10161020 const io = comp.io;
......@@ -1019,6 +1023,9 @@ pub fn ensureFilePopulated(pt: Zcu.PerThread, file_index: Zcu.File.Index) (Alloc
10191023
10201024 if (zcu.fileRootType(file_index) != .none) return; // already good
10211025
1026 const tracy_trace = traceNamed(@src(), "create_file_struct");
1027 defer tracy_trace.end();
1028
10221029 if (zcu.comp.time_report) |*tr| tr.stats.n_imported_files += 1;
10231030
10241031 const file = zcu.fileByIndex(file_index);
......@@ -1065,9 +1072,6 @@ pub fn ensureMemoizedStateUpToDate(
10651072 /// `null` is valid only for the "root" analysis, i.e. called from `Compilation.processOneJob`.
10661073 reason: ?*const Zcu.DependencyReason,
10671074) Zcu.SemaError!void {
1068 const tracy_trace = trace(@src());
1069 defer tracy_trace.end();
1070
10711075 const zcu = pt.zcu;
10721076 const gpa = zcu.gpa;
10731077
......@@ -1142,6 +1146,10 @@ fn analyzeMemoizedState(
11421146
11431147 log.debug("analyzeMemoizedState({t})", .{stage});
11441148
1149 const tracy_trace = trace(@src());
1150 defer tracy_trace.end();
1151 tracy_trace.addText(@tagName(stage));
1152
11451153 const unit: AnalUnit = .wrap(.{ .memoized_state = stage });
11461154
11471155 try zcu.analysis_in_progress.putNoClobber(gpa, unit, reason);
......@@ -1174,9 +1182,6 @@ fn analyzeMemoizedState(
11741182/// if necessary. Returns `error.AnalysisFail` if an analysis error is encountered; the caller is
11751183/// free to ignore this, since the error is already registered.
11761184pub fn ensureComptimeUnitUpToDate(pt: Zcu.PerThread, cu_id: InternPool.ComptimeUnit.Id) Zcu.SemaError!void {
1177 const tracy_trace = trace(@src());
1178 defer tracy_trace.end();
1179
11801185 const zcu = pt.zcu;
11811186 const gpa = zcu.gpa;
11821187
......@@ -1257,6 +1262,10 @@ fn analyzeComptimeUnit(pt: Zcu.PerThread, cu_id: InternPool.ComptimeUnit.Id) Zcu
12571262
12581263 log.debug("analyzeComptimeUnit {f}", .{zcu.fmtAnalUnit(anal_unit)});
12591264
1265 const tracy_trace = trace(@src());
1266 defer tracy_trace.end();
1267 tracy_trace.addTextFmt("cu_id={d}", .{cu_id});
1268
12601269 const inst_resolved = comptime_unit.zir_index.resolveFull(ip) orelse return error.AnalysisFail;
12611270 const file = zcu.fileByIndex(inst_resolved.file);
12621271 const zir = file.zir.?;
......@@ -1333,9 +1342,6 @@ pub fn ensureTypeLayoutUpToDate(
13331342 /// `null` is valid only for the "root" analysis, i.e. called from `Compilation.processOneJob`.
13341343 reason: ?*const Zcu.DependencyReason,
13351344) Zcu.SemaError!void {
1336 const tracy_trace = trace(@src());
1337 defer tracy_trace.end();
1338
13391345 const zcu = pt.zcu;
13401346 const ip = &zcu.intern_pool;
13411347 const comp = zcu.comp;
......@@ -1464,9 +1470,6 @@ pub fn ensureStructDefaultsUpToDate(
14641470 /// `null` is valid only for the "root" analysis, i.e. called from `Compilation.processOneJob`.
14651471 reason: ?*const Zcu.DependencyReason,
14661472) Zcu.SemaError!void {
1467 const tracy_trace = trace(@src());
1468 defer tracy_trace.end();
1469
14701473 const zcu = pt.zcu;
14711474 const ip = &zcu.intern_pool;
14721475 const comp = zcu.comp;
......@@ -1572,9 +1575,6 @@ pub fn ensureNavValUpToDate(
15721575 /// `null` is valid only for the "root" analysis, i.e. called from `Compilation.processOneJob`.
15731576 reason: ?*const Zcu.DependencyReason,
15741577) Zcu.SemaError!void {
1575 const tracy_trace = trace(@src());
1576 defer tracy_trace.end();
1577
15781578 const zcu = pt.zcu;
15791579 const gpa = zcu.gpa;
15801580 const ip = &zcu.intern_pool;
......@@ -1677,6 +1677,11 @@ fn analyzeNavVal(
16771677
16781678 log.debug("analyzeNavVal {f}", .{zcu.fmtAnalUnit(anal_unit)});
16791679
1680 const tracy_trace = trace(@src());
1681 defer tracy_trace.end();
1682 tracy_trace.addText(old_nav.fqn.toSlice(ip));
1683 tracy_trace.addTextFmt("nav_id={d}", .{nav_id});
1684
16801685 const inst_resolved = old_nav.analysis.?.zir_index.resolveFull(ip) orelse return error.AnalysisFail;
16811686 const file = zcu.fileByIndex(inst_resolved.file);
16821687 const zir = file.zir.?;
......@@ -1939,9 +1944,6 @@ pub fn ensureNavTypeUpToDate(
19391944 /// `null` is valid only for the "root" analysis, i.e. called from `Compilation.processOneJob`.
19401945 reason: ?*const Zcu.DependencyReason,
19411946) Zcu.SemaError!void {
1942 const tracy_trace = trace(@src());
1943 defer tracy_trace.end();
1944
19451947 const zcu = pt.zcu;
19461948 const gpa = zcu.gpa;
19471949 const ip = &zcu.intern_pool;
......@@ -2044,6 +2046,11 @@ fn analyzeNavType(
20442046
20452047 log.debug("analyzeNavType {f}", .{zcu.fmtAnalUnit(anal_unit)});
20462048
2049 const tracy_trace = trace(@src());
2050 defer tracy_trace.end();
2051 tracy_trace.addText(old_nav.fqn.toSlice(ip));
2052 tracy_trace.addTextFmt("nav_id={d}", .{nav_id});
2053
20472054 const inst_resolved = old_nav.analysis.?.zir_index.resolveFull(ip) orelse return error.AnalysisFail;
20482055 const file = zcu.fileByIndex(inst_resolved.file);
20492056 const zir = file.zir.?;
......@@ -2183,9 +2190,6 @@ pub fn ensureFuncBodyUpToDate(
21832190) Zcu.SemaError!void {
21842191 dev.check(.sema);
21852192
2186 const tracy_trace = trace(@src());
2187 defer tracy_trace.end();
2188
21892193 const zcu = pt.zcu;
21902194 const gpa = zcu.gpa;
21912195 const ip = &zcu.intern_pool;
......@@ -2283,6 +2287,11 @@ fn analyzeFuncBody(
22832287
22842288 log.debug("analyzeFuncBody {f}", .{zcu.fmtAnalUnit(anal_unit)});
22852289
2290 const tracy_trace = trace(@src());
2291 defer tracy_trace.end();
2292 tracy_trace.addText(ip.getNav(func.owner_nav).fqn.toSlice(ip));
2293 tracy_trace.addTextFmt("func_ip_index={d}", .{func_index});
2294
22862295 var air = try pt.analyzeFuncBodyInner(func_index, reason);
22872296 var air_owned = true;
22882297 defer if (air_owned) air.deinit(gpa);
......@@ -2592,6 +2601,9 @@ fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool {
25922601 const comp = zcu.comp;
25932602 const gpa = zcu.gpa;
25942603
2604 const tracy_trace = trace(@src());
2605 defer tracy_trace.end();
2606
25952607 var any_fatal_files = false;
25962608 zcu.multi_module_err = null;
25972609 zcu.failed_imports.clearRetainingCapacity();
......@@ -3028,14 +3040,16 @@ pub fn scanNamespace(
30283040 namespace_index: Zcu.Namespace.Index,
30293041 decls: []const Zir.Inst.Index,
30303042) Allocator.Error!void {
3031 const tracy_trace = trace(@src());
3032 defer tracy_trace.end();
3033
30343043 const zcu = pt.zcu;
30353044 const ip = &zcu.intern_pool;
30363045 const gpa = zcu.gpa;
30373046 const namespace = zcu.namespacePtr(namespace_index);
30383047
3048 const tracy_trace = trace(@src());
3049 defer tracy_trace.end();
3050 tracy_trace.addText(Type.fromInterned(namespace.owner_type).containerTypeName(ip).toSlice(ip));
3051 tracy_trace.addTextFmt("type_ip_index={d}", .{namespace.owner_type});
3052
30393053 const tracked_unit = zcu.trackUnitSema(
30403054 Type.fromInterned(namespace.owner_type).containerTypeName(ip).toSlice(ip),
30413055 null,
......@@ -3247,9 +3261,6 @@ fn analyzeFuncBodyInner(
32473261 func_index: InternPool.Index,
32483262 reason: ?*const Zcu.DependencyReason,
32493263) Zcu.SemaError!Air {
3250 const tracy_trace = trace(@src());
3251 defer tracy_trace.end();
3252
32533264 const zcu = pt.zcu;
32543265 const comp = zcu.comp;
32553266 const gpa = comp.gpa;
......@@ -4556,6 +4567,11 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e
45564567 const codegen_prog_node = zcu.codegen_prog_node.start(fqn.toSlice(ip), 0);
45574568 defer codegen_prog_node.end();
45584569
4570 const tracy_trace = trace(@src());
4571 defer tracy_trace.end();
4572 tracy_trace.addText(fqn.toSlice(ip));
4573 tracy_trace.addTextFmt("func_ip_index={d}", .{func_index});
4574
45594575 if (codegen.legalizeFeatures(pt, nav)) |features| {
45604576 try air.legalize(pt, features);
45614577 }
src/codegen.zig+7
......@@ -186,6 +186,12 @@ pub fn emitFunction(
186186 const zcu = pt.zcu;
187187 const func = zcu.funcInfo(func_index);
188188 const target = &zcu.navFileScope(func.owner_nav).mod.?.resolved_target.result;
189
190 const tracy_trace = trace(@src());
191 defer tracy_trace.end();
192 tracy_trace.addText(zcu.intern_pool.getNav(func.owner_nav).fqn.toSlice(&zcu.intern_pool));
193 tracy_trace.addTextFmt("func_ip_index={d}", .{func_index});
194
189195 switch (target_util.zigBackend(target, zcu.comp.config.use_llvm)) {
190196 else => unreachable,
191197 inline .stage2_aarch64,
......@@ -236,6 +242,7 @@ pub fn generateLazySymbol(
236242) (CodeGenError || std.Io.Writer.Error)!void {
237243 const tracy = trace(@src());
238244 defer tracy.end();
245 tracy.addTextFmt("{t}, {f}", .{ lazy_sym.kind, Type.fromInterned(lazy_sym.ty).fmt(pt) });
239246
240247 const comp = bin_file.comp;
241248 const zcu = pt.zcu;
src/link.zig+1-1
......@@ -1573,7 +1573,7 @@ pub fn doZcuTask(comp: *Compilation, tid: Zcu.PerThread.Id, task: ZcuTask) void
15731573 },
15741574 .link_func => |codegen_task| nav: {
15751575 timer.pause(io);
1576 const func, var mir = codegen_task.wait(&zcu.codegen_task_pool, io) catch |err| switch (err) {
1576 const func, var mir = codegen_task.wait(&zcu.codegen_task_pool, zcu) catch |err| switch (err) {
15771577 error.Canceled, error.AlreadyReported => {
15781578 comp.link_prog_node.completeOne();
15791579 return;
src/link/Elf2.zig+5
......@@ -14,6 +14,7 @@ const InternPool = @import("../InternPool.zig");
1414const link = @import("../link.zig");
1515const MappedFile = @import("MappedFile.zig");
1616const target_util = @import("../target.zig");
17const tracy = @import("../tracy.zig");
1718const Type = @import("../Type.zig");
1819const Value = @import("../Value.zig");
1920const Zcu = @import("../Zcu.zig");
......@@ -5865,6 +5866,8 @@ fn flushFileOffset(elf: *Elf, ni: MappedFile.Node.Index) !void {
58655866}
58665867
58675868fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) !void {
5869 const trace = tracy.trace(@src());
5870 defer trace.end();
58685871 switch (elf.getNode(ni)) {
58695872 .file => unreachable,
58705873 .ehdr, .shdr => try elf.flushFileOffset(ni),
......@@ -6019,6 +6022,8 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) !void {
60196022}
60206023
60216024fn flushResized(elf: *Elf, ni: MappedFile.Node.Index) !void {
6025 const trace = tracy.trace(@src());
6026 defer trace.end();
60226027 _, const size = ni.location(&elf.mf).resolve(&elf.mf);
60236028 switch (elf.getNode(ni)) {
60246029 .file => {},
src/main.zig+2-4
......@@ -218,8 +218,8 @@ pub fn main(init: std.process.Init.Minimal) anyerror!void {
218218 var environ_map = init.environ.createMap(arena) catch |err| fatal("failed to parse environment: {t}", .{err});
219219
220220 if (tracy.enable_allocation) {
221 var gpa_tracy = tracy.tracyAllocator(gpa);
222 return mainArgs(gpa_tracy.allocator(), arena, io, args, &environ_map);
221 var tracy_allocator: tracy.Allocator = .{ .parent_allocator = gpa };
222 return mainArgs(tracy_allocator.interface(), arena, io, args, &environ_map);
223223 }
224224
225225 if (native_os == .wasi) {
......@@ -4239,7 +4239,6 @@ fn serve(
42394239 switch (hdr.tag) {
42404240 .exit => return cleanExit(io),
42414241 .update => {
4242 tracy.frameMark();
42434242 file_system_inputs.clearRetainingCapacity();
42444243
42454244 if (arg_mode == .translate_c) {
......@@ -4296,7 +4295,6 @@ fn serve(
42964295 //);
42974296 },
42984297 .hot_update => {
4299 tracy.frameMark();
43004298 file_system_inputs.clearRetainingCapacity();
43014299 if (child_pid) |pid| {
43024300 try comp.hotCodeSwap(main_progress_node, pid);
src/tracy.zig+133-176
......@@ -1,11 +1,13 @@
11const std = @import("std");
2const assert = std.debug.assert;
3
24const builtin = @import("builtin");
35const build_options = @import("build_options");
46
57pub const enable = if (builtin.is_test) false else build_options.enable_tracy;
68pub const enable_allocation = enable and build_options.enable_tracy_allocation;
79pub const enable_callstack = enable and build_options.enable_tracy_callstack;
8pub const callstack_depth = if (enable_callstack and build_options.tracy_callstack_depth > 0) build_options.tracy_callstack_depth else 10;
10pub const callstack_depth = if (enable_callstack) build_options.tracy_callstack_depth else 0;
911
1012const ___tracy_c_zone_context = extern struct {
1113 id: u32,
......@@ -19,6 +21,12 @@ const ___tracy_c_zone_context = extern struct {
1921 ___tracy_emit_zone_text(self, text.ptr, text.len);
2022 }
2123
24 pub inline fn addTextFmt(self: @This(), comptime fmt: []const u8, args: anytype) void {
25 var buf: [512]u8 = undefined;
26 const slice = std.fmt.bufPrint(&buf, fmt, args) catch &buf;
27 self.addText(slice);
28 }
29
2230 pub inline fn setName(self: @This(), name: []const u8) void {
2331 ___tracy_emit_zone_name(self, name.ptr, name.len);
2432 }
......@@ -42,6 +50,12 @@ pub const Ctx = if (enable) ___tracy_c_zone_context else struct {
4250 _ = text;
4351 }
4452
53 pub inline fn addTextFmt(self: @This(), comptime fmt: []const u8, args: anytype) void {
54 _ = self;
55 _ = fmt;
56 _ = args;
57 }
58
4559 pub inline fn setName(self: @This(), name: []const u8) void {
4660 _ = self;
4761 _ = name;
......@@ -71,11 +85,7 @@ pub inline fn trace(comptime src: std.lang.SourceLocation) Ctx {
7185 };
7286 };
7387
74 if (enable_callstack) {
75 return ___tracy_emit_zone_begin_callstack(&global.loc, callstack_depth, 1);
76 } else {
77 return ___tracy_emit_zone_begin(&global.loc, 1);
78 }
88 return ___tracy_emit_zone_begin_callstack(&global.loc, callstack_depth, 1);
7989}
8090
8191pub inline fn traceNamed(comptime src: std.lang.SourceLocation, comptime name: [:0]const u8) Ctx {
......@@ -91,11 +101,7 @@ pub inline fn traceNamed(comptime src: std.lang.SourceLocation, comptime name: [
91101 };
92102 };
93103
94 if (enable_callstack) {
95 return ___tracy_emit_zone_begin_callstack(&global.loc, callstack_depth, 1);
96 } else {
97 return ___tracy_emit_zone_begin(&global.loc, 1);
98 }
104 return ___tracy_emit_zone_begin_callstack(&global.loc, callstack_depth, 1);
99105}
100106
101107pub inline fn fiberEnter(fiber: [*:0]const u8) void {
......@@ -108,102 +114,93 @@ pub inline fn fiberLeave() void {
108114 ___tracy_fiber_leave();
109115}
110116
111pub fn tracyAllocator(allocator: std.mem.Allocator) TracyAllocator(null) {
112 return TracyAllocator(null).init(allocator);
117pub inline fn plotConfig(comptime name: [*:0]const u8, config: PlotConfig) void {
118 if (!enable) return;
119 ___tracy_emit_plot_config(
120 name,
121 config.format,
122 config.mode,
123 @intFromBool(config.fill),
124 // https://github.com/wolfpld/tracy/issues/1232
125 @byteSwap(config.color),
126 );
113127}
114128
115pub fn TracyAllocator(comptime name: ?[:0]const u8) type {
116 return struct {
117 parent_allocator: std.mem.Allocator,
129pub inline fn plotInt(comptime name: [*:0]const u8, val: i64) void {
130 if (!enable) return;
131 ___tracy_emit_plot_int(name, val);
132}
118133
119 const Self = @This();
134pub const Allocator = struct {
135 parent_allocator: std.mem.Allocator,
120136
121 pub fn init(parent_allocator: std.mem.Allocator) Self {
122 return .{
123 .parent_allocator = parent_allocator,
124 };
125 }
137 comptime {
138 assert(enable); // used `tracy.Allocator` with Tracy disabled
139 }
126140
127 pub fn allocator(self: *Self) std.mem.Allocator {
128 return .{
129 .ptr = self,
130 .vtable = &.{
131 .alloc = allocFn,
132 .resize = resizeFn,
133 .remap = remapFn,
134 .free = freeFn,
135 },
136 };
137 }
141 pub fn interface(self: *Allocator) std.mem.Allocator {
142 return .{
143 .ptr = self,
144 .vtable = &.{
145 .alloc = allocFn,
146 .resize = resizeFn,
147 .remap = remapFn,
148 .free = freeFn,
149 },
150 };
151 }
138152
139 fn allocFn(ptr: *anyopaque, len: usize, alignment: std.mem.Alignment, ret_addr: usize) ?[*]u8 {
140 const self: *Self = @ptrCast(@alignCast(ptr));
141 const result = self.parent_allocator.rawAlloc(len, alignment, ret_addr);
142 if (result) |memory| {
143 if (len != 0) {
144 if (name) |n| {
145 allocNamed(memory, len, n);
146 } else {
147 alloc(memory, len);
148 }
149 }
150 } else {
151 messageColor("allocation failed", 0xFF0000);
152 }
153 return result;
153 fn allocFn(ptr: *anyopaque, len: usize, alignment: std.mem.Alignment, ret_addr: usize) ?[*]u8 {
154 const self: *Allocator = @ptrCast(@alignCast(ptr));
155 assert(len > 0);
156 if (self.parent_allocator.rawAlloc(len, alignment, ret_addr)) |memory| {
157 ___tracy_emit_memory_alloc_callstack(memory, len, callstack_depth, 0);
158 return memory;
159 } else {
160 messageColor("allocation failed", 0xFF0000);
161 return null;
154162 }
163 }
155164
156 fn resizeFn(ptr: *anyopaque, memory: []u8, alignment: std.mem.Alignment, new_len: usize, ret_addr: usize) bool {
157 const self: *Self = @ptrCast(@alignCast(ptr));
158 if (self.parent_allocator.rawResize(memory, alignment, new_len, ret_addr)) {
159 if (name) |n| {
160 freeNamed(memory.ptr, n);
161 allocNamed(memory.ptr, new_len, n);
162 } else {
163 free(memory.ptr);
164 alloc(memory.ptr, new_len);
165 }
166
167 return true;
168 }
169
170 // during normal operation the compiler hits this case thousands of times due to this
171 // emitting messages for it is both slow and causes clutter
165 fn resizeFn(ptr: *anyopaque, memory: []u8, alignment: std.mem.Alignment, new_len: usize, ret_addr: usize) bool {
166 const self: *Allocator = @ptrCast(@alignCast(ptr));
167 assert(memory.len > 0);
168 assert(new_len > 0);
169 // We need to mark the free before calling the implementation to avoid a race.
170 ___tracy_emit_memory_free_callstack(memory.ptr, callstack_depth, 0);
171 if (self.parent_allocator.rawResize(memory, alignment, new_len, ret_addr)) {
172 ___tracy_emit_memory_alloc_callstack(memory.ptr, new_len, callstack_depth, 0);
173 return true;
174 } else {
175 // No `messageColor` call here because this case is hit frequently in normal operation.
176 ___tracy_emit_memory_alloc_callstack(memory.ptr, memory.len, callstack_depth, 0);
172177 return false;
173178 }
179 }
174180
175 fn remapFn(ptr: *anyopaque, memory: []u8, alignment: std.mem.Alignment, new_len: usize, ret_addr: usize) ?[*]u8 {
176 const self: *Self = @ptrCast(@alignCast(ptr));
177 if (self.parent_allocator.rawRemap(memory, alignment, new_len, ret_addr)) |new_memory| {
178 if (name) |n| {
179 freeNamed(memory.ptr, n);
180 allocNamed(new_memory, new_len, n);
181 } else {
182 free(memory.ptr);
183 alloc(new_memory, new_len);
184 }
185 return new_memory;
186 } else {
187 messageColor("reallocation failed", 0xFF0000);
188 return null;
189 }
181 fn remapFn(ptr: *anyopaque, memory: []u8, alignment: std.mem.Alignment, new_len: usize, ret_addr: usize) ?[*]u8 {
182 const self: *Allocator = @ptrCast(@alignCast(ptr));
183 assert(memory.len > 0);
184 assert(new_len > 0);
185 // We need to mark the free before calling the implementation to avoid a race.
186 ___tracy_emit_memory_free_callstack(memory.ptr, callstack_depth, 0);
187 if (self.parent_allocator.rawRemap(memory, alignment, new_len, ret_addr)) |new_memory| {
188 ___tracy_emit_memory_alloc_callstack(new_memory, new_len, callstack_depth, 0);
189 return new_memory;
190 } else {
191 // No `messageColor` call here because this case is hit frequently in normal operation.
192 ___tracy_emit_memory_alloc_callstack(memory.ptr, memory.len, callstack_depth, 0);
193 return null;
190194 }
195 }
191196
192 fn freeFn(ptr: *anyopaque, memory: []u8, alignment: std.mem.Alignment, ret_addr: usize) void {
193 const self: *Self = @ptrCast(@alignCast(ptr));
194 self.parent_allocator.rawFree(memory, alignment, ret_addr);
195 // this condition is to handle free being called on an empty slice that was never even allocated
196 // example case: `std.process.getSelfExeSharedLibPaths` can return `&[_][:0]u8{}`
197 if (memory.len != 0) {
198 if (name) |n| {
199 freeNamed(memory.ptr, n);
200 } else {
201 free(memory.ptr);
202 }
203 }
204 }
205 };
206}
197 fn freeFn(ptr: *anyopaque, memory: []u8, alignment: std.mem.Alignment, ret_addr: usize) void {
198 const self: *Allocator = @ptrCast(@alignCast(ptr));
199 assert(memory.len > 0);
200 ___tracy_emit_memory_free_callstack(memory.ptr, callstack_depth, 0);
201 self.parent_allocator.rawFree(memory, alignment, ret_addr);
202 }
203};
207204
208205// This function only accepts comptime-known strings, see `messageCopy` for runtime strings
209206pub inline fn message(comptime msg: [:0]const u8) void {
......@@ -213,7 +210,7 @@ pub inline fn message(comptime msg: [:0]const u8) void {
213210// This function only accepts comptime-known strings, see `messageColorCopy` for runtime strings
214211pub inline fn messageColor(comptime msg: [:0]const u8, color: u24) void {
215212 if (!enable) return;
216 ___tracy_emit_logStringL(.Info, color, if (enable_callstack) callstack_depth else 0, msg.ptr);
213 ___tracy_emit_logStringL(.Info, color, callstack_depth, msg.ptr);
217214}
218215
219216pub inline fn messageCopy(msg: []const u8) void {
......@@ -222,84 +219,29 @@ pub inline fn messageCopy(msg: []const u8) void {
222219
223220pub inline fn messageColorCopy(msg: []const u8, color: u24) void {
224221 if (!enable) return;
225 ___tracy_emit_logString(.Info, color, if (enable_callstack) callstack_depth else 0, msg.len, msg.ptr);
222 ___tracy_emit_logString(.Info, color, callstack_depth, msg.len, msg.ptr);
226223}
227224
228pub inline fn frameMark() void {
229 if (!enable) return;
230 ___tracy_emit_frame_mark(null);
225/// Used to store strings which Tracy requires to have stable pointers for the program's entire
226/// lifetime. All such strings will be leaked.
227///
228/// The `enable` check ensures that this is not referenced if Tracy is disabled.
229var tracy_arena: std.heap.ArenaAllocator = if (enable) .init(std.heap.page_allocator);
230
231pub inline fn namedFrame(name: []const u8) Frame {
232 if (!enable) return .{ .name = {} };
233 const stable_name = tracy_arena.allocator().dupeSentinel(u8, name, 0) catch @panic("tracy arena OOM");
234 ___tracy_emit_frame_mark_start(stable_name.ptr);
235 return .{ .name = stable_name.ptr };
231236}
232237
233pub inline fn frameMarkNamed(comptime name: [:0]const u8) void {
234 if (!enable) return;
235 ___tracy_emit_frame_mark(name.ptr);
236}
237
238pub inline fn namedFrame(comptime name: [:0]const u8) Frame(name) {
239 frameMarkStart(name);
240 return .{};
241}
242
243pub fn Frame(comptime name: [:0]const u8) type {
244 return struct {
245 pub fn end(_: @This()) void {
246 frameMarkEnd(name);
247 }
248 };
249}
250
251inline fn frameMarkStart(comptime name: [:0]const u8) void {
252 if (!enable) return;
253 ___tracy_emit_frame_mark_start(name.ptr);
254}
255
256inline fn frameMarkEnd(comptime name: [:0]const u8) void {
257 if (!enable) return;
258 ___tracy_emit_frame_mark_end(name.ptr);
259}
260
261extern fn ___tracy_emit_frame_mark_start(name: [*:0]const u8) void;
262extern fn ___tracy_emit_frame_mark_end(name: [*:0]const u8) void;
263
264inline fn alloc(ptr: [*]u8, len: usize) void {
265 if (!enable) return;
266
267 if (enable_callstack) {
268 ___tracy_emit_memory_alloc_callstack(ptr, len, callstack_depth, 0);
269 } else {
270 ___tracy_emit_memory_alloc(ptr, len, 0);
271 }
272}
273
274inline fn allocNamed(ptr: [*]u8, len: usize, comptime name: [:0]const u8) void {
275 if (!enable) return;
276
277 if (enable_callstack) {
278 ___tracy_emit_memory_alloc_callstack_named(ptr, len, callstack_depth, 0, name.ptr);
279 } else {
280 ___tracy_emit_memory_alloc_named(ptr, len, 0, name.ptr);
281 }
282}
283
284inline fn free(ptr: [*]u8) void {
285 if (!enable) return;
286
287 if (enable_callstack) {
288 ___tracy_emit_memory_free_callstack(ptr, callstack_depth, 0);
289 } else {
290 ___tracy_emit_memory_free(ptr, 0);
238pub const Frame = struct {
239 name: if (enable) [*:0]const u8 else void,
240 pub inline fn end(frame: Frame) void {
241 if (!enable) return;
242 ___tracy_emit_frame_mark_end(frame.name);
291243 }
292}
293
294inline fn freeNamed(ptr: [*]u8, comptime name: [:0]const u8) void {
295 if (!enable) return;
296
297 if (enable_callstack) {
298 ___tracy_emit_memory_free_callstack_named(ptr, callstack_depth, 0, name.ptr);
299 } else {
300 ___tracy_emit_memory_free_named(ptr, 0, name.ptr);
301 }
302}
244};
303245
304246pub const MessageSeverity = enum(i8) {
305247 Trace, // Broadly track variable states and events in the software program.
......@@ -310,24 +252,39 @@ pub const MessageSeverity = enum(i8) {
310252 Fatal, // Describes a critical event that will lead to a software failure/crash.
311253};
312254
313extern fn ___tracy_emit_zone_begin(srcloc: *const ___tracy_source_location_data, active: i32) ___tracy_c_zone_context;
255pub const PlotConfig = struct {
256 format: Format,
257 mode: Mode,
258 fill: bool = true,
259 color: u24 = 0,
260
261 pub const Format = enum(i32) {
262 number = 0,
263 memory = 1,
264 percentage = 2,
265 watt = 3,
266 };
267
268 pub const Mode = enum(i32) {
269 line = 0,
270 step = 1,
271 };
272};
273
274extern fn ___tracy_emit_frame_mark_start(name: [*:0]const u8) void;
275extern fn ___tracy_emit_frame_mark_end(name: [*:0]const u8) void;
314276extern fn ___tracy_emit_zone_begin_callstack(srcloc: *const ___tracy_source_location_data, depth: i32, active: i32) ___tracy_c_zone_context;
315277extern fn ___tracy_emit_zone_text(ctx: ___tracy_c_zone_context, txt: [*]const u8, size: usize) void;
316278extern fn ___tracy_emit_zone_name(ctx: ___tracy_c_zone_context, txt: [*]const u8, size: usize) void;
317279extern fn ___tracy_emit_zone_color(ctx: ___tracy_c_zone_context, color: u32) void;
318280extern fn ___tracy_emit_zone_value(ctx: ___tracy_c_zone_context, value: u64) void;
319281extern fn ___tracy_emit_zone_end(ctx: ___tracy_c_zone_context) void;
320extern fn ___tracy_emit_memory_alloc(ptr: *const anyopaque, size: usize, secure: i32) void;
321282extern fn ___tracy_emit_memory_alloc_callstack(ptr: *const anyopaque, size: usize, depth: i32, secure: i32) void;
322extern fn ___tracy_emit_memory_free(ptr: *const anyopaque, secure: i32) void;
323283extern fn ___tracy_emit_memory_free_callstack(ptr: *const anyopaque, depth: i32, secure: i32) void;
324extern fn ___tracy_emit_memory_alloc_named(ptr: *const anyopaque, size: usize, secure: i32, name: [*:0]const u8) void;
325extern fn ___tracy_emit_memory_alloc_callstack_named(ptr: *const anyopaque, size: usize, depth: i32, secure: i32, name: [*:0]const u8) void;
326extern fn ___tracy_emit_memory_free_named(ptr: *const anyopaque, secure: i32, name: [*:0]const u8) void;
327extern fn ___tracy_emit_memory_free_callstack_named(ptr: *const anyopaque, depth: i32, secure: i32, name: [*:0]const u8) void;
328284extern fn ___tracy_emit_logString(severity: MessageSeverity, color: i32, callstack_depth: i32, size: usize, txt: [*]const u8) void;
329285extern fn ___tracy_emit_logStringL(severity: MessageSeverity, color: i32, callstack_depth: i32, txt: [*:0]const u8) void;
330extern fn ___tracy_emit_frame_mark(name: ?[*:0]const u8) void;
286extern fn ___tracy_emit_plot_int(name: [*:0]const u8, val: i64) void;
287extern fn ___tracy_emit_plot_config(name: [*:0]const u8, format: PlotConfig.Format, mode: PlotConfig.Mode, fill: i32, color: u32) void;
331288extern fn ___tracy_fiber_enter(fiber: [*:0]const u8) void;
332289extern fn ___tracy_fiber_leave() void;
333290