From 4184767f7d92e8efca05756abb12cf4d448f3f7a Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Thu, 20 Aug 2026 19:38:27 -0400 Subject: [PATCH] Sema: add unqualified container type names --- src/IncrementalDebugServer.zig | 6 ++-- src/InternPool.zig | 51 +++++++++++++++++++++++++++++++--- src/Sema.zig | 48 ++++++++++++++++++++++++-------- src/Sema/type_resolution.zig | 19 ++++++++++--- src/Type.zig | 45 ++++++++++++++++++++---------- src/Zcu.zig | 36 ++++++++++++------------ src/Zcu/PerThread.zig | 30 ++++++++++++++------ src/codegen/c.zig | 6 ++-- src/codegen/c/type.zig | 6 ++-- src/codegen/llvm.zig | 10 +++---- src/link.zig | 4 +-- src/link/Dwarf.zig | 30 ++++++++++---------- src/link/Dwarf2.zig | 28 +++++++++---------- 13 files changed, 213 insertions(+), 106 deletions(-) diff --git a/src/IncrementalDebugServer.zig b/src/IncrementalDebugServer.zig index c9302516c1fb433cc2a7bb4b11e61e3e86be9e7c..d88691372b30f5f0bfd2ce7638c07816a6661723 100644 --- a/src/IncrementalDebugServer.zig +++ b/src/IncrementalDebugServer.zig @@ -243,7 +243,7 @@ fn handleCommand(zcu: *Zcu, w: *Io.Writer, cmd_str: []const u8, arg_str: []const var num_results: usize = 0; for (zcu.incremental_debug_state.types.keys()) |type_ip_index| { const ty: Type = .fromInterned(type_ip_index); - const ty_name = ty.containerTypeName(ip).toSlice(ip); + const ty_name = ty.containerTypeName(ip).fqn.toSlice(ip); const success = switch (@as(u2, @intFromBool(anchor_start)) << 1 | @intFromBool(anchor_end)) { 0b00 => std.mem.find(u8, ty_name, query) != null, 0b01 => std.mem.endsWith(u8, ty_name, query), @@ -347,7 +347,7 @@ fn handleCommand(zcu: *Zcu, w: *Io.Writer, cmd_str: []const u8, arg_str: []const \\created on generation: {d} \\ , .{ - Type.fromInterned(ip_index).containerTypeName(ip).fmt(ip), + Type.fromInterned(ip_index).containerTypeName(ip).fqn.fmt(ip), create_gen, }); } else if (std.mem.eql(u8, cmd_str, "type_namespace")) { @@ -451,7 +451,7 @@ fn printType(ty: Type, zcu: *const Zcu, w: *Io.Writer) Io.Writer.Error!void { .union_type, .enum_type, .opaque_type, - => try w.print("{f}[{d}]", .{ ty.containerTypeName(ip).fmt(ip), @backingInt(ty.toIntern()) }), + => try w.print("{f}[{d}]", .{ ty.containerTypeName(ip).fqn.fmt(ip), @backingInt(ty.toIntern()) }), else => unreachable, } diff --git a/src/InternPool.zig b/src/InternPool.zig index a21518c53837621886ebe51f1f92c4badd75536e..30b9ab71f2d317be392537b01e1a1bc819cbb25d 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -3207,9 +3207,10 @@ pub const LoadedStructType = struct { captures: CaptureValue.Slice, is_reified: bool, - // TODO: the non-fqn will be needed by the new dwarf structure /// The name of this struct type. name: NullTerminatedString, + /// The fully-qualified name of this struct type. + fqn: NullTerminatedString, /// If this is a declared type with the `.parent` name strategy, this is the `Nav` it was named after. /// Otherwise, or if this is a file's root struct type, this is `.none`. name_nav: Nav.Index.Optional, @@ -3390,9 +3391,10 @@ pub const LoadedUnionType = struct { captures: CaptureValue.Slice, is_reified: bool, - // TODO: the non-fqn will be needed by the new dwarf structure /// The name of this union type. name: NullTerminatedString, + /// The fully-qualified name of this union type. + fqn: NullTerminatedString, /// If this is a declared type with the `.parent` name strategy, this is the `Nav` it was named after. /// Otherwise, this is `.none`. name_nav: Nav.Index.Optional, @@ -3457,9 +3459,10 @@ pub const LoadedEnumType = struct { owner_union: Index, is_reified: bool, - // TODO: the non-fqn will be needed by the new dwarf structure /// The name of this enum type. name: NullTerminatedString, + /// The fully-qualified name of this enum type. + fqn: NullTerminatedString, /// If this is a declared type with the `.parent` name strategy, this is the `Nav` it was named after. /// Otherwise, this is `.none`. name_nav: Nav.Index.Optional, @@ -3519,9 +3522,10 @@ pub const LoadedOpaqueType = struct { zir_index: TrackedInst.Index, captures: CaptureValue.Slice, - // TODO: the non-fqn will be needed by the new dwarf structure /// The name of this opaque type. name: NullTerminatedString, + /// The fully-qualified name of this opaque type. + fqn: NullTerminatedString, /// If this is a declared type with the `.parent` name strategy, this is the `Nav` it was named after. /// Otherwise, this is `.none`. name_nav: Nav.Index.Optional, @@ -3607,6 +3611,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { .captures = captures, .is_reified = extra.data.flags.any_captures == .reified, .name = extra.data.name, + .fqn = extra.data.fqn, .name_nav = extra.data.name_nav, .namespace = extra.data.namespace, .layout = switch (extra.data.flags.layout) { @@ -3670,6 +3675,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { .captures = captures, .is_reified = extra.data.bits.captures_len == .reified, .name = extra.data.name, + .fqn = extra.data.fqn, .name_nav = extra.data.name_nav, .namespace = extra.data.namespace, .layout = .@"packed", @@ -3745,6 +3751,7 @@ pub fn loadUnionType(ip: *const InternPool, index: Index) LoadedUnionType { .captures = captures, .is_reified = extra.data.flags.any_captures == .reified, .name = extra.data.name, + .fqn = extra.data.fqn, .name_nav = extra.data.name_nav, .namespace = extra.data.namespace, .layout = switch (extra.data.flags.layout) { @@ -3800,6 +3807,7 @@ pub fn loadUnionType(ip: *const InternPool, index: Index) LoadedUnionType { .captures = captures, .is_reified = extra.data.bits.captures_len == .reified, .name = extra.data.name, + .fqn = extra.data.fqn, .name_nav = extra.data.name_nav, .namespace = extra.data.namespace, .layout = .@"packed", @@ -3880,6 +3888,7 @@ pub fn loadEnumType(ip: *const InternPool, index: Index) LoadedEnumType { .is_reified = extra.data.bits.captures_len == .reified, .owner_union = owner_union, .name = extra.data.name, + .fqn = extra.data.fqn, .name_nav = extra.data.name_nav, .namespace = extra.data.namespace, .int_tag_type = extra.data.int_tag_type, @@ -3906,6 +3915,7 @@ pub fn loadOpaqueType(ip: *const InternPool, index: Index) LoadedOpaqueType { .len = extra.data.captures_len, }, .name = extra.data.name, + .fqn = extra.data.fqn, .name_nav = extra.data.name_nav, .namespace = extra.data.namespace, }; @@ -5538,6 +5548,7 @@ pub const Tag = enum(u8) { zir_index: TrackedInst.Index, name: NullTerminatedString, + fqn: NullTerminatedString, name_nav: Nav.Index.Optional, namespace: NamespaceIndex, @@ -5580,6 +5591,7 @@ pub const Tag = enum(u8) { bits: Bits, name: NullTerminatedString, + fqn: NullTerminatedString, name_nav: Nav.Index.Optional, namespace: NamespaceIndex, @@ -5614,6 +5626,7 @@ pub const Tag = enum(u8) { zir_index: TrackedInst.Index, name: NullTerminatedString, + fqn: NullTerminatedString, name_nav: Nav.Index.Optional, namespace: NamespaceIndex, /// The enum that provides the list of field names and values. @@ -5673,6 +5686,7 @@ pub const Tag = enum(u8) { bits: Bits, name: NullTerminatedString, + fqn: NullTerminatedString, name_nav: Nav.Index.Optional, namespace: NamespaceIndex, @@ -5708,6 +5722,7 @@ pub const Tag = enum(u8) { bits: Bits, name: NullTerminatedString, + fqn: NullTerminatedString, name_nav: Nav.Index.Optional, namespace: NamespaceIndex, @@ -5735,6 +5750,7 @@ pub const Tag = enum(u8) { captures_len: u32, name: NullTerminatedString, + fqn: NullTerminatedString, name_nav: Nav.Index.Optional, namespace: NamespaceIndex, }; @@ -8063,6 +8079,7 @@ pub fn getDeclaredStructType( .want_layout = false, }, .name = undefined, // set by `finish` + .fqn = undefined, // set by `finish` .name_nav = undefined, // set by `finish` .namespace = undefined, // set by `finish` .backing_int_type = .none, @@ -8086,6 +8103,7 @@ pub fn getDeclaredStructType( .index = gop.put(), .tid = tid, .type_name_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "name").?, + .type_fqn_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "fqn").?, .name_nav_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "name_nav").?, .namespace_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "namespace").?, .field_names = undefined, @@ -8111,6 +8129,7 @@ pub fn getDeclaredStructType( const extra_index = addExtraAssumeCapacity(extra, Tag.TypeStruct{ .zir_index = ini.zir_index, .name = undefined, // set by `finish` + .fqn = undefined, // set by `finish` .name_nav = undefined, // set by `finish` .namespace = undefined, // set by `finish` .fields_len = ini.fields_len, @@ -8154,6 +8173,7 @@ pub fn getDeclaredStructType( .index = gop.put(), .tid = tid, .type_name_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "name").?, + .type_fqn_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "fqn").?, .name_nav_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "name_nav").?, .namespace_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "namespace").?, .field_names = undefined, @@ -8207,6 +8227,7 @@ pub fn getReifiedStructType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Pe .want_layout = false, }, .name = undefined, // set by `finish` + .fqn = undefined, // set by `finish` .name_nav = undefined, // set by `finish` .namespace = undefined, // set by `finish` .backing_int_type = ini.packed_backing_int_type, @@ -8233,6 +8254,7 @@ pub fn getReifiedStructType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Pe .index = gop.put(), .tid = tid, .type_name_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "name").?, + .type_fqn_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "fqn").?, .name_nav_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "name_nav").?, .namespace_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "namespace").?, .field_names = .{ .tid = tid, .start = field_names_start, .len = ini.fields_len }, @@ -8260,6 +8282,7 @@ pub fn getReifiedStructType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Pe const extra_index = addExtraAssumeCapacity(extra, Tag.TypeStruct{ .zir_index = ini.zir_index, .name = undefined, // set by `finish` + .fqn = undefined, // set by `finish` .name_nav = undefined, // set by `finish` .namespace = undefined, // set by `finish` .fields_len = ini.fields_len, @@ -8305,6 +8328,7 @@ pub fn getReifiedStructType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Pe .index = gop.put(), .tid = tid, .type_name_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "name").?, + .type_fqn_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "fqn").?, .name_nav_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "name_nav").?, .namespace_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "namespace").?, .field_names = .{ .tid = tid, .start = field_names_start, .len = ini.fields_len }, @@ -8378,6 +8402,7 @@ pub fn getDeclaredUnionType( .want_layout = false, }, .name = undefined, // set by `finish` + .fqn = undefined, // set by `finish` .name_nav = undefined, // set by `finish` .namespace = undefined, // set by `finish` .backing_int_type = .none, @@ -8397,6 +8422,7 @@ pub fn getDeclaredUnionType( .index = gop.put(), .tid = tid, .type_name_index = extra_index + std.meta.fieldIndex(Tag.TypeUnionPacked, "name").?, + .type_fqn_index = extra_index + std.meta.fieldIndex(Tag.TypeUnionPacked, "fqn").?, .name_nav_index = extra_index + std.meta.fieldIndex(Tag.TypeUnionPacked, "name_nav").?, .namespace_index = extra_index + std.meta.fieldIndex(Tag.TypeUnionPacked, "namespace").?, .field_names = undefined, @@ -8417,6 +8443,7 @@ pub fn getDeclaredUnionType( const extra_index = addExtraAssumeCapacity(extra, Tag.TypeUnion{ .zir_index = ini.zir_index, .name = undefined, // set by `finish` + .fqn = undefined, // set by `finish` .name_nav = undefined, // set by `finish` .namespace = undefined, // set by `finish` .enum_tag_type = .none, @@ -8451,6 +8478,7 @@ pub fn getDeclaredUnionType( .index = gop.put(), .tid = tid, .type_name_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "name").?, + .type_fqn_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "fqn").?, .name_nav_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "name_nav").?, .namespace_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "namespace").?, .field_names = undefined, @@ -8501,6 +8529,7 @@ pub fn getReifiedUnionType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Per .want_layout = false, }, .name = undefined, // set by `finish` + .fqn = undefined, // set by `finish` .name_nav = undefined, // set by `finish` .namespace = undefined, // set by `finish` .backing_int_type = ini.packed_backing_int_type, @@ -8523,6 +8552,7 @@ pub fn getReifiedUnionType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Per .index = gop.put(), .tid = tid, .type_name_index = extra_index + std.meta.fieldIndex(Tag.TypeUnionPacked, "name").?, + .type_fqn_index = extra_index + std.meta.fieldIndex(Tag.TypeUnionPacked, "fqn").?, .name_nav_index = extra_index + std.meta.fieldIndex(Tag.TypeUnionPacked, "name_nav").?, .namespace_index = extra_index + std.meta.fieldIndex(Tag.TypeUnionPacked, "namespace").?, .field_names = .{ .tid = tid, .start = field_names_start, .len = ini.fields_len }, @@ -8543,6 +8573,7 @@ pub fn getReifiedUnionType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Per const extra_index = addExtraAssumeCapacity(extra, Tag.TypeUnion{ .zir_index = ini.zir_index, .name = undefined, // set by `finish` + .fqn = undefined, // set by `finish` .name_nav = undefined, // set by `finish` .namespace = undefined, // set by `finish` .enum_tag_type = ini.enum_tag_type, @@ -8578,6 +8609,7 @@ pub fn getReifiedUnionType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Per .index = gop.put(), .tid = tid, .type_name_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "name").?, + .type_fqn_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "fqn").?, .name_nav_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "name_nav").?, .namespace_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "namespace").?, .field_names = .{ .tid = tid, .start = field_names_start, .len = ini.fields_len }, @@ -8654,6 +8686,7 @@ pub fn getDeclaredEnumType( .want_layout = false, }, .name = undefined, // set by `finish` + .fqn = undefined, // set by `finish` .name_nav = undefined, // set by `finish` .namespace = undefined, // set by `finish` .int_tag_type = .none, @@ -8673,6 +8706,7 @@ pub fn getDeclaredEnumType( .index = gop.put(), .tid = tid, .type_name_index = extra_index + std.meta.fieldIndex(Tag.TypeEnum, "name").?, + .type_fqn_index = extra_index + std.meta.fieldIndex(Tag.TypeEnum, "fqn").?, .name_nav_index = extra_index + std.meta.fieldIndex(Tag.TypeEnum, "name_nav").?, .namespace_index = extra_index + std.meta.fieldIndex(Tag.TypeEnum, "namespace").?, .field_names = undefined, @@ -8729,6 +8763,7 @@ pub fn getReifiedEnumType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerT .want_layout = false, }, .name = undefined, // set by `finish` + .fqn = undefined, // set by `finish` .name_nav = undefined, // set by `finish` .namespace = undefined, // set by `finish` .int_tag_type = ini.int_tag_type, @@ -8750,6 +8785,7 @@ pub fn getReifiedEnumType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerT .index = gop.put(), .tid = tid, .type_name_index = extra_index + std.meta.fieldIndex(Tag.TypeEnum, "name").?, + .type_fqn_index = extra_index + std.meta.fieldIndex(Tag.TypeEnum, "fqn").?, .name_nav_index = extra_index + std.meta.fieldIndex(Tag.TypeEnum, "name_nav").?, .namespace_index = extra_index + std.meta.fieldIndex(Tag.TypeEnum, "namespace").?, .field_names = .{ .tid = tid, .start = field_names_start, .len = ini.fields_len }, @@ -8828,6 +8864,7 @@ pub fn getGeneratedEnumTagType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu .want_layout = false, }, .name = undefined, // set by `finish` + .fqn = undefined, // set by `finish` .name_nav = undefined, // set by `finish` .namespace = undefined, // set by `finish` .int_tag_type = .none, @@ -8849,6 +8886,7 @@ pub fn getGeneratedEnumTagType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu .index = gop.put(), .tid = tid, .type_name_index = extra_index + std.meta.fieldIndex(Tag.TypeEnum, "name").?, + .type_fqn_index = extra_index + std.meta.fieldIndex(Tag.TypeEnum, "fqn").?, .name_nav_index = extra_index + std.meta.fieldIndex(Tag.TypeEnum, "name_nav").?, .namespace_index = extra_index + std.meta.fieldIndex(Tag.TypeEnum, "namespace").?, .field_names = undefined, @@ -8880,6 +8918,7 @@ pub fn getDeclaredOpaqueType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.P .zir_index = ini.zir_index, .captures_len = @intCast(ini.captures.len), .name = undefined, // set by `finish` + .fqn = undefined, // set by `finish` .name_nav = undefined, // set by `finish` .namespace = undefined, // set by `finish` }); @@ -8892,6 +8931,7 @@ pub fn getDeclaredOpaqueType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.P .index = gop.put(), .tid = tid, .type_name_index = extra_index + std.meta.fieldIndex(Tag.TypeOpaque, "name").?, + .type_fqn_index = extra_index + std.meta.fieldIndex(Tag.TypeOpaque, "fqn").?, .name_nav_index = extra_index + std.meta.fieldIndex(Tag.TypeOpaque, "name_nav").?, .namespace_index = extra_index + std.meta.fieldIndex(Tag.TypeOpaque, "namespace").?, .field_names = undefined, @@ -8906,6 +8946,7 @@ pub const WipContainerType = struct { index: Index, tid: Zcu.PerThread.Id, type_name_index: u32, + type_fqn_index: u32, name_nav_index: u32, namespace_index: u32, @@ -8923,6 +8964,7 @@ pub const WipContainerType = struct { wip: WipContainerType, ip: *InternPool, type_name: NullTerminatedString, + type_fqn: NullTerminatedString, /// This should be the `Nav` we are named after if we use the `.parent` name strategy; `.none` otherwise. /// This is also `.none` if we use `.parent` because we are the root struct type for a file. name_nav: Nav.Index.Optional, @@ -8930,6 +8972,7 @@ pub const WipContainerType = struct { const extra = ip.getLocalShared(wip.tid).extra.acquire(); const extra_items = extra.view().items(.@"0"); extra_items[wip.type_name_index] = @backingInt(type_name); + extra_items[wip.type_fqn_index] = @backingInt(type_fqn); extra_items[wip.name_nav_index] = @backingInt(name_nav); } diff --git a/src/Sema.zig b/src/Sema.zig index 68e8524b838914d898a8b2b4764aaaba750e0da3..1090ecd135c01218c2020d740b8eada0bc5fef26 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -403,6 +403,7 @@ pub const Block = struct { /// is always incorporated into the type name somehow. /// See `Sema.setTypeName`. type_name_ctx: InternPool.NullTerminatedString, + type_fqn_ctx: InternPool.NullTerminatedString, /// Create a `LazySrcLoc` based on an `Offset` from the code being analyzed in this block. /// Specifically, the given `Offset` is treated as relative to `block.src_base_inst`. @@ -531,6 +532,7 @@ pub const Block = struct { .need_debug_scope = parent.need_debug_scope, .src_base_inst = parent.src_base_inst, .type_name_ctx = parent.type_name_ctx, + .type_fqn_ctx = parent.type_fqn_ctx, }; } @@ -4782,7 +4784,7 @@ fn failWithBadStructFieldAccess( const msg = try sema.errMsg( field_src, "no field named '{f}' in struct '{f}'", - .{ field_name.fmt(ip), struct_type.name.fmt(ip) }, + .{ field_name.fmt(ip), struct_type.fqn.fmt(ip) }, ); errdefer msg.destroy(sema.gpa); try sema.errNote(struct_ty.srcLoc(zcu), msg, "struct declared here", .{}); @@ -4808,7 +4810,7 @@ fn failWithBadUnionFieldAccess( const msg = try sema.errMsg( field_src, "no field named '{f}' in union '{f}'", - .{ field_name.fmt(ip), union_obj.name.fmt(ip) }, + .{ field_name.fmt(ip), union_obj.fqn.fmt(ip) }, ); errdefer msg.destroy(gpa); try sema.errNote(union_ty.srcLoc(zcu), msg, "union declared here", .{}); @@ -5291,6 +5293,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErro .error_return_trace_index = parent_block.error_return_trace_index, .src_base_inst = parent_block.src_base_inst, .type_name_ctx = parent_block.type_name_ctx, + .type_fqn_ctx = parent_block.type_fqn_ctx, }; defer child_block.instructions.deinit(gpa); @@ -6773,7 +6776,8 @@ fn analyzeCall( .instructions = .empty, .inlining = &generic_inlining, .src_base_inst = fn_nav.analysis.?.zir_index, - .type_name_ctx = fn_nav.fqn, + .type_name_ctx = fn_nav.name, + .type_fqn_ctx = fn_nav.fqn, } else undefined; defer if (any_generic_types) generic_block.instructions.deinit(gpa); @@ -7309,7 +7313,8 @@ fn analyzeCall( .runtime_loop = block.runtime_loop, .runtime_index = block.runtime_index, .src_base_inst = fn_nav.analysis.?.zir_index, - .type_name_ctx = fn_nav.fqn, + .type_name_ctx = fn_nav.name, + .type_fqn_ctx = fn_nav.fqn, }; defer child_block.instructions.deinit(gpa); @@ -17315,6 +17320,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr .error_return_trace_index = block.error_return_trace_index, .src_base_inst = block.src_base_inst, .type_name_ctx = block.type_name_ctx, + .type_fqn_ctx = block.type_fqn_ctx, }; defer child_block.instructions.deinit(sema.gpa); @@ -17381,6 +17387,7 @@ fn zirTypeofPeer( .runtime_index = block.runtime_index, .src_base_inst = block.src_base_inst, .type_name_ctx = block.type_name_ctx, + .type_fqn_ctx = block.type_fqn_ctx, }; defer child_block.instructions.deinit(sema.gpa); // Ignore the result, we only care about the instructions in `args`. @@ -17940,6 +17947,7 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label .comptime_reason = block.comptime_reason, .src_base_inst = block.src_base_inst, .type_name_ctx = block.type_name_ctx, + .type_fqn_ctx = block.type_fqn_ctx, }, }; sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block); @@ -25935,6 +25943,7 @@ fn addSafetyCheck( .comptime_reason = null, .src_base_inst = parent_block.src_base_inst, .type_name_ctx = parent_block.type_name_ctx, + .type_fqn_ctx = parent_block.type_fqn_ctx, }; defer fail_block.instructions.deinit(gpa); @@ -26029,6 +26038,7 @@ fn addSafetyCheckUnwrapError( .comptime_reason = null, .src_base_inst = parent_block.src_base_inst, .type_name_ctx = parent_block.type_name_ctx, + .type_fqn_ctx = parent_block.type_fqn_ctx, }; defer fail_block.instructions.deinit(gpa); @@ -26152,6 +26162,7 @@ fn addSafetyCheckCall( .comptime_reason = null, .src_base_inst = parent_block.src_base_inst, .type_name_ctx = parent_block.type_name_ctx, + .type_fqn_ctx = parent_block.type_fqn_ctx, }; defer fail_block.instructions.deinit(gpa); @@ -34994,6 +35005,7 @@ pub fn analyzeMemoizedState(sema: *Sema, stage: InternPool.MemoizedStateStage) C .comptime_reason = null, .src_base_inst = std_type.typeDeclInst(zcu).?, .type_name_ctx = .empty, + .type_fqn_ctx = .empty, }; }; defer block.instructions.deinit(gpa); @@ -35225,10 +35237,17 @@ pub fn setTypeName( "{f}__{s}_{d}", .{ block.type_name_ctx.fmt(ip), anon_prefix, zcu.anon_name_counter }, .no_embedded_nulls, + ), try ip.getOrPutStringFmt( + gpa, + io, + pt.tid, + "{f}__{s}_{d}", + .{ block.type_fqn_ctx.fmt(ip), anon_prefix, zcu.anon_name_counter }, + .no_embedded_nulls, ), .none); zcu.anon_name_counter += 1; }, - .parent => wip.setName(ip, block.type_name_ctx, sema.owner.unwrap().nav_val.toOptional()), + .parent => wip.setName(ip, block.type_name_ctx, block.type_fqn_ctx, sema.owner.unwrap().nav_val.toOptional()), .func => { const fn_info = sema.code.getFnInfo(ip.funcZirBodyInst(sema.func_index).resolve(ip) orelse { return sema.failTransitive(.{ .lost_tracking = ip.funcZirBodyInst(sema.func_index) }); @@ -35238,7 +35257,7 @@ pub fn setTypeName( var aw: std.Io.Writer.Allocating = .init(gpa); defer aw.deinit(); const w = &aw.writer; - w.print("{f}(", .{block.type_name_ctx.fmt(ip)}) catch return error.OutOfMemory; + w.writeByte('(') catch return error.OutOfMemory; var arg_i: usize = 0; for (fn_info.param_body) |zir_inst| switch (zir_tags[@backingInt(zir_inst)]) { @@ -35273,8 +35292,13 @@ pub fn setTypeName( }; w.writeByte(')') catch return error.OutOfMemory; - const name = try ip.getOrPutString(gpa, io, pt.tid, aw.written(), .no_embedded_nulls); - wip.setName(ip, name, .none); + wip.setName(ip, try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}{s}", .{ + block.type_name_ctx.fmt(ip), + aw.written(), + }, .no_embedded_nulls), try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}{s}", .{ + block.type_fqn_ctx.fmt(ip), + aw.written(), + }, .no_embedded_nulls), .none); }, .dbg_var => { // TODO: this logic is questionable. We ideally should be traversing the `Block` rather than relying on the order of AstGen instructions. @@ -35289,10 +35313,12 @@ pub fn setTypeName( } else { continue :strat .anon; }; - const name = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}.{s}", .{ + wip.setName(ip, try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}.{s}", .{ + // this "{f}." should be elided, but there's currently no way to get the parent function block.type_name_ctx.fmt(ip), var_name, - }, .no_embedded_nulls); - wip.setName(ip, name, .none); + }, .no_embedded_nulls), try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}.{s}", .{ + block.type_fqn_ctx.fmt(ip), var_name, + }, .no_embedded_nulls), .none); }, } } diff --git a/src/Sema/type_resolution.zig b/src/Sema/type_resolution.zig index 66f4aa63bb6a27fb96d24b0fcc702800b7d55bbf..164fe262037b8262cc1324319751a7e3173be4e4 100644 --- a/src/Sema/type_resolution.zig +++ b/src/Sema/type_resolution.zig @@ -187,7 +187,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void { const tracy = trace(@src()); defer tracy.end(); - tracy.addText(struct_ty.containerTypeName(ip).toSlice(ip)); + tracy.addText(struct_ty.containerTypeName(ip).fqn.toSlice(ip)); tracy.addTextFmt("ip_index={d}", .{struct_ty.toIntern()}); assert(sema.owner.unwrap().type_layout == struct_ty.toIntern()); @@ -207,6 +207,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void { .comptime_reason = undefined, // always set before using `block` .src_base_inst = struct_obj.zir_index, .type_name_ctx = struct_obj.name, + .type_fqn_ctx = struct_obj.fqn, }; defer block.instructions.deinit(gpa); @@ -613,7 +614,7 @@ pub fn resolveStructDefaults(sema: *Sema, struct_ty: Type) CompileError!void { const tracy = trace(@src()); defer tracy.end(); - tracy.addText(struct_ty.containerTypeName(ip).toSlice(ip)); + tracy.addText(struct_ty.containerTypeName(ip).fqn.toSlice(ip)); tracy.addTextFmt("ip_index={d}", .{struct_ty.toIntern()}); assert(sema.owner.unwrap().struct_defaults == struct_ty.toIntern()); @@ -653,6 +654,7 @@ pub fn resolveStructDefaults(sema: *Sema, struct_ty: Type) CompileError!void { .comptime_reason = undefined, // always set before using `block` .src_base_inst = struct_obj.zir_index, .type_name_ctx = struct_obj.name, + .type_fqn_ctx = struct_obj.fqn, }; defer block.instructions.deinit(gpa); @@ -727,7 +729,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void { const tracy = trace(@src()); defer tracy.end(); - tracy.addText(union_ty.containerTypeName(ip).toSlice(ip)); + tracy.addText(union_ty.containerTypeName(ip).fqn.toSlice(ip)); tracy.addTextFmt("ip_index={d}", .{union_ty.toIntern()}); assert(sema.owner.unwrap().type_layout == union_ty.toIntern()); @@ -747,6 +749,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void { .comptime_reason = undefined, // always set before using `block` .src_base_inst = union_obj.zir_index, .type_name_ctx = union_obj.name, + .type_fqn_ctx = union_obj.fqn, }; defer block.instructions.deinit(gpa); @@ -801,6 +804,13 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void { "@typeInfo({f}).@\"union\".tag_type.?", .{union_obj.name.fmt(ip)}, .no_embedded_nulls, + ), try ip.getOrPutStringFmt( + gpa, + io, + pt.tid, + "@typeInfo({f}).@\"union\".tag_type.?", + .{union_obj.fqn.fmt(ip)}, + .no_embedded_nulls, ), .none); const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{ .parent = union_obj.namespace.toOptional(), @@ -1221,7 +1231,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void { const tracy = trace(@src()); defer tracy.end(); - tracy.addText(enum_ty.containerTypeName(ip).toSlice(ip)); + tracy.addText(enum_ty.containerTypeName(ip).fqn.toSlice(ip)); tracy.addTextFmt("ip_index={d}", .{enum_ty.toIntern()}); assert(sema.owner.unwrap().type_layout == enum_ty.toIntern()); @@ -1248,6 +1258,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void { .comptime_reason = undefined, // always set before using `block` .src_base_inst = tracked_inst, .type_name_ctx = enum_obj.name, + .type_fqn_ctx = enum_obj.fqn, }; defer block.instructions.deinit(gpa); diff --git a/src/Type.zig b/src/Type.zig index 6493b3bd22efb4e8543d69189823ffe0b104f3e2..0d54cc48599d27d8ce866d582e3c89bf4f35a1d3 100644 --- a/src/Type.zig +++ b/src/Type.zig @@ -607,8 +607,8 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari .generic_poison => unreachable, }, .struct_type => { - const name = ip.loadStructType(ty.toIntern()).name; - try writer.print("{f}", .{name.fmt(ip)}); + const fqn = ip.loadStructType(ty.toIntern()).fqn; + try writer.print("{f}", .{fqn.fmt(ip)}); }, .tuple_type => |tuple| { if (tuple.types.len == 0) { @@ -625,16 +625,16 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari }, .union_type => { - const name = ip.loadUnionType(ty.toIntern()).name; - try writer.print("{f}", .{name.fmt(ip)}); + const fqn = ip.loadUnionType(ty.toIntern()).fqn; + try writer.print("{f}", .{fqn.fmt(ip)}); }, .opaque_type => { - const name = ip.loadOpaqueType(ty.toIntern()).name; - try writer.print("{f}", .{name.fmt(ip)}); + const fqn = ip.loadOpaqueType(ty.toIntern()).fqn; + try writer.print("{f}", .{fqn.fmt(ip)}); }, .enum_type => { - const name = ip.loadEnumType(ty.toIntern()).name; - try writer.print("{f}", .{name.fmt(ip)}); + const fqn = ip.loadEnumType(ty.toIntern()).fqn; + try writer.print("{f}", .{fqn.fmt(ip)}); }, .spirv_type => { const info = ip.loadSpirvType(ty.toIntern()); @@ -3020,14 +3020,29 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator return pt.ptrType(field_ptr_info); } -pub fn containerTypeName(ty: Type, ip: *const InternPool) InternPool.NullTerminatedString { - return switch (ip.indexToKey(ty.toIntern())) { - .struct_type => ip.loadStructType(ty.toIntern()).name, - .union_type => ip.loadUnionType(ty.toIntern()).name, - .enum_type => ip.loadEnumType(ty.toIntern()).name, - .opaque_type => ip.loadOpaqueType(ty.toIntern()).name, +pub fn containerTypeName(ty: Type, ip: *const InternPool) struct { + name: InternPool.NullTerminatedString, + fqn: InternPool.NullTerminatedString, +} { + switch (ip.indexToKey(ty.toIntern())) { + .struct_type => { + const loaded_struct = ip.loadStructType(ty.toIntern()); + return .{ .name = loaded_struct.name, .fqn = loaded_struct.fqn }; + }, + .union_type => { + const loaded_union = ip.loadUnionType(ty.toIntern()); + return .{ .name = loaded_union.name, .fqn = loaded_union.fqn }; + }, + .enum_type => { + const loaded_enum = ip.loadEnumType(ty.toIntern()); + return .{ .name = loaded_enum.name, .fqn = loaded_enum.fqn }; + }, + .opaque_type => { + const loaded_opaque = ip.loadOpaqueType(ty.toIntern()); + return .{ .name = loaded_opaque.name, .fqn = loaded_opaque.fqn }; + }, else => unreachable, - }; + } } pub fn destructurable(ty: Type, zcu: *const Zcu) bool { diff --git a/src/Zcu.zig b/src/Zcu.zig index 75aada8dd3831cdc7989617febe77000be066104..22badf6b81fcec09e1a85551e2d58d124927460d 100644 --- a/src/Zcu.zig +++ b/src/Zcu.zig @@ -947,9 +947,9 @@ pub const Namespace = struct { tid: Zcu.PerThread.Id, name: InternPool.NullTerminatedString, ) !InternPool.NullTerminatedString { - const ns_name = Type.fromInterned(ns.owner_type).containerTypeName(ip); - if (name == .empty) return ns_name; - return ip.getOrPutStringFmt(gpa, io, tid, "{f}.{f}", .{ ns_name.fmt(ip), name.fmt(ip) }, .no_embedded_nulls); + const ns_fqn = Type.fromInterned(ns.owner_type).containerTypeName(ip).fqn; + if (name == .empty) return ns_fqn; + return ip.getOrPutStringFmt(gpa, io, tid, "{f}.{f}", .{ ns_fqn.fmt(ip), name.fmt(ip) }, .no_embedded_nulls); } }; @@ -4237,7 +4237,7 @@ fn resolveReferencesInner(zcu: *Zcu) Allocator.Error!std.array_hash_map.Auto(Ana const referencer = types.values()[type_idx]; type_idx += 1; - refs_log.debug("handle type '{f}'", .{Type.fromInterned(ty).containerTypeName(ip).fmt(ip)}); + refs_log.debug("handle type '{f}'", .{Type.fromInterned(ty).containerTypeName(ip).fqn.fmt(ip)}); // Queue any decls within this type which would be automatically analyzed. // Keep in sync with analysis queueing logic in `Zcu.PerThread.ScanDeclIter.scanDecl`. @@ -4248,7 +4248,7 @@ fn resolveReferencesInner(zcu: *Zcu) Allocator.Error!std.array_hash_map.Auto(Ana const gop = try units.getOrPut(gpa, unit); if (!gop.found_existing) { refs_log.debug("type '{f}': ref comptime %{}", .{ - Type.fromInterned(ty).containerTypeName(ip).fmt(ip), + Type.fromInterned(ty).containerTypeName(ip).fqn.fmt(ip), @backingInt(ip.getComptimeUnit(cu).zir_index.resolve(ip) orelse continue), }); gop.value_ptr.* = referencer; @@ -4282,7 +4282,7 @@ fn resolveReferencesInner(zcu: *Zcu) Allocator.Error!std.array_hash_map.Auto(Ana const gop = try units.getOrPut(gpa, .wrap(.{ .nav_val = nav_id })); if (!gop.found_existing) { refs_log.debug("type '{f}': ref test %{}", .{ - Type.fromInterned(ty).containerTypeName(ip).fmt(ip), + Type.fromInterned(ty).containerTypeName(ip).fqn.fmt(ip), @backingInt(inst_info.inst), }); gop.value_ptr.* = referencer; @@ -4305,7 +4305,7 @@ fn resolveReferencesInner(zcu: *Zcu) Allocator.Error!std.array_hash_map.Auto(Ana const gop = try units.getOrPut(gpa, unit); if (!gop.found_existing) { refs_log.debug("type '{f}': ref named %{}", .{ - Type.fromInterned(ty).containerTypeName(ip).fmt(ip), + Type.fromInterned(ty).containerTypeName(ip).fqn.fmt(ip), @backingInt(inst_info.inst), }); gop.value_ptr.* = referencer; @@ -4322,7 +4322,7 @@ fn resolveReferencesInner(zcu: *Zcu) Allocator.Error!std.array_hash_map.Auto(Ana const gop = try units.getOrPut(gpa, unit); if (!gop.found_existing) { refs_log.debug("type '{f}': ref named %{}", .{ - Type.fromInterned(ty).containerTypeName(ip).fmt(ip), + Type.fromInterned(ty).containerTypeName(ip).fqn.fmt(ip), @backingInt(inst_info.inst), }); gop.value_ptr.* = referencer; @@ -4385,7 +4385,7 @@ fn resolveReferencesInner(zcu: *Zcu) Allocator.Error!std.array_hash_map.Auto(Ana if (!gop.found_existing) { refs_log.debug("unit '{f}': ref type '{f}'", .{ zcu.fmtAnalUnit(unit), - Type.fromInterned(ref.referenced).containerTypeName(ip).fmt(ip), + Type.fromInterned(ref.referenced).containerTypeName(ip).fqn.fmt(ip), }); gop.value_ptr.* = .{ .referencer = unit, @@ -4498,7 +4498,7 @@ fn formatAnalUnit(data: FormatAnalUnit, writer: *Io.Writer) Io.Writer.Error!void } }, .nav_val, .nav_ty => |nav, tag| return writer.print("{t}('{f}' [{}])", .{ tag, ip.getNav(nav).fqn.fmt(ip), @backingInt(nav) }), - .type_layout, .struct_defaults => |ty, tag| return writer.print("{t}('{f}' [{}])", .{ tag, Type.fromInterned(ty).containerTypeName(ip).fmt(ip), @backingInt(ty) }), + .type_layout, .struct_defaults => |ty, tag| return writer.print("{t}('{f}' [{}])", .{ tag, Type.fromInterned(ty).containerTypeName(ip).fqn.fmt(ip), @backingInt(ty) }), .func => |func| { const nav = zcu.funcInfo(func).owner_nav; return writer.print("func('{f}' [{}])", .{ ip.getNav(nav).fqn.fmt(ip), @backingInt(func) }); @@ -4524,8 +4524,8 @@ fn formatDependee(data: FormatDependee, writer: *Io.Writer) Io.Writer.Error!void return writer.print("{t}('{f}')", .{ tag, fqn.fmt(ip) }); }, .type_layout, .struct_defaults => |ip_index, tag| { - const name = Type.fromInterned(ip_index).containerTypeName(ip); - return writer.print("{t}('{f}')", .{ tag, name.fmt(ip) }); + const fqn = Type.fromInterned(ip_index).containerTypeName(ip).fqn; + return writer.print("{t}('{f}')", .{ tag, fqn.fmt(ip) }); }, .func_ies => |ip_index| { const fqn = ip.getNav(ip.indexToKey(ip_index).func.owner_nav).fqn; @@ -5002,7 +5002,7 @@ fn addDependencyLoopErrorLine( }), .struct_defaults => |ty| try eb.printString( "default field values of '{f}' depend on themselves for initialization here", - .{Type.fromInterned(ty).containerTypeName(ip).fmt(ip)}, + .{Type.fromInterned(ty).containerTypeName(ip).fqn.fmt(ip)}, ), } else switch (dep_node.unit.unwrap()) { .@"comptime" => unreachable, // cannot be involved in a dependency loop @@ -5021,12 +5021,12 @@ fn addDependencyLoopErrorLine( }), .type_layout => |ty| try eb.printString("{f} depends on type '{f}' {s}", .{ fmt_source, - Type.fromInterned(ty).containerTypeName(ip).fmt(ip), + Type.fromInterned(ty).containerTypeName(ip).fqn.fmt(ip), dep_node.reason.type_layout_reason.msg(), }), .struct_defaults => |ty| try eb.printString( "{f} uses default field values of '{f}' here", - .{ fmt_source, Type.fromInterned(ty).containerTypeName(ip).fmt(ip) }, + .{ fmt_source, Type.fromInterned(ty).containerTypeName(ip).fqn.fmt(ip) }, ), }; @@ -5068,10 +5068,10 @@ fn formatDependencyLoopSourceUnit(data: FormatAnalUnit, w: *Io.Writer) Io.Writer else => try w.writeAll("'std.lang' declarations"), }, .type_layout => |ty| try w.print("type '{f}'", .{ - Type.fromInterned(ty).containerTypeName(ip).fmt(ip), + Type.fromInterned(ty).containerTypeName(ip).fqn.fmt(ip), }), .struct_defaults => |ty| try w.print("default field value of '{f}'", .{ - Type.fromInterned(ty).containerTypeName(ip).fmt(ip), + Type.fromInterned(ty).containerTypeName(ip).fqn.fmt(ip), }), .func => |func| try w.print("function '{f}'", .{ ip.getNav(zcu.funcInfo(func).owner_nav).fqn.fmt(ip), @@ -5121,7 +5121,7 @@ pub fn populateReferenceTrace( const root_name: ?[]const u8 = switch (ref.referencer.unwrap()) { .@"comptime" => "comptime", .nav_val, .nav_ty => |nav| ip.getNav(nav).name.toSlice(ip), - .type_layout, .struct_defaults => |ty| Type.fromInterned(ty).containerTypeName(ip).toSlice(ip), + .type_layout, .struct_defaults => |ty| Type.fromInterned(ty).containerTypeName(ip).fqn.toSlice(ip), .func => |f| ip.getNav(zcu.funcInfo(f).owner_nav).name.toSlice(ip), .memoized_state => null, }; diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index 845451870513b8953dc77e72b28f49ea270cfa8f..32fe40b4559d4c2171b71c388eebca8026bbdfa8 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -1026,7 +1026,12 @@ pub fn ensureFilePopulated(pt: Zcu.PerThread, file_index: Zcu.File.Index) (Alloc }; errdefer wip.cancel(ip, pt.tid); - wip.setName(ip, try file.internFullyQualifiedName(pt), .none); + wip.setName( + ip, + try ip.getOrPutString(gpa, io, pt.tid, std.fs.path.stem(file.sub_file_path), .no_embedded_nulls), + try file.internFullyQualifiedName(pt), + .none, + ); const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{ .parent = .none, .owner_type = wip.index, @@ -1267,6 +1272,7 @@ fn analyzeComptimeUnit(pt: Zcu.PerThread, cu_id: InternPool.ComptimeUnit.Id) Zcu // The comptime unit declares on the source of the corresponding `comptime` declaration. try sema.declareDependency(.{ .src_hash = comptime_unit.zir_index }); + const parent_ns = Type.fromInterned(zcu.namespacePtr(comptime_unit.namespace).owner_type).containerTypeName(ip); var block: Sema.Block = .{ .parent = null, .sema = &sema, @@ -1282,7 +1288,10 @@ fn analyzeComptimeUnit(pt: Zcu.PerThread, cu_id: InternPool.ComptimeUnit.Id) Zcu } }, .src_base_inst = comptime_unit.zir_index, .type_name_ctx = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}.comptime", .{ - Type.fromInterned(zcu.namespacePtr(comptime_unit.namespace).owner_type).containerTypeName(ip).fmt(ip), + parent_ns.name.fmt(ip), + }, .no_embedded_nulls), + .type_fqn_ctx = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}.comptime", .{ + parent_ns.fqn.fmt(ip), }, .no_embedded_nulls), }; defer block.instructions.deinit(gpa); @@ -1358,7 +1367,7 @@ pub fn ensureTypeLayoutUpToDate( info.deps.clearRetainingCapacity(); } - const unit_tracking = zcu.trackUnitSema(ty.containerTypeName(ip).toSlice(ip), null); + const unit_tracking = zcu.trackUnitSema(ty.containerTypeName(ip).fqn.toSlice(ip), null); defer unit_tracking.end(zcu); try zcu.analysis_in_progress.put(gpa, anal_unit, reason); @@ -1470,7 +1479,7 @@ pub fn ensureStructDefaultsUpToDate( info.deps.clearRetainingCapacity(); } - const unit_tracking = zcu.trackUnitSema(ty.containerTypeName(ip).toSlice(ip), null); + const unit_tracking = zcu.trackUnitSema(ty.containerTypeName(ip).fqn.toSlice(ip), null); defer unit_tracking.end(zcu); try zcu.analysis_in_progress.put(gpa, anal_unit, reason); @@ -1679,7 +1688,8 @@ fn analyzeNavVal( .inlining = null, .comptime_reason = undefined, // set below .src_base_inst = old_nav.analysis.?.zir_index, - .type_name_ctx = old_nav.fqn, + .type_name_ctx = old_nav.name, + .type_fqn_ctx = old_nav.fqn, }; defer block.instructions.deinit(gpa); @@ -2048,7 +2058,8 @@ fn analyzeNavType( .inlining = null, .comptime_reason = undefined, // set below .src_base_inst = old_nav.analysis.?.zir_index, - .type_name_ctx = old_nav.fqn, + .type_name_ctx = old_nav.name, + .type_fqn_ctx = old_nav.fqn, }; defer block.instructions.deinit(gpa); @@ -2989,11 +3000,11 @@ pub fn scanNamespace( const tracy_trace = trace(@src()); defer tracy_trace.end(); - tracy_trace.addText(Type.fromInterned(namespace.owner_type).containerTypeName(ip).toSlice(ip)); + tracy_trace.addText(Type.fromInterned(namespace.owner_type).containerTypeName(ip).fqn.toSlice(ip)); tracy_trace.addTextFmt("type_ip_index={d}", .{namespace.owner_type}); const tracked_unit = zcu.trackUnitSema( - Type.fromInterned(namespace.owner_type).containerTypeName(ip).toSlice(ip), + Type.fromInterned(namespace.owner_type).containerTypeName(ip).fqn.toSlice(ip), null, ); defer tracked_unit.end(zcu); @@ -3315,7 +3326,8 @@ fn analyzeFuncBodyInner( .inlining = null, .comptime_reason = null, .src_base_inst = decl_analysis.zir_index, - .type_name_ctx = func_nav.fqn, + .type_name_ctx = func_nav.name, + .type_fqn_ctx = func_nav.fqn, }; defer inner_block.instructions.deinit(gpa); diff --git a/src/codegen/c.zig b/src/codegen/c.zig index b0144a7c54ba438fec756551cc611dad2e92a823..ea5688855c6c1149af7676b1f1072241e539c121 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -2175,11 +2175,11 @@ pub fn genTagNameFn( } if (!zcu.comp.config.root_strip) try w.print("/* @tagName({f}) */\n", .{ - loaded_enum.name.fmt(ip), + loaded_enum.fqn.fmt(ip), }); try w.print("static {s} zig_tagName_{f}__{d}({s} tag) {{\n", .{ slice_const_u8_sentinel_0_type_name, - fmtIdentUnsolo(loaded_enum.name.toSlice(ip)), + fmtIdentUnsolo(loaded_enum.fqn.toSlice(ip)), @backingInt(enum_ty.toIntern()), enum_type_name, }); @@ -6667,7 +6667,7 @@ fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue { try f.writeCValue(w, local, .other); try f.need_tag_name_funcs.put(gpa, enum_ty.toIntern(), {}); try w.print(" = zig_tagName_{f}__{d}(", .{ - fmtIdentUnsolo(enum_ty.containerTypeName(ip).toSlice(ip)), + fmtIdentUnsolo(enum_ty.containerTypeName(ip).fqn.toSlice(ip)), @backingInt(enum_ty.toIntern()), }); try f.writeCValue(w, operand, .other); diff --git a/src/codegen/c/type.zig b/src/codegen/c/type.zig index 01b474dc9c7cfa2c995cae0f3e75b238b8447619..4b0abd42ccba9bd00cbb5804b5e8e8ed43b0f221 100644 --- a/src/codegen/c/type.zig +++ b/src/codegen/c/type.zig @@ -1140,17 +1140,17 @@ pub const CType = union(enum) { try w.print("_{f}", .{fmtZigType(field_ty, zcu)}); } } else { - const name = ty.containerTypeName(ip).toSlice(ip); + const name = ty.containerTypeName(ip).fqn.toSlice(ip); try w.print("{f}", .{@import("../c.zig").fmtIdentUnsolo(name)}); }, .@"opaque" => if (ty.toIntern() == .anyopaque_type) { try w.writeAll("anyopaque"); } else { - const name = ty.containerTypeName(ip).toSlice(ip); + const name = ty.containerTypeName(ip).fqn.toSlice(ip); try w.print("{f}", .{@import("../c.zig").fmtIdentUnsolo(name)}); }, .@"union", .@"enum" => { - const name = ty.containerTypeName(ip).toSlice(ip); + const name = ty.containerTypeName(ip).fqn.toSlice(ip); try w.print("{f}", .{@import("../c.zig").fmtIdentUnsolo(name)}); }, } diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 5a5cec3bdf0f2d512e71695c0d0127d566184886..e818984ee00df74005032e49e7ca5178d52d5968 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -2893,7 +2893,7 @@ pub const Object = struct { } } - const ty = try o.builder.opaqueType(try o.builder.string(t.containerTypeName(ip).toSlice(ip))); + const ty = try o.builder.opaqueType(try o.builder.string(t.containerTypeName(ip).fqn.toSlice(ip))); try o.type_map.put(o.gpa, t.toIntern(), ty); o.builder.namedTypeSetBody( @@ -2983,7 +2983,7 @@ pub const Object = struct { }; if (layout.tag_size == 0) { - const ty = try o.builder.opaqueType(try o.builder.string(t.containerTypeName(ip).toSlice(ip))); + const ty = try o.builder.opaqueType(try o.builder.string(t.containerTypeName(ip).fqn.toSlice(ip))); try o.type_map.put(o.gpa, t.toIntern(), ty); o.builder.namedTypeSetBody( @@ -3011,7 +3011,7 @@ pub const Object = struct { llvm_fields_len += 1; } - const ty = try o.builder.opaqueType(try o.builder.string(t.containerTypeName(ip).toSlice(ip))); + const ty = try o.builder.opaqueType(try o.builder.string(t.containerTypeName(ip).fqn.toSlice(ip))); try o.type_map.put(o.gpa, t.toIntern(), ty); o.builder.namedTypeSetBody( @@ -4026,7 +4026,7 @@ pub const Object = struct { // Dummy function type; `updateEnumTagNameFunction` will replace it with the correct type. // TODO: change the builder API so we don't need to do this. try o.builder.fnType(.void, &.{}, .normal), - try o.builder.strtabStringFmt("__zig_tag_name_{f}", .{enum_ty.containerTypeName(ip).fmt(ip)}), + try o.builder.strtabStringFmt("__zig_tag_name_{f}", .{enum_ty.containerTypeName(ip).fqn.fmt(ip)}), toLlvmAddressSpace(.generic, zcu.getTarget()), ); gop.value_ptr.* = llvm_function; @@ -4123,7 +4123,7 @@ pub const Object = struct { // Dummy function type; `updateIsNamedEnumValue` will replace it with the correct type. // TODO: change the builder API so we don't need to do this. try o.builder.fnType(.void, &.{}, .normal), - try o.builder.strtabStringFmt("__zig_is_named_enum_value_{f}", .{enum_ty.containerTypeName(ip).fmt(ip)}), + try o.builder.strtabStringFmt("__zig_is_named_enum_value_{f}", .{enum_ty.containerTypeName(ip).fqn.fmt(ip)}), toLlvmAddressSpace(.generic, zcu.getTarget()), ); gop.value_ptr.* = llvm_function; diff --git a/src/link.zig b/src/link.zig index 361c020aff0b7d51e518c8f42dda8af2c6b86dde..16ed8b6571d8bc7d4575d4eaf9213cc366176aae 100644 --- a/src/link.zig +++ b/src/link.zig @@ -1705,8 +1705,8 @@ pub fn doZcuTask(comp: *Compilation, tid: Zcu.PerThread.Id, task: ZcuTask) void break :nav ip.indexToKey(func).func.owner_nav; }, .debug_update_container_type => |container_update| nav: { - const name = Type.fromInterned(container_update.ty).containerTypeName(ip).toSlice(ip); - const ty_prog_node = comp.link_prog_node.start(name, 0); + const fqn = Type.fromInterned(container_update.ty).containerTypeName(ip).fqn.toSlice(ip); + const ty_prog_node = comp.link_prog_node.start(fqn, 0); defer ty_prog_node.end(); (if (zcu.llvm_object) |llvm_object| llvm_object.updateContainerType(pt, container_update.ty, container_update.success) diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index b4b6982a9a5ff8ed66112878b9f8c1745c2f08a8..09492f416d2e1d23c034ce1003815916b2853da4 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -3387,12 +3387,12 @@ fn updateConstIncompleteInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_inde const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, file_index); try wip_nav.abbrevCode(.empty_file); try wip_nav.debug_info.writer.writeUleb128(file_gop.index); - try wip_nav.strp(loaded_struct.name.toSlice(ip)); + try wip_nav.strp(loaded_struct.fqn.toSlice(ip)); } else { try dwarf.emitIncompleteContainerType( &wip_nav, loaded_struct.zir_index, - loaded_struct.name, + loaded_struct.fqn, loaded_struct.name_nav, ); } @@ -3402,7 +3402,7 @@ fn updateConstIncompleteInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_inde try dwarf.emitIncompleteContainerType( &wip_nav, loaded_union.zir_index, - loaded_union.name, + loaded_union.fqn, loaded_union.name_nav, ); }, @@ -3412,12 +3412,12 @@ fn updateConstIncompleteInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_inde try dwarf.emitIncompleteContainerType( &wip_nav, zir_index, - loaded_enum.name, + loaded_enum.fqn, loaded_enum.name_nav, ); } else { try wip_nav.abbrevCode(.generated_empty_struct_type); - try wip_nav.strp(loaded_enum.name.toSlice(ip)); + try wip_nav.strp(loaded_enum.fqn.toSlice(ip)); try wip_nav.debug_info.writer.writeByte(@intFromBool(true)); } }, @@ -3426,7 +3426,7 @@ fn updateConstIncompleteInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_inde try dwarf.emitIncompleteContainerType( &wip_nav, loaded_opaque.zir_index, - loaded_opaque.name, + loaded_opaque.fqn, loaded_opaque.name_nav, ); }, @@ -3451,7 +3451,7 @@ fn emitIncompleteContainerType( dwarf: *Dwarf, wip_nav: *WipNav, zir_index: InternPool.TrackedInst.Index, - name: InternPool.NullTerminatedString, + fqn: InternPool.NullTerminatedString, name_nav: InternPool.Nav.Index.Optional, ) !void { const zcu = wip_nav.pt.zcu; @@ -3472,7 +3472,7 @@ fn emitIncompleteContainerType( const file_gop = try dwarf.getModInfo(wip_nav.unit).files.getOrPut(dwarf.gpa, file); try wip_nav.abbrevCode(.empty_struct_type); try diw.writeUleb128(file_gop.index); - try wip_nav.strp(name.toSlice(ip)); + try wip_nav.strp(fqn.toSlice(ip)); try diw.writeByte(@intFromBool(true)); } } @@ -3895,7 +3895,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co else => if (struct_is_file) .file else .struct_type, }); try diw.writeUleb128(file_gop.index); - try wip_nav.strp(loaded_struct.name.toSlice(ip)); + try wip_nav.strp(loaded_struct.fqn.toSlice(ip)); } if (loaded_struct.field_types.len == 0) { if (!struct_is_file) try diw.writeByte(@intFromBool(false)); @@ -3968,7 +3968,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, file); try wip_nav.abbrevCode(if (loaded_struct.field_types.len > 0) .packed_struct_type else .empty_packed_struct_type); try diw.writeUleb128(file_gop.index); - try wip_nav.strp(loaded_struct.name.toSlice(ip)); + try wip_nav.strp(loaded_struct.fqn.toSlice(ip)); break :t loaded_struct.field_types.len > 0; }; try wip_nav.refType(.fromInterned(loaded_struct.packed_backing_int_type)); @@ -4005,7 +4005,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, file); try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .union_type else .empty_union_type); try diw.writeUleb128(file_gop.index); - try wip_nav.strp(loaded_union.name.toSlice(ip)); + try wip_nav.strp(loaded_union.fqn.toSlice(ip)); break :t loaded_union.field_types.len > 0; }; const union_layout = Type.getUnionLayout(loaded_union, zcu); @@ -4067,7 +4067,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, file); try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .packed_union_type else .empty_packed_union_type); try diw.writeUleb128(file_gop.index); - try wip_nav.strp(loaded_union.name.toSlice(ip)); + try wip_nav.strp(loaded_union.fqn.toSlice(ip)); break :t loaded_union.field_types.len > 0; }; try wip_nav.refType(.fromInterned(loaded_union.packed_backing_int_type)); @@ -4103,7 +4103,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, file); try wip_nav.abbrevCode(if (loaded_enum.field_names.len > 0) .enum_type else .empty_enum_type); try diw.writeUleb128(file_gop.index); - try wip_nav.strp(loaded_enum.name.toSlice(ip)); + try wip_nav.strp(loaded_enum.fqn.toSlice(ip)); } try wip_nav.refType(.fromInterned(loaded_enum.int_tag_type)); for (0..loaded_enum.field_names.len) |field_index| { @@ -4115,7 +4115,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co } else { assert(loaded_enum.owner_union != .none); try wip_nav.abbrevCode(if (loaded_enum.field_names.len == 0) .generated_empty_enum_type else .generated_enum_type); - try wip_nav.strp(loaded_enum.name.toSlice(ip)); + try wip_nav.strp(loaded_enum.fqn.toSlice(ip)); try wip_nav.refType(.fromInterned(loaded_enum.int_tag_type)); for (0..loaded_enum.field_names.len) |field_index| { try wip_nav.abbrevCode(.enum_field); @@ -4141,7 +4141,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, file); try wip_nav.abbrevCode(.empty_struct_type); try diw.writeUleb128(file_gop.index); - try wip_nav.strp(loaded_opaque.name.toSlice(ip)); + try wip_nav.strp(loaded_opaque.fqn.toSlice(ip)); } try diw.writeByte(@intFromBool(true)); }, diff --git a/src/link/Dwarf2.zig b/src/link/Dwarf2.zig index e3c4eec7be17cd340230c2646b3584e8ffcaa3d5..83ecd06e8c4a7b6fa8f2f421d47e9e9081d84848 100644 --- a/src/link/Dwarf2.zig +++ b/src/link/Dwarf2.zig @@ -2349,7 +2349,7 @@ fn updateConstInner( else => if (struct_is_file) .file else .struct_type, })); try diw.writeUleb128(@backingInt(fi)); - try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip)); + try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.fqn.toSlice(ip)); } if (loaded_struct.field_types.len > 0) { const ty: Type = .fromInterned(val); @@ -2422,14 +2422,14 @@ fn updateConstInner( if (loaded_enum.field_names.len > 0) .enum_type else .empty_enum_type, )); try diw.writeUleb128(@backingInt(fi)); - try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip)); + try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip)); } } else { assert(loaded_enum.owner_union != .none); try diw.writeUleb128(try dwarf.refAbbrevCode( if (loaded_enum.field_names.len == 0) .generated_empty_enum_type else .generated_enum_type, )); - try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip)); + try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip)); } try dwarf.refConst(pt, di_nw, .fromInterned(loaded_enum.int_tag_type)); for (0..loaded_enum.field_names.len) |field_index| { @@ -2465,7 +2465,7 @@ fn updateConstIncompleteInner( const ip = &zcu.intern_pool; const diw = &di_nw.interface; done: { - const src_inst, const zf, const capture_names, const captures, const name, const maybe_name_nav, const namespace = container: switch (ip.indexToKey(val)) { + const src_inst, const zf, const capture_names, const captures, const fqn, const maybe_name_nav, const namespace = container: switch (ip.indexToKey(val)) { .struct_type => { const loaded_struct = ip.loadStructType(val); const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse { @@ -2479,7 +2479,7 @@ fn updateConstIncompleteInner( _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file); try diw.writeUleb128(try dwarf.refAbbrevCode(.empty_file)); try diw.writeUleb128(@backingInt(fi)); - try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip)); + try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.fqn.toSlice(ip)); try diw.writeByte(@intFromBool(true)); break :done; }, @@ -2488,7 +2488,7 @@ fn updateConstIncompleteInner( zf, zf.zir.?.getStructDecl(src_inst.inst).capture_names, loaded_struct.captures, - loaded_struct.name, + loaded_struct.fqn, loaded_struct.name_nav, loaded_struct.namespace, }, @@ -2506,7 +2506,7 @@ fn updateConstIncompleteInner( zf, zf.zir.?.getUnionDecl(src_inst.inst).capture_names, loaded_union.captures, - loaded_union.name, + loaded_union.fqn, loaded_union.name_nav, loaded_union.namespace, }; @@ -2515,7 +2515,7 @@ fn updateConstIncompleteInner( const loaded_enum = ip.loadEnumType(val); const zir_index = loaded_enum.zir_index.unwrap() orelse { try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_empty_struct_type)); - try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip)); + try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip)); try diw.writeByte(@intFromBool(true)); break :done; }; @@ -2529,7 +2529,7 @@ fn updateConstIncompleteInner( zf, zf.zir.?.getEnumDecl(src_inst.inst).capture_names, loaded_enum.captures, - loaded_enum.name, + loaded_enum.fqn, loaded_enum.name_nav, loaded_enum.namespace, }; @@ -2546,7 +2546,7 @@ fn updateConstIncompleteInner( zf, zf.zir.?.getOpaqueDecl(src_inst.inst).capture_names, loaded_opaque.captures, - loaded_opaque.name, + loaded_opaque.fqn, loaded_opaque.name_nav, loaded_opaque.namespace, }; @@ -2597,7 +2597,7 @@ fn updateConstIncompleteInner( if (capturing) .capturing_empty_struct_type else .empty_struct_type, )); try diw.writeUleb128(@backingInt(fi)); - try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip)); + try dwarf.strp(&dwarf.debug_str, di_nw, fqn.toSlice(ip)); } try diw.writeByte(@intFromBool(true)); if (capturing) { @@ -2661,7 +2661,7 @@ fn genDeclInner( try diw.writeInt(u32, 0, dwarf.endian); try diw.writeUleb128(0); try diw.writeByte(DW.ACCESS.public); - try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip)); + try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.fqn.toSlice(ip)); }, .enum_type => { const loaded_enum = ip.loadEnumType(instance_val); @@ -2673,7 +2673,7 @@ fn genDeclInner( try diw.writeInt(u32, 0, dwarf.endian); try diw.writeUleb128(0); try diw.writeByte(DW.ACCESS.public); - try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip)); + try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip)); }, .union_type => { const loaded_union = ip.loadUnionType(instance_val); @@ -2685,7 +2685,7 @@ fn genDeclInner( try diw.writeInt(u32, 0, dwarf.endian); try diw.writeUleb128(0); try diw.writeByte(DW.ACCESS.public); - try dwarf.strp(&dwarf.debug_str, di_nw, loaded_union.name.toSlice(ip)); + try dwarf.strp(&dwarf.debug_str, di_nw, loaded_union.fqn.toSlice(ip)); }, } try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen()); -- 2.54.0