authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-07-09 18:48:37-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-07-10 11:10:49-04:00
log667b4f9054cd0d4c8e9912bddc18049d09107678
tree8049d0f1dab34e4bf5994bd4aeacbd1ba7aa804d
parent95d9292a7a09ed883e65510ec054619747315c48

Zcu: cache fully qualified name on Decl

This avoids needing to mutate the intern pool from backends.

18 files changed, 135 insertions(+), 187 deletions(-)

src/InternPool.zig+1
......@@ -7955,6 +7955,7 @@ fn finishFuncInstance(
79557955 const fn_owner_decl = ip.declPtr(ip.funcDeclOwner(generic_owner));
79567956 const decl_index = try ip.createDecl(gpa, tid, .{
79577957 .name = undefined,
7958 .fqn = undefined,
79587959 .src_namespace = fn_owner_decl.src_namespace,
79597960 .has_tv = true,
79607961 .owns_tv = true,
src/Sema.zig+17-18
......@@ -2878,7 +2878,7 @@ fn createAnonymousDeclTypeNamed(
28782878 switch (name_strategy) {
28792879 .anon => {}, // handled after switch
28802880 .parent => {
2881 try zcu.initNewAnonDecl(new_decl_index, val, block.type_name_ctx);
2881 try pt.initNewAnonDecl(new_decl_index, val, block.type_name_ctx, .none);
28822882 return new_decl_index;
28832883 },
28842884 .func => func_strat: {
......@@ -2923,7 +2923,7 @@ fn createAnonymousDeclTypeNamed(
29232923
29242924 try writer.writeByte(')');
29252925 const name = try ip.getOrPutString(gpa, pt.tid, buf.items, .no_embedded_nulls);
2926 try zcu.initNewAnonDecl(new_decl_index, val, name);
2926 try pt.initNewAnonDecl(new_decl_index, val, name, .none);
29272927 return new_decl_index;
29282928 },
29292929 .dbg_var => {
......@@ -2937,7 +2937,7 @@ fn createAnonymousDeclTypeNamed(
29372937 const name = try ip.getOrPutStringFmt(gpa, pt.tid, "{}.{s}", .{
29382938 block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code),
29392939 }, .no_embedded_nulls);
2940 try zcu.initNewAnonDecl(new_decl_index, val, name);
2940 try pt.initNewAnonDecl(new_decl_index, val, name, .none);
29412941 return new_decl_index;
29422942 },
29432943 else => {},
......@@ -2958,7 +2958,7 @@ fn createAnonymousDeclTypeNamed(
29582958 const name = ip.getOrPutStringFmt(gpa, pt.tid, "{}__{s}_{d}", .{
29592959 block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),
29602960 }, .no_embedded_nulls) catch unreachable;
2961 try zcu.initNewAnonDecl(new_decl_index, val, name);
2961 try pt.initNewAnonDecl(new_decl_index, val, name, .none);
29622962 return new_decl_index;
29632963}
29642964
......@@ -5527,13 +5527,12 @@ fn failWithBadStructFieldAccess(
55275527 const zcu = pt.zcu;
55285528 const ip = &zcu.intern_pool;
55295529 const decl = zcu.declPtr(struct_type.decl.unwrap().?);
5530 const fqn = try decl.fullyQualifiedName(pt);
55315530
55325531 const msg = msg: {
55335532 const msg = try sema.errMsg(
55345533 field_src,
55355534 "no field named '{}' in struct '{}'",
5536 .{ field_name.fmt(ip), fqn.fmt(ip) },
5535 .{ field_name.fmt(ip), decl.fqn.fmt(ip) },
55375536 );
55385537 errdefer msg.destroy(sema.gpa);
55395538 try sema.errNote(struct_ty.srcLoc(zcu), msg, "struct declared here", .{});
......@@ -5554,15 +5553,13 @@ fn failWithBadUnionFieldAccess(
55545553 const zcu = pt.zcu;
55555554 const ip = &zcu.intern_pool;
55565555 const gpa = sema.gpa;
5557
55585556 const decl = zcu.declPtr(union_obj.decl);
5559 const fqn = try decl.fullyQualifiedName(pt);
55605557
55615558 const msg = msg: {
55625559 const msg = try sema.errMsg(
55635560 field_src,
55645561 "no field named '{}' in union '{}'",
5565 .{ field_name.fmt(ip), fqn.fmt(ip) },
5562 .{ field_name.fmt(ip), decl.fqn.fmt(ip) },
55665563 );
55675564 errdefer msg.destroy(gpa);
55685565 try sema.errNote(union_ty.srcLoc(zcu), msg, "union declared here", .{});
......@@ -9733,6 +9730,9 @@ fn funcCommon(
97339730 .generic_owner = sema.generic_owner,
97349731 .comptime_args = sema.comptime_args,
97359732 });
9733 const func_decl = mod.declPtr(ip.indexToKey(func_index).func.owner_decl);
9734 func_decl.fqn =
9735 try ip.namespacePtr(func_decl.src_namespace).internFullyQualifiedName(pt, func_decl.name);
97369736 return finishFunc(
97379737 sema,
97389738 block,
......@@ -26500,7 +26500,7 @@ fn zirBuiltinExtern(
2650026500 const new_decl_index = try pt.allocateNewDecl(sema.owner_decl.src_namespace);
2650126501 errdefer pt.destroyDecl(new_decl_index);
2650226502 const new_decl = mod.declPtr(new_decl_index);
26503 try mod.initNewAnonDecl(
26503 try pt.initNewAnonDecl(
2650426504 new_decl_index,
2650526505 Value.fromInterned(
2650626506 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn)
......@@ -26522,6 +26522,7 @@ fn zirBuiltinExtern(
2652226522 } }),
2652326523 ),
2652426524 options.name,
26525 .none,
2652526526 );
2652626527 new_decl.owns_tv = true;
2652726528 // Note that this will queue the anon decl for codegen, so that the backend can
......@@ -36735,24 +36736,23 @@ fn generateUnionTagTypeNumbered(
3673536736
3673636737 const new_decl_index = try pt.allocateNewDecl(block.namespace);
3673736738 errdefer pt.destroyDecl(new_decl_index);
36738 const fqn = try union_owner_decl.fullyQualifiedName(pt);
3673936739 const name = try ip.getOrPutStringFmt(
3674036740 gpa,
3674136741 pt.tid,
3674236742 "@typeInfo({}).Union.tag_type.?",
36743 .{fqn.fmt(ip)},
36743 .{union_owner_decl.fqn.fmt(ip)},
3674436744 .no_embedded_nulls,
3674536745 );
36746 try mod.initNewAnonDecl(
36746 try pt.initNewAnonDecl(
3674736747 new_decl_index,
3674836748 Value.@"unreachable",
3674936749 name,
36750 name.toOptional(),
3675036751 );
3675136752 errdefer pt.abortAnonDecl(new_decl_index);
3675236753
3675336754 const new_decl = mod.declPtr(new_decl_index);
3675436755 new_decl.owns_tv = true;
36755 new_decl.name_fully_qualified = true;
3675636756
3675736757 const enum_ty = try ip.getGeneratedTagEnumType(gpa, pt.tid, .{
3675836758 .decl = new_decl_index,
......@@ -36784,22 +36784,21 @@ fn generateUnionTagTypeSimple(
3678436784 const gpa = sema.gpa;
3678536785
3678636786 const new_decl_index = new_decl_index: {
36787 const fqn = try union_owner_decl.fullyQualifiedName(pt);
3678836787 const new_decl_index = try pt.allocateNewDecl(block.namespace);
3678936788 errdefer pt.destroyDecl(new_decl_index);
3679036789 const name = try ip.getOrPutStringFmt(
3679136790 gpa,
3679236791 pt.tid,
3679336792 "@typeInfo({}).Union.tag_type.?",
36794 .{fqn.fmt(ip)},
36793 .{union_owner_decl.fqn.fmt(ip)},
3679536794 .no_embedded_nulls,
3679636795 );
36797 try mod.initNewAnonDecl(
36796 try pt.initNewAnonDecl(
3679836797 new_decl_index,
3679936798 Value.@"unreachable",
3680036799 name,
36800 name.toOptional(),
3680136801 );
36802 mod.declPtr(new_decl_index).name_fully_qualified = true;
3680336802 break :new_decl_index new_decl_index;
3680436803 };
3680536804 errdefer pt.abortAnonDecl(new_decl_index);
src/Type.zig+7-7
......@@ -268,10 +268,10 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
268268 return;
269269 },
270270 .inferred_error_set_type => |func_index| {
271 try writer.writeAll("@typeInfo(@typeInfo(@TypeOf(");
272271 const owner_decl = mod.funcOwnerDeclPtr(func_index);
273 try owner_decl.renderFullyQualifiedName(mod, writer);
274 try writer.writeAll(")).Fn.return_type.?).ErrorUnion.error_set");
272 try writer.print("@typeInfo(@typeInfo(@TypeOf({})).Fn.return_type.?).ErrorUnion.error_set", .{
273 owner_decl.fqn.fmt(ip),
274 });
275275 },
276276 .error_set_type => |error_set_type| {
277277 const names = error_set_type.names;
......@@ -334,7 +334,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
334334 const struct_type = ip.loadStructType(ty.toIntern());
335335 if (struct_type.decl.unwrap()) |decl_index| {
336336 const decl = mod.declPtr(decl_index);
337 try decl.renderFullyQualifiedName(mod, writer);
337 try writer.print("{}", .{decl.fqn.fmt(ip)});
338338 } else if (ip.loadStructType(ty.toIntern()).namespace.unwrap()) |namespace_index| {
339339 const namespace = mod.namespacePtr(namespace_index);
340340 try namespace.renderFullyQualifiedName(mod, .empty, writer);
......@@ -367,15 +367,15 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
367367
368368 .union_type => {
369369 const decl = mod.declPtr(ip.loadUnionType(ty.toIntern()).decl);
370 try decl.renderFullyQualifiedName(mod, writer);
370 try writer.print("{}", .{decl.fqn.fmt(ip)});
371371 },
372372 .opaque_type => {
373373 const decl = mod.declPtr(ip.loadOpaqueType(ty.toIntern()).decl);
374 try decl.renderFullyQualifiedName(mod, writer);
374 try writer.print("{}", .{decl.fqn.fmt(ip)});
375375 },
376376 .enum_type => {
377377 const decl = mod.declPtr(ip.loadEnumType(ty.toIntern()).decl);
378 try decl.renderFullyQualifiedName(mod, writer);
378 try writer.print("{}", .{decl.fqn.fmt(ip)});
379379 },
380380 .func_type => |fn_info| {
381381 if (fn_info.is_noinline) {
src/Zcu.zig+5-39
......@@ -326,7 +326,10 @@ pub const Reference = struct {
326326};
327327
328328pub const Decl = struct {
329 /// Equal to `fqn` if already fully qualified.
329330 name: InternPool.NullTerminatedString,
331 /// Fully qualified name.
332 fqn: InternPool.NullTerminatedString,
330333 /// The most recent Value of the Decl after a successful semantic analysis.
331334 /// Populated when `has_tv`.
332335 val: Value,
......@@ -384,8 +387,6 @@ pub const Decl = struct {
384387 is_pub: bool,
385388 /// Whether the corresponding AST decl has a `export` keyword.
386389 is_exported: bool,
387 /// If true `name` is already fully qualified.
388 name_fully_qualified: bool = false,
389390 /// What kind of a declaration is this.
390391 kind: Kind,
391392
......@@ -408,25 +409,6 @@ pub const Decl = struct {
408409 return extra.data.getBodies(@intCast(extra.end), zir);
409410 }
410411
411 pub fn renderFullyQualifiedName(decl: Decl, zcu: *Zcu, writer: anytype) !void {
412 if (decl.name_fully_qualified) {
413 try writer.print("{}", .{decl.name.fmt(&zcu.intern_pool)});
414 } else {
415 try zcu.namespacePtr(decl.src_namespace).renderFullyQualifiedName(zcu, decl.name, writer);
416 }
417 }
418
419 pub fn renderFullyQualifiedDebugName(decl: Decl, zcu: *Zcu, writer: anytype) !void {
420 return zcu.namespacePtr(decl.src_namespace).renderFullyQualifiedDebugName(zcu, decl.name, writer);
421 }
422
423 pub fn fullyQualifiedName(decl: Decl, pt: Zcu.PerThread) !InternPool.NullTerminatedString {
424 return if (decl.name_fully_qualified)
425 decl.name
426 else
427 pt.zcu.namespacePtr(decl.src_namespace).fullyQualifiedName(pt, decl.name);
428 }
429
430412 pub fn typeOf(decl: Decl, zcu: *const Zcu) Type {
431413 assert(decl.has_tv);
432414 return decl.val.typeOf(zcu);
......@@ -686,7 +668,7 @@ pub const Namespace = struct {
686668 if (name != .empty) try writer.print("{c}{}", .{ sep, name.fmt(&zcu.intern_pool) });
687669 }
688670
689 pub fn fullyQualifiedName(
671 pub fn internFullyQualifiedName(
690672 ns: Namespace,
691673 pt: Zcu.PerThread,
692674 name: InternPool.NullTerminatedString,
......@@ -882,7 +864,7 @@ pub const File = struct {
882864 };
883865 }
884866
885 pub fn fullyQualifiedName(file: File, pt: Zcu.PerThread) !InternPool.NullTerminatedString {
867 pub fn internFullyQualifiedName(file: File, pt: Zcu.PerThread) !InternPool.NullTerminatedString {
886868 const gpa = pt.zcu.gpa;
887869 const ip = &pt.zcu.intern_pool;
888870 const strings = ip.getLocal(pt.tid).getMutableStrings(gpa);
......@@ -3313,22 +3295,6 @@ pub fn errorSetBits(mod: *Module) u16 {
33133295 return std.math.log2_int_ceil(ErrorInt, mod.error_limit + 1); // +1 for no error
33143296}
33153297
3316pub fn initNewAnonDecl(
3317 mod: *Module,
3318 new_decl_index: Decl.Index,
3319 val: Value,
3320 name: InternPool.NullTerminatedString,
3321) Allocator.Error!void {
3322 const new_decl = mod.declPtr(new_decl_index);
3323
3324 new_decl.name = name;
3325 new_decl.val = val;
3326 new_decl.alignment = .none;
3327 new_decl.@"linksection" = .none;
3328 new_decl.has_tv = true;
3329 new_decl.analysis = .complete;
3330}
3331
33323298pub fn errNote(
33333299 mod: *Module,
33343300 src_loc: LazySrcLoc,
src/Zcu/PerThread.zig+37-21
......@@ -548,7 +548,7 @@ pub fn ensureDeclAnalyzed(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) Zcu.Sem
548548 };
549549 }
550550
551 const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(pt)).toSlice(ip), 0);
551 const decl_prog_node = mod.sema_prog_node.start(decl.fqn.toSlice(ip), 0);
552552 defer decl_prog_node.end();
553553
554554 break :blk pt.semaDecl(decl_index) catch |err| switch (err) {
......@@ -747,10 +747,9 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
747747 defer liveness.deinit(gpa);
748748
749749 if (build_options.enable_debug_extensions and comp.verbose_air) {
750 const fqn = try decl.fullyQualifiedName(pt);
751 std.debug.print("# Begin Function AIR: {}:\n", .{fqn.fmt(ip)});
750 std.debug.print("# Begin Function AIR: {}:\n", .{decl.fqn.fmt(ip)});
752751 @import("../print_air.zig").dump(pt, air, liveness);
753 std.debug.print("# End Function AIR: {}\n\n", .{fqn.fmt(ip)});
752 std.debug.print("# End Function AIR: {}\n\n", .{decl.fqn.fmt(ip)});
754753 }
755754
756755 if (std.debug.runtime_safety) {
......@@ -781,7 +780,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
781780 };
782781 }
783782
784 const codegen_prog_node = zcu.codegen_prog_node.start((try decl.fullyQualifiedName(pt)).toSlice(ip), 0);
783 const codegen_prog_node = zcu.codegen_prog_node.start(decl.fqn.toSlice(ip), 0);
785784 defer codegen_prog_node.end();
786785
787786 if (!air.typesFullyResolved(zcu)) {
......@@ -996,8 +995,8 @@ fn semaFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.SemaError!void {
996995 zcu.setFileRootDecl(file_index, new_decl_index.toOptional());
997996 zcu.namespacePtr(new_namespace_index).decl_index = new_decl_index;
998997
999 new_decl.name = try file.fullyQualifiedName(pt);
1000 new_decl.name_fully_qualified = true;
998 new_decl.fqn = try file.internFullyQualifiedName(pt);
999 new_decl.name = new_decl.fqn;
10011000 new_decl.is_pub = true;
10021001 new_decl.is_exported = false;
10031002 new_decl.alignment = .none;
......@@ -1058,10 +1057,8 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult {
10581057 }
10591058
10601059 log.debug("semaDecl '{d}'", .{@intFromEnum(decl_index)});
1061 log.debug("decl name '{}'", .{(try decl.fullyQualifiedName(pt)).fmt(ip)});
1062 defer blk: {
1063 log.debug("finish decl name '{}'", .{(decl.fullyQualifiedName(pt) catch break :blk).fmt(ip)});
1064 }
1060 log.debug("decl name '{}'", .{decl.fqn.fmt(ip)});
1061 defer log.debug("finish decl name '{}'", .{decl.fqn.fmt(ip)});
10651062
10661063 const old_has_tv = decl.has_tv;
10671064 // The following values are ignored if `!old_has_tv`
......@@ -1728,6 +1725,7 @@ const ScanDeclIter = struct {
17281725 const was_exported = decl.is_exported;
17291726 assert(decl.kind == kind); // ZIR tracking should preserve this
17301727 decl.name = decl_name;
1728 decl.fqn = try namespace.internFullyQualifiedName(pt, decl_name);
17311729 decl.is_pub = declaration.flags.is_pub;
17321730 decl.is_exported = declaration.flags.is_export;
17331731 break :decl_index .{ was_exported, decl_index };
......@@ -1737,6 +1735,7 @@ const ScanDeclIter = struct {
17371735 const new_decl = zcu.declPtr(new_decl_index);
17381736 new_decl.kind = kind;
17391737 new_decl.name = decl_name;
1738 new_decl.fqn = try namespace.internFullyQualifiedName(pt, decl_name);
17401739 new_decl.is_pub = declaration.flags.is_pub;
17411740 new_decl.is_exported = declaration.flags.is_export;
17421741 new_decl.zir_decl_index = tracked_inst.toOptional();
......@@ -1761,10 +1760,9 @@ const ScanDeclIter = struct {
17611760 if (!comp.config.is_test) break :a false;
17621761 if (decl_mod != zcu.main_mod) break :a false;
17631762 if (is_named_test and comp.test_filters.len > 0) {
1764 const decl_fqn = try namespace.fullyQualifiedName(pt, decl_name);
1765 const decl_fqn_slice = decl_fqn.toSlice(ip);
1763 const decl_fqn = decl.fqn.toSlice(ip);
17661764 for (comp.test_filters) |test_filter| {
1767 if (std.mem.indexOf(u8, decl_fqn_slice, test_filter)) |_| break;
1765 if (std.mem.indexOf(u8, decl_fqn, test_filter)) |_| break;
17681766 } else break :a false;
17691767 }
17701768 zcu.test_functions.putAssumeCapacity(decl_index, {}); // may clobber on incremental update
......@@ -1805,12 +1803,10 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
18051803 const decl_index = func.owner_decl;
18061804 const decl = mod.declPtr(decl_index);
18071805
1808 log.debug("func name '{}'", .{(try decl.fullyQualifiedName(pt)).fmt(ip)});
1809 defer blk: {
1810 log.debug("finish func name '{}'", .{(decl.fullyQualifiedName(pt) catch break :blk).fmt(ip)});
1811 }
1806 log.debug("func name '{}'", .{decl.fqn.fmt(ip)});
1807 defer log.debug("finish func name '{}'", .{decl.fqn.fmt(ip)});
18121808
1813 const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(pt)).toSlice(ip), 0);
1809 const decl_prog_node = mod.sema_prog_node.start(decl.fqn.toSlice(ip), 0);
18141810 defer decl_prog_node.end();
18151811
18161812 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.AnalUnit.wrap(.{ .func = func_index }));
......@@ -2053,6 +2049,7 @@ pub fn allocateNewDecl(pt: Zcu.PerThread, namespace: Zcu.Namespace.Index) !Zcu.D
20532049 const gpa = zcu.gpa;
20542050 const decl_index = try zcu.intern_pool.createDecl(gpa, pt.tid, .{
20552051 .name = undefined,
2052 .fqn = undefined,
20562053 .src_namespace = namespace,
20572054 .has_tv = false,
20582055 .owns_tv = false,
......@@ -2077,6 +2074,25 @@ pub fn allocateNewDecl(pt: Zcu.PerThread, namespace: Zcu.Namespace.Index) !Zcu.D
20772074 return decl_index;
20782075}
20792076
2077pub fn initNewAnonDecl(
2078 pt: Zcu.PerThread,
2079 new_decl_index: Zcu.Decl.Index,
2080 val: Value,
2081 name: InternPool.NullTerminatedString,
2082 fqn: InternPool.OptionalNullTerminatedString,
2083) Allocator.Error!void {
2084 const new_decl = pt.zcu.declPtr(new_decl_index);
2085
2086 new_decl.name = name;
2087 new_decl.fqn = fqn.unwrap() orelse
2088 try pt.zcu.namespacePtr(new_decl.src_namespace).internFullyQualifiedName(pt, name);
2089 new_decl.val = val;
2090 new_decl.alignment = .none;
2091 new_decl.@"linksection" = .none;
2092 new_decl.has_tv = true;
2093 new_decl.analysis = .complete;
2094}
2095
20802096fn lockAndClearFileCompileError(pt: Zcu.PerThread, file: *Zcu.File) void {
20812097 switch (file.status) {
20822098 .success_zir, .retryable_failure => {},
......@@ -2260,7 +2276,7 @@ pub fn populateTestFunctions(
22602276
22612277 for (test_fn_vals, zcu.test_functions.keys()) |*test_fn_val, test_decl_index| {
22622278 const test_decl = zcu.declPtr(test_decl_index);
2263 const test_decl_name = try test_decl.fullyQualifiedName(pt);
2279 const test_decl_name = test_decl.fqn;
22642280 const test_decl_name_len = test_decl_name.length(ip);
22652281 const test_name_anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl = n: {
22662282 const test_name_ty = try pt.arrayType(.{
......@@ -2366,7 +2382,7 @@ pub fn linkerUpdateDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !void {
23662382
23672383 const decl = zcu.declPtr(decl_index);
23682384
2369 const codegen_prog_node = zcu.codegen_prog_node.start((try decl.fullyQualifiedName(pt)).toSlice(&zcu.intern_pool), 0);
2385 const codegen_prog_node = zcu.codegen_prog_node.start(decl.fqn.toSlice(&zcu.intern_pool), 0);
23702386 defer codegen_prog_node.end();
23712387
23722388 if (comp.bin_file) |lf| {
src/arch/riscv64/CodeGen.zig+1-1
......@@ -933,7 +933,7 @@ fn formatDecl(
933933 _: std.fmt.FormatOptions,
934934 writer: anytype,
935935) @TypeOf(writer).Error!void {
936 try data.mod.declPtr(data.decl_index).renderFullyQualifiedName(data.mod, writer);
936 try writer.print("{}", .{data.mod.declPtr(data.decl_index).fqn.fmt(&data.mod.intern_pool)});
937937}
938938fn fmtDecl(func: *Func, decl_index: InternPool.DeclIndex) std.fmt.Formatter(formatDecl) {
939939 return .{ .data = .{
src/arch/wasm/CodeGen.zig+2-2
......@@ -7284,8 +7284,8 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
72847284 defer arena_allocator.deinit();
72857285 const arena = arena_allocator.allocator();
72867286
7287 const fqn = try mod.declPtr(enum_decl_index).fullyQualifiedName(pt);
7288 const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{}", .{fqn.fmt(ip)});
7287 const decl = mod.declPtr(enum_decl_index);
7288 const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{}", .{decl.fqn.fmt(ip)});
72897289
72907290 // check if we already generated code for this.
72917291 if (func.bin_file.findGlobalSymbol(func_name)) |loc| {
src/arch/x86_64/CodeGen.zig+1-1
......@@ -1077,7 +1077,7 @@ fn formatDecl(
10771077 _: std.fmt.FormatOptions,
10781078 writer: anytype,
10791079) @TypeOf(writer).Error!void {
1080 try data.zcu.declPtr(data.decl_index).renderFullyQualifiedName(data.zcu, writer);
1080 try writer.print("{}", .{data.zcu.declPtr(data.decl_index).fqn.fmt(&data.zcu.intern_pool)});
10811081}
10821082fn fmtDecl(self: *Self, decl_index: InternPool.DeclIndex) std.fmt.Formatter(formatDecl) {
10831083 return .{ .data = .{
src/codegen/c.zig+6-14
......@@ -2194,13 +2194,9 @@ pub const DeclGen = struct {
21942194 }) else {
21952195 // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),
21962196 // expand to 3x the length of its input, but let's cut it off at a much shorter limit.
2197 var name: [100]u8 = undefined;
2198 var name_stream = std.io.fixedBufferStream(&name);
2199 decl.renderFullyQualifiedName(zcu, name_stream.writer()) catch |err| switch (err) {
2200 error.NoSpaceLeft => {},
2201 };
2197 const fqn_slice = decl.fqn.toSlice(ip);
22022198 try writer.print("{}__{d}", .{
2203 fmtIdent(name_stream.getWritten()),
2199 fmtIdent(fqn_slice[0..@min(fqn_slice.len, 100)]),
22042200 @intFromEnum(decl_index),
22052201 });
22062202 }
......@@ -2587,11 +2583,9 @@ pub fn genTypeDecl(
25872583 try writer.writeByte(';');
25882584 const owner_decl = zcu.declPtr(owner_decl_index);
25892585 const owner_mod = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu).mod;
2590 if (!owner_mod.strip) {
2591 try writer.writeAll(" /* ");
2592 try owner_decl.renderFullyQualifiedName(zcu, writer);
2593 try writer.writeAll(" */");
2594 }
2586 if (!owner_mod.strip) try writer.print(" /* {} */", .{
2587 owner_decl.fqn.fmt(&zcu.intern_pool),
2588 });
25952589 try writer.writeByte('\n');
25962590 },
25972591 },
......@@ -4563,9 +4557,7 @@ fn airDbgInlineBlock(f: *Function, inst: Air.Inst.Index) !CValue {
45634557 const extra = f.air.extraData(Air.DbgInlineBlock, ty_pl.payload);
45644558 const owner_decl = zcu.funcOwnerDeclPtr(extra.data.func);
45654559 const writer = f.object.writer();
4566 try writer.writeAll("/* inline:");
4567 try owner_decl.renderFullyQualifiedName(zcu, writer);
4568 try writer.writeAll(" */\n");
4560 try writer.print("/* inline:{} */\n", .{owner_decl.fqn.fmt(&zcu.intern_pool)});
45694561 return lowerBlock(f, inst, @ptrCast(f.air.extra[extra.end..][0..extra.data.body_len]));
45704562}
45714563
src/codegen/llvm.zig+17-24
......@@ -1744,7 +1744,7 @@ pub const Object = struct {
17441744 if (export_indices.len != 0) {
17451745 return updateExportedGlobal(self, zcu, global_index, export_indices);
17461746 } else {
1747 const fqn = try self.builder.strtabString((try decl.fullyQualifiedName(pt)).toSlice(ip));
1747 const fqn = try self.builder.strtabString(decl.fqn.toSlice(ip));
17481748 try global_index.rename(fqn, &self.builder);
17491749 global_index.setLinkage(.internal, &self.builder);
17501750 if (comp.config.dll_export_fns)
......@@ -2863,10 +2863,7 @@ pub const Object = struct {
28632863 const is_extern = decl.isExtern(zcu);
28642864 const function_index = try o.builder.addFunction(
28652865 try o.lowerType(zig_fn_type),
2866 try o.builder.strtabString((if (is_extern)
2867 decl.name
2868 else
2869 try decl.fullyQualifiedName(pt)).toSlice(ip)),
2866 try o.builder.strtabString((if (is_extern) decl.name else decl.fqn).toSlice(ip)),
28702867 toLlvmAddressSpace(decl.@"addrspace", target),
28712868 );
28722869 gop.value_ptr.* = function_index.ptrConst(&o.builder).global;
......@@ -3077,14 +3074,12 @@ pub const Object = struct {
30773074
30783075 const pt = o.pt;
30793076 const zcu = pt.zcu;
3077 const ip = &zcu.intern_pool;
30803078 const decl = zcu.declPtr(decl_index);
30813079 const is_extern = decl.isExtern(zcu);
30823080
30833081 const variable_index = try o.builder.addVariable(
3084 try o.builder.strtabString((if (is_extern)
3085 decl.name
3086 else
3087 try decl.fullyQualifiedName(pt)).toSlice(&zcu.intern_pool)),
3082 try o.builder.strtabString((if (is_extern) decl.name else decl.fqn).toSlice(ip)),
30883083 try o.lowerType(decl.typeOf(zcu)),
30893084 toLlvmGlobalAddressSpace(decl.@"addrspace", zcu.getTarget()),
30903085 );
......@@ -3312,7 +3307,7 @@ pub const Object = struct {
33123307 return int_ty;
33133308 }
33143309
3315 const fqn = try mod.declPtr(struct_type.decl.unwrap().?).fullyQualifiedName(pt);
3310 const decl = mod.declPtr(struct_type.decl.unwrap().?);
33163311
33173312 var llvm_field_types = std.ArrayListUnmanaged(Builder.Type){};
33183313 defer llvm_field_types.deinit(o.gpa);
......@@ -3377,7 +3372,7 @@ pub const Object = struct {
33773372 );
33783373 }
33793374
3380 const ty = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip)));
3375 const ty = try o.builder.opaqueType(try o.builder.string(decl.fqn.toSlice(ip)));
33813376 try o.type_map.put(o.gpa, t.toIntern(), ty);
33823377
33833378 o.builder.namedTypeSetBody(
......@@ -3466,7 +3461,7 @@ pub const Object = struct {
34663461 return enum_tag_ty;
34673462 }
34683463
3469 const fqn = try mod.declPtr(union_obj.decl).fullyQualifiedName(pt);
3464 const decl = mod.declPtr(union_obj.decl);
34703465
34713466 const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]);
34723467 const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty);
......@@ -3486,7 +3481,7 @@ pub const Object = struct {
34863481 };
34873482
34883483 if (layout.tag_size == 0) {
3489 const ty = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip)));
3484 const ty = try o.builder.opaqueType(try o.builder.string(decl.fqn.toSlice(ip)));
34903485 try o.type_map.put(o.gpa, t.toIntern(), ty);
34913486
34923487 o.builder.namedTypeSetBody(
......@@ -3514,7 +3509,7 @@ pub const Object = struct {
35143509 llvm_fields_len += 1;
35153510 }
35163511
3517 const ty = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip)));
3512 const ty = try o.builder.opaqueType(try o.builder.string(decl.fqn.toSlice(ip)));
35183513 try o.type_map.put(o.gpa, t.toIntern(), ty);
35193514
35203515 o.builder.namedTypeSetBody(
......@@ -3527,8 +3522,7 @@ pub const Object = struct {
35273522 const gop = try o.type_map.getOrPut(o.gpa, t.toIntern());
35283523 if (!gop.found_existing) {
35293524 const decl = mod.declPtr(ip.loadOpaqueType(t.toIntern()).decl);
3530 const fqn = try decl.fullyQualifiedName(pt);
3531 gop.value_ptr.* = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip)));
3525 gop.value_ptr.* = try o.builder.opaqueType(try o.builder.string(decl.fqn.toSlice(ip)));
35323526 }
35333527 return gop.value_ptr.*;
35343528 },
......@@ -4587,11 +4581,11 @@ pub const Object = struct {
45874581
45884582 const usize_ty = try o.lowerType(Type.usize);
45894583 const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0);
4590 const fqn = try zcu.declPtr(enum_type.decl).fullyQualifiedName(pt);
4584 const decl = zcu.declPtr(enum_type.decl);
45914585 const target = zcu.root_mod.resolved_target.result;
45924586 const function_index = try o.builder.addFunction(
45934587 try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
4594 try o.builder.strtabStringFmt("__zig_tag_name_{}", .{fqn.fmt(ip)}),
4588 try o.builder.strtabStringFmt("__zig_tag_name_{}", .{decl.fqn.fmt(ip)}),
45954589 toLlvmAddressSpace(.generic, target),
45964590 );
45974591
......@@ -5175,8 +5169,6 @@ pub const FuncGen = struct {
51755169 const line_number = decl.navSrcLine(zcu) + 1;
51765170 self.inlined = self.wip.debug_location;
51775171
5178 const fqn = try decl.fullyQualifiedName(pt);
5179
51805172 const fn_ty = try pt.funcType(.{
51815173 .param_types = &.{},
51825174 .return_type = .void_type,
......@@ -5185,7 +5177,7 @@ pub const FuncGen = struct {
51855177 self.scope = try o.builder.debugSubprogram(
51865178 self.file,
51875179 try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)),
5188 try o.builder.metadataString(fqn.toSlice(&zcu.intern_pool)),
5180 try o.builder.metadataString(decl.fqn.toSlice(&zcu.intern_pool)),
51895181 line_number,
51905182 line_number + func.lbrace_line,
51915183 try o.lowerDebugType(fn_ty),
......@@ -9702,18 +9694,19 @@ pub const FuncGen = struct {
97029694 const o = self.dg.object;
97039695 const pt = o.pt;
97049696 const zcu = pt.zcu;
9705 const enum_type = zcu.intern_pool.loadEnumType(enum_ty.toIntern());
9697 const ip = &zcu.intern_pool;
9698 const enum_type = ip.loadEnumType(enum_ty.toIntern());
97069699
97079700 // TODO: detect when the type changes and re-emit this function.
97089701 const gop = try o.named_enum_map.getOrPut(o.gpa, enum_type.decl);
97099702 if (gop.found_existing) return gop.value_ptr.*;
97109703 errdefer assert(o.named_enum_map.remove(enum_type.decl));
97119704
9712 const fqn = try zcu.declPtr(enum_type.decl).fullyQualifiedName(pt);
9705 const decl = zcu.declPtr(enum_type.decl);
97139706 const target = zcu.root_mod.resolved_target.result;
97149707 const function_index = try o.builder.addFunction(
97159708 try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
9716 try o.builder.strtabStringFmt("__zig_is_named_enum_value_{}", .{fqn.fmt(&zcu.intern_pool)}),
9709 try o.builder.strtabStringFmt("__zig_is_named_enum_value_{}", .{decl.fqn.fmt(ip)}),
97179710 toLlvmAddressSpace(.generic, target),
97189711 );
97199712
src/codegen/spirv.zig+4-7
......@@ -3012,12 +3012,11 @@ const DeclGen = struct {
30123012 // Append the actual code into the functions section.
30133013 try self.spv.addFunction(spv_decl_index, self.func);
30143014
3015 const fqn = try decl.fullyQualifiedName(self.pt);
3016 try self.spv.debugName(result_id, fqn.toSlice(ip));
3015 try self.spv.debugName(result_id, decl.fqn.toSlice(ip));
30173016
30183017 // Temporarily generate a test kernel declaration if this is a test function.
30193018 if (self.pt.zcu.test_functions.contains(self.decl_index)) {
3020 try self.generateTestEntryPoint(fqn.toSlice(ip), spv_decl_index);
3019 try self.generateTestEntryPoint(decl.fqn.toSlice(ip), spv_decl_index);
30213020 }
30223021 },
30233022 .global => {
......@@ -3041,8 +3040,7 @@ const DeclGen = struct {
30413040 .storage_class = final_storage_class,
30423041 });
30433042
3044 const fqn = try decl.fullyQualifiedName(self.pt);
3045 try self.spv.debugName(result_id, fqn.toSlice(ip));
3043 try self.spv.debugName(result_id, decl.fqn.toSlice(ip));
30463044 try self.spv.declareDeclDeps(spv_decl_index, &.{});
30473045 },
30483046 .invocation_global => {
......@@ -3086,8 +3084,7 @@ const DeclGen = struct {
30863084 try self.func.body.emit(self.spv.gpa, .OpFunctionEnd, {});
30873085 try self.spv.addFunction(spv_decl_index, self.func);
30883086
3089 const fqn = try decl.fullyQualifiedName(self.pt);
3090 try self.spv.debugNameFmt(initializer_id, "initializer of {}", .{fqn.fmt(ip)});
3087 try self.spv.debugNameFmt(initializer_id, "initializer of {}", .{decl.fqn.fmt(ip)});
30913088
30923089 try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpExtInst, .{
30933090 .id_result_type = ptr_ty_id,
src/link/Coff.zig+8-9
......@@ -1176,9 +1176,10 @@ pub fn lowerUnnamedConst(self: *Coff, pt: Zcu.PerThread, val: Value, decl_index:
11761176 gop.value_ptr.* = .{};
11771177 }
11781178 const unnamed_consts = gop.value_ptr;
1179 const decl_name = try decl.fullyQualifiedName(pt);
11801179 const index = unnamed_consts.items.len;
1181 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
1180 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{
1181 decl.fqn.fmt(&mod.intern_pool), index,
1182 });
11821183 defer gpa.free(sym_name);
11831184 const ty = val.typeOf(mod);
11841185 const atom_index = switch (try self.lowerConst(pt, sym_name, val, ty.abiAlignment(pt), self.rdata_section_index.?, decl.navSrcLoc(mod))) {
......@@ -1427,9 +1428,7 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd
14271428 const mod = pt.zcu;
14281429 const decl = mod.declPtr(decl_index);
14291430
1430 const decl_name = try decl.fullyQualifiedName(pt);
1431
1432 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
1431 log.debug("updateDeclCode {}{*}", .{ decl.fqn.fmt(&mod.intern_pool), decl });
14331432 const required_alignment: u32 = @intCast(decl.getAlignment(pt).toByteUnits() orelse 0);
14341433
14351434 const decl_metadata = self.decls.get(decl_index).?;
......@@ -1441,7 +1440,7 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd
14411440
14421441 if (atom.size != 0) {
14431442 const sym = atom.getSymbolPtr(self);
1444 try self.setSymbolName(sym, decl_name.toSlice(&mod.intern_pool));
1443 try self.setSymbolName(sym, decl.fqn.toSlice(&mod.intern_pool));
14451444 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));
14461445 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };
14471446
......@@ -1449,7 +1448,7 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd
14491448 const need_realloc = code.len > capacity or !mem.isAlignedGeneric(u64, sym.value, required_alignment);
14501449 if (need_realloc) {
14511450 const vaddr = try self.growAtom(atom_index, code_len, required_alignment);
1452 log.debug("growing {} from 0x{x} to 0x{x}", .{ decl_name.fmt(&mod.intern_pool), sym.value, vaddr });
1451 log.debug("growing {} from 0x{x} to 0x{x}", .{ decl.fqn.fmt(&mod.intern_pool), sym.value, vaddr });
14531452 log.debug(" (required alignment 0x{x}", .{required_alignment});
14541453
14551454 if (vaddr != sym.value) {
......@@ -1465,13 +1464,13 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd
14651464 self.getAtomPtr(atom_index).size = code_len;
14661465 } else {
14671466 const sym = atom.getSymbolPtr(self);
1468 try self.setSymbolName(sym, decl_name.toSlice(&mod.intern_pool));
1467 try self.setSymbolName(sym, decl.fqn.toSlice(&mod.intern_pool));
14691468 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));
14701469 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };
14711470
14721471 const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment);
14731472 errdefer self.freeAtom(atom_index);
1474 log.debug("allocated atom for {} at 0x{x}", .{ decl_name.fmt(&mod.intern_pool), vaddr });
1473 log.debug("allocated atom for {} at 0x{x}", .{ decl.fqn.fmt(&mod.intern_pool), vaddr });
14751474 self.getAtomPtr(atom_index).size = code_len;
14761475 sym.value = vaddr;
14771476
src/link/Dwarf.zig+2-4
......@@ -1082,9 +1082,7 @@ pub fn initDeclState(self: *Dwarf, pt: Zcu.PerThread, decl_index: InternPool.Dec
10821082 defer tracy.end();
10831083
10841084 const decl = pt.zcu.declPtr(decl_index);
1085 const decl_linkage_name = try decl.fullyQualifiedName(pt);
1086
1087 log.debug("initDeclState {}{*}", .{ decl_linkage_name.fmt(&pt.zcu.intern_pool), decl });
1085 log.debug("initDeclState {}{*}", .{ decl.fqn.fmt(&pt.zcu.intern_pool), decl });
10881086
10891087 const gpa = self.allocator;
10901088 var decl_state: DeclState = .{
......@@ -1157,7 +1155,7 @@ pub fn initDeclState(self: *Dwarf, pt: Zcu.PerThread, decl_index: InternPool.Dec
11571155
11581156 // .debug_info subprogram
11591157 const decl_name_slice = decl.name.toSlice(&pt.zcu.intern_pool);
1160 const decl_linkage_name_slice = decl_linkage_name.toSlice(&pt.zcu.intern_pool);
1158 const decl_linkage_name_slice = decl.fqn.toSlice(&pt.zcu.intern_pool);
11611159 try dbg_info_buffer.ensureUnusedCapacity(1 + ptr_width_bytes + 4 + 4 +
11621160 (decl_name_slice.len + 1) + (decl_linkage_name_slice.len + 1));
11631161
src/link/Elf/ZigObject.zig+9-11
......@@ -907,10 +907,10 @@ fn updateDeclCode(
907907) !void {
908908 const gpa = elf_file.base.comp.gpa;
909909 const mod = pt.zcu;
910 const ip = &mod.intern_pool;
910911 const decl = mod.declPtr(decl_index);
911 const decl_name = try decl.fullyQualifiedName(pt);
912912
913 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
913 log.debug("updateDeclCode {}{*}", .{ decl.fqn.fmt(ip), decl });
914914
915915 const required_alignment = decl.getAlignment(pt).max(
916916 target_util.minFunctionAlignment(mod.getTarget()),
......@@ -923,7 +923,7 @@ fn updateDeclCode(
923923 sym.output_section_index = shdr_index;
924924 atom_ptr.output_section_index = shdr_index;
925925
926 sym.name_offset = try self.strtab.insert(gpa, decl_name.toSlice(&mod.intern_pool));
926 sym.name_offset = try self.strtab.insert(gpa, decl.fqn.toSlice(ip));
927927 atom_ptr.flags.alive = true;
928928 atom_ptr.name_offset = sym.name_offset;
929929 esym.st_name = sym.name_offset;
......@@ -940,7 +940,7 @@ fn updateDeclCode(
940940 const need_realloc = code.len > capacity or !required_alignment.check(@intCast(atom_ptr.value));
941941 if (need_realloc) {
942942 try atom_ptr.grow(elf_file);
943 log.debug("growing {} from 0x{x} to 0x{x}", .{ decl_name.fmt(&mod.intern_pool), old_vaddr, atom_ptr.value });
943 log.debug("growing {} from 0x{x} to 0x{x}", .{ decl.fqn.fmt(ip), old_vaddr, atom_ptr.value });
944944 if (old_vaddr != atom_ptr.value) {
945945 sym.value = 0;
946946 esym.st_value = 0;
......@@ -1007,11 +1007,11 @@ fn updateTlv(
10071007 code: []const u8,
10081008) !void {
10091009 const mod = pt.zcu;
1010 const ip = &mod.intern_pool;
10101011 const gpa = mod.gpa;
10111012 const decl = mod.declPtr(decl_index);
1012 const decl_name = try decl.fullyQualifiedName(pt);
10131013
1014 log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&mod.intern_pool), decl });
1014 log.debug("updateTlv {} ({*})", .{ decl.fqn.fmt(ip), decl });
10151015
10161016 const required_alignment = decl.getAlignment(pt);
10171017
......@@ -1023,7 +1023,7 @@ fn updateTlv(
10231023 sym.output_section_index = shndx;
10241024 atom_ptr.output_section_index = shndx;
10251025
1026 sym.name_offset = try self.strtab.insert(gpa, decl_name.toSlice(&mod.intern_pool));
1026 sym.name_offset = try self.strtab.insert(gpa, decl.fqn.toSlice(ip));
10271027 atom_ptr.flags.alive = true;
10281028 atom_ptr.name_offset = sym.name_offset;
10291029 esym.st_value = 0;
......@@ -1286,9 +1286,8 @@ pub fn lowerUnnamedConst(
12861286 }
12871287 const unnamed_consts = gop.value_ptr;
12881288 const decl = mod.declPtr(decl_index);
1289 const decl_name = try decl.fullyQualifiedName(pt);
12901289 const index = unnamed_consts.items.len;
1291 const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
1290 const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl.fqn.fmt(&mod.intern_pool), index });
12921291 defer gpa.free(name);
12931292 const ty = val.typeOf(mod);
12941293 const sym_index = switch (try self.lowerConst(
......@@ -1473,9 +1472,8 @@ pub fn updateDeclLineNumber(
14731472 defer tracy.end();
14741473
14751474 const decl = pt.zcu.declPtr(decl_index);
1476 const decl_name = try decl.fullyQualifiedName(pt);
14771475
1478 log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&pt.zcu.intern_pool), decl });
1476 log.debug("updateDeclLineNumber {}{*}", .{ decl.fqn.fmt(&pt.zcu.intern_pool), decl });
14791477
14801478 if (self.dwarf) |*dw| {
14811479 try dw.updateDeclLineNumber(pt.zcu, decl_index);
src/link/MachO/ZigObject.zig+10-14
......@@ -809,10 +809,10 @@ fn updateDeclCode(
809809) !void {
810810 const gpa = macho_file.base.comp.gpa;
811811 const mod = pt.zcu;
812 const ip = &mod.intern_pool;
812813 const decl = mod.declPtr(decl_index);
813 const decl_name = try decl.fullyQualifiedName(pt);
814814
815 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
815 log.debug("updateDeclCode {}{*}", .{ decl.fqn.fmt(ip), decl });
816816
817817 const required_alignment = decl.getAlignment(pt);
818818
......@@ -824,7 +824,7 @@ fn updateDeclCode(
824824 sym.out_n_sect = sect_index;
825825 atom.out_n_sect = sect_index;
826826
827 sym.name = try self.strtab.insert(gpa, decl_name.toSlice(&mod.intern_pool));
827 sym.name = try self.strtab.insert(gpa, decl.fqn.toSlice(ip));
828828 atom.flags.alive = true;
829829 atom.name = sym.name;
830830 nlist.n_strx = sym.name;
......@@ -843,7 +843,7 @@ fn updateDeclCode(
843843
844844 if (need_realloc) {
845845 try atom.grow(macho_file);
846 log.debug("growing {} from 0x{x} to 0x{x}", .{ decl_name.fmt(&mod.intern_pool), old_vaddr, atom.value });
846 log.debug("growing {} from 0x{x} to 0x{x}", .{ decl.fqn.fmt(ip), old_vaddr, atom.value });
847847 if (old_vaddr != atom.value) {
848848 sym.value = 0;
849849 nlist.n_value = 0;
......@@ -893,25 +893,22 @@ fn updateTlv(
893893 sect_index: u8,
894894 code: []const u8,
895895) !void {
896 const ip = &pt.zcu.intern_pool;
896897 const decl = pt.zcu.declPtr(decl_index);
897 const decl_name = try decl.fullyQualifiedName(pt);
898898
899 log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&pt.zcu.intern_pool), decl });
900
901 const decl_name_slice = decl_name.toSlice(&pt.zcu.intern_pool);
902 const required_alignment = decl.getAlignment(pt);
899 log.debug("updateTlv {} ({*})", .{ decl.fqn.fmt(&pt.zcu.intern_pool), decl });
903900
904901 // 1. Lower TLV initializer
905902 const init_sym_index = try self.createTlvInitializer(
906903 macho_file,
907 decl_name_slice,
908 required_alignment,
904 decl.fqn.toSlice(ip),
905 decl.getAlignment(pt),
909906 sect_index,
910907 code,
911908 );
912909
913910 // 2. Create TLV descriptor
914 try self.createTlvDescriptor(macho_file, sym_index, init_sym_index, decl_name_slice);
911 try self.createTlvDescriptor(macho_file, sym_index, init_sym_index, decl.fqn.toSlice(ip));
915912}
916913
917914fn createTlvInitializer(
......@@ -1099,9 +1096,8 @@ pub fn lowerUnnamedConst(
10991096 }
11001097 const unnamed_consts = gop.value_ptr;
11011098 const decl = mod.declPtr(decl_index);
1102 const decl_name = try decl.fullyQualifiedName(pt);
11031099 const index = unnamed_consts.items.len;
1104 const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
1100 const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl.fqn.fmt(&mod.intern_pool), index });
11051101 defer gpa.free(name);
11061102 const sym_index = switch (try self.lowerConst(
11071103 macho_file,
src/link/Plan9.zig+1-3
......@@ -483,11 +483,9 @@ pub fn lowerUnnamedConst(self: *Plan9, pt: Zcu.PerThread, val: Value, decl_index
483483 }
484484 const unnamed_consts = gop.value_ptr;
485485
486 const decl_name = try decl.fullyQualifiedName(pt);
487
488486 const index = unnamed_consts.items.len;
489487 // name is freed when the unnamed const is freed
490 const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
488 const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl.fqn.fmt(&mod.intern_pool), index });
491489
492490 const sym_index = try self.allocateSymbolIndex();
493491 const new_atom_idx = try self.createAtom();
src/link/Wasm/ZigObject.zig+5-10
......@@ -346,8 +346,7 @@ fn finishUpdateDecl(
346346 const atom_index = decl_info.atom;
347347 const atom = wasm_file.getAtomPtr(atom_index);
348348 const sym = zig_object.symbol(atom.sym_index);
349 const full_name = try decl.fullyQualifiedName(pt);
350 sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(ip));
349 sym.name = try zig_object.string_table.insert(gpa, decl.fqn.toSlice(ip));
351350 try atom.code.appendSlice(gpa, code);
352351 atom.size = @intCast(code.len);
353352
......@@ -387,7 +386,7 @@ fn finishUpdateDecl(
387386 // Will be freed upon freeing of decl or after cleanup of Wasm binary.
388387 const full_segment_name = try std.mem.concat(gpa, u8, &.{
389388 segment_name,
390 full_name.toSlice(ip),
389 decl.fqn.toSlice(ip),
391390 });
392391 errdefer gpa.free(full_segment_name);
393392 sym.tag = .data;
......@@ -436,9 +435,8 @@ pub fn getOrCreateAtomForDecl(
436435 const sym_index = try zig_object.allocateSymbol(gpa);
437436 gop.value_ptr.* = .{ .atom = try wasm_file.createAtom(sym_index, zig_object.index) };
438437 const decl = pt.zcu.declPtr(decl_index);
439 const full_name = try decl.fullyQualifiedName(pt);
440438 const sym = zig_object.symbol(sym_index);
441 sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&pt.zcu.intern_pool));
439 sym.name = try zig_object.string_table.insert(gpa, decl.fqn.toSlice(&pt.zcu.intern_pool));
442440 }
443441 return gop.value_ptr.atom;
444442}
......@@ -494,9 +492,8 @@ pub fn lowerUnnamedConst(
494492 const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index);
495493 const parent_atom = wasm_file.getAtom(parent_atom_index);
496494 const local_index = parent_atom.locals.items.len;
497 const fqn = try decl.fullyQualifiedName(pt);
498495 const name = try std.fmt.allocPrintZ(gpa, "__unnamed_{}_{d}", .{
499 fqn.fmt(&mod.intern_pool), local_index,
496 decl.fqn.fmt(&mod.intern_pool), local_index,
500497 });
501498 defer gpa.free(name);
502499
......@@ -1127,9 +1124,7 @@ pub fn updateDeclLineNumber(
11271124) !void {
11281125 if (zig_object.dwarf) |*dw| {
11291126 const decl = pt.zcu.declPtr(decl_index);
1130 const decl_name = try decl.fullyQualifiedName(pt);
1131
1132 log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&pt.zcu.intern_pool), decl });
1127 log.debug("updateDeclLineNumber {}{*}", .{ decl.fqn.fmt(&pt.zcu.intern_pool), decl });
11331128 try dw.updateDeclLineNumber(pt.zcu, decl_index);
11341129 }
11351130}
src/print_value.zig+2-2
......@@ -299,8 +299,8 @@ fn printPtrDerivation(derivation: Value.PointerDeriveStep, writer: anytype, leve
299299 int.ptr_ty.fmt(pt),
300300 int.addr,
301301 }),
302 .decl_ptr => |decl| {
303 try zcu.declPtr(decl).renderFullyQualifiedName(zcu, writer);
302 .decl_ptr => |decl_index| {
303 try writer.print("{}", .{zcu.declPtr(decl_index).fqn.fmt(ip)});
304304 },
305305 .anon_decl_ptr => |anon| {
306306 const ty = Value.fromInterned(anon.val).typeOf(zcu);