authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-08-11 10:16:38-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-03 11:00:55-04:00
log2a122576c3042c30f9a78492252cbbc4c0424a40
tree693b48f7dbd595d24c750e770e7ffe4c236b9731
parente761d5200a0888e4c56e04a725979c70de457e71

Sema: avoid using `InternPool.Index` in names

These are not planned to ever be deterministic.

7 files changed, 29 insertions(+), 34 deletions(-)

src/Compilation.zig+1
......@@ -2101,6 +2101,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
21012101 .analysis_roots_buffer = undefined,
21022102 .analysis_roots_len = 0,
21032103 .codegen_task_pool = try .init(arena),
2104 .anon_name_counter = 0,
21042105 };
21052106 try zcu.init(gpa, io, options.thread_limit);
21062107 break :blk zcu;
src/InternPool.zig+7-2
......@@ -9503,6 +9503,7 @@ pub const GetFuncInstanceKey = struct {
95039503 is_noinline: bool,
95049504 generic_owner: Index,
95059505 inferred_error_set: bool,
9506 anon_name_counter: *u32,
95069507};
95079508
95089509pub fn getFuncInstance(
......@@ -9580,6 +9581,7 @@ pub fn getFuncInstance(
95809581 generic_owner,
95819582 func_index,
95829583 func_extra_index,
9584 arg.anon_name_counter,
95839585 );
95849586 return gop.put();
95859587}
......@@ -9731,6 +9733,7 @@ fn getFuncInstanceIes(
97319733 generic_owner,
97329734 func_index,
97339735 func_extra_index,
9736 arg.anon_name_counter,
97349737 );
97359738
97369739 func_gop.putFinal(func_index);
......@@ -9749,14 +9752,16 @@ fn finishFuncInstance(
97499752 generic_owner: Index,
97509753 func_index: Index,
97519754 func_extra_index: u32,
9755 anon_name_counter: *u32,
97529756) Allocator.Error!void {
97539757 const fn_owner_nav = ip.getNav(ip.funcDeclInfo(generic_owner).owner_nav);
97549758 const fn_namespace = fn_owner_nav.analysis.?.namespace;
97559759
97569760 // TODO: improve this name
9757 const nav_name = try ip.getOrPutStringFmt(gpa, io, tid, "{f}__anon_{d}", .{
9758 fn_owner_nav.name.fmt(ip), @backingInt(func_index),
9761 const nav_name = try ip.getOrPutStringFmt(gpa, io, tid, "{f}__func_{d}", .{
9762 fn_owner_nav.name.fmt(ip), anon_name_counter.*,
97599763 }, .no_embedded_nulls);
9764 anon_name_counter.* += 1;
97609765 const nav_fqn = try ip.namespacePtr(fn_namespace).internFullyQualifiedName(ip, gpa, io, tid, nav_name);
97619766 const nav_index = try ip.createNav(gpa, io, tid, nav_name, nav_fqn, .{
97629767 .type = ip.typeOf(func_index),
src/Sema.zig+3-1
......@@ -7039,6 +7039,7 @@ fn analyzeCall(
70397039 .inferred_error_set = fn_zir_info.inferred_error_set,
70407040 .generic_owner = func_val.?.toIntern(),
70417041 .comptime_args = comptime_args,
7042 .anon_name_counter = &zcu.anon_name_counter,
70427043 });
70437044 if (zcu.comp.debugIncremental()) {
70447045 const nav = ip.indexToKey(func_instance).func.owner_nav;
......@@ -35222,9 +35223,10 @@ pub fn setTypeName(
3522235223 io,
3522335224 pt.tid,
3522435225 "{f}__{s}_{d}",
35225 .{ block.type_name_ctx.fmt(ip), anon_prefix, @backingInt(wip.index) },
35226 .{ block.type_name_ctx.fmt(ip), anon_prefix, zcu.anon_name_counter },
3522635227 .no_embedded_nulls,
3522735228 ), .none);
35229 zcu.anon_name_counter += 1;
3522835230 },
3522935231 .parent => wip.setName(ip, block.type_name_ctx, sema.owner.unwrap().nav_val.toOptional()),
3523035232 .func => {
src/Zcu.zig+3
......@@ -348,6 +348,9 @@ codegen_task_pool: CodegenTaskPool,
348348
349349generation: u32 = 0,
350350
351/// Only access from the Sema thread.
352anon_name_counter: u32,
353
351354pub const DependencyReason = struct {
352355 src: LazySrcLoc,
353356 /// Only populated if this is for a `.type_layout` unit.
src/link/Coff.zig+10-11
......@@ -3108,7 +3108,7 @@ fn ensureMemberSymbol(coff: *Coff, mi: Member.Index, name: String) !void {
31083108 coff.member_prog_node.increaseEstimatedTotalItems(1);
31093109}
31103110
3111fn flushSymbolTableEntry(coff: *Coff, index: u32, pt: Zcu.PerThread) !void {
3111fn flushSymbolTableEntry(coff: *Coff, index: u32) !void {
31123112 assert(!coff.isImage());
31133113 const gpa = coff.base.comp.gpa;
31143114
......@@ -3119,7 +3119,6 @@ fn flushSymbolTableEntry(coff: *Coff, index: u32, pt: Zcu.PerThread) !void {
31193119 assert(sym.ni != .none or sym.gmi != .none);
31203120
31213121 const entry = coff.symbolTableEntryPtr(sti.*) orelse entry: {
3122 var buf: [15]u8 = undefined;
31233122 const symbol_name, const num_aux_symbols: u8, const complex_type: std.coff.ComplexType =
31243123 if (sym.gmi != .none) blk: {
31253124 const name = sym.gmi.name(coff);
......@@ -3148,21 +3147,22 @@ fn flushSymbolTableEntry(coff: *Coff, index: u32, pt: Zcu.PerThread) !void {
31483147 };
31493148 },
31503149 .uav => |umi| {
3151 var w = Io.Writer.fixed(&buf);
3152 w.print("__anon_{x}", .{umi.uavValue(coff)}) catch unreachable;
3150 var name_buf: [std.fmt.count("__anon_{d}", .{std.math.maxInt(u32)})]u8 = undefined;
3151 const name = std.mem.print(&name_buf, "__anon_{d}", .{umi}) catch unreachable;
31533152 break :blk .{
3154 try coff.getOrPutSymbolName(w.buffered(), null),
3153 try coff.getOrPutSymbolName(name, null),
31553154 0,
31563155 .NULL,
31573156 };
31583157 },
31593158 inline .lazy_code, .lazy_const_data => |mi, tag| {
31603159 const lazy_sym = mi.lazySymbol(coff);
3161 const name = try gpa.print("__lazy_{s}_{f}", .{
3162 @tagName(lazy_sym.kind),
3163 Type.fromInterned(lazy_sym.ty).fmt(pt),
3164 });
3165 defer gpa.free(name);
3160 var name_buf: [
3161 std.fmt.count("__lazy_const_data_{d}", .{std.math.maxInt(u32)})
3162 ]u8 = undefined;
3163 const name = std.mem.print(&name_buf, "__lazy_{t}_{d}", .{
3164 lazy_sym.kind, mi,
3165 }) catch unreachable;
31663166
31673167 const string = try coff.getOrPutString(name);
31683168 break :blk .{
......@@ -6023,7 +6023,6 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
60236023 defer sub_prog_node.end();
60246024 coff.flushSymbolTableEntry(
60256025 coff.symbol_table.pending_symbol_index,
6026 .{ .zcu = comp.zcu.?, .tid = tid },
60276026 ) catch |err| switch (err) {
60286027 error.OutOfMemory => return error.OutOfMemory,
60296028 else => |e| return comp.link_diags.fail(
src/link/Elf2.zig+3-10
......@@ -3309,11 +3309,8 @@ fn lazySymbolInner(elf: *Elf, pt: Zcu.PerThread, lazy: link.File.LazySymbol) Err
33093309 };
33103310 const node = try shndx.get(elf).ni.addFloatingChild(&elf.mf, gpa, .{});
33113311 var name_buf: [std.fmt.count("__lazy_const_data_{d}", .{std.math.maxInt(u32)})]u8 = undefined;
3312 const name = std.mem.print(
3313 &name_buf,
3314 "__lazy_{t}_{d}",
3315 .{ lazy.kind, @backingInt(lazy.ty) },
3316 ) catch unreachable;
3312 const name = std.mem.print(&name_buf, "__lazy_{t}_{d}", .{ lazy.kind, gop.index }) catch
3313 unreachable;
33173314 gop.value_ptr.* = .{
33183315 .lsi = elf.addLocalSymbolAssumeCapacity(.{
33193316 .node = .wrap(node),
......@@ -5921,11 +5918,7 @@ fn uavMapIndex(
59215918 .alignment = resolved_align,
59225919 });
59235920 var name_buf: [std.fmt.count("__anon_{d}", .{std.math.maxInt(u32)})]u8 = undefined;
5924 const name = std.mem.print(
5925 &name_buf,
5926 "__anon_{d}",
5927 .{@backingInt(uav_val)},
5928 ) catch unreachable;
5921 const name = std.mem.print(&name_buf, "__anon_{d}", .{umi}) catch unreachable;
59295922 uav_gop.value_ptr.* = .{
59305923 .lsi = elf.addLocalSymbolAssumeCapacity(.{
59315924 .node = .wrap(node),
src/link/Wasm.zig+2-10
......@@ -1374,11 +1374,7 @@ pub const GlobalImport = extern struct {
13741374 .__tls_base => @tagName(Unpacked.__tls_base),
13751375 .__tls_size => @tagName(Unpacked.__tls_size),
13761376 .object_global => |i| i.name(wasm).slice(wasm),
1377 inline .uav_obj, .uav_exe => |i| std.mem.print(
1378 buf,
1379 "__anon_{d}",
1380 .{@backingInt(i.key(wasm).*)},
1381 ) catch unreachable,
1377 inline .uav_obj, .uav_exe => |i| std.mem.print(buf, "__anon_{d}", .{i}) catch unreachable,
13821378 .nav_obj => |i| i.name(wasm),
13831379 .nav_exe => |i| i.name(wasm),
13841380 };
......@@ -1997,11 +1993,7 @@ pub const ObjectDataImport = extern struct {
19971993 .__heap_base => @tagName(.__heap_base),
19981994 .__heap_end => @tagName(.__heap_end),
19991995 .__wasm_first_page_end => @tagName(.__wasm_first_page_end),
2000 inline .uav_exe, .uav_obj => |i| std.mem.print(
2001 buf,
2002 "__anon_{d}",
2003 .{@backingInt(i.key(wasm).*)},
2004 ) catch unreachable,
1996 inline .uav_exe, .uav_obj => |i| std.mem.print(buf, "__anon_{d}", .{i}) catch unreachable,
20051997 inline .nav_exe, .nav_obj => |i| i.name(wasm),
20061998 };
20071999 }