Skip to content

Commit 5c76e08

Browse files
committed
lldb: add pretty printer for intern pool indices
1 parent 0620647 commit 5c76e08

File tree

13 files changed

+616
-220
lines changed

13 files changed

+616
-220
lines changed

src/Compilation.zig

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,8 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
21812181
}
21822182

21832183
if (comp.zcu) |zcu| {
2184-
const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
2184+
const pt: Zcu.PerThread = .activate(zcu, .main);
2185+
defer pt.deactivate();
21852186

21862187
zcu.compile_log_text.shrinkAndFree(gpa, 0);
21872188

@@ -2251,7 +2252,8 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
22512252
try comp.performAllTheWork(main_progress_node);
22522253

22532254
if (comp.zcu) |zcu| {
2254-
const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
2255+
const pt: Zcu.PerThread = .activate(zcu, .main);
2256+
defer pt.deactivate();
22552257

22562258
if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {
22572259
std.debug.print("intern pool stats for '{s}':\n", .{
@@ -3609,7 +3611,8 @@ fn performAllTheWorkInner(
36093611
}
36103612

36113613
if (comp.zcu) |zcu| {
3612-
const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
3614+
const pt: Zcu.PerThread = .activate(zcu, .main);
3615+
defer pt.deactivate();
36133616
if (comp.incremental) {
36143617
const update_zir_refs_node = main_progress_node.start("Update ZIR References", 0);
36153618
defer update_zir_refs_node.end();
@@ -3683,14 +3686,16 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
36833686
const named_frame = tracy.namedFrame("analyze_func");
36843687
defer named_frame.end();
36853688

3686-
const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
3689+
const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
3690+
defer pt.deactivate();
36873691
pt.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
36883692
error.OutOfMemory => return error.OutOfMemory,
36893693
error.AnalysisFail => return,
36903694
};
36913695
},
36923696
.analyze_cau => |cau_index| {
3693-
const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
3697+
const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
3698+
defer pt.deactivate();
36943699
pt.ensureCauAnalyzed(cau_index) catch |err| switch (err) {
36953700
error.OutOfMemory => return error.OutOfMemory,
36963701
error.AnalysisFail => return,
@@ -3719,7 +3724,8 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
37193724
const named_frame = tracy.namedFrame("resolve_type_fully");
37203725
defer named_frame.end();
37213726

3722-
const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
3727+
const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
3728+
defer pt.deactivate();
37233729
Type.fromInterned(ty).resolveFully(pt) catch |err| switch (err) {
37243730
error.OutOfMemory => return error.OutOfMemory,
37253731
error.AnalysisFail => return,
@@ -3729,7 +3735,8 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
37293735
const named_frame = tracy.namedFrame("analyze_mod");
37303736
defer named_frame.end();
37313737

3732-
const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
3738+
const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
3739+
defer pt.deactivate();
37333740
pt.semaPkg(mod) catch |err| switch (err) {
37343741
error.OutOfMemory => return error.OutOfMemory,
37353742
error.AnalysisFail => return,
@@ -4183,7 +4190,8 @@ fn workerAstGenFile(
41834190
const child_prog_node = prog_node.start(file.sub_file_path, 0);
41844191
defer child_prog_node.end();
41854192

4186-
const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
4193+
const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
4194+
defer pt.deactivate();
41874195
pt.astGenFile(file, path_digest) catch |err| switch (err) {
41884196
error.AnalysisFail => return,
41894197
else => {

src/InternPool.zig

Lines changed: 313 additions & 119 deletions
Large diffs are not rendered by default.

src/Type.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ pub const ResolveStratLazy = enum {
891891
};
892892

893893
/// The chosen strategy can be easily optimized away in release builds.
894-
/// However, in debug builds, it helps to avoid acceidentally resolving types in backends.
894+
/// However, in debug builds, it helps to avoid accidentally resolving types in backends.
895895
pub const ResolveStrat = enum {
896896
/// Assert that all necessary resolution is completed.
897897
/// Backends should typically use this, since they must not perform type resolution.

src/Zcu.zig

Lines changed: 67 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,90 +2169,92 @@ pub fn init(zcu: *Zcu, thread_count: usize) !void {
21692169
}
21702170

21712171
pub fn deinit(zcu: *Zcu) void {
2172-
const pt: Zcu.PerThread = .{ .tid = .main, .zcu = zcu };
21732172
const gpa = zcu.gpa;
2173+
{
2174+
const pt: Zcu.PerThread = .activate(zcu, .main);
2175+
defer pt.deactivate();
21742176

2175-
if (zcu.llvm_object) |llvm_object| llvm_object.deinit();
2176-
2177-
for (zcu.import_table.keys()) |key| {
2178-
gpa.free(key);
2179-
}
2180-
for (zcu.import_table.values()) |file_index| {
2181-
pt.destroyFile(file_index);
2182-
}
2183-
zcu.import_table.deinit(gpa);
2177+
if (zcu.llvm_object) |llvm_object| llvm_object.deinit();
21842178

2185-
for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| {
2186-
gpa.free(path);
2187-
gpa.destroy(embed_file);
2188-
}
2189-
zcu.embed_table.deinit(gpa);
2179+
for (zcu.import_table.keys()) |key| {
2180+
gpa.free(key);
2181+
}
2182+
for (zcu.import_table.values()) |file_index| {
2183+
pt.destroyFile(file_index);
2184+
}
2185+
zcu.import_table.deinit(gpa);
21902186

2191-
zcu.compile_log_text.deinit(gpa);
2187+
for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| {
2188+
gpa.free(path);
2189+
gpa.destroy(embed_file);
2190+
}
2191+
zcu.embed_table.deinit(gpa);
21922192

2193-
zcu.local_zir_cache.handle.close();
2194-
zcu.global_zir_cache.handle.close();
2193+
zcu.compile_log_text.deinit(gpa);
21952194

2196-
for (zcu.failed_analysis.values()) |value| {
2197-
value.destroy(gpa);
2198-
}
2199-
for (zcu.failed_codegen.values()) |value| {
2200-
value.destroy(gpa);
2201-
}
2202-
zcu.analysis_in_progress.deinit(gpa);
2203-
zcu.failed_analysis.deinit(gpa);
2204-
zcu.transitive_failed_analysis.deinit(gpa);
2205-
zcu.failed_codegen.deinit(gpa);
2195+
zcu.local_zir_cache.handle.close();
2196+
zcu.global_zir_cache.handle.close();
22062197

2207-
for (zcu.failed_files.values()) |value| {
2208-
if (value) |msg| msg.destroy(gpa);
2209-
}
2210-
zcu.failed_files.deinit(gpa);
2198+
for (zcu.failed_analysis.values()) |value| {
2199+
value.destroy(gpa);
2200+
}
2201+
for (zcu.failed_codegen.values()) |value| {
2202+
value.destroy(gpa);
2203+
}
2204+
zcu.analysis_in_progress.deinit(gpa);
2205+
zcu.failed_analysis.deinit(gpa);
2206+
zcu.transitive_failed_analysis.deinit(gpa);
2207+
zcu.failed_codegen.deinit(gpa);
22112208

2212-
for (zcu.failed_embed_files.values()) |msg| {
2213-
msg.destroy(gpa);
2214-
}
2215-
zcu.failed_embed_files.deinit(gpa);
2209+
for (zcu.failed_files.values()) |value| {
2210+
if (value) |msg| msg.destroy(gpa);
2211+
}
2212+
zcu.failed_files.deinit(gpa);
22162213

2217-
for (zcu.failed_exports.values()) |value| {
2218-
value.destroy(gpa);
2219-
}
2220-
zcu.failed_exports.deinit(gpa);
2214+
for (zcu.failed_embed_files.values()) |msg| {
2215+
msg.destroy(gpa);
2216+
}
2217+
zcu.failed_embed_files.deinit(gpa);
22212218

2222-
for (zcu.cimport_errors.values()) |*errs| {
2223-
errs.deinit(gpa);
2224-
}
2225-
zcu.cimport_errors.deinit(gpa);
2219+
for (zcu.failed_exports.values()) |value| {
2220+
value.destroy(gpa);
2221+
}
2222+
zcu.failed_exports.deinit(gpa);
22262223

2227-
zcu.compile_log_sources.deinit(gpa);
2224+
for (zcu.cimport_errors.values()) |*errs| {
2225+
errs.deinit(gpa);
2226+
}
2227+
zcu.cimport_errors.deinit(gpa);
22282228

2229-
zcu.all_exports.deinit(gpa);
2230-
zcu.free_exports.deinit(gpa);
2231-
zcu.single_exports.deinit(gpa);
2232-
zcu.multi_exports.deinit(gpa);
2229+
zcu.compile_log_sources.deinit(gpa);
22332230

2234-
zcu.potentially_outdated.deinit(gpa);
2235-
zcu.outdated.deinit(gpa);
2236-
zcu.outdated_ready.deinit(gpa);
2237-
zcu.retryable_failures.deinit(gpa);
2231+
zcu.all_exports.deinit(gpa);
2232+
zcu.free_exports.deinit(gpa);
2233+
zcu.single_exports.deinit(gpa);
2234+
zcu.multi_exports.deinit(gpa);
22382235

2239-
zcu.test_functions.deinit(gpa);
2236+
zcu.potentially_outdated.deinit(gpa);
2237+
zcu.outdated.deinit(gpa);
2238+
zcu.outdated_ready.deinit(gpa);
2239+
zcu.retryable_failures.deinit(gpa);
22402240

2241-
for (zcu.global_assembly.values()) |s| {
2242-
gpa.free(s);
2243-
}
2244-
zcu.global_assembly.deinit(gpa);
2241+
zcu.test_functions.deinit(gpa);
22452242

2246-
zcu.reference_table.deinit(gpa);
2247-
zcu.all_references.deinit(gpa);
2248-
zcu.free_references.deinit(gpa);
2243+
for (zcu.global_assembly.values()) |s| {
2244+
gpa.free(s);
2245+
}
2246+
zcu.global_assembly.deinit(gpa);
22492247

2250-
zcu.type_reference_table.deinit(gpa);
2251-
zcu.all_type_references.deinit(gpa);
2252-
zcu.free_type_references.deinit(gpa);
2248+
zcu.reference_table.deinit(gpa);
2249+
zcu.all_references.deinit(gpa);
2250+
zcu.free_references.deinit(gpa);
22532251

2254-
if (zcu.resolved_references) |*r| r.deinit(gpa);
2252+
zcu.type_reference_table.deinit(gpa);
2253+
zcu.all_type_references.deinit(gpa);
2254+
zcu.free_type_references.deinit(gpa);
22552255

2256+
if (zcu.resolved_references) |*r| r.deinit(gpa);
2257+
}
22562258
zcu.intern_pool.deinit(gpa);
22572259
}
22582260

src/Zcu/PerThread.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ tid: Id,
3535
pub const IdBacking = u7;
3636
pub const Id = if (InternPool.single_threaded) enum { main } else enum(IdBacking) { main, _ };
3737

38+
pub fn activate(zcu: *Zcu, tid: Id) Zcu.PerThread {
39+
zcu.intern_pool.activate();
40+
return .{ .zcu = zcu, .tid = tid };
41+
}
42+
43+
pub fn deactivate(pt: Zcu.PerThread) void {
44+
pt.zcu.intern_pool.deactivate();
45+
}
46+
3847
fn deinitFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) void {
3948
const zcu = pt.zcu;
4049
const gpa = zcu.gpa;

src/link.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,20 +1537,23 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
15371537
};
15381538
},
15391539
.codegen_nav => |nav_index| {
1540-
const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
1540+
const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
1541+
defer pt.deactivate();
15411542
pt.linkerUpdateNav(nav_index) catch |err| switch (err) {
15421543
error.OutOfMemory => diags.setAllocFailure(),
15431544
};
15441545
},
15451546
.codegen_func => |func| {
1546-
const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
1547+
const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
1548+
defer pt.deactivate();
15471549
// This call takes ownership of `func.air`.
15481550
pt.linkerUpdateFunc(func.func, func.air) catch |err| switch (err) {
15491551
error.OutOfMemory => diags.setAllocFailure(),
15501552
};
15511553
},
15521554
.codegen_type => |ty| {
1553-
const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
1555+
const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
1556+
defer pt.deactivate();
15541557
pt.linkerUpdateContainerType(ty) catch |err| switch (err) {
15551558
error.OutOfMemory => diags.setAllocFailure(),
15561559
};

src/link/C.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ pub fn flushModule(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
419419
const gpa = comp.gpa;
420420
const zcu = self.base.comp.zcu.?;
421421
const ip = &zcu.intern_pool;
422-
const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = tid };
422+
const pt: Zcu.PerThread = .activate(zcu, tid);
423+
defer pt.deactivate();
423424

424425
{
425426
var i: usize = 0;

src/link/Coff.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,10 +2218,11 @@ pub fn flushModule(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
22182218
const sub_prog_node = prog_node.start("COFF Flush", 0);
22192219
defer sub_prog_node.end();
22202220

2221-
const pt: Zcu.PerThread = .{
2222-
.zcu = comp.zcu orelse return error.LinkingWithoutZigSourceUnimplemented,
2223-
.tid = tid,
2224-
};
2221+
const pt: Zcu.PerThread = .activate(
2222+
comp.zcu orelse return error.LinkingWithoutZigSourceUnimplemented,
2223+
tid,
2224+
);
2225+
defer pt.deactivate();
22252226

22262227
if (coff.lazy_syms.getPtr(.anyerror_type)) |metadata| {
22272228
// Most lazy symbols can be updated on first use, but

src/link/Elf/ZigObject.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ pub fn deinit(self: *ZigObject, allocator: Allocator) void {
267267
pub 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 = .{ .zcu = elf_file.base.comp.zcu.?, .tid = tid };
270+
const pt: Zcu.PerThread = .activate(elf_file.base.comp.zcu.?, tid);
271+
defer pt.deactivate();
271272

272273
// Most lazy symbols can be updated on first use, but
273274
// anyerror needs to wait for everything to be flushed.
@@ -296,7 +297,8 @@ pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
296297
}
297298

298299
if (build_options.enable_logging) {
299-
const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.zcu.?, .tid = tid };
300+
const pt: Zcu.PerThread = .activate(elf_file.base.comp.zcu.?, tid);
301+
defer pt.deactivate();
300302
for (self.navs.keys(), self.navs.values()) |nav_index, meta| {
301303
checkNavAllocated(pt, nav_index, meta);
302304
}
@@ -306,7 +308,8 @@ pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
306308
}
307309

308310
if (self.dwarf) |*dwarf| {
309-
const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.zcu.?, .tid = tid };
311+
const pt: Zcu.PerThread = .activate(elf_file.base.comp.zcu.?, tid);
312+
defer pt.deactivate();
310313
try dwarf.flushModule(pt);
311314

312315
const gpa = elf_file.base.comp.gpa;

src/link/MachO/ZigObject.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@ pub fn getInputSection(self: ZigObject, atom: Atom, macho_file: *MachO) macho.se
549549
pub fn flushModule(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id) !void {
550550
// Handle any lazy symbols that were emitted by incremental compilation.
551551
if (self.lazy_syms.getPtr(.anyerror_type)) |metadata| {
552-
const pt: Zcu.PerThread = .{ .zcu = macho_file.base.comp.zcu.?, .tid = tid };
552+
const pt: Zcu.PerThread = .activate(macho_file.base.comp.zcu.?, tid);
553+
defer pt.deactivate();
553554

554555
// Most lazy symbols can be updated on first use, but
555556
// anyerror needs to wait for everything to be flushed.
@@ -578,7 +579,8 @@ pub fn flushModule(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id)
578579
}
579580

580581
if (self.dwarf) |*dwarf| {
581-
const pt: Zcu.PerThread = .{ .zcu = macho_file.base.comp.zcu.?, .tid = tid };
582+
const pt: Zcu.PerThread = .activate(macho_file.base.comp.zcu.?, tid);
583+
defer pt.deactivate();
582584
try dwarf.flushModule(pt);
583585

584586
self.debug_abbrev_dirty = false;

0 commit comments

Comments
 (0)