authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-06-03 20:59:17-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-06 20:00:55-07:00
log2019faa57678e00d73f8ed0eb29101717039230a
treea7ac98b1b507b6780ce12f54cf6a40bce8dbd4e2
parentd7d131c0503ae8a02677faa01d7d518a5441cb6f

InternPool: restore debugger pretty printing


10 files changed, 152 insertions(+), 141 deletions(-)

lib/lldb/pretty_printers.py+7-6
......@@ -707,7 +707,7 @@ def root_InternPool_Index_SummaryProvider(value, _=None):
707707 return re.sub(
708708 expr_path_re,
709709 lambda matchobj: getattr(unwrapped.GetValueForExpressionPath(matchobj[1]), matchobj[2]).strip(matchobj[3] or ''),
710 summary.summary.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"'),
710 summary.value.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"'),
711711 )
712712
713713class root_InternPool_Index_SynthProvider:
......@@ -773,7 +773,7 @@ class root_InternPool_Index_Unwrapped_SynthProvider:
773773 trailing_type = encoding_trailing.GetValueAsType()
774774 trailing_bytes, trailing_data = bytearray(trailing_type.size), lldb.SBData()
775775 def eval_config(config_name):
776 expr = encoding_config.GetChildMemberWithName(config_name).summary.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"')
776 expr = encoding_config.GetChildMemberWithName(config_name).value.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"')
777777 if 'payload.' in expr:
778778 return self.payload.EvaluateExpression(expr.replace('payload.', '@this().'))
779779 elif expr.startswith('trailing.'):
......@@ -848,7 +848,8 @@ def root_InternPool_String_SummaryProvider(value, _=None):
848848 if local_value is None:
849849 wrapped = 0
850850 local_value = locals_value.child[0]
851 string = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('strings').GetChildMemberWithName('view').GetChildMemberWithName('0').child[wrapped & (1 << tid_shift_32) - 1].address_of
851 shared = local_value.GetChildMemberWithName('shared')
852 string = shared.GetChildMemberWithName('string_bytes').GetChildMemberWithName('view').GetChildMemberWithName('0').child[shared.GetChildMemberWithName('strings').GetChildMemberWithName('view').GetChildMemberWithName('0').child[wrapped & (1 << tid_shift_32) - 1].unsigned].address_of
852853 string.format = lldb.eFormatCString
853854 return string.value
854855
......@@ -878,13 +879,13 @@ class root_InternPool_Nav_Index_SynthProvider:
878879 wrapped = self.value.unsigned
879880 if wrapped == (1 << 32) - 1: return
880881 ip = self.value.CreateValueFromType(self.value.type).GetChildMemberWithName('debug_state').GetChildMemberWithName('intern_pool').GetNonSyntheticValue().GetChildMemberWithName('?')
881 tid_shift_32 = ip.GetChildMemberWithName('tid_shift_32').unsigned
882 tid_shift_30 = ip.GetChildMemberWithName('tid_shift_30').unsigned
882883 locals_value = ip.GetChildMemberWithName('locals').GetSyntheticValue()
883 local_value = locals_value.child[wrapped >> tid_shift_32]
884 local_value = locals_value.child[wrapped >> tid_shift_30]
884885 if local_value is None:
885886 wrapped = 0
886887 local_value = locals_value.child[0]
887 self.nav = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('navs').GetChildMemberWithName('view').child[wrapped & (1 << tid_shift_32) - 1]
888 self.nav = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('navs').GetChildMemberWithName('view').child[wrapped & (1 << tid_shift_30) - 1]
888889 def has_children(self): return False if self.nav is None else self.nav.GetNumChildren(1) > 0
889890 def num_children(self): return 0 if self.nav is None else self.nav.GetNumChildren()
890891 def get_child_index(self, name): return -1 if self.nav is None else self.nav.GetIndexOfChildWithName(name)
src/Compilation.zig+19-23
......@@ -2308,9 +2308,9 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
23082308
23092309 if (opt_zcu) |zcu| {
23102310 // Populate `zcu.module_roots`.
2311 const pt: Zcu.PerThread = .activate(zcu, .main);
2312 defer pt.deactivate();
2313 pt.populateModuleRootTable() catch |err| switch (err) {
2311 const active = zcu.acquire();
2312 defer active.release();
2313 active.pt.populateModuleRootTable() catch |err| switch (err) {
23142314 error.OutOfMemory => |e| return e,
23152315 error.IllegalZigImport => return diag.fail(.illegal_zig_import),
23162316 };
......@@ -3044,9 +3044,6 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
30443044 }
30453045
30463046 if (comp.zcu) |zcu| {
3047 const pt: Zcu.PerThread = .activate(zcu, .main);
3048 defer pt.deactivate();
3049
30503047 assert(zcu.cur_analysis_timer == null);
30513048
30523049 zcu.skip_analysis_this_update = false;
......@@ -3099,8 +3096,9 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
30993096 try comp.performAllTheWork(main_progress_node, arena);
31003097
31013098 if (comp.zcu) |zcu| {
3102 const pt: Zcu.PerThread = .activate(zcu, .main);
3103 defer pt.deactivate();
3099 const active = zcu.acquire();
3100 defer active.release();
3101 const pt = active.pt;
31043102
31053103 assert(zcu.cur_analysis_timer == null);
31063104
......@@ -3151,9 +3149,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
31513149 }
31523150
31533151 switch (comp.cache_use) {
3154 .none, .incremental => {
3155 try flush(comp, arena, .main);
3156 },
3152 .none, .incremental => try flush(comp, arena),
31573153 .whole => |whole| {
31583154 if (comp.file_system_inputs) |buf| try man.populateFileSystemInputs(buf);
31593155 if (comp.parent_whole_cache) |pwc| {
......@@ -3234,7 +3230,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
32343230 };
32353231 }
32363232
3237 try flush(comp, arena, .main);
3233 try flush(comp, arena);
32383234
32393235 // Calling `flush` may have produced errors, in which case the
32403236 // cache manifest must not be written.
......@@ -3325,12 +3321,12 @@ pub fn resolveEmitPathFlush(
33253321 }
33263322}
33273323
3328fn flush(comp: *Compilation, arena: Allocator, tid: Zcu.PerThread.Id) (Io.Cancelable || Allocator.Error)!void {
3324fn flush(comp: *Compilation, arena: Allocator) (Io.Cancelable || Allocator.Error)!void {
33293325 const io = comp.io;
3326 const tid: Zcu.PerThread.Id = .acquire(io);
3327 defer tid.release(io);
33303328 if (comp.zcu) |zcu| {
33313329 if (zcu.llvm_object) |llvm_object| {
3332 const pt: Zcu.PerThread = .activate(zcu, tid);
3333 defer pt.deactivate();
33343330
33353331 // Emit the ZCU object from LLVM now; it's required to flush the output file.
33363332 // If there's an output file, it wants to decide where the LLVM object goes!
......@@ -3348,7 +3344,9 @@ fn flush(comp: *Compilation, arena: Allocator, tid: Zcu.PerThread.Id) (Io.Cancel
33483344 break :p try comp.resolveEmitPathFlush(arena, .temp, llvm_object.out_bin_basename);
33493345 } else null;
33503346
3351 llvm_object.emit(pt, .{
3347 const active = zcu.activate(tid);
3348 defer active.deactivate();
3349 llvm_object.emit(active.pt, .{
33523350 .pre_ir_path = comp.verbose_llvm_ir,
33533351 .pre_bc_path = comp.verbose_llvm_bc,
33543352
......@@ -4502,13 +4500,11 @@ fn performAllTheWork(
45024500
45034501 defer if (comp.zcu) |zcu| zcu.codegen_task_pool.cancel(zcu);
45044502 if (comp.zcu) |zcu| {
4505 const pt: Zcu.PerThread = .activate(zcu, .main);
4506 defer {
4507 pt.deactivate();
4508 // Regardless of errors, `comp.zcu` needs to update its generation number.
4509 zcu.generation += 1;
4510 }
4511 try pt.update(main_progress_node, &decl_work_timer);
4503 // Regardless of errors, `comp.zcu` needs to update its generation number.
4504 defer zcu.generation += 1;
4505 const active = zcu.acquire();
4506 defer active.release();
4507 try active.pt.update(main_progress_node, &decl_work_timer);
45124508 }
45134509
45144510 comp.link_queue.finishZcuQueue(comp);
src/InternPool.zig+43-43
......@@ -108,9 +108,9 @@ pub const empty: InternPool = .{
108108 .shards = &.{},
109109 .global_error_set = .empty,
110110 .tid_width = 0,
111 .tid_shift_30 = if (single_threaded) 0 else 31,
112 .tid_shift_31 = if (single_threaded) 0 else 31,
113 .tid_shift_32 = if (single_threaded) 0 else 31,
111 .tid_shift_30 = 0,
112 .tid_shift_31 = 0,
113 .tid_shift_32 = 0,
114114 .src_hash_deps = .empty,
115115 .nav_val_deps = .empty,
116116 .nav_ty_deps = .empty,
......@@ -648,15 +648,15 @@ pub const Nav = struct {
648648
649649 fn wrap(unwrapped: Unwrapped, ip: *const InternPool) Nav.Index {
650650 assert(@intFromEnum(unwrapped.tid) <= ip.getTidMask());
651 assert(unwrapped.index <= ip.getIndexMask(u32));
652 return @enumFromInt(@shlExact(@as(u32, @intFromEnum(unwrapped.tid)), ip.tid_shift_32) |
651 assert(unwrapped.index <= ip.getIndexMask(u30));
652 return @enumFromInt(@shlExact(@as(u32, @intFromEnum(unwrapped.tid)), ip.tid_shift_30) |
653653 unwrapped.index);
654654 }
655655 };
656656 fn unwrap(nav_index: Nav.Index, ip: *const InternPool) Unwrapped {
657657 return .{
658 .tid = @enumFromInt(@intFromEnum(nav_index) >> ip.tid_shift_32 & ip.getTidMask()),
659 .index = @intFromEnum(nav_index) & ip.getIndexMask(u32),
658 .tid = @enumFromInt(@intFromEnum(nav_index) >> ip.tid_shift_30 & ip.getTidMask()),
659 .index = @intFromEnum(nav_index) & ip.getIndexMask(u30),
660660 };
661661 }
662662
......@@ -4168,10 +4168,7 @@ pub const Index = enum(u32) {
41684168 const debug_state = InternPool.debug_state;
41694169 };
41704170 pub fn unwrap(index: Index, ip: *const InternPool) Unwrapped {
4171 return if (single_threaded) .{
4172 .tid = .main,
4173 .index = @intFromEnum(index),
4174 } else .{
4171 return .{
41754172 .tid = @enumFromInt(@intFromEnum(index) >> ip.tid_shift_30 & ip.getTidMask()),
41764173 .index = @intFromEnum(index) & ip.getIndexMask(u30),
41774174 };
......@@ -5061,9 +5058,9 @@ pub const Tag = enum(u8) {
50615058 field_types: []Index,
50625059 },
50635060 .config = .{
5064 .@"trailing.type_hash.?" = .@"payload.captures_len == .reified",
5065 .@"trailing.captures.?" = .@"payload.captures_len != .reified",
5066 .@"trailing.captures.?.len" = .@"@intFromEnum(payload.captures_len)",
5061 .@"trailing.type_hash.?" = .@"payload.bits.captures_len == .reified",
5062 .@"trailing.captures.?" = .@"payload.bits.captures_len != .reified",
5063 .@"trailing.captures.?.len" = .@"@intFromEnum(payload.bits.captures_len)",
50675064 .@"trailing.field_names.len" = .@"payload.fields_len",
50685065 .@"trailing.field_types.len" = .@"payload.fields_len",
50695066 },
......@@ -5079,9 +5076,9 @@ pub const Tag = enum(u8) {
50795076 field_defaults: []Index,
50805077 },
50815078 .config = .{
5082 .@"trailing.type_hash.?" = .@"payload.captures_len == .reified",
5083 .@"trailing.captures.?" = .@"payload.captures_len != .reified",
5084 .@"trailing.captures.?.len" = .@"@intFromEnum(payload.captures_len)",
5079 .@"trailing.type_hash.?" = .@"payload.bits.captures_len == .reified",
5080 .@"trailing.captures.?" = .@"payload.bits.captures_len != .reified",
5081 .@"trailing.captures.?.len" = .@"@intFromEnum(payload.bits.captures_len)",
50855082 .@"trailing.field_names.len" = .@"payload.fields_len",
50865083 .@"trailing.field_types.len" = .@"payload.fields_len",
50875084 .@"trailing.field_defaults.len" = .@"payload.fields_len",
......@@ -5096,9 +5093,9 @@ pub const Tag = enum(u8) {
50965093 field_types: []Index,
50975094 },
50985095 .config = .{
5099 .@"trailing.type_hash.?" = .@"payload.captures_len == .reified",
5100 .@"trailing.captures.?" = .@"payload.captures_len != .reified",
5101 .@"trailing.captures.?.len" = .@"@intFromEnum(payload.captures_len)",
5096 .@"trailing.type_hash.?" = .@"payload.bits.captures_len == .reified",
5097 .@"trailing.captures.?" = .@"payload.bits.captures_len != .reified",
5098 .@"trailing.captures.?.len" = .@"@intFromEnum(payload.bits.captures_len)",
51025099 .@"trailing.field_types.len" = .@"payload.fields_len",
51035100 },
51045101 };
......@@ -5115,11 +5112,11 @@ pub const Tag = enum(u8) {
51155112 field_values: []Index,
51165113 },
51175114 .config = .{
5118 .@"trailing.owner_union.?" = .@"payload.captures_len == .generated_union_tag",
5119 .@"trailing.zir_index.?" = .@"payload.captures_len != .generated_union_tag",
5120 .@"trailing.type_hash.?" = .@"payload.captures_len == .reified",
5121 .@"trailing.captures.?" = .@"payload.captures_len != .reified and payload.captures_len != .generated_enum_tag",
5122 .@"trailing.captures.?.len" = .@"@intFromEnum(payload.captures_len)",
5115 .@"trailing.owner_union.?" = .@"payload.bits.captures_len == .generated_union_tag",
5116 .@"trailing.zir_index.?" = .@"payload.bits.captures_len != .generated_union_tag",
5117 .@"trailing.type_hash.?" = .@"payload.bits.captures_len == .reified",
5118 .@"trailing.captures.?" = .@"payload.bits.captures_len != .reified and payload.bits.captures_len != .generated_union_tag",
5119 .@"trailing.captures.?.len" = .@"@intFromEnum(payload.bits.captures_len)",
51235120 .@"trailing.field_names.len" = .@"payload.fields_len",
51245121 .@"trailing.field_values.len" = .@"payload.fields_len",
51255122 },
......@@ -5249,11 +5246,11 @@ pub const Tag = enum(u8) {
52495246 field_names: []NullTerminatedString,
52505247 },
52515248 .config = .{
5252 .@"trailing.owner_union.?" = .@"payload.captures_len == .generated_union_tag",
5253 .@"trailing.zir_index.?" = .@"payload.captures_len != .generated_union_tag",
5254 .@"trailing.type_hash.?" = .@"payload.captures_len == .reified",
5255 .@"trailing.captures.?" = .@"payload.captures_len != .reified and payload.captures_len != .generated_enum_tag",
5256 .@"trailing.captures.?.len" = .@"@intFromEnum(payload.captures_len)",
5249 .@"trailing.owner_union.?" = .@"payload.bits.captures_len == .generated_union_tag",
5250 .@"trailing.zir_index.?" = .@"payload.bits.captures_len != .generated_union_tag",
5251 .@"trailing.type_hash.?" = .@"payload.bits.captures_len == .reified",
5252 .@"trailing.captures.?" = .@"payload.bits.captures_len != .reified and payload.bits.captures_len != .generated_union_tag",
5253 .@"trailing.captures.?.len" = .@"@intFromEnum(payload.bits.captures_len)",
52575254 .@"trailing.field_names.len" = .@"payload.fields_len",
52585255 },
52595256 },
......@@ -6379,7 +6376,7 @@ pub fn init(ip: *InternPool, gpa: Allocator, io: Io, available_threads: usize) !
63796376}
63806377
63816378pub fn deinit(ip: *InternPool, gpa: Allocator, io: Io) void {
6382 if (debug_state.enable_checks) std.debug.assert(debug_state.intern_pool == null);
6379 std.debug.assert(debug_state.intern_pool == null);
63836380
63846381 ip.src_hash_deps.deinit(gpa);
63856382 ip.nav_val_deps.deinit(gpa);
......@@ -6424,8 +6421,15 @@ pub fn deinit(ip: *InternPool, gpa: Allocator, io: Io) void {
64246421 ip.* = undefined;
64256422}
64266423
6427pub fn activate(ip: *const InternPool) void {
6428 if (!debug_state.enable) return;
6424pub const Active = struct {
6425 prev_ip: if (debug_state.enable) ?*const InternPool else void,
6426 pub fn deactivate(active: Active) void {
6427 if (!debug_state.enable) return;
6428 debug_state.intern_pool = active.prev_ip;
6429 }
6430};
6431pub fn activate(ip: *const InternPool) Active {
6432 if (!debug_state.enable) return .{ .prev_ip = {} };
64296433 _ = Index.Unwrapped.debug_state;
64306434 _ = String.debug_state;
64316435 _ = OptionalString.debug_state;
......@@ -6435,20 +6439,16 @@ pub fn activate(ip: *const InternPool) void {
64356439 _ = TrackedInst.Index.Optional.debug_state;
64366440 _ = Nav.Index.debug_state;
64376441 _ = Nav.Index.Optional.debug_state;
6438 if (debug_state.enable_checks) std.debug.assert(debug_state.intern_pool == null);
6439 debug_state.intern_pool = ip;
6440}
6441
6442pub fn deactivate(ip: *const InternPool) void {
6443 if (!debug_state.enable) return;
6444 std.debug.assert(debug_state.intern_pool == ip);
6445 if (debug_state.enable_checks) debug_state.intern_pool = null;
6442 defer debug_state.intern_pool = ip;
6443 return .{ .prev_ip = debug_state.intern_pool };
64466444}
64476445
64486446/// For debugger access only.
64496447const debug_state = struct {
6450 const enable = false;
6451 const enable_checks = enable and !builtin.single_threaded;
6448 const enable = switch (builtin.zig_backend) {
6449 else => false,
6450 .stage2_x86_64 => !builtin.strip_debug_info and build_options.io_mode == .threaded,
6451 };
64526452 threadlocal var intern_pool: ?*const InternPool = null;
64536453};
64546454
src/Zcu.zig+48-10
......@@ -2822,15 +2822,12 @@ pub fn deinit(zcu: *Zcu) void {
28222822 const io = comp.io;
28232823 const gpa = zcu.gpa;
28242824 {
2825 const pt: Zcu.PerThread = .activate(zcu, .main);
2826 defer pt.deactivate();
2827
28282825 if (zcu.llvm_object) |llvm_object| llvm_object.deinit();
28292826
28302827 zcu.builtin_modules.deinit(gpa);
28312828 zcu.module_roots.deinit(gpa);
28322829 for (zcu.import_table.keys()) |file_index| {
2833 pt.destroyFile(file_index);
2830 zcu.destroyFile(file_index);
28342831 }
28352832 zcu.import_table.deinit(gpa);
28362833 zcu.alive_files.deinit(gpa);
......@@ -2913,6 +2910,26 @@ pub fn deinit(zcu: *Zcu) void {
29132910 zcu.intern_pool.deinit(gpa, io);
29142911}
29152912
2913fn deinitFile(zcu: *Zcu, file_index: Zcu.File.Index) void {
2914 const gpa = zcu.gpa;
2915 const file = zcu.fileByIndex(file_index);
2916 log.debug("deinit File {f}", .{file.path.fmt(zcu.comp)});
2917 file.path.deinit(gpa);
2918 file.unload(gpa);
2919 if (file.prev_zir) |prev_zir| {
2920 prev_zir.deinit(gpa);
2921 gpa.destroy(prev_zir);
2922 }
2923 file.* = undefined;
2924}
2925
2926fn destroyFile(zcu: *Zcu, file_index: Zcu.File.Index) void {
2927 const gpa = zcu.gpa;
2928 const file = zcu.fileByIndex(file_index);
2929 deinitFile(zcu, file_index);
2930 gpa.destroy(file);
2931}
2932
29162933pub fn namespacePtr(zcu: *Zcu, index: Namespace.Index) *Namespace {
29172934 return zcu.intern_pool.namespacePtr(index);
29182935}
......@@ -5376,9 +5393,9 @@ pub const CodegenTaskPool = struct {
53765393 const io = zcu.comp.io;
53775394 const tid: Zcu.PerThread.Id = .acquire(io);
53785395 defer tid.release(io);
5379 const pt: Zcu.PerThread = .activate(zcu, tid);
5380 defer pt.deactivate();
5381 return pt.runCodegen(func_index, &air);
5396 const active = zcu.activate(tid);
5397 defer active.deactivate();
5398 return active.pt.runCodegen(func_index, &air);
53825399 }
53835400 fn workerCodegenExternalAir(
53845401 zcu: *Zcu,
......@@ -5388,9 +5405,9 @@ pub const CodegenTaskPool = struct {
53885405 const io = zcu.comp.io;
53895406 const tid: Zcu.PerThread.Id = .acquire(io);
53905407 defer tid.release(io);
5391 const pt: Zcu.PerThread = .activate(zcu, tid);
5392 defer pt.deactivate();
5393 return pt.runCodegen(func_index, air);
5408 const active = zcu.activate(tid);
5409 defer active.deactivate();
5410 return active.pt.runCodegen(func_index, air);
53945411 }
53955412};
53965413
......@@ -5419,3 +5436,24 @@ fn updateTracyOutdatedPlots(zcu: *const Zcu) void {
54195436 zcu.updateTracyPlot("potentially_outdated", zcu.potentially_outdated.count());
54205437 zcu.updateTracyPlot("outdated_ready", zcu.outdated_ready.funcs.count() + zcu.outdated_ready.other.count());
54215438}
5439
5440pub const Active = struct {
5441 pt: Zcu.PerThread,
5442 ip: InternPool.Active,
5443 pub fn deactivate(active: Active) void {
5444 active.ip.deactivate();
5445 }
5446 pub fn release(active: Active) void {
5447 active.deactivate();
5448 active.pt.tid.release(active.pt.zcu.comp.io);
5449 }
5450};
5451pub fn activate(zcu: *Zcu, tid: PerThread.Id) Active {
5452 return .{
5453 .pt = .{ .zcu = zcu, .tid = tid },
5454 .ip = zcu.intern_pool.activate(),
5455 };
5456}
5457pub fn acquire(zcu: *Zcu) Active {
5458 return zcu.activate(.acquire(zcu.comp.io));
5459}
src/Zcu/PerThread.zig+10-37
......@@ -125,14 +125,6 @@ pub const Id = if (InternPool.single_threaded) enum {
125125 }
126126};
127127
128pub fn activate(zcu: *Zcu, tid: Id) Zcu.PerThread {
129 zcu.intern_pool.activate();
130 return .{ .zcu = zcu, .tid = tid };
131}
132pub fn deactivate(pt: Zcu.PerThread) void {
133 pt.zcu.intern_pool.deactivate();
134}
135
136128/// Called from `Compilation.performAllTheWork`. Performs one incremental update of the ZCU: detects
137129/// changes to files, runs AstGen, and then enters the main semantic analysis loop, where we build
138130/// up a graph of declarations, functions, etc, while also sending declarations and functions to
......@@ -378,10 +370,10 @@ fn workerUpdateFile(
378370 const child_prog_node = prog_node.start(std.fs.path.basename(file.path.sub_path), 0);
379371 defer child_prog_node.end();
380372
381 const pt: Zcu.PerThread = .activate(comp.zcu.?, tid);
382 defer pt.deactivate();
383 pt.updateFile(file_index, file) catch |err| {
384 pt.reportRetryableFileError(file_index, "unable to load '{s}': {s}", .{ std.fs.path.basename(file.path.sub_path), @errorName(err) }) catch |oom| switch (oom) {
373 const active = comp.zcu.?.activate(tid);
374 defer active.deactivate();
375 active.pt.updateFile(file_index, file) catch |err| {
376 active.pt.reportRetryableFileError(file_index, "unable to load '{s}': {s}", .{ std.fs.path.basename(file.path.sub_path), @errorName(err) }) catch |oom| switch (oom) {
385377 error.OutOfMemory => {
386378 comp.mutex.lockUncancelable(io);
387379 defer comp.mutex.unlock(io);
......@@ -411,7 +403,7 @@ fn workerUpdateFile(
411403
412404 const import_path = file.zir.?.nullTerminatedString(item.data.name);
413405
414 if (pt.discoverImport(file.path, import_path)) |res| switch (res) {
406 if (active.pt.discoverImport(file.path, import_path)) |res| switch (res) {
415407 .module, .existing_file => {},
416408 .new_file => |new| {
417409 group.async(io, workerUpdateFile, .{
......@@ -443,13 +435,15 @@ fn workerUpdateEmbedFile(comp: *Compilation, ef_index: Zcu.EmbedFile.Index, ef:
443435fn detectEmbedFileUpdate(comp: *Compilation, tid: Zcu.PerThread.Id, ef_index: Zcu.EmbedFile.Index, ef: *Zcu.EmbedFile) !void {
444436 const io = comp.io;
445437 const zcu = comp.zcu.?;
446 const pt: Zcu.PerThread = .activate(zcu, tid);
447 defer pt.deactivate();
448438
449439 const old_val = ef.val;
450440 const old_err = ef.err;
451441
452 try pt.updateEmbedFile(ef, null);
442 {
443 const active = zcu.activate(tid);
444 defer active.deactivate();
445 try active.pt.updateEmbedFile(ef, null);
446 }
453447
454448 if (ef.val != .none and ef.val == old_val) return; // success, value unchanged
455449 if (ef.val == .none and old_val == .none and ef.err == old_err) return; // failure, error unchanged
......@@ -460,27 +454,6 @@ fn detectEmbedFileUpdate(comp: *Compilation, tid: Zcu.PerThread.Id, ef_index: Zc
460454 try zcu.markDependeeOutdated(.not_marked_po, .{ .embed_file = ef_index });
461455}
462456
463fn deinitFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) void {
464 const zcu = pt.zcu;
465 const gpa = zcu.gpa;
466 const file = zcu.fileByIndex(file_index);
467 log.debug("deinit File {f}", .{file.path.fmt(zcu.comp)});
468 file.path.deinit(gpa);
469 file.unload(gpa);
470 if (file.prev_zir) |prev_zir| {
471 prev_zir.deinit(gpa);
472 gpa.destroy(prev_zir);
473 }
474 file.* = undefined;
475}
476
477pub fn destroyFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) void {
478 const gpa = pt.zcu.gpa;
479 const file = pt.zcu.fileByIndex(file_index);
480 pt.deinitFile(file_index);
481 gpa.destroy(file);
482}
483
484457/// Ensures that `file` has up-to-date ZIR. If not, loads the ZIR cache or runs
485458/// AstGen as needed. Also updates `file.status`. Does not assume that `file.mod`
486459/// is populated. Does not return `error.AnalysisFail` on AstGen failures.
src/link.zig+3-2
......@@ -1529,8 +1529,9 @@ pub fn doZcuTask(comp: *Compilation, tid: Zcu.PerThread.Id, task: ZcuTask) void
15291529 const diags = &comp.link_diags;
15301530 const zcu = comp.zcu.?;
15311531 const ip = &zcu.intern_pool;
1532 const pt: Zcu.PerThread = .activate(zcu, tid);
1533 defer pt.deactivate();
1532 const active = zcu.activate(tid);
1533 defer active.deactivate();
1534 const pt = active.pt;
15341535
15351536 var timer = comp.startTimer();
15361537
src/link/C.zig+3-2
......@@ -728,8 +728,9 @@ pub fn flush(c: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Prog
728728 const zcu = c.base.comp.zcu.?;
729729 const ip = &zcu.intern_pool;
730730 const target = zcu.getTarget();
731 const pt: Zcu.PerThread = .activate(zcu, tid);
732 defer pt.deactivate();
731 const active = zcu.activate(tid);
732 defer active.deactivate();
733 const pt = active.pt;
733734
734735 // If it's somehow not made it into the pool, we need to generate the type `[:0]const u8` for
735736 // error names.
src/link/Elf/ZigObject.zig+12-9
......@@ -267,8 +267,9 @@ pub fn deinit(self: *ZigObject, allocator: Allocator) void {
267267pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
268268 // Handle any lazy symbols that were emitted by incremental compilation.
269269 if (self.lazy_syms.getPtr(.anyerror_type)) |metadata| {
270 const pt: Zcu.PerThread = .activate(elf_file.base.comp.zcu.?, tid);
271 defer pt.deactivate();
270 const active = elf_file.base.comp.zcu.?.activate(tid);
271 defer active.deactivate();
272 const pt = active.pt;
272273
273274 // Most lazy symbols can be updated on first use, but
274275 // anyerror needs to wait for everything to be flushed.
......@@ -291,20 +292,22 @@ pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
291292 }
292293
293294 if (build_options.enable_logging) {
294 const pt: Zcu.PerThread = .activate(elf_file.base.comp.zcu.?, tid);
295 defer pt.deactivate();
295 const active = elf_file.base.comp.zcu.?.activate(tid);
296 defer active.deactivate();
296297 for (self.navs.keys(), self.navs.values()) |nav_index, meta| {
297 checkNavAllocated(pt, nav_index, meta);
298 checkNavAllocated(active.pt, nav_index, meta);
298299 }
299300 for (self.uavs.keys(), self.uavs.values()) |uav_index, meta| {
300 checkUavAllocated(pt, uav_index, meta);
301 checkUavAllocated(active.pt, uav_index, meta);
301302 }
302303 }
303304
304305 if (self.dwarf) |*dwarf| {
305 const pt: Zcu.PerThread = .activate(elf_file.base.comp.zcu.?, tid);
306 defer pt.deactivate();
307 try dwarf.flush(pt);
306 {
307 const active = elf_file.base.comp.zcu.?.activate(tid);
308 defer active.deactivate();
309 try dwarf.flush(active.pt);
310 }
308311
309312 const gpa = elf_file.base.comp.gpa;
310313 const cpu_arch = elf_file.getTarget().cpu.arch;
src/link/MachO/ZigObject.zig+7-7
......@@ -560,14 +560,14 @@ pub fn flush(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id) link.E
560560
561561 // Handle any lazy symbols that were emitted by incremental compilation.
562562 if (self.lazy_syms.getPtr(.anyerror_type)) |metadata| {
563 const pt: Zcu.PerThread = .activate(macho_file.base.comp.zcu.?, tid);
564 defer pt.deactivate();
563 const active = macho_file.base.comp.zcu.?.activate(tid);
564 defer active.deactivate();
565565
566566 // Most lazy symbols can be updated on first use, but
567567 // anyerror needs to wait for everything to be flushed.
568568 if (metadata.text_state != .unused) self.updateLazySymbol(
569569 macho_file,
570 pt,
570 active.pt,
571571 .{ .kind = .code, .ty = .anyerror_type },
572572 metadata.text_symbol_index,
573573 ) catch |err| switch (err) {
......@@ -576,7 +576,7 @@ pub fn flush(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id) link.E
576576 };
577577 if (metadata.const_state != .unused) self.updateLazySymbol(
578578 macho_file,
579 pt,
579 active.pt,
580580 .{ .kind = .const_data, .ty = .anyerror_type },
581581 metadata.const_symbol_index,
582582 ) catch |err| switch (err) {
......@@ -590,9 +590,9 @@ pub fn flush(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id) link.E
590590 }
591591
592592 if (self.dwarf) |*dwarf| {
593 const pt: Zcu.PerThread = .activate(macho_file.base.comp.zcu.?, tid);
594 defer pt.deactivate();
595 dwarf.flush(pt) catch |err| switch (err) {
593 const active = macho_file.base.comp.zcu.?.activate(tid);
594 defer active.deactivate();
595 dwarf.flush(active.pt) catch |err| switch (err) {
596596 error.OutOfMemory => |e| return e,
597597 else => |e| return diags.fail("failed to flush dwarf module: {s}", .{@errorName(e)}),
598598 };
src/link/Queue.zig-2
......@@ -101,8 +101,6 @@ pub fn enqueueZcu(
101101) Io.Cancelable!void {
102102 const io = comp.io;
103103
104 assert(tid == .main);
105
106104 if (q.future != null) {
107105 if (q.zcu_queue.putOne(io, task)) |_| {
108106 return;