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(...@@ -7955,6 +7955,7 @@ fn finishFuncInstance(
7955 const fn_owner_decl = ip.declPtr(ip.funcDeclOwner(generic_owner));7955 const fn_owner_decl = ip.declPtr(ip.funcDeclOwner(generic_owner));
7956 const decl_index = try ip.createDecl(gpa, tid, .{7956 const decl_index = try ip.createDecl(gpa, tid, .{
7957 .name = undefined,7957 .name = undefined,
7958 .fqn = undefined,
7958 .src_namespace = fn_owner_decl.src_namespace,7959 .src_namespace = fn_owner_decl.src_namespace,
7959 .has_tv = true,7960 .has_tv = true,
7960 .owns_tv = true,7961 .owns_tv = true,
src/Sema.zig+17-18
...@@ -2878,7 +2878,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2878,7 +2878,7 @@ fn createAnonymousDeclTypeNamed(
2878 switch (name_strategy) {2878 switch (name_strategy) {
2879 .anon => {}, // handled after switch2879 .anon => {}, // handled after switch
2880 .parent => {2880 .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);
2882 return new_decl_index;2882 return new_decl_index;
2883 },2883 },
2884 .func => func_strat: {2884 .func => func_strat: {
...@@ -2923,7 +2923,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2923,7 +2923,7 @@ fn createAnonymousDeclTypeNamed(
29232923
2924 try writer.writeByte(')');2924 try writer.writeByte(')');
2925 const name = try ip.getOrPutString(gpa, pt.tid, buf.items, .no_embedded_nulls);2925 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);
2927 return new_decl_index;2927 return new_decl_index;
2928 },2928 },
2929 .dbg_var => {2929 .dbg_var => {
...@@ -2937,7 +2937,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2937,7 +2937,7 @@ fn createAnonymousDeclTypeNamed(
2937 const name = try ip.getOrPutStringFmt(gpa, pt.tid, "{}.{s}", .{2937 const name = try ip.getOrPutStringFmt(gpa, pt.tid, "{}.{s}", .{
2938 block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code),2938 block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code),
2939 }, .no_embedded_nulls);2939 }, .no_embedded_nulls);
2940 try zcu.initNewAnonDecl(new_decl_index, val, name);2940 try pt.initNewAnonDecl(new_decl_index, val, name, .none);
2941 return new_decl_index;2941 return new_decl_index;
2942 },2942 },
2943 else => {},2943 else => {},
...@@ -2958,7 +2958,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2958,7 +2958,7 @@ fn createAnonymousDeclTypeNamed(
2958 const name = ip.getOrPutStringFmt(gpa, pt.tid, "{}__{s}_{d}", .{2958 const name = ip.getOrPutStringFmt(gpa, pt.tid, "{}__{s}_{d}", .{
2959 block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),2959 block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),
2960 }, .no_embedded_nulls) catch unreachable;2960 }, .no_embedded_nulls) catch unreachable;
2961 try zcu.initNewAnonDecl(new_decl_index, val, name);2961 try pt.initNewAnonDecl(new_decl_index, val, name, .none);
2962 return new_decl_index;2962 return new_decl_index;
2963}2963}
29642964
...@@ -5527,13 +5527,12 @@ fn failWithBadStructFieldAccess(...@@ -5527,13 +5527,12 @@ fn failWithBadStructFieldAccess(
5527 const zcu = pt.zcu;5527 const zcu = pt.zcu;
5528 const ip = &zcu.intern_pool;5528 const ip = &zcu.intern_pool;
5529 const decl = zcu.declPtr(struct_type.decl.unwrap().?);5529 const decl = zcu.declPtr(struct_type.decl.unwrap().?);
5530 const fqn = try decl.fullyQualifiedName(pt);
55315530
5532 const msg = msg: {5531 const msg = msg: {
5533 const msg = try sema.errMsg(5532 const msg = try sema.errMsg(
5534 field_src,5533 field_src,
5535 "no field named '{}' in struct '{}'",5534 "no field named '{}' in struct '{}'",
5536 .{ field_name.fmt(ip), fqn.fmt(ip) },5535 .{ field_name.fmt(ip), decl.fqn.fmt(ip) },
5537 );5536 );
5538 errdefer msg.destroy(sema.gpa);5537 errdefer msg.destroy(sema.gpa);
5539 try sema.errNote(struct_ty.srcLoc(zcu), msg, "struct declared here", .{});5538 try sema.errNote(struct_ty.srcLoc(zcu), msg, "struct declared here", .{});
...@@ -5554,15 +5553,13 @@ fn failWithBadUnionFieldAccess(...@@ -5554,15 +5553,13 @@ fn failWithBadUnionFieldAccess(
5554 const zcu = pt.zcu;5553 const zcu = pt.zcu;
5555 const ip = &zcu.intern_pool;5554 const ip = &zcu.intern_pool;
5556 const gpa = sema.gpa;5555 const gpa = sema.gpa;
5557
5558 const decl = zcu.declPtr(union_obj.decl);5556 const decl = zcu.declPtr(union_obj.decl);
5559 const fqn = try decl.fullyQualifiedName(pt);
55605557
5561 const msg = msg: {5558 const msg = msg: {
5562 const msg = try sema.errMsg(5559 const msg = try sema.errMsg(
5563 field_src,5560 field_src,
5564 "no field named '{}' in union '{}'",5561 "no field named '{}' in union '{}'",
5565 .{ field_name.fmt(ip), fqn.fmt(ip) },5562 .{ field_name.fmt(ip), decl.fqn.fmt(ip) },
5566 );5563 );
5567 errdefer msg.destroy(gpa);5564 errdefer msg.destroy(gpa);
5568 try sema.errNote(union_ty.srcLoc(zcu), msg, "union declared here", .{});5565 try sema.errNote(union_ty.srcLoc(zcu), msg, "union declared here", .{});
...@@ -9733,6 +9730,9 @@ fn funcCommon(...@@ -9733,6 +9730,9 @@ fn funcCommon(
9733 .generic_owner = sema.generic_owner,9730 .generic_owner = sema.generic_owner,
9734 .comptime_args = sema.comptime_args,9731 .comptime_args = sema.comptime_args,
9735 });9732 });
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);
9736 return finishFunc(9736 return finishFunc(
9737 sema,9737 sema,
9738 block,9738 block,
...@@ -26500,7 +26500,7 @@ fn zirBuiltinExtern(...@@ -26500,7 +26500,7 @@ fn zirBuiltinExtern(
26500 const new_decl_index = try pt.allocateNewDecl(sema.owner_decl.src_namespace);26500 const new_decl_index = try pt.allocateNewDecl(sema.owner_decl.src_namespace);
26501 errdefer pt.destroyDecl(new_decl_index);26501 errdefer pt.destroyDecl(new_decl_index);
26502 const new_decl = mod.declPtr(new_decl_index);26502 const new_decl = mod.declPtr(new_decl_index);
26503 try mod.initNewAnonDecl(26503 try pt.initNewAnonDecl(
26504 new_decl_index,26504 new_decl_index,
26505 Value.fromInterned(26505 Value.fromInterned(
26506 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn)26506 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn)
...@@ -26522,6 +26522,7 @@ fn zirBuiltinExtern(...@@ -26522,6 +26522,7 @@ fn zirBuiltinExtern(
26522 } }),26522 } }),
26523 ),26523 ),
26524 options.name,26524 options.name,
26525 .none,
26525 );26526 );
26526 new_decl.owns_tv = true;26527 new_decl.owns_tv = true;
26527 // Note that this will queue the anon decl for codegen, so that the backend can26528 // Note that this will queue the anon decl for codegen, so that the backend can
...@@ -36735,24 +36736,23 @@ fn generateUnionTagTypeNumbered(...@@ -36735,24 +36736,23 @@ fn generateUnionTagTypeNumbered(
3673536736
36736 const new_decl_index = try pt.allocateNewDecl(block.namespace);36737 const new_decl_index = try pt.allocateNewDecl(block.namespace);
36737 errdefer pt.destroyDecl(new_decl_index);36738 errdefer pt.destroyDecl(new_decl_index);
36738 const fqn = try union_owner_decl.fullyQualifiedName(pt);
36739 const name = try ip.getOrPutStringFmt(36739 const name = try ip.getOrPutStringFmt(
36740 gpa,36740 gpa,
36741 pt.tid,36741 pt.tid,
36742 "@typeInfo({}).Union.tag_type.?",36742 "@typeInfo({}).Union.tag_type.?",
36743 .{fqn.fmt(ip)},36743 .{union_owner_decl.fqn.fmt(ip)},
36744 .no_embedded_nulls,36744 .no_embedded_nulls,
36745 );36745 );
36746 try mod.initNewAnonDecl(36746 try pt.initNewAnonDecl(
36747 new_decl_index,36747 new_decl_index,
36748 Value.@"unreachable",36748 Value.@"unreachable",
36749 name,36749 name,
36750 name.toOptional(),
36750 );36751 );
36751 errdefer pt.abortAnonDecl(new_decl_index);36752 errdefer pt.abortAnonDecl(new_decl_index);
3675236753
36753 const new_decl = mod.declPtr(new_decl_index);36754 const new_decl = mod.declPtr(new_decl_index);
36754 new_decl.owns_tv = true;36755 new_decl.owns_tv = true;
36755 new_decl.name_fully_qualified = true;
3675636756
36757 const enum_ty = try ip.getGeneratedTagEnumType(gpa, pt.tid, .{36757 const enum_ty = try ip.getGeneratedTagEnumType(gpa, pt.tid, .{
36758 .decl = new_decl_index,36758 .decl = new_decl_index,
...@@ -36784,22 +36784,21 @@ fn generateUnionTagTypeSimple(...@@ -36784,22 +36784,21 @@ fn generateUnionTagTypeSimple(
36784 const gpa = sema.gpa;36784 const gpa = sema.gpa;
3678536785
36786 const new_decl_index = new_decl_index: {36786 const new_decl_index = new_decl_index: {
36787 const fqn = try union_owner_decl.fullyQualifiedName(pt);
36788 const new_decl_index = try pt.allocateNewDecl(block.namespace);36787 const new_decl_index = try pt.allocateNewDecl(block.namespace);
36789 errdefer pt.destroyDecl(new_decl_index);36788 errdefer pt.destroyDecl(new_decl_index);
36790 const name = try ip.getOrPutStringFmt(36789 const name = try ip.getOrPutStringFmt(
36791 gpa,36790 gpa,
36792 pt.tid,36791 pt.tid,
36793 "@typeInfo({}).Union.tag_type.?",36792 "@typeInfo({}).Union.tag_type.?",
36794 .{fqn.fmt(ip)},36793 .{union_owner_decl.fqn.fmt(ip)},
36795 .no_embedded_nulls,36794 .no_embedded_nulls,
36796 );36795 );
36797 try mod.initNewAnonDecl(36796 try pt.initNewAnonDecl(
36798 new_decl_index,36797 new_decl_index,
36799 Value.@"unreachable",36798 Value.@"unreachable",
36800 name,36799 name,
36800 name.toOptional(),
36801 );36801 );
36802 mod.declPtr(new_decl_index).name_fully_qualified = true;
36803 break :new_decl_index new_decl_index;36802 break :new_decl_index new_decl_index;
36804 };36803 };
36805 errdefer pt.abortAnonDecl(new_decl_index);36804 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...@@ -268,10 +268,10 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
268 return;268 return;
269 },269 },
270 .inferred_error_set_type => |func_index| {270 .inferred_error_set_type => |func_index| {
271 try writer.writeAll("@typeInfo(@typeInfo(@TypeOf(");
272 const owner_decl = mod.funcOwnerDeclPtr(func_index);271 const owner_decl = mod.funcOwnerDeclPtr(func_index);
273 try owner_decl.renderFullyQualifiedName(mod, writer);272 try writer.print("@typeInfo(@typeInfo(@TypeOf({})).Fn.return_type.?).ErrorUnion.error_set", .{
274 try writer.writeAll(")).Fn.return_type.?).ErrorUnion.error_set");273 owner_decl.fqn.fmt(ip),
274 });
275 },275 },
276 .error_set_type => |error_set_type| {276 .error_set_type => |error_set_type| {
277 const names = error_set_type.names;277 const names = error_set_type.names;
...@@ -334,7 +334,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error...@@ -334,7 +334,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
334 const struct_type = ip.loadStructType(ty.toIntern());334 const struct_type = ip.loadStructType(ty.toIntern());
335 if (struct_type.decl.unwrap()) |decl_index| {335 if (struct_type.decl.unwrap()) |decl_index| {
336 const decl = mod.declPtr(decl_index);336 const decl = mod.declPtr(decl_index);
337 try decl.renderFullyQualifiedName(mod, writer);337 try writer.print("{}", .{decl.fqn.fmt(ip)});
338 } else if (ip.loadStructType(ty.toIntern()).namespace.unwrap()) |namespace_index| {338 } else if (ip.loadStructType(ty.toIntern()).namespace.unwrap()) |namespace_index| {
339 const namespace = mod.namespacePtr(namespace_index);339 const namespace = mod.namespacePtr(namespace_index);
340 try namespace.renderFullyQualifiedName(mod, .empty, writer);340 try namespace.renderFullyQualifiedName(mod, .empty, writer);
...@@ -367,15 +367,15 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error...@@ -367,15 +367,15 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
367367
368 .union_type => {368 .union_type => {
369 const decl = mod.declPtr(ip.loadUnionType(ty.toIntern()).decl);369 const decl = mod.declPtr(ip.loadUnionType(ty.toIntern()).decl);
370 try decl.renderFullyQualifiedName(mod, writer);370 try writer.print("{}", .{decl.fqn.fmt(ip)});
371 },371 },
372 .opaque_type => {372 .opaque_type => {
373 const decl = mod.declPtr(ip.loadOpaqueType(ty.toIntern()).decl);373 const decl = mod.declPtr(ip.loadOpaqueType(ty.toIntern()).decl);
374 try decl.renderFullyQualifiedName(mod, writer);374 try writer.print("{}", .{decl.fqn.fmt(ip)});
375 },375 },
376 .enum_type => {376 .enum_type => {
377 const decl = mod.declPtr(ip.loadEnumType(ty.toIntern()).decl);377 const decl = mod.declPtr(ip.loadEnumType(ty.toIntern()).decl);
378 try decl.renderFullyQualifiedName(mod, writer);378 try writer.print("{}", .{decl.fqn.fmt(ip)});
379 },379 },
380 .func_type => |fn_info| {380 .func_type => |fn_info| {
381 if (fn_info.is_noinline) {381 if (fn_info.is_noinline) {
src/Zcu.zig+5-39
...@@ -326,7 +326,10 @@ pub const Reference = struct {...@@ -326,7 +326,10 @@ pub const Reference = struct {
326};326};
327327
328pub const Decl = struct {328pub const Decl = struct {
329 /// Equal to `fqn` if already fully qualified.
329 name: InternPool.NullTerminatedString,330 name: InternPool.NullTerminatedString,
331 /// Fully qualified name.
332 fqn: InternPool.NullTerminatedString,
330 /// The most recent Value of the Decl after a successful semantic analysis.333 /// The most recent Value of the Decl after a successful semantic analysis.
331 /// Populated when `has_tv`.334 /// Populated when `has_tv`.
332 val: Value,335 val: Value,
...@@ -384,8 +387,6 @@ pub const Decl = struct {...@@ -384,8 +387,6 @@ pub const Decl = struct {
384 is_pub: bool,387 is_pub: bool,
385 /// Whether the corresponding AST decl has a `export` keyword.388 /// Whether the corresponding AST decl has a `export` keyword.
386 is_exported: bool,389 is_exported: bool,
387 /// If true `name` is already fully qualified.
388 name_fully_qualified: bool = false,
389 /// What kind of a declaration is this.390 /// What kind of a declaration is this.
390 kind: Kind,391 kind: Kind,
391392
...@@ -408,25 +409,6 @@ pub const Decl = struct {...@@ -408,25 +409,6 @@ pub const Decl = struct {
408 return extra.data.getBodies(@intCast(extra.end), zir);409 return extra.data.getBodies(@intCast(extra.end), zir);
409 }410 }
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
430 pub fn typeOf(decl: Decl, zcu: *const Zcu) Type {412 pub fn typeOf(decl: Decl, zcu: *const Zcu) Type {
431 assert(decl.has_tv);413 assert(decl.has_tv);
432 return decl.val.typeOf(zcu);414 return decl.val.typeOf(zcu);
...@@ -686,7 +668,7 @@ pub const Namespace = struct {...@@ -686,7 +668,7 @@ pub const Namespace = struct {
686 if (name != .empty) try writer.print("{c}{}", .{ sep, name.fmt(&zcu.intern_pool) });668 if (name != .empty) try writer.print("{c}{}", .{ sep, name.fmt(&zcu.intern_pool) });
687 }669 }
688670
689 pub fn fullyQualifiedName(671 pub fn internFullyQualifiedName(
690 ns: Namespace,672 ns: Namespace,
691 pt: Zcu.PerThread,673 pt: Zcu.PerThread,
692 name: InternPool.NullTerminatedString,674 name: InternPool.NullTerminatedString,
...@@ -882,7 +864,7 @@ pub const File = struct {...@@ -882,7 +864,7 @@ pub const File = struct {
882 };864 };
883 }865 }
884866
885 pub fn fullyQualifiedName(file: File, pt: Zcu.PerThread) !InternPool.NullTerminatedString {867 pub fn internFullyQualifiedName(file: File, pt: Zcu.PerThread) !InternPool.NullTerminatedString {
886 const gpa = pt.zcu.gpa;868 const gpa = pt.zcu.gpa;
887 const ip = &pt.zcu.intern_pool;869 const ip = &pt.zcu.intern_pool;
888 const strings = ip.getLocal(pt.tid).getMutableStrings(gpa);870 const strings = ip.getLocal(pt.tid).getMutableStrings(gpa);
...@@ -3313,22 +3295,6 @@ pub fn errorSetBits(mod: *Module) u16 {...@@ -3313,22 +3295,6 @@ pub fn errorSetBits(mod: *Module) u16 {
3313 return std.math.log2_int_ceil(ErrorInt, mod.error_limit + 1); // +1 for no error3295 return std.math.log2_int_ceil(ErrorInt, mod.error_limit + 1); // +1 for no error
3314}3296}
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
3332pub fn errNote(3298pub fn errNote(
3333 mod: *Module,3299 mod: *Module,
3334 src_loc: LazySrcLoc,3300 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...@@ -548,7 +548,7 @@ pub fn ensureDeclAnalyzed(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) Zcu.Sem
548 };548 };
549 }549 }
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);
552 defer decl_prog_node.end();552 defer decl_prog_node.end();
553553
554 break :blk pt.semaDecl(decl_index) catch |err| switch (err) {554 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...@@ -747,10 +747,9 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
747 defer liveness.deinit(gpa);747 defer liveness.deinit(gpa);
748748
749 if (build_options.enable_debug_extensions and comp.verbose_air) {749 if (build_options.enable_debug_extensions and comp.verbose_air) {
750 const fqn = try decl.fullyQualifiedName(pt);750 std.debug.print("# Begin Function AIR: {}:\n", .{decl.fqn.fmt(ip)});
751 std.debug.print("# Begin Function AIR: {}:\n", .{fqn.fmt(ip)});
752 @import("../print_air.zig").dump(pt, air, liveness);751 @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)});
754 }753 }
755754
756 if (std.debug.runtime_safety) {755 if (std.debug.runtime_safety) {
...@@ -781,7 +780,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai...@@ -781,7 +780,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
781 };780 };
782 }781 }
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);
785 defer codegen_prog_node.end();784 defer codegen_prog_node.end();
786785
787 if (!air.typesFullyResolved(zcu)) {786 if (!air.typesFullyResolved(zcu)) {
...@@ -996,8 +995,8 @@ fn semaFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.SemaError!void {...@@ -996,8 +995,8 @@ fn semaFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.SemaError!void {
996 zcu.setFileRootDecl(file_index, new_decl_index.toOptional());995 zcu.setFileRootDecl(file_index, new_decl_index.toOptional());
997 zcu.namespacePtr(new_namespace_index).decl_index = new_decl_index;996 zcu.namespacePtr(new_namespace_index).decl_index = new_decl_index;
998997
999 new_decl.name = try file.fullyQualifiedName(pt);998 new_decl.fqn = try file.internFullyQualifiedName(pt);
1000 new_decl.name_fully_qualified = true;999 new_decl.name = new_decl.fqn;
1001 new_decl.is_pub = true;1000 new_decl.is_pub = true;
1002 new_decl.is_exported = false;1001 new_decl.is_exported = false;
1003 new_decl.alignment = .none;1002 new_decl.alignment = .none;
...@@ -1058,10 +1057,8 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult {...@@ -1058,10 +1057,8 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult {
1058 }1057 }
10591058
1060 log.debug("semaDecl '{d}'", .{@intFromEnum(decl_index)});1059 log.debug("semaDecl '{d}'", .{@intFromEnum(decl_index)});
1061 log.debug("decl name '{}'", .{(try decl.fullyQualifiedName(pt)).fmt(ip)});1060 log.debug("decl name '{}'", .{decl.fqn.fmt(ip)});
1062 defer blk: {1061 defer log.debug("finish decl name '{}'", .{decl.fqn.fmt(ip)});
1063 log.debug("finish decl name '{}'", .{(decl.fullyQualifiedName(pt) catch break :blk).fmt(ip)});
1064 }
10651062
1066 const old_has_tv = decl.has_tv;1063 const old_has_tv = decl.has_tv;
1067 // The following values are ignored if `!old_has_tv`1064 // The following values are ignored if `!old_has_tv`
...@@ -1728,6 +1725,7 @@ const ScanDeclIter = struct {...@@ -1728,6 +1725,7 @@ const ScanDeclIter = struct {
1728 const was_exported = decl.is_exported;1725 const was_exported = decl.is_exported;
1729 assert(decl.kind == kind); // ZIR tracking should preserve this1726 assert(decl.kind == kind); // ZIR tracking should preserve this
1730 decl.name = decl_name;1727 decl.name = decl_name;
1728 decl.fqn = try namespace.internFullyQualifiedName(pt, decl_name);
1731 decl.is_pub = declaration.flags.is_pub;1729 decl.is_pub = declaration.flags.is_pub;
1732 decl.is_exported = declaration.flags.is_export;1730 decl.is_exported = declaration.flags.is_export;
1733 break :decl_index .{ was_exported, decl_index };1731 break :decl_index .{ was_exported, decl_index };
...@@ -1737,6 +1735,7 @@ const ScanDeclIter = struct {...@@ -1737,6 +1735,7 @@ const ScanDeclIter = struct {
1737 const new_decl = zcu.declPtr(new_decl_index);1735 const new_decl = zcu.declPtr(new_decl_index);
1738 new_decl.kind = kind;1736 new_decl.kind = kind;
1739 new_decl.name = decl_name;1737 new_decl.name = decl_name;
1738 new_decl.fqn = try namespace.internFullyQualifiedName(pt, decl_name);
1740 new_decl.is_pub = declaration.flags.is_pub;1739 new_decl.is_pub = declaration.flags.is_pub;
1741 new_decl.is_exported = declaration.flags.is_export;1740 new_decl.is_exported = declaration.flags.is_export;
1742 new_decl.zir_decl_index = tracked_inst.toOptional();1741 new_decl.zir_decl_index = tracked_inst.toOptional();
...@@ -1761,10 +1760,9 @@ const ScanDeclIter = struct {...@@ -1761,10 +1760,9 @@ const ScanDeclIter = struct {
1761 if (!comp.config.is_test) break :a false;1760 if (!comp.config.is_test) break :a false;
1762 if (decl_mod != zcu.main_mod) break :a false;1761 if (decl_mod != zcu.main_mod) break :a false;
1763 if (is_named_test and comp.test_filters.len > 0) {1762 if (is_named_test and comp.test_filters.len > 0) {
1764 const decl_fqn = try namespace.fullyQualifiedName(pt, decl_name);1763 const decl_fqn = decl.fqn.toSlice(ip);
1765 const decl_fqn_slice = decl_fqn.toSlice(ip);
1766 for (comp.test_filters) |test_filter| {1764 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;
1768 } else break :a false;1766 } else break :a false;
1769 }1767 }
1770 zcu.test_functions.putAssumeCapacity(decl_index, {}); // may clobber on incremental update1768 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...@@ -1805,12 +1803,10 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
1805 const decl_index = func.owner_decl;1803 const decl_index = func.owner_decl;
1806 const decl = mod.declPtr(decl_index);1804 const decl = mod.declPtr(decl_index);
18071805
1808 log.debug("func name '{}'", .{(try decl.fullyQualifiedName(pt)).fmt(ip)});1806 log.debug("func name '{}'", .{decl.fqn.fmt(ip)});
1809 defer blk: {1807 defer log.debug("finish func name '{}'", .{decl.fqn.fmt(ip)});
1810 log.debug("finish func name '{}'", .{(decl.fullyQualifiedName(pt) catch break :blk).fmt(ip)});
1811 }
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);
1814 defer decl_prog_node.end();1810 defer decl_prog_node.end();
18151811
1816 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.AnalUnit.wrap(.{ .func = func_index }));1812 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...@@ -2053,6 +2049,7 @@ pub fn allocateNewDecl(pt: Zcu.PerThread, namespace: Zcu.Namespace.Index) !Zcu.D
2053 const gpa = zcu.gpa;2049 const gpa = zcu.gpa;
2054 const decl_index = try zcu.intern_pool.createDecl(gpa, pt.tid, .{2050 const decl_index = try zcu.intern_pool.createDecl(gpa, pt.tid, .{
2055 .name = undefined,2051 .name = undefined,
2052 .fqn = undefined,
2056 .src_namespace = namespace,2053 .src_namespace = namespace,
2057 .has_tv = false,2054 .has_tv = false,
2058 .owns_tv = false,2055 .owns_tv = false,
...@@ -2077,6 +2074,25 @@ pub fn allocateNewDecl(pt: Zcu.PerThread, namespace: Zcu.Namespace.Index) !Zcu.D...@@ -2077,6 +2074,25 @@ pub fn allocateNewDecl(pt: Zcu.PerThread, namespace: Zcu.Namespace.Index) !Zcu.D
2077 return decl_index;2074 return decl_index;
2078}2075}
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
2080fn lockAndClearFileCompileError(pt: Zcu.PerThread, file: *Zcu.File) void {2096fn lockAndClearFileCompileError(pt: Zcu.PerThread, file: *Zcu.File) void {
2081 switch (file.status) {2097 switch (file.status) {
2082 .success_zir, .retryable_failure => {},2098 .success_zir, .retryable_failure => {},
...@@ -2260,7 +2276,7 @@ pub fn populateTestFunctions(...@@ -2260,7 +2276,7 @@ pub fn populateTestFunctions(
22602276
2261 for (test_fn_vals, zcu.test_functions.keys()) |*test_fn_val, test_decl_index| {2277 for (test_fn_vals, zcu.test_functions.keys()) |*test_fn_val, test_decl_index| {
2262 const test_decl = zcu.declPtr(test_decl_index);2278 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;
2264 const test_decl_name_len = test_decl_name.length(ip);2280 const test_decl_name_len = test_decl_name.length(ip);
2265 const test_name_anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl = n: {2281 const test_name_anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl = n: {
2266 const test_name_ty = try pt.arrayType(.{2282 const test_name_ty = try pt.arrayType(.{
...@@ -2366,7 +2382,7 @@ pub fn linkerUpdateDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !void {...@@ -2366,7 +2382,7 @@ pub fn linkerUpdateDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !void {
23662382
2367 const decl = zcu.declPtr(decl_index);2383 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);
2370 defer codegen_prog_node.end();2386 defer codegen_prog_node.end();
23712387
2372 if (comp.bin_file) |lf| {2388 if (comp.bin_file) |lf| {
src/arch/riscv64/CodeGen.zig+1-1
...@@ -933,7 +933,7 @@ fn formatDecl(...@@ -933,7 +933,7 @@ fn formatDecl(
933 _: std.fmt.FormatOptions,933 _: std.fmt.FormatOptions,
934 writer: anytype,934 writer: anytype,
935) @TypeOf(writer).Error!void {935) @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)});
937}937}
938fn fmtDecl(func: *Func, decl_index: InternPool.DeclIndex) std.fmt.Formatter(formatDecl) {938fn fmtDecl(func: *Func, decl_index: InternPool.DeclIndex) std.fmt.Formatter(formatDecl) {
939 return .{ .data = .{939 return .{ .data = .{
src/arch/wasm/CodeGen.zig+2-2
...@@ -7284,8 +7284,8 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -7284,8 +7284,8 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
7284 defer arena_allocator.deinit();7284 defer arena_allocator.deinit();
7285 const arena = arena_allocator.allocator();7285 const arena = arena_allocator.allocator();
72867286
7287 const fqn = try mod.declPtr(enum_decl_index).fullyQualifiedName(pt);7287 const decl = mod.declPtr(enum_decl_index);
7288 const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{}", .{fqn.fmt(ip)});7288 const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{}", .{decl.fqn.fmt(ip)});
72897289
7290 // check if we already generated code for this.7290 // check if we already generated code for this.
7291 if (func.bin_file.findGlobalSymbol(func_name)) |loc| {7291 if (func.bin_file.findGlobalSymbol(func_name)) |loc| {
src/arch/x86_64/CodeGen.zig+1-1
...@@ -1077,7 +1077,7 @@ fn formatDecl(...@@ -1077,7 +1077,7 @@ fn formatDecl(
1077 _: std.fmt.FormatOptions,1077 _: std.fmt.FormatOptions,
1078 writer: anytype,1078 writer: anytype,
1079) @TypeOf(writer).Error!void {1079) @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)});
1081}1081}
1082fn fmtDecl(self: *Self, decl_index: InternPool.DeclIndex) std.fmt.Formatter(formatDecl) {1082fn fmtDecl(self: *Self, decl_index: InternPool.DeclIndex) std.fmt.Formatter(formatDecl) {
1083 return .{ .data = .{1083 return .{ .data = .{
src/codegen/c.zig+6-14
...@@ -2194,13 +2194,9 @@ pub const DeclGen = struct {...@@ -2194,13 +2194,9 @@ pub const DeclGen = struct {
2194 }) else {2194 }) else {
2195 // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),2195 // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),
2196 // expand to 3x the length of its input, but let's cut it off at a much shorter limit.2196 // 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;2197 const fqn_slice = decl.fqn.toSlice(ip);
2198 var name_stream = std.io.fixedBufferStream(&name);
2199 decl.renderFullyQualifiedName(zcu, name_stream.writer()) catch |err| switch (err) {
2200 error.NoSpaceLeft => {},
2201 };
2202 try writer.print("{}__{d}", .{2198 try writer.print("{}__{d}", .{
2203 fmtIdent(name_stream.getWritten()),2199 fmtIdent(fqn_slice[0..@min(fqn_slice.len, 100)]),
2204 @intFromEnum(decl_index),2200 @intFromEnum(decl_index),
2205 });2201 });
2206 }2202 }
...@@ -2587,11 +2583,9 @@ pub fn genTypeDecl(...@@ -2587,11 +2583,9 @@ pub fn genTypeDecl(
2587 try writer.writeByte(';');2583 try writer.writeByte(';');
2588 const owner_decl = zcu.declPtr(owner_decl_index);2584 const owner_decl = zcu.declPtr(owner_decl_index);
2589 const owner_mod = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu).mod;2585 const owner_mod = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu).mod;
2590 if (!owner_mod.strip) {2586 if (!owner_mod.strip) try writer.print(" /* {} */", .{
2591 try writer.writeAll(" /* ");2587 owner_decl.fqn.fmt(&zcu.intern_pool),
2592 try owner_decl.renderFullyQualifiedName(zcu, writer);2588 });
2593 try writer.writeAll(" */");
2594 }
2595 try writer.writeByte('\n');2589 try writer.writeByte('\n');
2596 },2590 },
2597 },2591 },
...@@ -4563,9 +4557,7 @@ fn airDbgInlineBlock(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4563,9 +4557,7 @@ fn airDbgInlineBlock(f: *Function, inst: Air.Inst.Index) !CValue {
4563 const extra = f.air.extraData(Air.DbgInlineBlock, ty_pl.payload);4557 const extra = f.air.extraData(Air.DbgInlineBlock, ty_pl.payload);
4564 const owner_decl = zcu.funcOwnerDeclPtr(extra.data.func);4558 const owner_decl = zcu.funcOwnerDeclPtr(extra.data.func);
4565 const writer = f.object.writer();4559 const writer = f.object.writer();
4566 try writer.writeAll("/* inline:");4560 try writer.print("/* inline:{} */\n", .{owner_decl.fqn.fmt(&zcu.intern_pool)});
4567 try owner_decl.renderFullyQualifiedName(zcu, writer);
4568 try writer.writeAll(" */\n");
4569 return lowerBlock(f, inst, @ptrCast(f.air.extra[extra.end..][0..extra.data.body_len]));4561 return lowerBlock(f, inst, @ptrCast(f.air.extra[extra.end..][0..extra.data.body_len]));
4570}4562}
45714563
src/codegen/llvm.zig+17-24
...@@ -1744,7 +1744,7 @@ pub const Object = struct {...@@ -1744,7 +1744,7 @@ pub const Object = struct {
1744 if (export_indices.len != 0) {1744 if (export_indices.len != 0) {
1745 return updateExportedGlobal(self, zcu, global_index, export_indices);1745 return updateExportedGlobal(self, zcu, global_index, export_indices);
1746 } else {1746 } 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));
1748 try global_index.rename(fqn, &self.builder);1748 try global_index.rename(fqn, &self.builder);
1749 global_index.setLinkage(.internal, &self.builder);1749 global_index.setLinkage(.internal, &self.builder);
1750 if (comp.config.dll_export_fns)1750 if (comp.config.dll_export_fns)
...@@ -2863,10 +2863,7 @@ pub const Object = struct {...@@ -2863,10 +2863,7 @@ pub const Object = struct {
2863 const is_extern = decl.isExtern(zcu);2863 const is_extern = decl.isExtern(zcu);
2864 const function_index = try o.builder.addFunction(2864 const function_index = try o.builder.addFunction(
2865 try o.lowerType(zig_fn_type),2865 try o.lowerType(zig_fn_type),
2866 try o.builder.strtabString((if (is_extern)2866 try o.builder.strtabString((if (is_extern) decl.name else decl.fqn).toSlice(ip)),
2867 decl.name
2868 else
2869 try decl.fullyQualifiedName(pt)).toSlice(ip)),
2870 toLlvmAddressSpace(decl.@"addrspace", target),2867 toLlvmAddressSpace(decl.@"addrspace", target),
2871 );2868 );
2872 gop.value_ptr.* = function_index.ptrConst(&o.builder).global;2869 gop.value_ptr.* = function_index.ptrConst(&o.builder).global;
...@@ -3077,14 +3074,12 @@ pub const Object = struct {...@@ -3077,14 +3074,12 @@ pub const Object = struct {
30773074
3078 const pt = o.pt;3075 const pt = o.pt;
3079 const zcu = pt.zcu;3076 const zcu = pt.zcu;
3077 const ip = &zcu.intern_pool;
3080 const decl = zcu.declPtr(decl_index);3078 const decl = zcu.declPtr(decl_index);
3081 const is_extern = decl.isExtern(zcu);3079 const is_extern = decl.isExtern(zcu);
30823080
3083 const variable_index = try o.builder.addVariable(3081 const variable_index = try o.builder.addVariable(
3084 try o.builder.strtabString((if (is_extern)3082 try o.builder.strtabString((if (is_extern) decl.name else decl.fqn).toSlice(ip)),
3085 decl.name
3086 else
3087 try decl.fullyQualifiedName(pt)).toSlice(&zcu.intern_pool)),
3088 try o.lowerType(decl.typeOf(zcu)),3083 try o.lowerType(decl.typeOf(zcu)),
3089 toLlvmGlobalAddressSpace(decl.@"addrspace", zcu.getTarget()),3084 toLlvmGlobalAddressSpace(decl.@"addrspace", zcu.getTarget()),
3090 );3085 );
...@@ -3312,7 +3307,7 @@ pub const Object = struct {...@@ -3312,7 +3307,7 @@ pub const Object = struct {
3312 return int_ty;3307 return int_ty;
3313 }3308 }
33143309
3315 const fqn = try mod.declPtr(struct_type.decl.unwrap().?).fullyQualifiedName(pt);3310 const decl = mod.declPtr(struct_type.decl.unwrap().?);
33163311
3317 var llvm_field_types = std.ArrayListUnmanaged(Builder.Type){};3312 var llvm_field_types = std.ArrayListUnmanaged(Builder.Type){};
3318 defer llvm_field_types.deinit(o.gpa);3313 defer llvm_field_types.deinit(o.gpa);
...@@ -3377,7 +3372,7 @@ pub const Object = struct {...@@ -3377,7 +3372,7 @@ pub const Object = struct {
3377 );3372 );
3378 }3373 }
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)));
3381 try o.type_map.put(o.gpa, t.toIntern(), ty);3376 try o.type_map.put(o.gpa, t.toIntern(), ty);
33823377
3383 o.builder.namedTypeSetBody(3378 o.builder.namedTypeSetBody(
...@@ -3466,7 +3461,7 @@ pub const Object = struct {...@@ -3466,7 +3461,7 @@ pub const Object = struct {
3466 return enum_tag_ty;3461 return enum_tag_ty;
3467 }3462 }
34683463
3469 const fqn = try mod.declPtr(union_obj.decl).fullyQualifiedName(pt);3464 const decl = mod.declPtr(union_obj.decl);
34703465
3471 const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]);3466 const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]);
3472 const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty);3467 const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty);
...@@ -3486,7 +3481,7 @@ pub const Object = struct {...@@ -3486,7 +3481,7 @@ pub const Object = struct {
3486 };3481 };
34873482
3488 if (layout.tag_size == 0) {3483 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)));
3490 try o.type_map.put(o.gpa, t.toIntern(), ty);3485 try o.type_map.put(o.gpa, t.toIntern(), ty);
34913486
3492 o.builder.namedTypeSetBody(3487 o.builder.namedTypeSetBody(
...@@ -3514,7 +3509,7 @@ pub const Object = struct {...@@ -3514,7 +3509,7 @@ pub const Object = struct {
3514 llvm_fields_len += 1;3509 llvm_fields_len += 1;
3515 }3510 }
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)));
3518 try o.type_map.put(o.gpa, t.toIntern(), ty);3513 try o.type_map.put(o.gpa, t.toIntern(), ty);
35193514
3520 o.builder.namedTypeSetBody(3515 o.builder.namedTypeSetBody(
...@@ -3527,8 +3522,7 @@ pub const Object = struct {...@@ -3527,8 +3522,7 @@ pub const Object = struct {
3527 const gop = try o.type_map.getOrPut(o.gpa, t.toIntern());3522 const gop = try o.type_map.getOrPut(o.gpa, t.toIntern());
3528 if (!gop.found_existing) {3523 if (!gop.found_existing) {
3529 const decl = mod.declPtr(ip.loadOpaqueType(t.toIntern()).decl);3524 const decl = mod.declPtr(ip.loadOpaqueType(t.toIntern()).decl);
3530 const fqn = try decl.fullyQualifiedName(pt);3525 gop.value_ptr.* = try o.builder.opaqueType(try o.builder.string(decl.fqn.toSlice(ip)));
3531 gop.value_ptr.* = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip)));
3532 }3526 }
3533 return gop.value_ptr.*;3527 return gop.value_ptr.*;
3534 },3528 },
...@@ -4587,11 +4581,11 @@ pub const Object = struct {...@@ -4587,11 +4581,11 @@ pub const Object = struct {
45874581
4588 const usize_ty = try o.lowerType(Type.usize);4582 const usize_ty = try o.lowerType(Type.usize);
4589 const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0);4583 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);
4591 const target = zcu.root_mod.resolved_target.result;4585 const target = zcu.root_mod.resolved_target.result;
4592 const function_index = try o.builder.addFunction(4586 const function_index = try o.builder.addFunction(
4593 try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),4587 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)}),
4595 toLlvmAddressSpace(.generic, target),4589 toLlvmAddressSpace(.generic, target),
4596 );4590 );
45974591
...@@ -5175,8 +5169,6 @@ pub const FuncGen = struct {...@@ -5175,8 +5169,6 @@ pub const FuncGen = struct {
5175 const line_number = decl.navSrcLine(zcu) + 1;5169 const line_number = decl.navSrcLine(zcu) + 1;
5176 self.inlined = self.wip.debug_location;5170 self.inlined = self.wip.debug_location;
51775171
5178 const fqn = try decl.fullyQualifiedName(pt);
5179
5180 const fn_ty = try pt.funcType(.{5172 const fn_ty = try pt.funcType(.{
5181 .param_types = &.{},5173 .param_types = &.{},
5182 .return_type = .void_type,5174 .return_type = .void_type,
...@@ -5185,7 +5177,7 @@ pub const FuncGen = struct {...@@ -5185,7 +5177,7 @@ pub const FuncGen = struct {
5185 self.scope = try o.builder.debugSubprogram(5177 self.scope = try o.builder.debugSubprogram(
5186 self.file,5178 self.file,
5187 try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)),5179 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)),
5189 line_number,5181 line_number,
5190 line_number + func.lbrace_line,5182 line_number + func.lbrace_line,
5191 try o.lowerDebugType(fn_ty),5183 try o.lowerDebugType(fn_ty),
...@@ -9702,18 +9694,19 @@ pub const FuncGen = struct {...@@ -9702,18 +9694,19 @@ pub const FuncGen = struct {
9702 const o = self.dg.object;9694 const o = self.dg.object;
9703 const pt = o.pt;9695 const pt = o.pt;
9704 const zcu = pt.zcu;9696 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
9707 // TODO: detect when the type changes and re-emit this function.9700 // TODO: detect when the type changes and re-emit this function.
9708 const gop = try o.named_enum_map.getOrPut(o.gpa, enum_type.decl);9701 const gop = try o.named_enum_map.getOrPut(o.gpa, enum_type.decl);
9709 if (gop.found_existing) return gop.value_ptr.*;9702 if (gop.found_existing) return gop.value_ptr.*;
9710 errdefer assert(o.named_enum_map.remove(enum_type.decl));9703 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);
9713 const target = zcu.root_mod.resolved_target.result;9706 const target = zcu.root_mod.resolved_target.result;
9714 const function_index = try o.builder.addFunction(9707 const function_index = try o.builder.addFunction(
9715 try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),9708 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)}),
9717 toLlvmAddressSpace(.generic, target),9710 toLlvmAddressSpace(.generic, target),
9718 );9711 );
97199712
src/codegen/spirv.zig+4-7
...@@ -3012,12 +3012,11 @@ const DeclGen = struct {...@@ -3012,12 +3012,11 @@ const DeclGen = struct {
3012 // Append the actual code into the functions section.3012 // Append the actual code into the functions section.
3013 try self.spv.addFunction(spv_decl_index, self.func);3013 try self.spv.addFunction(spv_decl_index, self.func);
30143014
3015 const fqn = try decl.fullyQualifiedName(self.pt);3015 try self.spv.debugName(result_id, decl.fqn.toSlice(ip));
3016 try self.spv.debugName(result_id, fqn.toSlice(ip));
30173016
3018 // Temporarily generate a test kernel declaration if this is a test function.3017 // Temporarily generate a test kernel declaration if this is a test function.
3019 if (self.pt.zcu.test_functions.contains(self.decl_index)) {3018 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);
3021 }3020 }
3022 },3021 },
3023 .global => {3022 .global => {
...@@ -3041,8 +3040,7 @@ const DeclGen = struct {...@@ -3041,8 +3040,7 @@ const DeclGen = struct {
3041 .storage_class = final_storage_class,3040 .storage_class = final_storage_class,
3042 });3041 });
30433042
3044 const fqn = try decl.fullyQualifiedName(self.pt);3043 try self.spv.debugName(result_id, decl.fqn.toSlice(ip));
3045 try self.spv.debugName(result_id, fqn.toSlice(ip));
3046 try self.spv.declareDeclDeps(spv_decl_index, &.{});3044 try self.spv.declareDeclDeps(spv_decl_index, &.{});
3047 },3045 },
3048 .invocation_global => {3046 .invocation_global => {
...@@ -3086,8 +3084,7 @@ const DeclGen = struct {...@@ -3086,8 +3084,7 @@ const DeclGen = struct {
3086 try self.func.body.emit(self.spv.gpa, .OpFunctionEnd, {});3084 try self.func.body.emit(self.spv.gpa, .OpFunctionEnd, {});
3087 try self.spv.addFunction(spv_decl_index, self.func);3085 try self.spv.addFunction(spv_decl_index, self.func);
30883086
3089 const fqn = try decl.fullyQualifiedName(self.pt);3087 try self.spv.debugNameFmt(initializer_id, "initializer of {}", .{decl.fqn.fmt(ip)});
3090 try self.spv.debugNameFmt(initializer_id, "initializer of {}", .{fqn.fmt(ip)});
30913088
3092 try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpExtInst, .{3089 try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpExtInst, .{
3093 .id_result_type = ptr_ty_id,3090 .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:...@@ -1176,9 +1176,10 @@ pub fn lowerUnnamedConst(self: *Coff, pt: Zcu.PerThread, val: Value, decl_index:
1176 gop.value_ptr.* = .{};1176 gop.value_ptr.* = .{};
1177 }1177 }
1178 const unnamed_consts = gop.value_ptr;1178 const unnamed_consts = gop.value_ptr;
1179 const decl_name = try decl.fullyQualifiedName(pt);
1180 const index = unnamed_consts.items.len;1179 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 });
1182 defer gpa.free(sym_name);1183 defer gpa.free(sym_name);
1183 const ty = val.typeOf(mod);1184 const ty = val.typeOf(mod);
1184 const atom_index = switch (try self.lowerConst(pt, sym_name, val, ty.abiAlignment(pt), self.rdata_section_index.?, decl.navSrcLoc(mod))) {1185 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...@@ -1427,9 +1428,7 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd
1427 const mod = pt.zcu;1428 const mod = pt.zcu;
1428 const decl = mod.declPtr(decl_index);1429 const decl = mod.declPtr(decl_index);
14291430
1430 const decl_name = try decl.fullyQualifiedName(pt);1431 log.debug("updateDeclCode {}{*}", .{ decl.fqn.fmt(&mod.intern_pool), decl });
1431
1432 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
1433 const required_alignment: u32 = @intCast(decl.getAlignment(pt).toByteUnits() orelse 0);1432 const required_alignment: u32 = @intCast(decl.getAlignment(pt).toByteUnits() orelse 0);
14341433
1435 const decl_metadata = self.decls.get(decl_index).?;1434 const decl_metadata = self.decls.get(decl_index).?;
...@@ -1441,7 +1440,7 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd...@@ -1441,7 +1440,7 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd
14411440
1442 if (atom.size != 0) {1441 if (atom.size != 0) {
1443 const sym = atom.getSymbolPtr(self);1442 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));
1445 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));1444 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));
1446 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };1445 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...@@ -1449,7 +1448,7 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd
1449 const need_realloc = code.len > capacity or !mem.isAlignedGeneric(u64, sym.value, required_alignment);1448 const need_realloc = code.len > capacity or !mem.isAlignedGeneric(u64, sym.value, required_alignment);
1450 if (need_realloc) {1449 if (need_realloc) {
1451 const vaddr = try self.growAtom(atom_index, code_len, required_alignment);1450 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 });
1453 log.debug(" (required alignment 0x{x}", .{required_alignment});1452 log.debug(" (required alignment 0x{x}", .{required_alignment});
14541453
1455 if (vaddr != sym.value) {1454 if (vaddr != sym.value) {
...@@ -1465,13 +1464,13 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd...@@ -1465,13 +1464,13 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd
1465 self.getAtomPtr(atom_index).size = code_len;1464 self.getAtomPtr(atom_index).size = code_len;
1466 } else {1465 } else {
1467 const sym = atom.getSymbolPtr(self);1466 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));
1469 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));1468 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));
1470 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };1469 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };
14711470
1472 const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment);1471 const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment);
1473 errdefer self.freeAtom(atom_index);1472 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 });
1475 self.getAtomPtr(atom_index).size = code_len;1474 self.getAtomPtr(atom_index).size = code_len;
1476 sym.value = vaddr;1475 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...@@ -1082,9 +1082,7 @@ pub fn initDeclState(self: *Dwarf, pt: Zcu.PerThread, decl_index: InternPool.Dec
1082 defer tracy.end();1082 defer tracy.end();
10831083
1084 const decl = pt.zcu.declPtr(decl_index);1084 const decl = pt.zcu.declPtr(decl_index);
1085 const decl_linkage_name = try decl.fullyQualifiedName(pt);1085 log.debug("initDeclState {}{*}", .{ decl.fqn.fmt(&pt.zcu.intern_pool), decl });
1086
1087 log.debug("initDeclState {}{*}", .{ decl_linkage_name.fmt(&pt.zcu.intern_pool), decl });
10881086
1089 const gpa = self.allocator;1087 const gpa = self.allocator;
1090 var decl_state: DeclState = .{1088 var decl_state: DeclState = .{
...@@ -1157,7 +1155,7 @@ pub fn initDeclState(self: *Dwarf, pt: Zcu.PerThread, decl_index: InternPool.Dec...@@ -1157,7 +1155,7 @@ pub fn initDeclState(self: *Dwarf, pt: Zcu.PerThread, decl_index: InternPool.Dec
11571155
1158 // .debug_info subprogram1156 // .debug_info subprogram
1159 const decl_name_slice = decl.name.toSlice(&pt.zcu.intern_pool);1157 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);
1161 try dbg_info_buffer.ensureUnusedCapacity(1 + ptr_width_bytes + 4 + 4 +1159 try dbg_info_buffer.ensureUnusedCapacity(1 + ptr_width_bytes + 4 + 4 +
1162 (decl_name_slice.len + 1) + (decl_linkage_name_slice.len + 1));1160 (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(...@@ -907,10 +907,10 @@ fn updateDeclCode(
907) !void {907) !void {
908 const gpa = elf_file.base.comp.gpa;908 const gpa = elf_file.base.comp.gpa;
909 const mod = pt.zcu;909 const mod = pt.zcu;
910 const ip = &mod.intern_pool;
910 const decl = mod.declPtr(decl_index);911 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
915 const required_alignment = decl.getAlignment(pt).max(915 const required_alignment = decl.getAlignment(pt).max(
916 target_util.minFunctionAlignment(mod.getTarget()),916 target_util.minFunctionAlignment(mod.getTarget()),
...@@ -923,7 +923,7 @@ fn updateDeclCode(...@@ -923,7 +923,7 @@ fn updateDeclCode(
923 sym.output_section_index = shdr_index;923 sym.output_section_index = shdr_index;
924 atom_ptr.output_section_index = shdr_index;924 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));
927 atom_ptr.flags.alive = true;927 atom_ptr.flags.alive = true;
928 atom_ptr.name_offset = sym.name_offset;928 atom_ptr.name_offset = sym.name_offset;
929 esym.st_name = sym.name_offset;929 esym.st_name = sym.name_offset;
...@@ -940,7 +940,7 @@ fn updateDeclCode(...@@ -940,7 +940,7 @@ fn updateDeclCode(
940 const need_realloc = code.len > capacity or !required_alignment.check(@intCast(atom_ptr.value));940 const need_realloc = code.len > capacity or !required_alignment.check(@intCast(atom_ptr.value));
941 if (need_realloc) {941 if (need_realloc) {
942 try atom_ptr.grow(elf_file);942 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 });
944 if (old_vaddr != atom_ptr.value) {944 if (old_vaddr != atom_ptr.value) {
945 sym.value = 0;945 sym.value = 0;
946 esym.st_value = 0;946 esym.st_value = 0;
...@@ -1007,11 +1007,11 @@ fn updateTlv(...@@ -1007,11 +1007,11 @@ fn updateTlv(
1007 code: []const u8,1007 code: []const u8,
1008) !void {1008) !void {
1009 const mod = pt.zcu;1009 const mod = pt.zcu;
1010 const ip = &mod.intern_pool;
1010 const gpa = mod.gpa;1011 const gpa = mod.gpa;
1011 const decl = mod.declPtr(decl_index);1012 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
1016 const required_alignment = decl.getAlignment(pt);1016 const required_alignment = decl.getAlignment(pt);
10171017
...@@ -1023,7 +1023,7 @@ fn updateTlv(...@@ -1023,7 +1023,7 @@ fn updateTlv(
1023 sym.output_section_index = shndx;1023 sym.output_section_index = shndx;
1024 atom_ptr.output_section_index = shndx;1024 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));
1027 atom_ptr.flags.alive = true;1027 atom_ptr.flags.alive = true;
1028 atom_ptr.name_offset = sym.name_offset;1028 atom_ptr.name_offset = sym.name_offset;
1029 esym.st_value = 0;1029 esym.st_value = 0;
...@@ -1286,9 +1286,8 @@ pub fn lowerUnnamedConst(...@@ -1286,9 +1286,8 @@ pub fn lowerUnnamedConst(
1286 }1286 }
1287 const unnamed_consts = gop.value_ptr;1287 const unnamed_consts = gop.value_ptr;
1288 const decl = mod.declPtr(decl_index);1288 const decl = mod.declPtr(decl_index);
1289 const decl_name = try decl.fullyQualifiedName(pt);
1290 const index = unnamed_consts.items.len;1289 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 });
1292 defer gpa.free(name);1291 defer gpa.free(name);
1293 const ty = val.typeOf(mod);1292 const ty = val.typeOf(mod);
1294 const sym_index = switch (try self.lowerConst(1293 const sym_index = switch (try self.lowerConst(
...@@ -1473,9 +1472,8 @@ pub fn updateDeclLineNumber(...@@ -1473,9 +1472,8 @@ pub fn updateDeclLineNumber(
1473 defer tracy.end();1472 defer tracy.end();
14741473
1475 const decl = pt.zcu.declPtr(decl_index);1474 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
1480 if (self.dwarf) |*dw| {1478 if (self.dwarf) |*dw| {
1481 try dw.updateDeclLineNumber(pt.zcu, decl_index);1479 try dw.updateDeclLineNumber(pt.zcu, decl_index);
src/link/MachO/ZigObject.zig+10-14
...@@ -809,10 +809,10 @@ fn updateDeclCode(...@@ -809,10 +809,10 @@ fn updateDeclCode(
809) !void {809) !void {
810 const gpa = macho_file.base.comp.gpa;810 const gpa = macho_file.base.comp.gpa;
811 const mod = pt.zcu;811 const mod = pt.zcu;
812 const ip = &mod.intern_pool;
812 const decl = mod.declPtr(decl_index);813 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
817 const required_alignment = decl.getAlignment(pt);817 const required_alignment = decl.getAlignment(pt);
818818
...@@ -824,7 +824,7 @@ fn updateDeclCode(...@@ -824,7 +824,7 @@ fn updateDeclCode(
824 sym.out_n_sect = sect_index;824 sym.out_n_sect = sect_index;
825 atom.out_n_sect = sect_index;825 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));
828 atom.flags.alive = true;828 atom.flags.alive = true;
829 atom.name = sym.name;829 atom.name = sym.name;
830 nlist.n_strx = sym.name;830 nlist.n_strx = sym.name;
...@@ -843,7 +843,7 @@ fn updateDeclCode(...@@ -843,7 +843,7 @@ fn updateDeclCode(
843843
844 if (need_realloc) {844 if (need_realloc) {
845 try atom.grow(macho_file);845 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 });
847 if (old_vaddr != atom.value) {847 if (old_vaddr != atom.value) {
848 sym.value = 0;848 sym.value = 0;
849 nlist.n_value = 0;849 nlist.n_value = 0;
...@@ -893,25 +893,22 @@ fn updateTlv(...@@ -893,25 +893,22 @@ fn updateTlv(
893 sect_index: u8,893 sect_index: u8,
894 code: []const u8,894 code: []const u8,
895) !void {895) !void {
896 const ip = &pt.zcu.intern_pool;
896 const decl = pt.zcu.declPtr(decl_index);897 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 });899 log.debug("updateTlv {} ({*})", .{ decl.fqn.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);
903900
904 // 1. Lower TLV initializer901 // 1. Lower TLV initializer
905 const init_sym_index = try self.createTlvInitializer(902 const init_sym_index = try self.createTlvInitializer(
906 macho_file,903 macho_file,
907 decl_name_slice,904 decl.fqn.toSlice(ip),
908 required_alignment,905 decl.getAlignment(pt),
909 sect_index,906 sect_index,
910 code,907 code,
911 );908 );
912909
913 // 2. Create TLV descriptor910 // 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));
915}912}
916913
917fn createTlvInitializer(914fn createTlvInitializer(
...@@ -1099,9 +1096,8 @@ pub fn lowerUnnamedConst(...@@ -1099,9 +1096,8 @@ pub fn lowerUnnamedConst(
1099 }1096 }
1100 const unnamed_consts = gop.value_ptr;1097 const unnamed_consts = gop.value_ptr;
1101 const decl = mod.declPtr(decl_index);1098 const decl = mod.declPtr(decl_index);
1102 const decl_name = try decl.fullyQualifiedName(pt);
1103 const index = unnamed_consts.items.len;1099 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 });
1105 defer gpa.free(name);1101 defer gpa.free(name);
1106 const sym_index = switch (try self.lowerConst(1102 const sym_index = switch (try self.lowerConst(
1107 macho_file,1103 macho_file,
src/link/Plan9.zig+1-3
...@@ -483,11 +483,9 @@ pub fn lowerUnnamedConst(self: *Plan9, pt: Zcu.PerThread, val: Value, decl_index...@@ -483,11 +483,9 @@ pub fn lowerUnnamedConst(self: *Plan9, pt: Zcu.PerThread, val: Value, decl_index
483 }483 }
484 const unnamed_consts = gop.value_ptr;484 const unnamed_consts = gop.value_ptr;
485485
486 const decl_name = try decl.fullyQualifiedName(pt);
487
488 const index = unnamed_consts.items.len;486 const index = unnamed_consts.items.len;
489 // name is freed when the unnamed const is freed487 // 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
492 const sym_index = try self.allocateSymbolIndex();490 const sym_index = try self.allocateSymbolIndex();
493 const new_atom_idx = try self.createAtom();491 const new_atom_idx = try self.createAtom();
src/link/Wasm/ZigObject.zig+5-10
...@@ -346,8 +346,7 @@ fn finishUpdateDecl(...@@ -346,8 +346,7 @@ fn finishUpdateDecl(
346 const atom_index = decl_info.atom;346 const atom_index = decl_info.atom;
347 const atom = wasm_file.getAtomPtr(atom_index);347 const atom = wasm_file.getAtomPtr(atom_index);
348 const sym = zig_object.symbol(atom.sym_index);348 const sym = zig_object.symbol(atom.sym_index);
349 const full_name = try decl.fullyQualifiedName(pt);349 sym.name = try zig_object.string_table.insert(gpa, decl.fqn.toSlice(ip));
350 sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(ip));
351 try atom.code.appendSlice(gpa, code);350 try atom.code.appendSlice(gpa, code);
352 atom.size = @intCast(code.len);351 atom.size = @intCast(code.len);
353352
...@@ -387,7 +386,7 @@ fn finishUpdateDecl(...@@ -387,7 +386,7 @@ fn finishUpdateDecl(
387 // Will be freed upon freeing of decl or after cleanup of Wasm binary.386 // Will be freed upon freeing of decl or after cleanup of Wasm binary.
388 const full_segment_name = try std.mem.concat(gpa, u8, &.{387 const full_segment_name = try std.mem.concat(gpa, u8, &.{
389 segment_name,388 segment_name,
390 full_name.toSlice(ip),389 decl.fqn.toSlice(ip),
391 });390 });
392 errdefer gpa.free(full_segment_name);391 errdefer gpa.free(full_segment_name);
393 sym.tag = .data;392 sym.tag = .data;
...@@ -436,9 +435,8 @@ pub fn getOrCreateAtomForDecl(...@@ -436,9 +435,8 @@ pub fn getOrCreateAtomForDecl(
436 const sym_index = try zig_object.allocateSymbol(gpa);435 const sym_index = try zig_object.allocateSymbol(gpa);
437 gop.value_ptr.* = .{ .atom = try wasm_file.createAtom(sym_index, zig_object.index) };436 gop.value_ptr.* = .{ .atom = try wasm_file.createAtom(sym_index, zig_object.index) };
438 const decl = pt.zcu.declPtr(decl_index);437 const decl = pt.zcu.declPtr(decl_index);
439 const full_name = try decl.fullyQualifiedName(pt);
440 const sym = zig_object.symbol(sym_index);438 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));
442 }440 }
443 return gop.value_ptr.atom;441 return gop.value_ptr.atom;
444}442}
...@@ -494,9 +492,8 @@ pub fn lowerUnnamedConst(...@@ -494,9 +492,8 @@ pub fn lowerUnnamedConst(
494 const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index);492 const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index);
495 const parent_atom = wasm_file.getAtom(parent_atom_index);493 const parent_atom = wasm_file.getAtom(parent_atom_index);
496 const local_index = parent_atom.locals.items.len;494 const local_index = parent_atom.locals.items.len;
497 const fqn = try decl.fullyQualifiedName(pt);
498 const name = try std.fmt.allocPrintZ(gpa, "__unnamed_{}_{d}", .{495 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,
500 });497 });
501 defer gpa.free(name);498 defer gpa.free(name);
502499
...@@ -1127,9 +1124,7 @@ pub fn updateDeclLineNumber(...@@ -1127,9 +1124,7 @@ pub fn updateDeclLineNumber(
1127) !void {1124) !void {
1128 if (zig_object.dwarf) |*dw| {1125 if (zig_object.dwarf) |*dw| {
1129 const decl = pt.zcu.declPtr(decl_index);1126 const decl = pt.zcu.declPtr(decl_index);
1130 const decl_name = try decl.fullyQualifiedName(pt);1127 log.debug("updateDeclLineNumber {}{*}", .{ decl.fqn.fmt(&pt.zcu.intern_pool), decl });
1131
1132 log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&pt.zcu.intern_pool), decl });
1133 try dw.updateDeclLineNumber(pt.zcu, decl_index);1128 try dw.updateDeclLineNumber(pt.zcu, decl_index);
1134 }1129 }
1135}1130}
src/print_value.zig+2-2
...@@ -299,8 +299,8 @@ fn printPtrDerivation(derivation: Value.PointerDeriveStep, writer: anytype, leve...@@ -299,8 +299,8 @@ fn printPtrDerivation(derivation: Value.PointerDeriveStep, writer: anytype, leve
299 int.ptr_ty.fmt(pt),299 int.ptr_ty.fmt(pt),
300 int.addr,300 int.addr,
301 }),301 }),
302 .decl_ptr => |decl| {302 .decl_ptr => |decl_index| {
303 try zcu.declPtr(decl).renderFullyQualifiedName(zcu, writer);303 try writer.print("{}", .{zcu.declPtr(decl_index).fqn.fmt(ip)});
304 },304 },
305 .anon_decl_ptr => |anon| {305 .anon_decl_ptr => |anon| {
306 const ty = Value.fromInterned(anon.val).typeOf(zcu);306 const ty = Value.fromInterned(anon.val).typeOf(zcu);