zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 2019faa57678e00d73f8ed0eb29101717039230a (tree)
parent d7d131c0503ae8a02677faa01d7d518a5441cb6f
Author: Jacob Young <jacobly@ziglang.org>
Date:   Wed,  3 Jun 2026 20:59:17 -0400

InternPool: restore debugger pretty printing

Diffstat:
Mlib/lldb/pretty_printers.py | 13+++++++------
Msrc/Compilation.zig | 42+++++++++++++++++++-----------------------
Msrc/InternPool.zig | 86++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/Zcu.zig | 58++++++++++++++++++++++++++++++++++++++++++++++++----------
Msrc/Zcu/PerThread.zig | 47++++++++++-------------------------------------
Msrc/link.zig | 5+++--
Msrc/link/C.zig | 5+++--
Msrc/link/Elf/ZigObject.zig | 21++++++++++++---------
Msrc/link/MachO/ZigObject.zig | 14+++++++-------
Msrc/link/Queue.zig | 2--
10 files changed, 152 insertions(+), 141 deletions(-)

diff --git a/lib/lldb/pretty_printers.py b/lib/lldb/pretty_printers.py @@ -707,7 +707,7 @@ def root_InternPool_Index_SummaryProvider(value, _=None): return re.sub( expr_path_re, lambda matchobj: getattr(unwrapped.GetValueForExpressionPath(matchobj[1]), matchobj[2]).strip(matchobj[3] or ''), - summary.summary.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"'), + summary.value.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"'), ) class root_InternPool_Index_SynthProvider: @@ -773,7 +773,7 @@ class root_InternPool_Index_Unwrapped_SynthProvider: trailing_type = encoding_trailing.GetValueAsType() trailing_bytes, trailing_data = bytearray(trailing_type.size), lldb.SBData() def eval_config(config_name): - expr = encoding_config.GetChildMemberWithName(config_name).summary.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"') + expr = encoding_config.GetChildMemberWithName(config_name).value.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"') if 'payload.' in expr: return self.payload.EvaluateExpression(expr.replace('payload.', '@this().')) elif expr.startswith('trailing.'): @@ -848,7 +848,8 @@ def root_InternPool_String_SummaryProvider(value, _=None): if local_value is None: wrapped = 0 local_value = locals_value.child[0] - string = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('strings').GetChildMemberWithName('view').GetChildMemberWithName('0').child[wrapped & (1 << tid_shift_32) - 1].address_of + shared = local_value.GetChildMemberWithName('shared') + 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 string.format = lldb.eFormatCString return string.value @@ -878,13 +879,13 @@ class root_InternPool_Nav_Index_SynthProvider: wrapped = self.value.unsigned if wrapped == (1 << 32) - 1: return ip = self.value.CreateValueFromType(self.value.type).GetChildMemberWithName('debug_state').GetChildMemberWithName('intern_pool').GetNonSyntheticValue().GetChildMemberWithName('?') - tid_shift_32 = ip.GetChildMemberWithName('tid_shift_32').unsigned + tid_shift_30 = ip.GetChildMemberWithName('tid_shift_30').unsigned locals_value = ip.GetChildMemberWithName('locals').GetSyntheticValue() - local_value = locals_value.child[wrapped >> tid_shift_32] + local_value = locals_value.child[wrapped >> tid_shift_30] if local_value is None: wrapped = 0 local_value = locals_value.child[0] - self.nav = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('navs').GetChildMemberWithName('view').child[wrapped & (1 << tid_shift_32) - 1] + self.nav = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('navs').GetChildMemberWithName('view').child[wrapped & (1 << tid_shift_30) - 1] def has_children(self): return False if self.nav is None else self.nav.GetNumChildren(1) > 0 def num_children(self): return 0 if self.nav is None else self.nav.GetNumChildren() def get_child_index(self, name): return -1 if self.nav is None else self.nav.GetIndexOfChildWithName(name) diff --git a/src/Compilation.zig b/src/Compilation.zig @@ -2308,9 +2308,9 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, if (opt_zcu) |zcu| { // Populate `zcu.module_roots`. - const pt: Zcu.PerThread = .activate(zcu, .main); - defer pt.deactivate(); - pt.populateModuleRootTable() catch |err| switch (err) { + const active = zcu.acquire(); + defer active.release(); + active.pt.populateModuleRootTable() catch |err| switch (err) { error.OutOfMemory => |e| return e, error.IllegalZigImport => return diag.fail(.illegal_zig_import), }; @@ -3044,9 +3044,6 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE } if (comp.zcu) |zcu| { - const pt: Zcu.PerThread = .activate(zcu, .main); - defer pt.deactivate(); - assert(zcu.cur_analysis_timer == null); zcu.skip_analysis_this_update = false; @@ -3099,8 +3096,9 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE try comp.performAllTheWork(main_progress_node, arena); if (comp.zcu) |zcu| { - const pt: Zcu.PerThread = .activate(zcu, .main); - defer pt.deactivate(); + const active = zcu.acquire(); + defer active.release(); + const pt = active.pt; assert(zcu.cur_analysis_timer == null); @@ -3151,9 +3149,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE } switch (comp.cache_use) { - .none, .incremental => { - try flush(comp, arena, .main); - }, + .none, .incremental => try flush(comp, arena), .whole => |whole| { if (comp.file_system_inputs) |buf| try man.populateFileSystemInputs(buf); if (comp.parent_whole_cache) |pwc| { @@ -3234,7 +3230,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE }; } - try flush(comp, arena, .main); + try flush(comp, arena); // Calling `flush` may have produced errors, in which case the // cache manifest must not be written. @@ -3325,12 +3321,12 @@ pub fn resolveEmitPathFlush( } } -fn flush(comp: *Compilation, arena: Allocator, tid: Zcu.PerThread.Id) (Io.Cancelable || Allocator.Error)!void { +fn flush(comp: *Compilation, arena: Allocator) (Io.Cancelable || Allocator.Error)!void { const io = comp.io; + const tid: Zcu.PerThread.Id = .acquire(io); + defer tid.release(io); if (comp.zcu) |zcu| { if (zcu.llvm_object) |llvm_object| { - const pt: Zcu.PerThread = .activate(zcu, tid); - defer pt.deactivate(); // Emit the ZCU object from LLVM now; it's required to flush the output file. // 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 break :p try comp.resolveEmitPathFlush(arena, .temp, llvm_object.out_bin_basename); } else null; - llvm_object.emit(pt, .{ + const active = zcu.activate(tid); + defer active.deactivate(); + llvm_object.emit(active.pt, .{ .pre_ir_path = comp.verbose_llvm_ir, .pre_bc_path = comp.verbose_llvm_bc, @@ -4502,13 +4500,11 @@ fn performAllTheWork( defer if (comp.zcu) |zcu| zcu.codegen_task_pool.cancel(zcu); if (comp.zcu) |zcu| { - const pt: Zcu.PerThread = .activate(zcu, .main); - defer { - pt.deactivate(); - // Regardless of errors, `comp.zcu` needs to update its generation number. - zcu.generation += 1; - } - try pt.update(main_progress_node, &decl_work_timer); + // Regardless of errors, `comp.zcu` needs to update its generation number. + defer zcu.generation += 1; + const active = zcu.acquire(); + defer active.release(); + try active.pt.update(main_progress_node, &decl_work_timer); } comp.link_queue.finishZcuQueue(comp); diff --git a/src/InternPool.zig b/src/InternPool.zig @@ -108,9 +108,9 @@ pub const empty: InternPool = .{ .shards = &.{}, .global_error_set = .empty, .tid_width = 0, - .tid_shift_30 = if (single_threaded) 0 else 31, - .tid_shift_31 = if (single_threaded) 0 else 31, - .tid_shift_32 = if (single_threaded) 0 else 31, + .tid_shift_30 = 0, + .tid_shift_31 = 0, + .tid_shift_32 = 0, .src_hash_deps = .empty, .nav_val_deps = .empty, .nav_ty_deps = .empty, @@ -648,15 +648,15 @@ pub const Nav = struct { fn wrap(unwrapped: Unwrapped, ip: *const InternPool) Nav.Index { assert(@intFromEnum(unwrapped.tid) <= ip.getTidMask()); - assert(unwrapped.index <= ip.getIndexMask(u32)); - return @enumFromInt(@shlExact(@as(u32, @intFromEnum(unwrapped.tid)), ip.tid_shift_32) | + assert(unwrapped.index <= ip.getIndexMask(u30)); + return @enumFromInt(@shlExact(@as(u32, @intFromEnum(unwrapped.tid)), ip.tid_shift_30) | unwrapped.index); } }; fn unwrap(nav_index: Nav.Index, ip: *const InternPool) Unwrapped { return .{ - .tid = @enumFromInt(@intFromEnum(nav_index) >> ip.tid_shift_32 & ip.getTidMask()), - .index = @intFromEnum(nav_index) & ip.getIndexMask(u32), + .tid = @enumFromInt(@intFromEnum(nav_index) >> ip.tid_shift_30 & ip.getTidMask()), + .index = @intFromEnum(nav_index) & ip.getIndexMask(u30), }; } @@ -4168,10 +4168,7 @@ pub const Index = enum(u32) { const debug_state = InternPool.debug_state; }; pub fn unwrap(index: Index, ip: *const InternPool) Unwrapped { - return if (single_threaded) .{ - .tid = .main, - .index = @intFromEnum(index), - } else .{ + return .{ .tid = @enumFromInt(@intFromEnum(index) >> ip.tid_shift_30 & ip.getTidMask()), .index = @intFromEnum(index) & ip.getIndexMask(u30), }; @@ -5061,9 +5058,9 @@ pub const Tag = enum(u8) { field_types: []Index, }, .config = .{ - .@"trailing.type_hash.?" = .@"payload.captures_len == .reified", - .@"trailing.captures.?" = .@"payload.captures_len != .reified", - .@"trailing.captures.?.len" = .@"@intFromEnum(payload.captures_len)", + .@"trailing.type_hash.?" = .@"payload.bits.captures_len == .reified", + .@"trailing.captures.?" = .@"payload.bits.captures_len != .reified", + .@"trailing.captures.?.len" = .@"@intFromEnum(payload.bits.captures_len)", .@"trailing.field_names.len" = .@"payload.fields_len", .@"trailing.field_types.len" = .@"payload.fields_len", }, @@ -5079,9 +5076,9 @@ pub const Tag = enum(u8) { field_defaults: []Index, }, .config = .{ - .@"trailing.type_hash.?" = .@"payload.captures_len == .reified", - .@"trailing.captures.?" = .@"payload.captures_len != .reified", - .@"trailing.captures.?.len" = .@"@intFromEnum(payload.captures_len)", + .@"trailing.type_hash.?" = .@"payload.bits.captures_len == .reified", + .@"trailing.captures.?" = .@"payload.bits.captures_len != .reified", + .@"trailing.captures.?.len" = .@"@intFromEnum(payload.bits.captures_len)", .@"trailing.field_names.len" = .@"payload.fields_len", .@"trailing.field_types.len" = .@"payload.fields_len", .@"trailing.field_defaults.len" = .@"payload.fields_len", @@ -5096,9 +5093,9 @@ pub const Tag = enum(u8) { field_types: []Index, }, .config = .{ - .@"trailing.type_hash.?" = .@"payload.captures_len == .reified", - .@"trailing.captures.?" = .@"payload.captures_len != .reified", - .@"trailing.captures.?.len" = .@"@intFromEnum(payload.captures_len)", + .@"trailing.type_hash.?" = .@"payload.bits.captures_len == .reified", + .@"trailing.captures.?" = .@"payload.bits.captures_len != .reified", + .@"trailing.captures.?.len" = .@"@intFromEnum(payload.bits.captures_len)", .@"trailing.field_types.len" = .@"payload.fields_len", }, }; @@ -5115,11 +5112,11 @@ pub const Tag = enum(u8) { field_values: []Index, }, .config = .{ - .@"trailing.owner_union.?" = .@"payload.captures_len == .generated_union_tag", - .@"trailing.zir_index.?" = .@"payload.captures_len != .generated_union_tag", - .@"trailing.type_hash.?" = .@"payload.captures_len == .reified", - .@"trailing.captures.?" = .@"payload.captures_len != .reified and payload.captures_len != .generated_enum_tag", - .@"trailing.captures.?.len" = .@"@intFromEnum(payload.captures_len)", + .@"trailing.owner_union.?" = .@"payload.bits.captures_len == .generated_union_tag", + .@"trailing.zir_index.?" = .@"payload.bits.captures_len != .generated_union_tag", + .@"trailing.type_hash.?" = .@"payload.bits.captures_len == .reified", + .@"trailing.captures.?" = .@"payload.bits.captures_len != .reified and payload.bits.captures_len != .generated_union_tag", + .@"trailing.captures.?.len" = .@"@intFromEnum(payload.bits.captures_len)", .@"trailing.field_names.len" = .@"payload.fields_len", .@"trailing.field_values.len" = .@"payload.fields_len", }, @@ -5249,11 +5246,11 @@ pub const Tag = enum(u8) { field_names: []NullTerminatedString, }, .config = .{ - .@"trailing.owner_union.?" = .@"payload.captures_len == .generated_union_tag", - .@"trailing.zir_index.?" = .@"payload.captures_len != .generated_union_tag", - .@"trailing.type_hash.?" = .@"payload.captures_len == .reified", - .@"trailing.captures.?" = .@"payload.captures_len != .reified and payload.captures_len != .generated_enum_tag", - .@"trailing.captures.?.len" = .@"@intFromEnum(payload.captures_len)", + .@"trailing.owner_union.?" = .@"payload.bits.captures_len == .generated_union_tag", + .@"trailing.zir_index.?" = .@"payload.bits.captures_len != .generated_union_tag", + .@"trailing.type_hash.?" = .@"payload.bits.captures_len == .reified", + .@"trailing.captures.?" = .@"payload.bits.captures_len != .reified and payload.bits.captures_len != .generated_union_tag", + .@"trailing.captures.?.len" = .@"@intFromEnum(payload.bits.captures_len)", .@"trailing.field_names.len" = .@"payload.fields_len", }, }, @@ -6379,7 +6376,7 @@ pub fn init(ip: *InternPool, gpa: Allocator, io: Io, available_threads: usize) ! } pub fn deinit(ip: *InternPool, gpa: Allocator, io: Io) void { - if (debug_state.enable_checks) std.debug.assert(debug_state.intern_pool == null); + std.debug.assert(debug_state.intern_pool == null); ip.src_hash_deps.deinit(gpa); ip.nav_val_deps.deinit(gpa); @@ -6424,8 +6421,15 @@ pub fn deinit(ip: *InternPool, gpa: Allocator, io: Io) void { ip.* = undefined; } -pub fn activate(ip: *const InternPool) void { - if (!debug_state.enable) return; +pub const Active = struct { + prev_ip: if (debug_state.enable) ?*const InternPool else void, + pub fn deactivate(active: Active) void { + if (!debug_state.enable) return; + debug_state.intern_pool = active.prev_ip; + } +}; +pub fn activate(ip: *const InternPool) Active { + if (!debug_state.enable) return .{ .prev_ip = {} }; _ = Index.Unwrapped.debug_state; _ = String.debug_state; _ = OptionalString.debug_state; @@ -6435,20 +6439,16 @@ pub fn activate(ip: *const InternPool) void { _ = TrackedInst.Index.Optional.debug_state; _ = Nav.Index.debug_state; _ = Nav.Index.Optional.debug_state; - if (debug_state.enable_checks) std.debug.assert(debug_state.intern_pool == null); - debug_state.intern_pool = ip; -} - -pub fn deactivate(ip: *const InternPool) void { - if (!debug_state.enable) return; - std.debug.assert(debug_state.intern_pool == ip); - if (debug_state.enable_checks) debug_state.intern_pool = null; + defer debug_state.intern_pool = ip; + return .{ .prev_ip = debug_state.intern_pool }; } /// For debugger access only. const debug_state = struct { - const enable = false; - const enable_checks = enable and !builtin.single_threaded; + const enable = switch (builtin.zig_backend) { + else => false, + .stage2_x86_64 => !builtin.strip_debug_info and build_options.io_mode == .threaded, + }; threadlocal var intern_pool: ?*const InternPool = null; }; diff --git a/src/Zcu.zig b/src/Zcu.zig @@ -2822,15 +2822,12 @@ pub fn deinit(zcu: *Zcu) void { const io = comp.io; const gpa = zcu.gpa; { - const pt: Zcu.PerThread = .activate(zcu, .main); - defer pt.deactivate(); - if (zcu.llvm_object) |llvm_object| llvm_object.deinit(); zcu.builtin_modules.deinit(gpa); zcu.module_roots.deinit(gpa); for (zcu.import_table.keys()) |file_index| { - pt.destroyFile(file_index); + zcu.destroyFile(file_index); } zcu.import_table.deinit(gpa); zcu.alive_files.deinit(gpa); @@ -2913,6 +2910,26 @@ pub fn deinit(zcu: *Zcu) void { zcu.intern_pool.deinit(gpa, io); } +fn deinitFile(zcu: *Zcu, file_index: Zcu.File.Index) void { + const gpa = zcu.gpa; + const file = zcu.fileByIndex(file_index); + log.debug("deinit File {f}", .{file.path.fmt(zcu.comp)}); + file.path.deinit(gpa); + file.unload(gpa); + if (file.prev_zir) |prev_zir| { + prev_zir.deinit(gpa); + gpa.destroy(prev_zir); + } + file.* = undefined; +} + +fn destroyFile(zcu: *Zcu, file_index: Zcu.File.Index) void { + const gpa = zcu.gpa; + const file = zcu.fileByIndex(file_index); + deinitFile(zcu, file_index); + gpa.destroy(file); +} + pub fn namespacePtr(zcu: *Zcu, index: Namespace.Index) *Namespace { return zcu.intern_pool.namespacePtr(index); } @@ -5376,9 +5393,9 @@ pub const CodegenTaskPool = struct { const io = zcu.comp.io; const tid: Zcu.PerThread.Id = .acquire(io); defer tid.release(io); - const pt: Zcu.PerThread = .activate(zcu, tid); - defer pt.deactivate(); - return pt.runCodegen(func_index, &air); + const active = zcu.activate(tid); + defer active.deactivate(); + return active.pt.runCodegen(func_index, &air); } fn workerCodegenExternalAir( zcu: *Zcu, @@ -5388,9 +5405,9 @@ pub const CodegenTaskPool = struct { const io = zcu.comp.io; const tid: Zcu.PerThread.Id = .acquire(io); defer tid.release(io); - const pt: Zcu.PerThread = .activate(zcu, tid); - defer pt.deactivate(); - return pt.runCodegen(func_index, air); + const active = zcu.activate(tid); + defer active.deactivate(); + return active.pt.runCodegen(func_index, air); } }; @@ -5419,3 +5436,24 @@ fn updateTracyOutdatedPlots(zcu: *const Zcu) void { zcu.updateTracyPlot("potentially_outdated", zcu.potentially_outdated.count()); zcu.updateTracyPlot("outdated_ready", zcu.outdated_ready.funcs.count() + zcu.outdated_ready.other.count()); } + +pub const Active = struct { + pt: Zcu.PerThread, + ip: InternPool.Active, + pub fn deactivate(active: Active) void { + active.ip.deactivate(); + } + pub fn release(active: Active) void { + active.deactivate(); + active.pt.tid.release(active.pt.zcu.comp.io); + } +}; +pub fn activate(zcu: *Zcu, tid: PerThread.Id) Active { + return .{ + .pt = .{ .zcu = zcu, .tid = tid }, + .ip = zcu.intern_pool.activate(), + }; +} +pub fn acquire(zcu: *Zcu) Active { + return zcu.activate(.acquire(zcu.comp.io)); +} diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig @@ -125,14 +125,6 @@ pub const Id = if (InternPool.single_threaded) enum { } }; -pub fn activate(zcu: *Zcu, tid: Id) Zcu.PerThread { - zcu.intern_pool.activate(); - return .{ .zcu = zcu, .tid = tid }; -} -pub fn deactivate(pt: Zcu.PerThread) void { - pt.zcu.intern_pool.deactivate(); -} - /// Called from `Compilation.performAllTheWork`. Performs one incremental update of the ZCU: detects /// changes to files, runs AstGen, and then enters the main semantic analysis loop, where we build /// up a graph of declarations, functions, etc, while also sending declarations and functions to @@ -378,10 +370,10 @@ fn workerUpdateFile( const child_prog_node = prog_node.start(std.fs.path.basename(file.path.sub_path), 0); defer child_prog_node.end(); - const pt: Zcu.PerThread = .activate(comp.zcu.?, tid); - defer pt.deactivate(); - pt.updateFile(file_index, file) catch |err| { - pt.reportRetryableFileError(file_index, "unable to load '{s}': {s}", .{ std.fs.path.basename(file.path.sub_path), @errorName(err) }) catch |oom| switch (oom) { + const active = comp.zcu.?.activate(tid); + defer active.deactivate(); + active.pt.updateFile(file_index, file) catch |err| { + active.pt.reportRetryableFileError(file_index, "unable to load '{s}': {s}", .{ std.fs.path.basename(file.path.sub_path), @errorName(err) }) catch |oom| switch (oom) { error.OutOfMemory => { comp.mutex.lockUncancelable(io); defer comp.mutex.unlock(io); @@ -411,7 +403,7 @@ fn workerUpdateFile( const import_path = file.zir.?.nullTerminatedString(item.data.name); - if (pt.discoverImport(file.path, import_path)) |res| switch (res) { + if (active.pt.discoverImport(file.path, import_path)) |res| switch (res) { .module, .existing_file => {}, .new_file => |new| { group.async(io, workerUpdateFile, .{ @@ -443,13 +435,15 @@ fn workerUpdateEmbedFile(comp: *Compilation, ef_index: Zcu.EmbedFile.Index, ef: fn detectEmbedFileUpdate(comp: *Compilation, tid: Zcu.PerThread.Id, ef_index: Zcu.EmbedFile.Index, ef: *Zcu.EmbedFile) !void { const io = comp.io; const zcu = comp.zcu.?; - const pt: Zcu.PerThread = .activate(zcu, tid); - defer pt.deactivate(); const old_val = ef.val; const old_err = ef.err; - try pt.updateEmbedFile(ef, null); + { + const active = zcu.activate(tid); + defer active.deactivate(); + try active.pt.updateEmbedFile(ef, null); + } if (ef.val != .none and ef.val == old_val) return; // success, value unchanged 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 try zcu.markDependeeOutdated(.not_marked_po, .{ .embed_file = ef_index }); } -fn deinitFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) void { - const zcu = pt.zcu; - const gpa = zcu.gpa; - const file = zcu.fileByIndex(file_index); - log.debug("deinit File {f}", .{file.path.fmt(zcu.comp)}); - file.path.deinit(gpa); - file.unload(gpa); - if (file.prev_zir) |prev_zir| { - prev_zir.deinit(gpa); - gpa.destroy(prev_zir); - } - file.* = undefined; -} - -pub fn destroyFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) void { - const gpa = pt.zcu.gpa; - const file = pt.zcu.fileByIndex(file_index); - pt.deinitFile(file_index); - gpa.destroy(file); -} - /// Ensures that `file` has up-to-date ZIR. If not, loads the ZIR cache or runs /// AstGen as needed. Also updates `file.status`. Does not assume that `file.mod` /// is populated. Does not return `error.AnalysisFail` on AstGen failures. diff --git a/src/link.zig b/src/link.zig @@ -1529,8 +1529,9 @@ pub fn doZcuTask(comp: *Compilation, tid: Zcu.PerThread.Id, task: ZcuTask) void const diags = &comp.link_diags; const zcu = comp.zcu.?; const ip = &zcu.intern_pool; - const pt: Zcu.PerThread = .activate(zcu, tid); - defer pt.deactivate(); + const active = zcu.activate(tid); + defer active.deactivate(); + const pt = active.pt; var timer = comp.startTimer(); diff --git a/src/link/C.zig b/src/link/C.zig @@ -728,8 +728,9 @@ pub fn flush(c: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Prog const zcu = c.base.comp.zcu.?; const ip = &zcu.intern_pool; const target = zcu.getTarget(); - const pt: Zcu.PerThread = .activate(zcu, tid); - defer pt.deactivate(); + const active = zcu.activate(tid); + defer active.deactivate(); + const pt = active.pt; // If it's somehow not made it into the pool, we need to generate the type `[:0]const u8` for // error names. diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig @@ -267,8 +267,9 @@ pub fn deinit(self: *ZigObject, allocator: Allocator) void { pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void { // Handle any lazy symbols that were emitted by incremental compilation. if (self.lazy_syms.getPtr(.anyerror_type)) |metadata| { - const pt: Zcu.PerThread = .activate(elf_file.base.comp.zcu.?, tid); - defer pt.deactivate(); + const active = elf_file.base.comp.zcu.?.activate(tid); + defer active.deactivate(); + const pt = active.pt; // Most lazy symbols can be updated on first use, but // 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 { } if (build_options.enable_logging) { - const pt: Zcu.PerThread = .activate(elf_file.base.comp.zcu.?, tid); - defer pt.deactivate(); + const active = elf_file.base.comp.zcu.?.activate(tid); + defer active.deactivate(); for (self.navs.keys(), self.navs.values()) |nav_index, meta| { - checkNavAllocated(pt, nav_index, meta); + checkNavAllocated(active.pt, nav_index, meta); } for (self.uavs.keys(), self.uavs.values()) |uav_index, meta| { - checkUavAllocated(pt, uav_index, meta); + checkUavAllocated(active.pt, uav_index, meta); } } if (self.dwarf) |*dwarf| { - const pt: Zcu.PerThread = .activate(elf_file.base.comp.zcu.?, tid); - defer pt.deactivate(); - try dwarf.flush(pt); + { + const active = elf_file.base.comp.zcu.?.activate(tid); + defer active.deactivate(); + try dwarf.flush(active.pt); + } const gpa = elf_file.base.comp.gpa; const cpu_arch = elf_file.getTarget().cpu.arch; diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig @@ -560,14 +560,14 @@ pub fn flush(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id) link.E // Handle any lazy symbols that were emitted by incremental compilation. if (self.lazy_syms.getPtr(.anyerror_type)) |metadata| { - const pt: Zcu.PerThread = .activate(macho_file.base.comp.zcu.?, tid); - defer pt.deactivate(); + const active = macho_file.base.comp.zcu.?.activate(tid); + defer active.deactivate(); // Most lazy symbols can be updated on first use, but // anyerror needs to wait for everything to be flushed. if (metadata.text_state != .unused) self.updateLazySymbol( macho_file, - pt, + active.pt, .{ .kind = .code, .ty = .anyerror_type }, metadata.text_symbol_index, ) catch |err| switch (err) { @@ -576,7 +576,7 @@ pub fn flush(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id) link.E }; if (metadata.const_state != .unused) self.updateLazySymbol( macho_file, - pt, + active.pt, .{ .kind = .const_data, .ty = .anyerror_type }, metadata.const_symbol_index, ) catch |err| switch (err) { @@ -590,9 +590,9 @@ pub fn flush(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id) link.E } if (self.dwarf) |*dwarf| { - const pt: Zcu.PerThread = .activate(macho_file.base.comp.zcu.?, tid); - defer pt.deactivate(); - dwarf.flush(pt) catch |err| switch (err) { + const active = macho_file.base.comp.zcu.?.activate(tid); + defer active.deactivate(); + dwarf.flush(active.pt) catch |err| switch (err) { error.OutOfMemory => |e| return e, else => |e| return diags.fail("failed to flush dwarf module: {s}", .{@errorName(e)}), }; diff --git a/src/link/Queue.zig b/src/link/Queue.zig @@ -101,8 +101,6 @@ pub fn enqueueZcu( ) Io.Cancelable!void { const io = comp.io; - assert(tid == .main); - if (q.future != null) { if (q.zcu_queue.putOne(io, task)) |_| { return;