authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-17 01:26:09-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-12-17 01:26:09-05:00
logdebba652a3f5af76840517321d389a2ec98a88f4
tree662c71e00a60dcd921400fceb64bdcfa7a5bc9fc
parente5c188e59a827bd7049f80bf51c8c4e59e016af2
parent8c0628d0e290c7c1168c52c3adb408b48b48f8d0
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #22252 from jacobly0/dwarf-deduped-structs

Dwarf: preserve deduped struct navs

6 files changed, 1044 insertions(+), 209 deletions(-)

lib/std/dwarf/AT.zig+2
......@@ -224,6 +224,8 @@ pub const ZIG_parent = 0x2ccd;
224224pub const ZIG_padding = 0x2cce;
225225pub const ZIG_relative_decl = 0x2cd0;
226226pub const ZIG_decl_line_relative = 0x2cd1;
227pub const ZIG_comptime_value = 0x2cd2;
228pub const ZIG_comptime_default_value = 0x2cd3;
227229pub const ZIG_sentinel = 0x2ce2;
228230
229231// UPC extension.
lib/std/dwarf/TAG.zig+1
......@@ -119,3 +119,4 @@ pub const PGI_interface_block = 0xA020;
119119
120120// ZIG extensions.
121121pub const ZIG_padding = 0xfdb1;
122pub const ZIG_comptime_value = 0xfdb2;
src/InternPool.zig+74-5
......@@ -1163,7 +1163,7 @@ const Local = struct {
11631163 capacity: u32,
11641164 };
11651165 fn header(list: ListSelf) *Header {
1166 return @ptrFromInt(@intFromPtr(list.bytes) - bytes_offset);
1166 return @alignCast(@ptrCast(list.bytes - bytes_offset));
11671167 }
11681168 pub fn view(list: ListSelf) View {
11691169 const capacity = list.header().capacity;
......@@ -1372,7 +1372,7 @@ const Shard = struct {
13721372 }
13731373 };
13741374 fn header(map: @This()) *Header {
1375 return @ptrFromInt(@intFromPtr(map.entries) - entries_offset);
1375 return @alignCast(@ptrCast(@as([*]u8, @ptrCast(map.entries)) - entries_offset));
13761376 }
13771377
13781378 const Entry = extern struct {
......@@ -4704,9 +4704,45 @@ pub const Index = enum(u32) {
47044704 }
47054705
47064706 comptime {
4707 if (builtin.zig_backend == .stage2_llvm and !builtin.strip_debug_info) {
4708 _ = &dbHelper;
4709 }
4707 if (!builtin.strip_debug_info) switch (builtin.zig_backend) {
4708 .stage2_llvm => _ = &dbHelper,
4709 .stage2_x86_64 => {
4710 for (@typeInfo(Tag).@"enum".fields) |tag| {
4711 if (!@hasField(@TypeOf(Tag.encodings), tag.name)) {
4712 if (false) @compileLog("missing: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name);
4713 continue;
4714 }
4715 const encoding = @field(Tag.encodings, tag.name);
4716 for (@typeInfo(encoding.trailing).@"struct".fields) |field| {
4717 struct {
4718 fn checkConfig(name: []const u8) void {
4719 if (!@hasField(@TypeOf(encoding.config), name)) @compileError("missing field: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\"");
4720 const FieldType = @TypeOf(@field(encoding.config, name));
4721 if (@typeInfo(FieldType) != .enum_literal) @compileError("expected enum literal: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\": " ++ @typeName(FieldType));
4722 }
4723 fn checkField(name: []const u8, Type: type) void {
4724 switch (@typeInfo(Type)) {
4725 .int => {},
4726 .@"enum" => {},
4727 .@"struct" => |info| assert(info.layout == .@"packed"),
4728 .optional => |info| {
4729 checkConfig(name ++ ".?");
4730 checkField(name ++ ".?", info.child);
4731 },
4732 .pointer => |info| {
4733 assert(info.size == .Slice);
4734 checkConfig(name ++ ".len");
4735 checkField(name ++ "[0]", info.child);
4736 },
4737 else => @compileError("unsupported type: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ "." ++ name ++ ": " ++ @typeName(Type)),
4738 }
4739 }
4740 }.checkField("trailing." ++ field.name, field.type);
4741 }
4742 }
4743 },
4744 else => {},
4745 };
47104746 }
47114747};
47124748
......@@ -5302,6 +5338,39 @@ pub const Tag = enum(u8) {
53025338 };
53035339 }
53045340
5341 const encodings = .{
5342 .type_struct = .{
5343 .payload = TypeStruct,
5344 .trailing = struct {
5345 captures_len: ?u32,
5346 captures: ?[]CaptureValue,
5347 type_hash: ?u64,
5348 field_types: []Index,
5349 field_inits: ?[]Index,
5350 field_aligns: ?[]Alignment,
5351 field_is_comptime_bits: ?[]u32,
5352 field_index: ?[]LoadedStructType.RuntimeOrder,
5353 field_offset: []u32,
5354 },
5355 .config = .{
5356 .@"trailing.captures_len.?" = .@"payload.flags.any_captures",
5357 .@"trailing.captures.?" = .@"payload.flags.any_captures",
5358 .@"trailing.captures.?.len" = .@"trailing.captures_len",
5359 .@"trailing.type_hash.?" = .@"payload.flags.is_reified",
5360 .@"trailing.field_types.len" = .@"payload.fields_len",
5361 .@"trailing.field_inits.?" = .@"payload.flags.any_default_inits",
5362 .@"trailing.field_inits.?.len" = .@"payload.fields_len",
5363 .@"trailing.field_aligns.?" = .@"payload.flags.any_aligned_fields",
5364 .@"trailing.field_aligns.?.len" = .@"payload.fields_len",
5365 .@"trailing.field_is_comptime_bits.?" = .@"payload.flags.any_comptime_fields",
5366 .@"trailing.field_is_comptime_bits.?.len" = .@"(payload.fields_len + 31) / 32",
5367 .@"trailing.field_index.?" = .@"!payload.flags.is_extern",
5368 .@"trailing.field_index.?.len" = .@"!payload.flags.is_extern",
5369 .@"trailing.field_offset.len" = .@"payload.fields_len",
5370 },
5371 },
5372 };
5373
53055374 pub const Variable = struct {
53065375 ty: Index,
53075376 /// May be `none`.
src/Type.zig+1
......@@ -4126,6 +4126,7 @@ pub const @"anyframe": Type = .{ .ip_index = .anyframe_type };
41264126pub const @"null": Type = .{ .ip_index = .null_type };
41274127pub const @"undefined": Type = .{ .ip_index = .undefined_type };
41284128pub const @"noreturn": Type = .{ .ip_index = .noreturn_type };
4129pub const enum_literal: Type = .{ .ip_index = .enum_literal_type };
41294130
41304131pub const @"c_char": Type = .{ .ip_index = .c_char_type };
41314132pub const @"c_short": Type = .{ .ip_index = .c_short_type };
src/link/Dwarf.zig+929-204
......@@ -6,6 +6,7 @@ address_size: AddressSize,
66
77mods: std.AutoArrayHashMapUnmanaged(*Module, ModInfo),
88types: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index),
9values: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index),
910navs: std.AutoArrayHashMapUnmanaged(InternPool.Nav.Index, Entry.Index),
1011
1112debug_abbrev: DebugAbbrev,
......@@ -1055,6 +1056,11 @@ pub const Loc = union(enum) {
10551056 form_tls_address: *const Loc,
10561057 implicit_value: []const u8,
10571058 stack_value: *const Loc,
1059 implicit_pointer: struct {
1060 unit: Unit.Index,
1061 entry: Entry.Index,
1062 offset: i65,
1063 },
10581064 wasm_ext: union(enum) {
10591065 local: u32,
10601066 global: u32,
......@@ -1193,6 +1199,11 @@ pub const Loc = union(enum) {
11931199 try value.write(adapter);
11941200 try writer.writeByte(DW.OP.stack_value);
11951201 },
1202 .implicit_pointer => |implicit_pointer| {
1203 try writer.writeByte(DW.OP.implicit_pointer);
1204 try adapter.infoEntry(implicit_pointer.unit, implicit_pointer.entry);
1205 try sleb128(writer, implicit_pointer.offset);
1206 },
11961207 .wasm_ext => |wasm_ext| {
11971208 try writer.writeByte(DW.OP.WASM_location);
11981209 switch (wasm_ext) {
......@@ -1386,7 +1397,7 @@ pub const WipNav = struct {
13861397 debug_info: std.ArrayListUnmanaged(u8),
13871398 debug_line: std.ArrayListUnmanaged(u8),
13881399 debug_loclists: std.ArrayListUnmanaged(u8),
1389 pending_types: std.ArrayListUnmanaged(InternPool.Index),
1400 pending_lazy: std.ArrayListUnmanaged(InternPool.Index),
13901401
13911402 pub fn deinit(wip_nav: *WipNav) void {
13921403 const gpa = wip_nav.dwarf.gpa;
......@@ -1395,7 +1406,7 @@ pub const WipNav = struct {
13951406 wip_nav.debug_info.deinit(gpa);
13961407 wip_nav.debug_line.deinit(gpa);
13971408 wip_nav.debug_loclists.deinit(gpa);
1398 wip_nav.pending_types.deinit(gpa);
1409 wip_nav.pending_lazy.deinit(gpa);
13991410 }
14001411
14011412 pub fn genDebugFrame(wip_nav: *WipNav, loc: u32, cfa: Cfa) UpdateError!void {
......@@ -1420,7 +1431,7 @@ pub const WipNav = struct {
14201431 });
14211432 try wip_nav.strp(name);
14221433 try wip_nav.refType(ty);
1423 try wip_nav.exprloc(loc);
1434 try wip_nav.infoExprloc(loc);
14241435 wip_nav.any_children = true;
14251436 }
14261437
......@@ -1627,33 +1638,39 @@ pub const WipNav = struct {
16271638 try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), try wip_nav.dwarf.refAbbrevCode(abbrev_code));
16281639 }
16291640
1630 fn infoSectionOffset(wip_nav: *WipNav, sec: Section.Index, unit: Unit.Index, entry: Entry.Index, off: u32) UpdateError!void {
1641 fn sectionOffset(wip_nav: *WipNav, comptime sec: Section.Index, target_sec: Section.Index, target_unit: Unit.Index, target_entry: Entry.Index, target_off: u32) UpdateError!void {
16311642 const dwarf = wip_nav.dwarf;
16321643 const gpa = dwarf.gpa;
1633 const entry_ptr = dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry);
1634 if (sec != .debug_info) {
1644 const entry_ptr = @field(dwarf, @tagName(sec)).section.getUnit(wip_nav.unit).getEntry(wip_nav.entry);
1645 const bytes = &@field(wip_nav, @tagName(sec));
1646 const source_off: u32 = @intCast(bytes.items.len);
1647 if (target_sec != sec) {
16351648 try entry_ptr.cross_section_relocs.append(gpa, .{
1636 .source_off = @intCast(wip_nav.debug_info.items.len),
1637 .target_sec = sec,
1638 .target_unit = unit,
1639 .target_entry = entry.toOptional(),
1640 .target_off = off,
1649 .source_off = source_off,
1650 .target_sec = target_sec,
1651 .target_unit = target_unit,
1652 .target_entry = target_entry.toOptional(),
1653 .target_off = target_off,
16411654 });
1642 } else if (unit != wip_nav.unit) {
1655 } else if (target_unit != wip_nav.unit) {
16431656 try entry_ptr.cross_unit_relocs.append(gpa, .{
1644 .source_off = @intCast(wip_nav.debug_info.items.len),
1645 .target_unit = unit,
1646 .target_entry = entry.toOptional(),
1647 .target_off = off,
1657 .source_off = source_off,
1658 .target_unit = target_unit,
1659 .target_entry = target_entry.toOptional(),
1660 .target_off = target_off,
16481661 });
16491662 } else {
16501663 try entry_ptr.cross_entry_relocs.append(gpa, .{
1651 .source_off = @intCast(wip_nav.debug_info.items.len),
1652 .target_entry = entry.toOptional(),
1653 .target_off = off,
1664 .source_off = source_off,
1665 .target_entry = target_entry.toOptional(),
1666 .target_off = target_off,
16541667 });
16551668 }
1656 try wip_nav.debug_info.appendNTimes(gpa, 0, dwarf.sectionOffsetBytes());
1669 try bytes.appendNTimes(gpa, 0, dwarf.sectionOffsetBytes());
1670 }
1671
1672 fn infoSectionOffset(wip_nav: *WipNav, target_sec: Section.Index, target_unit: Unit.Index, target_entry: Entry.Index, target_off: u32) UpdateError!void {
1673 try wip_nav.sectionOffset(.debug_info, target_sec, target_unit, target_entry, target_off);
16571674 }
16581675
16591676 fn strp(wip_nav: *WipNav, str: []const u8) UpdateError!void {
......@@ -1663,7 +1680,15 @@ pub const WipNav = struct {
16631680 const ExprLocCounter = struct {
16641681 const Stream = std.io.CountingWriter(std.io.NullWriter);
16651682 stream: Stream,
1683 section_offset_bytes: u32,
16661684 address_size: AddressSize,
1685 fn init(dwarf: *Dwarf) ExprLocCounter {
1686 return .{
1687 .stream = std.io.countingWriter(std.io.null_writer),
1688 .section_offset_bytes = dwarf.sectionOffsetBytes(),
1689 .address_size = dwarf.address_size,
1690 };
1691 }
16671692 fn writer(counter: *ExprLocCounter) Stream.Writer {
16681693 return counter.stream.writer();
16691694 }
......@@ -1673,13 +1698,13 @@ pub const WipNav = struct {
16731698 fn addrSym(counter: *ExprLocCounter, _: u32) error{}!void {
16741699 counter.stream.bytes_written += @intFromEnum(counter.address_size);
16751700 }
1701 fn infoEntry(counter: *ExprLocCounter, _: Unit.Index, _: Entry.Index) error{}!void {
1702 counter.stream.bytes_written += counter.section_offset_bytes;
1703 }
16761704 };
16771705
1678 fn exprloc(wip_nav: *WipNav, loc: Loc) UpdateError!void {
1679 var counter: ExprLocCounter = .{
1680 .stream = std.io.countingWriter(std.io.null_writer),
1681 .address_size = wip_nav.dwarf.address_size,
1682 };
1706 fn infoExprloc(wip_nav: *WipNav, loc: Loc) UpdateError!void {
1707 var counter: ExprLocCounter = .init(wip_nav.dwarf);
16831708 try loc.write(&counter);
16841709
16851710 const adapter: struct {
......@@ -1693,6 +1718,9 @@ pub const WipNav = struct {
16931718 fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void {
16941719 try ctx.wip_nav.infoAddrSym(sym_index, 0);
16951720 }
1721 fn infoEntry(ctx: @This(), unit: Unit.Index, entry: Entry.Index) UpdateError!void {
1722 try ctx.wip_nav.infoSectionOffset(.debug_info, unit, entry, 0);
1723 }
16961724 } = .{ .wip_nav = wip_nav };
16971725 try uleb128(adapter.writer(), counter.stream.bytes_written);
16981726 try loc.write(adapter);
......@@ -1708,10 +1736,7 @@ pub const WipNav = struct {
17081736 }
17091737
17101738 fn frameExprloc(wip_nav: *WipNav, loc: Loc) UpdateError!void {
1711 var counter: ExprLocCounter = .{
1712 .stream = std.io.countingWriter(std.io.null_writer),
1713 .address_size = wip_nav.dwarf.address_size,
1714 };
1739 var counter: ExprLocCounter = .init(wip_nav.dwarf);
17151740 try loc.write(&counter);
17161741
17171742 const adapter: struct {
......@@ -1725,6 +1750,9 @@ pub const WipNav = struct {
17251750 fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void {
17261751 try ctx.wip_nav.frameAddrSym(sym_index, 0);
17271752 }
1753 fn infoEntry(ctx: @This(), unit: Unit.Index, entry: Entry.Index) UpdateError!void {
1754 try ctx.wip_nav.sectionOffset(.debug_frame, .debug_info, unit, entry, 0);
1755 }
17281756 } = .{ .wip_nav = wip_nav };
17291757 try uleb128(adapter.writer(), counter.stream.bytes_written);
17301758 try loc.write(adapter);
......@@ -1739,6 +1767,22 @@ pub const WipNav = struct {
17391767 try wip_nav.debug_frame.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size));
17401768 }
17411769
1770 fn getNavEntry(wip_nav: *WipNav, nav_index: InternPool.Nav.Index) UpdateError!struct { Unit.Index, Entry.Index } {
1771 const zcu = wip_nav.pt.zcu;
1772 const ip = &zcu.intern_pool;
1773 const unit = try wip_nav.dwarf.getUnit(zcu.fileByIndex(ip.getNav(nav_index).srcInst(ip).resolveFile(ip)).mod);
1774 const gop = try wip_nav.dwarf.navs.getOrPut(wip_nav.dwarf.gpa, nav_index);
1775 if (gop.found_existing) return .{ unit, gop.value_ptr.* };
1776 const entry = try wip_nav.dwarf.addCommonEntry(unit);
1777 gop.value_ptr.* = entry;
1778 return .{ unit, entry };
1779 }
1780
1781 fn refNav(wip_nav: *WipNav, nav_index: InternPool.Nav.Index) UpdateError!void {
1782 const unit, const entry = try wip_nav.getNavEntry(nav_index);
1783 try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0);
1784 }
1785
17421786 fn getTypeEntry(wip_nav: *WipNav, ty: Type) UpdateError!struct { Unit.Index, Entry.Index } {
17431787 const zcu = wip_nav.pt.zcu;
17441788 const ip = &zcu.intern_pool;
......@@ -1751,7 +1795,7 @@ pub const WipNav = struct {
17511795 if (gop.found_existing) return .{ unit, gop.value_ptr.* };
17521796 const entry = try wip_nav.dwarf.addCommonEntry(unit);
17531797 gop.value_ptr.* = entry;
1754 if (maybe_inst_index == null) try wip_nav.pending_types.append(wip_nav.dwarf.gpa, ty.toIntern());
1798 if (maybe_inst_index == null) try wip_nav.pending_lazy.append(wip_nav.dwarf.gpa, ty.toIntern());
17551799 return .{ unit, entry };
17561800 }
17571801
......@@ -1760,13 +1804,25 @@ pub const WipNav = struct {
17601804 try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0);
17611805 }
17621806
1763 fn refNav(wip_nav: *WipNav, nav_index: InternPool.Nav.Index) UpdateError!void {
1807 fn getValueEntry(wip_nav: *WipNav, value: Value) UpdateError!struct { Unit.Index, Entry.Index } {
17641808 const zcu = wip_nav.pt.zcu;
17651809 const ip = &zcu.intern_pool;
1766 const unit = try wip_nav.dwarf.getUnit(zcu.fileByIndex(ip.getNav(nav_index).srcInst(ip).resolveFile(ip)).mod);
1767 const nav_gop = try wip_nav.dwarf.navs.getOrPut(wip_nav.dwarf.gpa, nav_index);
1768 if (!nav_gop.found_existing) nav_gop.value_ptr.* = try wip_nav.dwarf.addCommonEntry(unit);
1769 try wip_nav.infoSectionOffset(.debug_info, unit, nav_gop.value_ptr.*, 0);
1810 const ty = value.typeOf(zcu);
1811 if (std.debug.runtime_safety) assert(ty.comptimeOnly(zcu) and try ty.onePossibleValue(wip_nav.pt) == null);
1812 if (ty.toIntern() == .type_type) return wip_nav.getTypeEntry(value.toType());
1813 if (ip.isFunctionType(ty.toIntern())) return wip_nav.getNavEntry(zcu.funcInfo(value.toIntern()).owner_nav);
1814 const gop = try wip_nav.dwarf.values.getOrPut(wip_nav.dwarf.gpa, value.toIntern());
1815 const unit: Unit.Index = .main;
1816 if (gop.found_existing) return .{ unit, gop.value_ptr.* };
1817 const entry = try wip_nav.dwarf.addCommonEntry(unit);
1818 gop.value_ptr.* = entry;
1819 try wip_nav.pending_lazy.append(wip_nav.dwarf.gpa, value.toIntern());
1820 return .{ unit, entry };
1821 }
1822
1823 fn refValue(wip_nav: *WipNav, value: Value) UpdateError!void {
1824 const unit, const entry = try wip_nav.getValueEntry(value);
1825 try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0);
17701826 }
17711827
17721828 fn refForward(wip_nav: *WipNav) std.mem.Allocator.Error!u32 {
......@@ -1809,73 +1865,81 @@ pub const WipNav = struct {
18091865 }
18101866 }
18111867
1812 fn enumConstValue(
1868 const AbbrevCodeForForm = struct {
1869 sdata: AbbrevCode,
1870 udata: AbbrevCode,
1871 block: AbbrevCode,
1872 };
1873
1874 fn bigIntConstValue(
18131875 wip_nav: *WipNav,
1814 loaded_enum: InternPool.LoadedEnumType,
1815 abbrev_code: struct {
1816 sdata: AbbrevCode,
1817 udata: AbbrevCode,
1818 block: AbbrevCode,
1819 },
1820 field_index: usize,
1876 abbrev_code: AbbrevCodeForForm,
1877 ty: Type,
1878 big_int: std.math.big.int.Const,
18211879 ) UpdateError!void {
18221880 const zcu = wip_nav.pt.zcu;
1823 const ip = &zcu.intern_pool;
18241881 const diw = wip_nav.debug_info.writer(wip_nav.dwarf.gpa);
1825 const signedness = switch (loaded_enum.tag_ty) {
1826 .comptime_int_type => .signed,
1827 else => Type.fromInterned(loaded_enum.tag_ty).intInfo(zcu).signedness,
1882 const signedness = switch (ty.toIntern()) {
1883 .comptime_int_type, .comptime_float_type => .signed,
1884 else => ty.intInfo(zcu).signedness,
18281885 };
1829 if (loaded_enum.values.len > 0) {
1830 var big_int_space: Value.BigIntSpace = undefined;
1831 const big_int = ip.indexToKey(loaded_enum.values.get(ip)[field_index]).int.storage.toBigInt(&big_int_space);
1832 const bits = @max(1, big_int.bitCountTwosCompForSignedness(signedness));
1833 if (bits <= 64) {
1834 try wip_nav.abbrevCode(switch (signedness) {
1835 .signed => abbrev_code.sdata,
1836 .unsigned => abbrev_code.udata,
1837 });
1838 try wip_nav.debug_info.ensureUnusedCapacity(wip_nav.dwarf.gpa, std.math.divCeil(usize, bits, 7) catch unreachable);
1839 var bit: usize = 0;
1840 var carry: u1 = 1;
1841 while (bit < bits) : (bit += 7) {
1842 const limb_bits = @typeInfo(std.math.big.Limb).int.bits;
1843 const limb_index = bit / limb_bits;
1844 const limb_shift: std.math.Log2Int(std.math.big.Limb) = @intCast(bit % limb_bits);
1845 const low_abs_part: u7 = @truncate(big_int.limbs[limb_index] >> limb_shift);
1846 const abs_part = if (limb_shift > limb_bits - 7 and limb_index + 1 < big_int.limbs.len) abs_part: {
1847 const high_abs_part: u7 = @truncate(big_int.limbs[limb_index + 1] << -%limb_shift);
1848 break :abs_part high_abs_part | low_abs_part;
1849 } else low_abs_part;
1850 const twos_comp_part = if (big_int.positive) abs_part else twos_comp_part: {
1851 const twos_comp_part, carry = @addWithOverflow(~abs_part, carry);
1852 break :twos_comp_part twos_comp_part;
1853 };
1854 wip_nav.debug_info.appendAssumeCapacity(@as(u8, if (bit + 7 < bits) 0x80 else 0x00) | twos_comp_part);
1855 }
1856 } else {
1857 try wip_nav.abbrevCode(abbrev_code.block);
1858 const bytes = Type.fromInterned(loaded_enum.tag_ty).abiSize(zcu);
1859 try uleb128(diw, bytes);
1860 big_int.writeTwosComplement(
1861 try wip_nav.debug_info.addManyAsSlice(wip_nav.dwarf.gpa, @intCast(bytes)),
1862 wip_nav.dwarf.endian,
1863 );
1886 const bits = @max(1, big_int.bitCountTwosCompForSignedness(signedness));
1887 if (bits <= 64) {
1888 try wip_nav.abbrevCode(switch (signedness) {
1889 .signed => abbrev_code.sdata,
1890 .unsigned => abbrev_code.udata,
1891 });
1892 try wip_nav.debug_info.ensureUnusedCapacity(wip_nav.dwarf.gpa, std.math.divCeil(usize, bits, 7) catch unreachable);
1893 var bit: usize = 0;
1894 var carry: u1 = 1;
1895 while (bit < bits) {
1896 const limb_bits = @typeInfo(std.math.big.Limb).int.bits;
1897 const limb_index = bit / limb_bits;
1898 const limb_shift: std.math.Log2Int(std.math.big.Limb) = @intCast(bit % limb_bits);
1899 const low_abs_part: u7 = @truncate(big_int.limbs[limb_index] >> limb_shift);
1900 const abs_part = if (limb_shift > limb_bits - 7 and limb_index + 1 < big_int.limbs.len) abs_part: {
1901 const high_abs_part: u7 = @truncate(big_int.limbs[limb_index + 1] << -%limb_shift);
1902 break :abs_part high_abs_part | low_abs_part;
1903 } else low_abs_part;
1904 const twos_comp_part = if (big_int.positive) abs_part else twos_comp_part: {
1905 const twos_comp_part, carry = @addWithOverflow(~abs_part, carry);
1906 break :twos_comp_part twos_comp_part;
1907 };
1908 bit += 7;
1909 wip_nav.debug_info.appendAssumeCapacity(@as(u8, if (bit < bits) 0x80 else 0x00) | twos_comp_part);
18641910 }
1865 } else switch (signedness) {
1866 .signed => {
1867 try wip_nav.abbrevCode(abbrev_code.sdata);
1868 try sleb128(diw, field_index);
1869 },
1870 .unsigned => {
1871 try wip_nav.abbrevCode(abbrev_code.udata);
1872 try uleb128(diw, field_index);
1873 },
1911 } else {
1912 try wip_nav.abbrevCode(abbrev_code.block);
1913 const bytes = @max(ty.abiSize(zcu), std.math.divCeil(usize, bits, 8) catch unreachable);
1914 try uleb128(diw, bytes);
1915 big_int.writeTwosComplement(
1916 try wip_nav.debug_info.addManyAsSlice(wip_nav.dwarf.gpa, @intCast(bytes)),
1917 wip_nav.dwarf.endian,
1918 );
18741919 }
18751920 }
18761921
1877 fn flush(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc) UpdateError!void {
1878 while (wip_nav.pending_types.popOrNull()) |ty| try wip_nav.dwarf.updateType(wip_nav.pt, src_loc, ty, &wip_nav.pending_types);
1922 fn enumConstValue(
1923 wip_nav: *WipNav,
1924 loaded_enum: InternPool.LoadedEnumType,
1925 abbrev_code: AbbrevCodeForForm,
1926 field_index: usize,
1927 ) UpdateError!void {
1928 const zcu = wip_nav.pt.zcu;
1929 const ip = &zcu.intern_pool;
1930 var big_int_space: Value.BigIntSpace = undefined;
1931 try wip_nav.bigIntConstValue(abbrev_code, .fromInterned(loaded_enum.tag_ty), if (loaded_enum.values.len > 0)
1932 Value.fromInterned(loaded_enum.values.get(ip)[field_index]).toBigInt(&big_int_space, zcu)
1933 else
1934 std.math.big.int.Mutable.init(&big_int_space.limbs, field_index).toConst());
1935 }
1936
1937 fn updateLazy(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc) UpdateError!void {
1938 const ip = &wip_nav.pt.zcu.intern_pool;
1939 while (wip_nav.pending_lazy.popOrNull()) |val| switch (ip.typeOf(val)) {
1940 .type_type => try wip_nav.dwarf.updateLazyType(wip_nav.pt, src_loc, val, &wip_nav.pending_lazy),
1941 else => try wip_nav.dwarf.updateLazyValue(wip_nav.pt, src_loc, val, &wip_nav.pending_lazy),
1942 };
18791943 }
18801944};
18811945
......@@ -1904,6 +1968,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {
19041968
19051969 .mods = .{},
19061970 .types = .{},
1971 .values = .{},
19071972 .navs = .{},
19081973
19091974 .debug_abbrev = .{ .section = Section.init },
......@@ -2075,6 +2140,7 @@ pub fn deinit(dwarf: *Dwarf) void {
20752140 for (dwarf.mods.values()) |*mod_info| mod_info.deinit(gpa);
20762141 dwarf.mods.deinit(gpa);
20772142 dwarf.types.deinit(gpa);
2143 dwarf.values.deinit(gpa);
20782144 dwarf.navs.deinit(gpa);
20792145 dwarf.debug_abbrev.section.deinit(gpa);
20802146 dwarf.debug_aranges.section.deinit(gpa);
......@@ -2186,7 +2252,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
21862252 .debug_info = .{},
21872253 .debug_line = .{},
21882254 .debug_loclists = .{},
2189 .pending_types = .{},
2255 .pending_lazy = .{},
21902256 };
21912257 errdefer wip_nav.deinit();
21922258
......@@ -2223,7 +2289,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
22232289
22242290 const diw = wip_nav.debug_info.writer(dwarf.gpa);
22252291 try wip_nav.abbrevCode(.decl_var);
2226 try wip_nav.refType(Type.fromInterned(parent_type));
2292 try wip_nav.refType(.fromInterned(parent_type));
22272293 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
22282294 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
22292295 try uleb128(diw, loc.column + 1);
......@@ -2232,7 +2298,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
22322298 try wip_nav.strp(nav.fqn.toSlice(ip));
22332299 const nav_ty = nav_val.typeOf(zcu);
22342300 const nav_ty_reloc_index = try wip_nav.refForward();
2235 try wip_nav.exprloc(.{ .addr = .{ .sym = sym_index } });
2301 try wip_nav.infoExprloc(.{ .addr = .{ .sym = sym_index } });
22362302 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
22372303 nav_ty.abiAlignment(zcu).toByteUnits().?);
22382304 try diw.writeByte(@intFromBool(false));
......@@ -2272,17 +2338,17 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
22722338
22732339 const diw = wip_nav.debug_info.writer(dwarf.gpa);
22742340 try wip_nav.abbrevCode(.decl_var);
2275 try wip_nav.refType(Type.fromInterned(parent_type));
2341 try wip_nav.refType(.fromInterned(parent_type));
22762342 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
22772343 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
22782344 try uleb128(diw, loc.column + 1);
22792345 try diw.writeByte(accessibility);
22802346 try wip_nav.strp(nav.name.toSlice(ip));
22812347 try wip_nav.strp(nav.fqn.toSlice(ip));
2282 const ty = Type.fromInterned(variable.ty);
2348 const ty: Type = .fromInterned(variable.ty);
22832349 try wip_nav.refType(ty);
22842350 const addr: Loc = .{ .addr = .{ .sym = sym_index } };
2285 try wip_nav.exprloc(if (variable.is_threadlocal) .{ .form_tls_address = &addr } else addr);
2351 try wip_nav.infoExprloc(if (variable.is_threadlocal) .{ .form_tls_address = &addr } else addr);
22862352 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
22872353 ty.abiAlignment(zcu).toByteUnits().?);
22882354 try diw.writeByte(@intFromBool(false));
......@@ -2364,14 +2430,14 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
23642430
23652431 const diw = wip_nav.debug_info.writer(dwarf.gpa);
23662432 try wip_nav.abbrevCode(.decl_func);
2367 try wip_nav.refType(Type.fromInterned(parent_type));
2433 try wip_nav.refType(.fromInterned(parent_type));
23682434 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
23692435 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
23702436 try uleb128(diw, loc.column + 1);
23712437 try diw.writeByte(accessibility);
23722438 try wip_nav.strp(nav.name.toSlice(ip));
23732439 try wip_nav.strp(nav.fqn.toSlice(ip));
2374 try wip_nav.refType(Type.fromInterned(func_type.return_type));
2440 try wip_nav.refType(.fromInterned(func_type.return_type));
23752441 try wip_nav.infoAddrSym(sym_index, 0);
23762442 wip_nav.func_high_pc = @intCast(wip_nav.debug_info.items.len);
23772443 try diw.writeInt(u32, 0, dwarf.endian);
......@@ -2525,7 +2591,7 @@ pub fn finishWipNav(
25252591 }
25262592 try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.items);
25272593
2528 try wip_nav.flush(zcu.navSrcLoc(nav_index));
2594 try wip_nav.updateLazy(zcu.navSrcLoc(nav_index));
25292595}
25302596
25312597pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) UpdateError!void {
......@@ -2586,7 +2652,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
25862652 .debug_info = .{},
25872653 .debug_line = .{},
25882654 .debug_loclists = .{},
2589 .pending_types = .{},
2655 .pending_lazy = .{},
25902656 };
25912657 defer wip_nav.deinit();
25922658
......@@ -2632,7 +2698,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
26322698
26332699 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
26342700 if (type_gop.found_existing) {
2635 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).clear();
2701 if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias;
26362702 nav_gop.value_ptr.* = type_gop.value_ptr.*;
26372703 } else {
26382704 if (nav_gop.found_existing)
......@@ -2648,7 +2714,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
26482714 switch (loaded_struct.layout) {
26492715 .auto, .@"extern" => {
26502716 try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .decl_namespace_struct else .decl_struct);
2651 try wip_nav.refType(Type.fromInterned(parent_type));
2717 try wip_nav.refType(.fromInterned(parent_type));
26522718 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
26532719 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
26542720 try uleb128(diw, loc.column + 1);
......@@ -2661,43 +2727,65 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
26612727 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
26622728 const field_init = loaded_struct.fieldInit(ip, field_index);
26632729 assert(!(is_comptime and field_init == .none));
2730 const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2731 const has_runtime_bits, const has_comptime_state = switch (field_init) {
2732 .none => .{ false, false },
2733 else => .{
2734 field_type.hasRuntimeBits(zcu),
2735 field_type.comptimeOnly(zcu) and try field_type.onePossibleValue(pt) == null,
2736 },
2737 };
26642738 try wip_nav.abbrevCode(if (is_comptime)
2665 .struct_field_comptime
2739 if (has_runtime_bits and has_comptime_state)
2740 .struct_field_comptime_runtime_bits_comptime_state
2741 else if (has_comptime_state)
2742 .struct_field_comptime_comptime_state
2743 else if (has_runtime_bits)
2744 .struct_field_comptime_runtime_bits
2745 else
2746 .struct_field_comptime
26662747 else if (field_init != .none)
2667 .struct_field_default
2748 if (has_runtime_bits and has_comptime_state)
2749 .struct_field_default_runtime_bits_comptime_state
2750 else if (has_comptime_state)
2751 .struct_field_default_comptime_state
2752 else if (has_runtime_bits)
2753 .struct_field_default_runtime_bits
2754 else
2755 .struct_field_default
26682756 else
26692757 .struct_field);
26702758 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
2671 const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index});
2672 defer dwarf.gpa.free(field_name);
2759 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
2760 const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{field_index}) catch unreachable;
26732761 try wip_nav.strp(field_name);
26742762 }
2675 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
26762763 try wip_nav.refType(field_type);
26772764 if (!is_comptime) {
26782765 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
26792766 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
26802767 field_type.abiAlignment(zcu).toByteUnits().?);
26812768 }
2682 if (field_init != .none) try wip_nav.blockValue(nav_src_loc, Value.fromInterned(field_init));
2769 if (has_runtime_bits) try wip_nav.blockValue(nav_src_loc, .fromInterned(field_init));
2770 if (has_comptime_state) try wip_nav.refValue(.fromInterned(field_init));
26832771 }
26842772 try uleb128(diw, @intFromEnum(AbbrevCode.null));
26852773 }
26862774 },
26872775 .@"packed" => {
26882776 try wip_nav.abbrevCode(.decl_packed_struct);
2689 try wip_nav.refType(Type.fromInterned(parent_type));
2777 try wip_nav.refType(.fromInterned(parent_type));
26902778 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
26912779 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
26922780 try uleb128(diw, loc.column + 1);
26932781 try diw.writeByte(accessibility);
26942782 try wip_nav.strp(nav.name.toSlice(ip));
2695 try wip_nav.refType(Type.fromInterned(loaded_struct.backingIntTypeUnordered(ip)));
2783 try wip_nav.refType(.fromInterned(loaded_struct.backingIntTypeUnordered(ip)));
26962784 var field_bit_offset: u16 = 0;
26972785 for (0..loaded_struct.field_types.len) |field_index| {
26982786 try wip_nav.abbrevCode(.packed_struct_field);
26992787 try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip));
2700 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2788 const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
27012789 try wip_nav.refType(field_type);
27022790 try uleb128(diw, field_bit_offset);
27032791 field_bit_offset += @intCast(field_type.bitSize(zcu));
......@@ -2733,7 +2821,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
27332821
27342822 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
27352823 if (type_gop.found_existing) {
2736 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).clear();
2824 if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias;
27372825 nav_gop.value_ptr.* = type_gop.value_ptr.*;
27382826 } else {
27392827 if (nav_gop.found_existing)
......@@ -2745,13 +2833,13 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
27452833 wip_nav.entry = nav_gop.value_ptr.*;
27462834 const diw = wip_nav.debug_info.writer(dwarf.gpa);
27472835 try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .decl_enum else .decl_empty_enum);
2748 try wip_nav.refType(Type.fromInterned(parent_type));
2836 try wip_nav.refType(.fromInterned(parent_type));
27492837 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
27502838 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
27512839 try uleb128(diw, loc.column + 1);
27522840 try diw.writeByte(accessibility);
27532841 try wip_nav.strp(nav.name.toSlice(ip));
2754 try wip_nav.refType(Type.fromInterned(loaded_enum.tag_ty));
2842 try wip_nav.refType(.fromInterned(loaded_enum.tag_ty));
27552843 for (0..loaded_enum.names.len) |field_index| {
27562844 try wip_nav.enumConstValue(loaded_enum, .{
27572845 .sdata = .signed_enum_field,
......@@ -2788,7 +2876,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
27882876
27892877 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
27902878 if (type_gop.found_existing) {
2791 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).clear();
2879 if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias;
27922880 nav_gop.value_ptr.* = type_gop.value_ptr.*;
27932881 } else {
27942882 if (nav_gop.found_existing)
......@@ -2800,7 +2888,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
28002888 wip_nav.entry = nav_gop.value_ptr.*;
28012889 const diw = wip_nav.debug_info.writer(dwarf.gpa);
28022890 try wip_nav.abbrevCode(.decl_union);
2803 try wip_nav.refType(Type.fromInterned(parent_type));
2891 try wip_nav.refType(.fromInterned(parent_type));
28042892 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
28052893 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
28062894 try uleb128(diw, loc.column + 1);
......@@ -2821,7 +2909,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
28212909 {
28222910 try wip_nav.abbrevCode(.generated_field);
28232911 try wip_nav.strp("tag");
2824 try wip_nav.refType(Type.fromInterned(loaded_union.enum_tag_ty));
2912 try wip_nav.refType(.fromInterned(loaded_union.enum_tag_ty));
28252913 try uleb128(diw, union_layout.tagOffset());
28262914
28272915 for (0..loaded_union.field_types.len) |field_index| {
......@@ -2833,7 +2921,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
28332921 {
28342922 try wip_nav.abbrevCode(.struct_field);
28352923 try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip));
2836 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
2924 const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
28372925 try wip_nav.refType(field_type);
28382926 try uleb128(diw, union_layout.payloadOffset());
28392927 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
......@@ -2846,7 +2934,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
28462934 } else for (0..loaded_union.field_types.len) |field_index| {
28472935 try wip_nav.abbrevCode(.untagged_union_field);
28482936 try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip));
2849 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
2937 const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
28502938 try wip_nav.refType(field_type);
28512939 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
28522940 field_type.abiAlignment(zcu).toByteUnits().?);
......@@ -2879,7 +2967,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
28792967
28802968 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
28812969 if (type_gop.found_existing) {
2882 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).clear();
2970 if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias;
28832971 nav_gop.value_ptr.* = type_gop.value_ptr.*;
28842972 } else {
28852973 if (nav_gop.found_existing)
......@@ -2891,7 +2979,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
28912979 wip_nav.entry = nav_gop.value_ptr.*;
28922980 const diw = wip_nav.debug_info.writer(dwarf.gpa);
28932981 try wip_nav.abbrevCode(.decl_namespace_struct);
2894 try wip_nav.refType(Type.fromInterned(parent_type));
2982 try wip_nav.refType(.fromInterned(parent_type));
28952983 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
28962984 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
28972985 try uleb128(diw, loc.column + 1);
......@@ -2947,17 +3035,17 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
29473035 .decl_func_generic
29483036 else
29493037 .decl_empty_func_generic);
2950 try wip_nav.refType(Type.fromInterned(parent_type));
3038 try wip_nav.refType(.fromInterned(parent_type));
29513039 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
29523040 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
29533041 try uleb128(diw, loc.column + 1);
29543042 try diw.writeByte(accessibility);
29553043 try wip_nav.strp(nav.name.toSlice(ip));
2956 try wip_nav.refType(Type.fromInterned(func_type.return_type));
3044 try wip_nav.refType(.fromInterned(func_type.return_type));
29573045 if (func_type.param_types.len > 0 or func_type.is_var_args) {
29583046 for (0..func_type.param_types.len) |param_index| {
29593047 try wip_nav.abbrevCode(.func_type_param);
2960 try wip_nav.refType(Type.fromInterned(func_type.param_types.get(ip)[param_index]));
3048 try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index]));
29613049 }
29623050 if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args);
29633051 try uleb128(diw, @intFromEnum(AbbrevCode.null));
......@@ -2979,7 +3067,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
29793067 .decl_alias => {
29803068 const diw = wip_nav.debug_info.writer(dwarf.gpa);
29813069 try wip_nav.abbrevCode(.decl_alias);
2982 try wip_nav.refType(Type.fromInterned(parent_type));
3070 try wip_nav.refType(.fromInterned(parent_type));
29833071 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
29843072 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
29853073 try uleb128(diw, loc.column + 1);
......@@ -2990,7 +3078,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
29903078 .decl_var => {
29913079 const diw = wip_nav.debug_info.writer(dwarf.gpa);
29923080 try wip_nav.abbrevCode(.decl_var);
2993 try wip_nav.refType(Type.fromInterned(parent_type));
3081 try wip_nav.refType(.fromInterned(parent_type));
29943082 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
29953083 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
29963084 try uleb128(diw, loc.column + 1);
......@@ -3006,42 +3094,52 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
30063094 },
30073095 .decl_const => {
30083096 const diw = wip_nav.debug_info.writer(dwarf.gpa);
3009 try wip_nav.abbrevCode(.decl_const);
3010 try wip_nav.refType(Type.fromInterned(parent_type));
3097 const nav_ty = nav_val.typeOf(zcu);
3098 const has_runtime_bits = nav_ty.hasRuntimeBits(zcu);
3099 const has_comptime_state = nav_ty.comptimeOnly(zcu) and try nav_ty.onePossibleValue(pt) == null;
3100 try wip_nav.abbrevCode(if (has_runtime_bits and has_comptime_state)
3101 .decl_const_runtime_bits_comptime_state
3102 else if (has_comptime_state)
3103 .decl_const_comptime_state
3104 else if (has_runtime_bits)
3105 .decl_const_runtime_bits
3106 else
3107 .decl_const);
3108 try wip_nav.refType(.fromInterned(parent_type));
30113109 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
30123110 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
30133111 try uleb128(diw, loc.column + 1);
30143112 try diw.writeByte(accessibility);
30153113 try wip_nav.strp(nav.name.toSlice(ip));
30163114 try wip_nav.strp(nav.fqn.toSlice(ip));
3017 const nav_ty = nav_val.typeOf(zcu);
30183115 const nav_ty_reloc_index = try wip_nav.refForward();
3019 try wip_nav.blockValue(nav_src_loc, nav_val);
30203116 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
30213117 nav_ty.abiAlignment(zcu).toByteUnits().?);
30223118 try diw.writeByte(@intFromBool(false));
3119 if (has_runtime_bits) try wip_nav.blockValue(nav_src_loc, nav_val);
3120 if (has_comptime_state) try wip_nav.refValue(nav_val);
30233121 wip_nav.finishForward(nav_ty_reloc_index);
30243122 try wip_nav.abbrevCode(.is_const);
30253123 try wip_nav.refType(nav_ty);
30263124 },
30273125 }
30283126 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);
3029 try wip_nav.flush(nav_src_loc);
3127 try wip_nav.updateLazy(nav_src_loc);
30303128}
30313129
3032fn updateType(
3130fn updateLazyType(
30333131 dwarf: *Dwarf,
30343132 pt: Zcu.PerThread,
30353133 src_loc: Zcu.LazySrcLoc,
30363134 type_index: InternPool.Index,
3037 pending_types: *std.ArrayListUnmanaged(InternPool.Index),
3135 pending_lazy: *std.ArrayListUnmanaged(InternPool.Index),
30383136) UpdateError!void {
30393137 const zcu = pt.zcu;
30403138 const ip = &zcu.intern_pool;
3041 const ty = Type.fromInterned(type_index);
3139 const ty: Type = .fromInterned(type_index);
30423140 switch (type_index) {
3043 .generic_poison_type => log.debug("updateType({s})", .{"anytype"}),
3044 else => log.debug("updateType({})", .{ty.fmt(pt)}),
3141 .generic_poison_type => log.debug("updateLazyType({s})", .{"anytype"}),
3142 else => log.debug("updateLazyType({})", .{ty.fmt(pt)}),
30453143 }
30463144
30473145 var wip_nav: WipNav = .{
......@@ -3059,11 +3157,11 @@ fn updateType(
30593157 .debug_info = .{},
30603158 .debug_line = .{},
30613159 .debug_loclists = .{},
3062 .pending_types = pending_types.*,
3160 .pending_lazy = pending_lazy.*,
30633161 };
30643162 defer {
3065 pending_types.* = wip_nav.pending_types;
3066 wip_nav.pending_types = .{};
3163 pending_lazy.* = wip_nav.pending_lazy;
3164 wip_nav.pending_lazy = .{};
30673165 wip_nav.deinit();
30683166 }
30693167 const diw = wip_nav.debug_info.writer(dwarf.gpa);
......@@ -3086,13 +3184,10 @@ fn updateType(
30863184 },
30873185 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
30883186 .One, .Many, .C => {
3089 const ptr_child_type = Type.fromInterned(ptr_type.child);
3187 const ptr_child_type: Type = .fromInterned(ptr_type.child);
30903188 try wip_nav.abbrevCode(if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type);
30913189 try wip_nav.strp(name);
3092 if (ptr_type.sentinel != .none) try wip_nav.blockValue(
3093 src_loc,
3094 Value.fromInterned(ptr_type.sentinel),
3095 );
3190 if (ptr_type.sentinel != .none) try wip_nav.blockValue(src_loc, .fromInterned(ptr_type.sentinel));
30963191 try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse
30973192 ptr_child_type.abiAlignment(zcu).toByteUnits().?);
30983193 try diw.writeByte(@intFromEnum(ptr_type.flags.address_space));
......@@ -3128,37 +3223,34 @@ fn updateType(
31283223 try uleb128(diw, 0);
31293224 try wip_nav.abbrevCode(.generated_field);
31303225 try wip_nav.strp("len");
3131 const len_field_type = Type.usize;
3226 const len_field_type: Type = .usize;
31323227 try wip_nav.refType(len_field_type);
31333228 try uleb128(diw, len_field_type.abiAlignment(zcu).forward(ptr_field_type.abiSize(zcu)));
31343229 try uleb128(diw, @intFromEnum(AbbrevCode.null));
31353230 },
31363231 },
31373232 .array_type => |array_type| {
3138 const array_child_type = Type.fromInterned(array_type.child);
3233 const array_child_type: Type = .fromInterned(array_type.child);
31393234 try wip_nav.abbrevCode(if (array_type.sentinel == .none) .array_type else .array_sentinel_type);
31403235 try wip_nav.strp(name);
3141 if (array_type.sentinel != .none) try wip_nav.blockValue(
3142 src_loc,
3143 Value.fromInterned(array_type.sentinel),
3144 );
3236 if (array_type.sentinel != .none) try wip_nav.blockValue(src_loc, .fromInterned(array_type.sentinel));
31453237 try wip_nav.refType(array_child_type);
31463238 try wip_nav.abbrevCode(.array_index);
3147 try wip_nav.refType(Type.usize);
3239 try wip_nav.refType(.usize);
31483240 try uleb128(diw, array_type.len);
31493241 try uleb128(diw, @intFromEnum(AbbrevCode.null));
31503242 },
31513243 .vector_type => |vector_type| {
31523244 try wip_nav.abbrevCode(.vector_type);
31533245 try wip_nav.strp(name);
3154 try wip_nav.refType(Type.fromInterned(vector_type.child));
3246 try wip_nav.refType(.fromInterned(vector_type.child));
31553247 try wip_nav.abbrevCode(.array_index);
3156 try wip_nav.refType(Type.usize);
3248 try wip_nav.refType(.usize);
31573249 try uleb128(diw, vector_type.len);
31583250 try uleb128(diw, @intFromEnum(AbbrevCode.null));
31593251 },
31603252 .opt_type => |opt_child_type_index| {
3161 const opt_child_type = Type.fromInterned(opt_child_type_index);
3253 const opt_child_type: Type = .fromInterned(opt_child_type_index);
31623254 try wip_nav.abbrevCode(.union_type);
31633255 try wip_nav.strp(name);
31643256 try uleb128(diw, ty.abiSize(zcu));
......@@ -3166,7 +3258,7 @@ fn updateType(
31663258 if (opt_child_type.isNoReturn(zcu)) {
31673259 try wip_nav.abbrevCode(.generated_field);
31683260 try wip_nav.strp("null");
3169 try wip_nav.refType(Type.null);
3261 try wip_nav.refType(.null);
31703262 try uleb128(diw, 0);
31713263 } else {
31723264 try wip_nav.abbrevCode(.tagged_union);
......@@ -3189,21 +3281,21 @@ fn updateType(
31893281 };
31903282 switch (repr) {
31913283 .unpacked => {
3192 try wip_nav.refType(Type.bool);
3284 try wip_nav.refType(.bool);
31933285 try uleb128(diw, if (opt_child_type.hasRuntimeBits(zcu))
31943286 opt_child_type.abiSize(zcu)
31953287 else
31963288 0);
31973289 },
31983290 .error_set => {
3199 try wip_nav.refType(Type.fromInterned(try pt.intern(.{ .int_type = .{
3291 try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{
32003292 .signedness = .unsigned,
32013293 .bits = zcu.errorSetBits(),
32023294 } })));
32033295 try uleb128(diw, 0);
32043296 },
32053297 .pointer => {
3206 try wip_nav.refType(Type.usize);
3298 try wip_nav.refType(.usize);
32073299 try uleb128(diw, 0);
32083300 },
32093301 }
......@@ -3213,7 +3305,7 @@ fn updateType(
32133305 {
32143306 try wip_nav.abbrevCode(.generated_field);
32153307 try wip_nav.strp("null");
3216 try wip_nav.refType(Type.null);
3308 try wip_nav.refType(.null);
32173309 try uleb128(diw, 0);
32183310 }
32193311 try uleb128(diw, @intFromEnum(AbbrevCode.null));
......@@ -3233,8 +3325,8 @@ fn updateType(
32333325 },
32343326 .anyframe_type => unreachable,
32353327 .error_union_type => |error_union_type| {
3236 const error_union_error_set_type = Type.fromInterned(error_union_type.error_set_type);
3237 const error_union_payload_type = Type.fromInterned(error_union_type.payload_type);
3328 const error_union_error_set_type: Type = .fromInterned(error_union_type.error_set_type);
3329 const error_union_payload_type: Type = .fromInterned(error_union_type.payload_type);
32383330 const error_union_error_set_offset, const error_union_payload_offset = switch (error_union_type.payload_type) {
32393331 .generic_poison_type => .{ 0, 0 },
32403332 else => .{
......@@ -3265,7 +3357,7 @@ fn updateType(
32653357 {
32663358 try wip_nav.abbrevCode(.generated_field);
32673359 try wip_nav.strp("is_error");
3268 try wip_nav.refType(Type.fromInterned(try pt.intern(.{ .int_type = .{
3360 try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{
32693361 .signedness = .unsigned,
32703362 .bits = zcu.errorSetBits(),
32713363 } })));
......@@ -3363,24 +3455,39 @@ fn updateType(
33633455 var field_byte_offset: u64 = 0;
33643456 for (0..tuple_type.types.len) |field_index| {
33653457 const comptime_value = tuple_type.values.get(ip)[field_index];
3366 try wip_nav.abbrevCode(if (comptime_value != .none) .struct_field_comptime else .struct_field);
3458 const field_type: Type = .fromInterned(tuple_type.types.get(ip)[field_index]);
3459 const has_runtime_bits, const has_comptime_state = switch (comptime_value) {
3460 .none => .{ false, false },
3461 else => .{
3462 field_type.hasRuntimeBits(zcu),
3463 field_type.comptimeOnly(zcu) and try field_type.onePossibleValue(pt) == null,
3464 },
3465 };
3466 try wip_nav.abbrevCode(if (has_runtime_bits and has_comptime_state)
3467 .struct_field_comptime_runtime_bits_comptime_state
3468 else if (has_comptime_state)
3469 .struct_field_comptime_comptime_state
3470 else if (has_runtime_bits)
3471 .struct_field_comptime_runtime_bits
3472 else if (comptime_value != .none)
3473 .struct_field_comptime
3474 else
3475 .struct_field);
33673476 {
3368 var name_buf: [32]u8 = undefined;
3369 const field_name = std.fmt.bufPrint(&name_buf, "{d}", .{field_index}) catch unreachable;
3477 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
3478 const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{field_index}) catch unreachable;
33703479 try wip_nav.strp(field_name);
33713480 }
3372 const field_type = Type.fromInterned(tuple_type.types.get(ip)[field_index]);
33733481 try wip_nav.refType(field_type);
3374 if (comptime_value != .none) try wip_nav.blockValue(
3375 src_loc,
3376 Value.fromInterned(comptime_value),
3377 ) else {
3482 if (comptime_value == .none) {
33783483 const field_align = field_type.abiAlignment(zcu);
33793484 field_byte_offset = field_align.forward(field_byte_offset);
33803485 try uleb128(diw, field_byte_offset);
33813486 try uleb128(diw, field_type.abiAlignment(zcu).toByteUnits().?);
33823487 field_byte_offset += field_type.abiSize(zcu);
33833488 }
3489 if (has_runtime_bits) try wip_nav.blockValue(src_loc, .fromInterned(comptime_value));
3490 if (has_comptime_state) try wip_nav.refValue(.fromInterned(comptime_value));
33843491 }
33853492 try uleb128(diw, @intFromEnum(AbbrevCode.null));
33863493 },
......@@ -3388,7 +3495,7 @@ fn updateType(
33883495 const loaded_enum = ip.loadEnumType(type_index);
33893496 try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type);
33903497 try wip_nav.strp(name);
3391 try wip_nav.refType(Type.fromInterned(loaded_enum.tag_ty));
3498 try wip_nav.refType(.fromInterned(loaded_enum.tag_ty));
33923499 for (0..loaded_enum.names.len) |field_index| {
33933500 try wip_nav.enumConstValue(loaded_enum, .{
33943501 .sdata = .signed_enum_field,
......@@ -3469,10 +3576,10 @@ fn updateType(
34693576 };
34703577 };
34713578 try diw.writeByte(@intFromEnum(cc));
3472 try wip_nav.refType(Type.fromInterned(func_type.return_type));
3579 try wip_nav.refType(.fromInterned(func_type.return_type));
34733580 for (0..func_type.param_types.len) |param_index| {
34743581 try wip_nav.abbrevCode(.func_type_param);
3475 try wip_nav.refType(Type.fromInterned(func_type.param_types.get(ip)[param_index]));
3582 try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index]));
34763583 }
34773584 if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args);
34783585 if (!is_nullary) try uleb128(diw, @intFromEnum(AbbrevCode.null));
......@@ -3480,7 +3587,7 @@ fn updateType(
34803587 .error_set_type => |error_set_type| {
34813588 try wip_nav.abbrevCode(if (error_set_type.names.len > 0) .enum_type else .empty_enum_type);
34823589 try wip_nav.strp(name);
3483 try wip_nav.refType(Type.fromInterned(try pt.intern(.{ .int_type = .{
3590 try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{
34843591 .signedness = .unsigned,
34853592 .bits = zcu.errorSetBits(),
34863593 } })));
......@@ -3495,7 +3602,7 @@ fn updateType(
34953602 .inferred_error_set_type => |func| {
34963603 try wip_nav.abbrevCode(.inferred_error_set_type);
34973604 try wip_nav.strp(name);
3498 try wip_nav.refType(Type.fromInterned(switch (ip.funcIesResolvedUnordered(func)) {
3605 try wip_nav.refType(.fromInterned(switch (ip.funcIesResolvedUnordered(func)) {
34993606 .none => .anyerror_type,
35003607 else => |ies| ies,
35013608 }));
......@@ -3526,10 +3633,378 @@ fn updateType(
35263633 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);
35273634}
35283635
3636fn updateLazyValue(
3637 dwarf: *Dwarf,
3638 pt: Zcu.PerThread,
3639 src_loc: Zcu.LazySrcLoc,
3640 value_index: InternPool.Index,
3641 pending_lazy: *std.ArrayListUnmanaged(InternPool.Index),
3642) UpdateError!void {
3643 const zcu = pt.zcu;
3644 const ip = &zcu.intern_pool;
3645 log.debug("updateLazyValue({})", .{Value.fromInterned(value_index).fmtValue(pt)});
3646 var wip_nav: WipNav = .{
3647 .dwarf = dwarf,
3648 .pt = pt,
3649 .unit = .main,
3650 .entry = dwarf.values.get(value_index).?,
3651 .any_children = false,
3652 .func = .none,
3653 .func_sym_index = undefined,
3654 .func_high_pc = undefined,
3655 .blocks = undefined,
3656 .cfi = undefined,
3657 .debug_frame = .{},
3658 .debug_info = .{},
3659 .debug_line = .{},
3660 .debug_loclists = .{},
3661 .pending_lazy = pending_lazy.*,
3662 };
3663 defer {
3664 pending_lazy.* = wip_nav.pending_lazy;
3665 wip_nav.pending_lazy = .{};
3666 wip_nav.deinit();
3667 }
3668 const diw = wip_nav.debug_info.writer(dwarf.gpa);
3669 var big_int_space: Value.BigIntSpace = undefined;
3670 switch (ip.indexToKey(value_index)) {
3671 .int_type,
3672 .ptr_type,
3673 .array_type,
3674 .vector_type,
3675 .opt_type,
3676 .anyframe_type,
3677 .error_union_type,
3678 .simple_type,
3679 .struct_type,
3680 .tuple_type,
3681 .union_type,
3682 .opaque_type,
3683 .enum_type,
3684 .func_type,
3685 .error_set_type,
3686 .inferred_error_set_type,
3687 => unreachable, // already handled
3688 .undef => |ty| {
3689 try wip_nav.abbrevCode(.aggregate_comptime_value);
3690 try wip_nav.refType(.fromInterned(ty));
3691 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3692 },
3693 .simple_value => unreachable, // opv state
3694 .variable, .@"extern" => unreachable, // not a value
3695 .func => unreachable, // already handled
3696 .int => |int| {
3697 try wip_nav.bigIntConstValue(.{
3698 .sdata = .sdata_comptime_value,
3699 .udata = .udata_comptime_value,
3700 .block = .block_comptime_value,
3701 }, .fromInterned(int.ty), Value.fromInterned(value_index).toBigInt(&big_int_space, zcu));
3702 try wip_nav.refType(.fromInterned(int.ty));
3703 },
3704 .err => |err| {
3705 try wip_nav.abbrevCode(.udata_comptime_value);
3706 try wip_nav.refType(.fromInterned(err.ty));
3707 try uleb128(diw, try pt.getErrorValue(err.name));
3708 },
3709 .error_union => |error_union| {
3710 try wip_nav.abbrevCode(.aggregate_comptime_value);
3711 const err_abi_size = std.math.divCeil(u17, zcu.errorSetBits(), 8) catch unreachable;
3712 const err_value = switch (error_union.val) {
3713 .err_name => |err_name| try pt.getErrorValue(err_name),
3714 .payload => 0,
3715 };
3716 {
3717 try wip_nav.abbrevCode(.comptime_value_field_runtime_bits);
3718 try wip_nav.strp("is_error");
3719 try uleb128(diw, err_abi_size);
3720 dwarf.writeInt(try wip_nav.debug_info.addManyAsSlice(dwarf.gpa, err_abi_size), err_value);
3721 }
3722 payload_field: switch (error_union.val) {
3723 .err_name => {},
3724 .payload => |payload_val| {
3725 const payload_type: Type = .fromInterned(ip.typeOf(payload_val));
3726 const has_runtime_bits = payload_type.hasRuntimeBits(zcu);
3727 const has_comptime_state = payload_type.comptimeOnly(zcu) and try payload_type.onePossibleValue(pt) == null;
3728 try wip_nav.abbrevCode(if (has_comptime_state)
3729 .comptime_value_field_comptime_state
3730 else if (has_runtime_bits)
3731 .comptime_value_field_runtime_bits
3732 else
3733 break :payload_field);
3734 try wip_nav.strp("value");
3735 if (has_comptime_state)
3736 try wip_nav.refValue(.fromInterned(payload_val))
3737 else
3738 try wip_nav.blockValue(src_loc, .fromInterned(payload_val));
3739 },
3740 }
3741 {
3742 try wip_nav.abbrevCode(.comptime_value_field_runtime_bits);
3743 try wip_nav.strp("error");
3744 try uleb128(diw, err_abi_size);
3745 dwarf.writeInt(try wip_nav.debug_info.addManyAsSlice(dwarf.gpa, err_abi_size), err_value);
3746 }
3747 switch (error_union.val) {
3748 .err_name => {},
3749 .payload => |payload| {
3750 _ = payload;
3751 try wip_nav.abbrevCode(.aggregate_comptime_value);
3752 },
3753 }
3754 try wip_nav.refType(.fromInterned(error_union.ty));
3755 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3756 },
3757 .enum_literal => |enum_literal| {
3758 try wip_nav.abbrevCode(.string_comptime_value);
3759 try wip_nav.strp(enum_literal.toSlice(ip));
3760 try wip_nav.refType(.enum_literal);
3761 },
3762 .enum_tag => |enum_tag| {
3763 const int = ip.indexToKey(enum_tag.int).int;
3764 try wip_nav.bigIntConstValue(.{
3765 .sdata = .sdata_comptime_value,
3766 .udata = .udata_comptime_value,
3767 .block = .block_comptime_value,
3768 }, .fromInterned(int.ty), Value.fromInterned(value_index).toBigInt(&big_int_space, zcu));
3769 try wip_nav.refType(.fromInterned(enum_tag.ty));
3770 },
3771 .empty_enum_value => unreachable,
3772 .float => |float| {
3773 switch (float.storage) {
3774 .f16 => |f16_val| {
3775 try wip_nav.abbrevCode(.data2_comptime_value);
3776 try diw.writeInt(u16, @bitCast(f16_val), dwarf.endian);
3777 },
3778 .f32 => |f32_val| {
3779 try wip_nav.abbrevCode(.data4_comptime_value);
3780 try diw.writeInt(u32, @bitCast(f32_val), dwarf.endian);
3781 },
3782 .f64 => |f64_val| {
3783 try wip_nav.abbrevCode(.data8_comptime_value);
3784 try diw.writeInt(u64, @bitCast(f64_val), dwarf.endian);
3785 },
3786 .f80 => |f80_val| {
3787 try wip_nav.abbrevCode(.block_comptime_value);
3788 try uleb128(diw, @divExact(80, 8));
3789 try diw.writeInt(u80, @bitCast(f80_val), dwarf.endian);
3790 },
3791 .f128 => |f128_val| {
3792 try wip_nav.abbrevCode(.data16_comptime_value);
3793 try diw.writeInt(u128, @bitCast(f128_val), dwarf.endian);
3794 },
3795 }
3796 try wip_nav.refType(.fromInterned(float.ty));
3797 },
3798 .ptr => |ptr| {
3799 location: {
3800 var base_addr = ptr.base_addr;
3801 var byte_offset = ptr.byte_offset;
3802 const base_unit, const base_entry = while (true) {
3803 const base_ptr = base_ptr: switch (base_addr) {
3804 .nav => |nav_index| break try wip_nav.getNavEntry(nav_index),
3805 .comptime_alloc, .comptime_field => unreachable,
3806 .uav => |uav| {
3807 const uav_ty: Type = .fromInterned(ip.typeOf(uav.val));
3808 if (try uav_ty.onePossibleValue(pt)) |_| {
3809 try wip_nav.abbrevCode(.udata_comptime_value);
3810 try uleb128(diw, ip.indexToKey(uav.orig_ty).ptr_type.flags.alignment.toByteUnits() orelse
3811 uav_ty.abiAlignment(zcu).toByteUnits().?);
3812 break :location;
3813 } else break try wip_nav.getValueEntry(.fromInterned(uav.val));
3814 },
3815 .int => {
3816 try wip_nav.abbrevCode(.udata_comptime_value);
3817 try uleb128(diw, byte_offset);
3818 break :location;
3819 },
3820 .eu_payload => |eu_ptr| {
3821 const base_ptr = ip.indexToKey(eu_ptr).ptr;
3822 byte_offset += codegen.errUnionPayloadOffset(.fromInterned(ip.indexToKey(
3823 ip.indexToKey(base_ptr.ty).ptr_type.child,
3824 ).error_union_type.payload_type), zcu);
3825 break :base_ptr base_ptr;
3826 },
3827 .opt_payload => |opt_ptr| ip.indexToKey(opt_ptr).ptr,
3828 .field => unreachable,
3829 .arr_elem => unreachable,
3830 };
3831 base_addr = base_ptr.base_addr;
3832 byte_offset += base_ptr.byte_offset;
3833 };
3834 try wip_nav.abbrevCode(.location_comptime_value);
3835 try wip_nav.infoExprloc(.{ .implicit_pointer = .{
3836 .unit = base_unit,
3837 .entry = base_entry,
3838 .offset = byte_offset,
3839 } });
3840 }
3841 try wip_nav.refType(.fromInterned(ptr.ty));
3842 },
3843 .slice => |slice| {
3844 try wip_nav.abbrevCode(.aggregate_comptime_value);
3845 try wip_nav.refType(.fromInterned(slice.ty));
3846 {
3847 try wip_nav.abbrevCode(.comptime_value_field_comptime_state);
3848 try wip_nav.strp("ptr");
3849 try wip_nav.refValue(.fromInterned(slice.ptr));
3850 }
3851 {
3852 try wip_nav.abbrevCode(.comptime_value_field_runtime_bits);
3853 try wip_nav.strp("len");
3854 try wip_nav.blockValue(src_loc, .fromInterned(slice.len));
3855 }
3856 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3857 },
3858 .opt => |opt| {
3859 const child_type: Type = .fromInterned(ip.indexToKey(opt.ty).opt_type);
3860 try wip_nav.abbrevCode(.aggregate_comptime_value);
3861 try wip_nav.refType(.fromInterned(opt.ty));
3862 {
3863 try wip_nav.abbrevCode(.comptime_value_field_runtime_bits);
3864 try wip_nav.strp("has_value");
3865 if (Type.fromInterned(opt.ty).optionalReprIsPayload(zcu)) {
3866 try wip_nav.blockValue(src_loc, .fromInterned(opt.val));
3867 } else {
3868 try uleb128(diw, 1);
3869 try diw.writeByte(@intFromBool(opt.val != .none));
3870 }
3871 }
3872 if (opt.val != .none) child_field: {
3873 const has_runtime_bits = child_type.hasRuntimeBits(zcu);
3874 const has_comptime_state = child_type.comptimeOnly(zcu) and try child_type.onePossibleValue(pt) == null;
3875 try wip_nav.abbrevCode(if (has_comptime_state)
3876 .comptime_value_field_comptime_state
3877 else if (has_runtime_bits)
3878 .comptime_value_field_runtime_bits
3879 else
3880 break :child_field);
3881 try wip_nav.strp("?");
3882 if (has_comptime_state)
3883 try wip_nav.refValue(.fromInterned(opt.val))
3884 else
3885 try wip_nav.blockValue(src_loc, .fromInterned(opt.val));
3886 }
3887 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3888 },
3889 .aggregate => |aggregate| {
3890 try wip_nav.abbrevCode(.aggregate_comptime_value);
3891 try wip_nav.refType(.fromInterned(aggregate.ty));
3892 switch (ip.indexToKey(aggregate.ty)) {
3893 .struct_type => {
3894 const loaded_struct_type = ip.loadStructType(aggregate.ty);
3895 assert(loaded_struct_type.layout == .auto);
3896 for (0..loaded_struct_type.field_types.len) |field_index| {
3897 if (loaded_struct_type.fieldIsComptime(ip, field_index)) continue;
3898 const field_type: Type = .fromInterned(loaded_struct_type.field_types.get(ip)[field_index]);
3899 const has_runtime_bits = field_type.hasRuntimeBits(zcu);
3900 const has_comptime_state = field_type.comptimeOnly(zcu) and try field_type.onePossibleValue(pt) == null;
3901 try wip_nav.abbrevCode(if (has_comptime_state)
3902 .comptime_value_field_comptime_state
3903 else if (has_runtime_bits)
3904 .comptime_value_field_runtime_bits
3905 else
3906 continue);
3907 if (loaded_struct_type.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
3908 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
3909 const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{field_index}) catch unreachable;
3910 try wip_nav.strp(field_name);
3911 }
3912 const field_value: Value = .fromInterned(switch (aggregate.storage) {
3913 .bytes => unreachable,
3914 .elems => |elems| elems[field_index],
3915 .repeated_elem => |repeated_elem| repeated_elem,
3916 });
3917 if (has_comptime_state)
3918 try wip_nav.refValue(field_value)
3919 else
3920 try wip_nav.blockValue(src_loc, field_value);
3921 }
3922 },
3923 .tuple_type => |tuple_type| for (0..tuple_type.types.len) |field_index| {
3924 if (tuple_type.values.get(ip)[field_index] != .none) continue;
3925 const field_type: Type = .fromInterned(tuple_type.types.get(ip)[field_index]);
3926 const has_runtime_bits = field_type.hasRuntimeBits(zcu);
3927 const has_comptime_state = field_type.comptimeOnly(zcu) and try field_type.onePossibleValue(pt) == null;
3928 try wip_nav.abbrevCode(if (has_comptime_state)
3929 .comptime_value_field_comptime_state
3930 else if (has_runtime_bits)
3931 .comptime_value_field_runtime_bits
3932 else
3933 continue);
3934 {
3935 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
3936 const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{field_index}) catch unreachable;
3937 try wip_nav.strp(field_name);
3938 }
3939 const field_value: Value = .fromInterned(switch (aggregate.storage) {
3940 .bytes => unreachable,
3941 .elems => |elems| elems[field_index],
3942 .repeated_elem => |repeated_elem| repeated_elem,
3943 });
3944 if (has_comptime_state)
3945 try wip_nav.refValue(field_value)
3946 else
3947 try wip_nav.blockValue(src_loc, field_value);
3948 },
3949 inline .array_type, .vector_type => |sequence_type| {
3950 const child_type: Type = .fromInterned(sequence_type.child);
3951 const has_runtime_bits = child_type.hasRuntimeBits(zcu);
3952 const has_comptime_state = child_type.comptimeOnly(zcu) and try child_type.onePossibleValue(pt) == null;
3953 for (switch (aggregate.storage) {
3954 .bytes => unreachable,
3955 .elems => |elems| elems,
3956 .repeated_elem => |*repeated_elem| repeated_elem[0..1],
3957 }) |elem| {
3958 try wip_nav.abbrevCode(if (has_comptime_state)
3959 .comptime_value_elem_comptime_state
3960 else if (has_runtime_bits)
3961 .comptime_value_elem_runtime_bits
3962 else
3963 break);
3964 if (has_comptime_state)
3965 try wip_nav.refValue(.fromInterned(elem))
3966 else
3967 try wip_nav.blockValue(src_loc, .fromInterned(elem));
3968 }
3969 },
3970 else => unreachable,
3971 }
3972 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3973 },
3974 .un => |un| {
3975 try wip_nav.abbrevCode(.aggregate_comptime_value);
3976 try wip_nav.refType(.fromInterned(un.ty));
3977 field: {
3978 const loaded_union_type = ip.loadUnionType(un.ty);
3979 assert(loaded_union_type.flagsUnordered(ip).layout == .auto);
3980 const field_index = zcu.unionTagFieldIndex(loaded_union_type, Value.fromInterned(un.tag)).?;
3981 const field_ty: Type = .fromInterned(loaded_union_type.field_types.get(ip)[field_index]);
3982 const field_name = loaded_union_type.loadTagType(ip).names.get(ip)[field_index];
3983 const has_runtime_bits = field_ty.hasRuntimeBits(zcu);
3984 const has_comptime_state = field_ty.comptimeOnly(zcu) and try field_ty.onePossibleValue(pt) == null;
3985 try wip_nav.abbrevCode(if (has_comptime_state)
3986 .comptime_value_field_comptime_state
3987 else if (has_runtime_bits)
3988 .comptime_value_field_runtime_bits
3989 else
3990 break :field);
3991 try wip_nav.strp(field_name.toSlice(ip));
3992 if (has_comptime_state)
3993 try wip_nav.refValue(.fromInterned(un.val))
3994 else
3995 try wip_nav.blockValue(src_loc, .fromInterned(un.val));
3996 }
3997 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3998 },
3999 .memoized_call => unreachable, // not a value
4000 }
4001 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);
4002}
4003
35294004pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternPool.Index) UpdateError!void {
35304005 const zcu = pt.zcu;
35314006 const ip = &zcu.intern_pool;
3532 const ty = Type.fromInterned(type_index);
4007 const ty: Type = .fromInterned(type_index);
35334008 const ty_src_loc = ty.srcLoc(zcu);
35344009 log.debug("updateContainerType({}({d}))", .{ ty.fmt(pt), @intFromEnum(type_index) });
35354010
......@@ -3554,7 +4029,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
35544029 .debug_info = .{},
35554030 .debug_line = .{},
35564031 .debug_loclists = .{},
3557 .pending_types = .{},
4032 .pending_lazy = .{},
35584033 };
35594034 defer wip_nav.deinit();
35604035
......@@ -3572,31 +4047,53 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
35724047 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
35734048 const field_init = loaded_struct.fieldInit(ip, field_index);
35744049 assert(!(is_comptime and field_init == .none));
4050 const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
4051 const has_runtime_bits, const has_comptime_state = switch (field_init) {
4052 .none => .{ false, false },
4053 else => .{
4054 field_type.hasRuntimeBits(zcu),
4055 field_type.comptimeOnly(zcu) and try field_type.onePossibleValue(pt) == null,
4056 },
4057 };
35754058 try wip_nav.abbrevCode(if (is_comptime)
3576 .struct_field_comptime
4059 if (has_runtime_bits and has_comptime_state)
4060 .struct_field_comptime_runtime_bits_comptime_state
4061 else if (has_comptime_state)
4062 .struct_field_comptime_comptime_state
4063 else if (has_runtime_bits)
4064 .struct_field_comptime_runtime_bits
4065 else
4066 .struct_field_comptime
35774067 else if (field_init != .none)
3578 .struct_field_default
4068 if (has_runtime_bits and has_comptime_state)
4069 .struct_field_default_runtime_bits_comptime_state
4070 else if (has_comptime_state)
4071 .struct_field_default_comptime_state
4072 else if (has_runtime_bits)
4073 .struct_field_default_runtime_bits
4074 else
4075 .struct_field_default
35794076 else
35804077 .struct_field);
35814078 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
3582 const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index});
3583 defer dwarf.gpa.free(field_name);
4079 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
4080 const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{field_index}) catch unreachable;
35844081 try wip_nav.strp(field_name);
35854082 }
3586 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
35874083 try wip_nav.refType(field_type);
35884084 if (!is_comptime) {
35894085 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
35904086 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
35914087 field_type.abiAlignment(zcu).toByteUnits().?);
35924088 }
3593 if (field_init != .none) try wip_nav.blockValue(ty_src_loc, Value.fromInterned(field_init));
4089 if (has_runtime_bits) try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init));
4090 if (has_comptime_state) try wip_nav.refValue(.fromInterned(field_init));
35944091 }
35954092 try uleb128(diw, @intFromEnum(AbbrevCode.null));
35964093 }
35974094
35984095 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);
3599 try wip_nav.flush(ty_src_loc);
4096 try wip_nav.updateLazy(ty_src_loc);
36004097 } else {
36014098 {
36024099 // Note that changes to ZIR instruction tracking only need to update this code
......@@ -3637,7 +4134,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
36374134 .debug_info = .{},
36384135 .debug_line = .{},
36394136 .debug_loclists = .{},
3640 .pending_types = .{},
4137 .pending_lazy = .{},
36414138 };
36424139 defer wip_nav.deinit();
36434140 const diw = wip_nav.debug_info.writer(dwarf.gpa);
......@@ -3658,25 +4155,47 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
36584155 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
36594156 const field_init = loaded_struct.fieldInit(ip, field_index);
36604157 assert(!(is_comptime and field_init == .none));
4158 const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
4159 const has_runtime_bits, const has_comptime_state = switch (field_init) {
4160 .none => .{ false, false },
4161 else => .{
4162 field_type.hasRuntimeBits(zcu),
4163 field_type.comptimeOnly(zcu) and try field_type.onePossibleValue(pt) == null,
4164 },
4165 };
36614166 try wip_nav.abbrevCode(if (is_comptime)
3662 .struct_field_comptime
4167 if (has_runtime_bits and has_comptime_state)
4168 .struct_field_comptime_runtime_bits_comptime_state
4169 else if (has_comptime_state)
4170 .struct_field_comptime_comptime_state
4171 else if (has_runtime_bits)
4172 .struct_field_comptime_runtime_bits
4173 else
4174 .struct_field_comptime
36634175 else if (field_init != .none)
3664 .struct_field_default
4176 if (has_runtime_bits and has_comptime_state)
4177 .struct_field_default_runtime_bits_comptime_state
4178 else if (has_comptime_state)
4179 .struct_field_default_comptime_state
4180 else if (has_runtime_bits)
4181 .struct_field_default_runtime_bits
4182 else
4183 .struct_field_default
36654184 else
36664185 .struct_field);
36674186 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
3668 const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index});
3669 defer dwarf.gpa.free(field_name);
4187 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
4188 const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{field_index}) catch unreachable;
36704189 try wip_nav.strp(field_name);
36714190 }
3672 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
36734191 try wip_nav.refType(field_type);
36744192 if (!is_comptime) {
36754193 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
36764194 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
36774195 field_type.abiAlignment(zcu).toByteUnits().?);
36784196 }
3679 if (field_init != .none) try wip_nav.blockValue(ty_src_loc, Value.fromInterned(field_init));
4197 if (has_runtime_bits) try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init));
4198 if (has_comptime_state) try wip_nav.refValue(.fromInterned(field_init));
36804199 }
36814200 try uleb128(diw, @intFromEnum(AbbrevCode.null));
36824201 }
......@@ -3684,12 +4203,12 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
36844203 .@"packed" => {
36854204 try wip_nav.abbrevCode(if (loaded_struct.field_types.len > 0) .packed_struct_type else .empty_packed_struct_type);
36864205 try wip_nav.strp(name);
3687 try wip_nav.refType(Type.fromInterned(loaded_struct.backingIntTypeUnordered(ip)));
4206 try wip_nav.refType(.fromInterned(loaded_struct.backingIntTypeUnordered(ip)));
36884207 var field_bit_offset: u16 = 0;
36894208 for (0..loaded_struct.field_types.len) |field_index| {
36904209 try wip_nav.abbrevCode(.packed_struct_field);
36914210 try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip));
3692 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
4211 const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
36934212 try wip_nav.refType(field_type);
36944213 try uleb128(diw, field_bit_offset);
36954214 field_bit_offset += @intCast(field_type.bitSize(zcu));
......@@ -3702,7 +4221,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
37024221 const loaded_enum = ip.loadEnumType(type_index);
37034222 try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type);
37044223 try wip_nav.strp(name);
3705 try wip_nav.refType(Type.fromInterned(loaded_enum.tag_ty));
4224 try wip_nav.refType(.fromInterned(loaded_enum.tag_ty));
37064225 for (0..loaded_enum.names.len) |field_index| {
37074226 try wip_nav.enumConstValue(loaded_enum, .{
37084227 .sdata = .signed_enum_field,
......@@ -3732,7 +4251,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
37324251 {
37334252 try wip_nav.abbrevCode(.generated_field);
37344253 try wip_nav.strp("tag");
3735 try wip_nav.refType(Type.fromInterned(loaded_union.enum_tag_ty));
4254 try wip_nav.refType(.fromInterned(loaded_union.enum_tag_ty));
37364255 try uleb128(diw, union_layout.tagOffset());
37374256
37384257 for (0..loaded_union.field_types.len) |field_index| {
......@@ -3744,7 +4263,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
37444263 {
37454264 try wip_nav.abbrevCode(.struct_field);
37464265 try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip));
3747 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
4266 const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
37484267 try wip_nav.refType(field_type);
37494268 try uleb128(diw, union_layout.payloadOffset());
37504269 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
......@@ -3757,7 +4276,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
37574276 } else for (0..loaded_union.field_types.len) |field_index| {
37584277 try wip_nav.abbrevCode(.untagged_union_field);
37594278 try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip));
3760 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
4279 const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
37614280 try wip_nav.refType(field_type);
37624281 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
37634282 field_type.abiAlignment(zcu).toByteUnits().?);
......@@ -3773,7 +4292,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
37734292 }
37744293 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);
37754294 try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.items);
3776 try wip_nav.flush(ty_src_loc);
4295 try wip_nav.updateLazy(ty_src_loc);
37774296 }
37784297}
37794298
......@@ -3840,14 +4359,14 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
38404359 .debug_info = .{},
38414360 .debug_line = .{},
38424361 .debug_loclists = .{},
3843 .pending_types = .{},
4362 .pending_lazy = .{},
38444363 };
38454364 defer wip_nav.deinit();
38464365 const diw = wip_nav.debug_info.writer(dwarf.gpa);
38474366 const global_error_set_names = ip.global_error_set.getNamesFromMainThread();
38484367 try wip_nav.abbrevCode(if (global_error_set_names.len > 0) .enum_type else .empty_enum_type);
38494368 try wip_nav.strp("anyerror");
3850 try wip_nav.refType(Type.fromInterned(try pt.intern(.{ .int_type = .{
4369 try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{
38514370 .signedness = .unsigned,
38524371 .bits = zcu.errorSetBits(),
38534372 } })));
......@@ -3858,7 +4377,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
38584377 }
38594378 if (global_error_set_names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));
38604379 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);
3861 try wip_nav.flush(.unneeded);
4380 try wip_nav.updateLazy(.unneeded);
38624381 }
38634382
38644383 {
......@@ -4244,6 +4763,9 @@ const AbbrevCode = enum {
42444763 decl_union,
42454764 decl_var,
42464765 decl_const,
4766 decl_const_runtime_bits,
4767 decl_const_comptime_state,
4768 decl_const_runtime_bits_comptime_state,
42474769 decl_func,
42484770 decl_empty_func,
42494771 decl_func_generic,
......@@ -4259,7 +4781,13 @@ const AbbrevCode = enum {
42594781 generated_field,
42604782 struct_field,
42614783 struct_field_default,
4784 struct_field_default_runtime_bits,
4785 struct_field_default_comptime_state,
4786 struct_field_default_runtime_bits_comptime_state,
42624787 struct_field_comptime,
4788 struct_field_comptime_runtime_bits,
4789 struct_field_comptime_comptime_state,
4790 struct_field_comptime_runtime_bits_comptime_state,
42634791 packed_struct_field,
42644792 untagged_union_field,
42654793 tagged_union,
......@@ -4296,6 +4824,20 @@ const AbbrevCode = enum {
42964824 inlined_func,
42974825 local_arg,
42984826 local_var,
4827 data2_comptime_value,
4828 data4_comptime_value,
4829 data8_comptime_value,
4830 data16_comptime_value,
4831 sdata_comptime_value,
4832 udata_comptime_value,
4833 block_comptime_value,
4834 string_comptime_value,
4835 location_comptime_value,
4836 aggregate_comptime_value,
4837 comptime_value_field_runtime_bits,
4838 comptime_value_field_comptime_state,
4839 comptime_value_elem_runtime_bits,
4840 comptime_value_elem_comptime_state,
42994841
43004842 const decl_bytes = uleb128Bytes(@intFromEnum(AbbrevCode.decl_empty_func_generic));
43014843
......@@ -4387,9 +4929,39 @@ const AbbrevCode = enum {
43874929 .attrs = decl_abbrev_common_attrs ++ .{
43884930 .{ .linkage_name, .strp },
43894931 .{ .type, .ref_addr },
4932 .{ .alignment, .udata },
4933 .{ .external, .flag },
4934 },
4935 },
4936 .decl_const_runtime_bits = .{
4937 .tag = .constant,
4938 .attrs = decl_abbrev_common_attrs ++ .{
4939 .{ .linkage_name, .strp },
4940 .{ .type, .ref_addr },
4941 .{ .alignment, .udata },
4942 .{ .external, .flag },
43904943 .{ .const_value, .block },
4944 },
4945 },
4946 .decl_const_comptime_state = .{
4947 .tag = .constant,
4948 .attrs = decl_abbrev_common_attrs ++ .{
4949 .{ .linkage_name, .strp },
4950 .{ .type, .ref_addr },
4951 .{ .alignment, .udata },
4952 .{ .external, .flag },
4953 .{ .ZIG_comptime_value, .ref_addr },
4954 },
4955 },
4956 .decl_const_runtime_bits_comptime_state = .{
4957 .tag = .constant,
4958 .attrs = decl_abbrev_common_attrs ++ .{
4959 .{ .linkage_name, .strp },
4960 .{ .type, .ref_addr },
43914961 .{ .alignment, .udata },
43924962 .{ .external, .flag },
4963 .{ .const_value, .block },
4964 .{ .ZIG_comptime_value, .ref_addr },
43934965 },
43944966 },
43954967 .decl_func = .{
......@@ -4509,6 +5081,15 @@ const AbbrevCode = enum {
45095081 },
45105082 },
45115083 .struct_field_default = .{
5084 .tag = .member,
5085 .attrs = &.{
5086 .{ .name, .strp },
5087 .{ .type, .ref_addr },
5088 .{ .data_member_location, .udata },
5089 .{ .alignment, .udata },
5090 },
5091 },
5092 .struct_field_default_runtime_bits = .{
45125093 .tag = .member,
45135094 .attrs = &.{
45145095 .{ .name, .strp },
......@@ -4518,13 +5099,61 @@ const AbbrevCode = enum {
45185099 .{ .default_value, .block },
45195100 },
45205101 },
5102 .struct_field_default_comptime_state = .{
5103 .tag = .member,
5104 .attrs = &.{
5105 .{ .name, .strp },
5106 .{ .type, .ref_addr },
5107 .{ .data_member_location, .udata },
5108 .{ .alignment, .udata },
5109 .{ .ZIG_comptime_default_value, .ref_addr },
5110 },
5111 },
5112 .struct_field_default_runtime_bits_comptime_state = .{
5113 .tag = .member,
5114 .attrs = &.{
5115 .{ .name, .strp },
5116 .{ .type, .ref_addr },
5117 .{ .data_member_location, .udata },
5118 .{ .alignment, .udata },
5119 .{ .default_value, .block },
5120 .{ .ZIG_comptime_default_value, .ref_addr },
5121 },
5122 },
45215123 .struct_field_comptime = .{
5124 .tag = .member,
5125 .attrs = &.{
5126 .{ .const_expr, .flag_present },
5127 .{ .name, .strp },
5128 .{ .type, .ref_addr },
5129 },
5130 },
5131 .struct_field_comptime_runtime_bits = .{
5132 .tag = .member,
5133 .attrs = &.{
5134 .{ .const_expr, .flag_present },
5135 .{ .name, .strp },
5136 .{ .type, .ref_addr },
5137 .{ .const_value, .block },
5138 },
5139 },
5140 .struct_field_comptime_comptime_state = .{
5141 .tag = .member,
5142 .attrs = &.{
5143 .{ .const_expr, .flag_present },
5144 .{ .name, .strp },
5145 .{ .type, .ref_addr },
5146 .{ .ZIG_comptime_value, .ref_addr },
5147 },
5148 },
5149 .struct_field_comptime_runtime_bits_comptime_state = .{
45225150 .tag = .member,
45235151 .attrs = &.{
45245152 .{ .const_expr, .flag_present },
45255153 .{ .name, .strp },
45265154 .{ .type, .ref_addr },
45275155 .{ .const_value, .block },
5156 .{ .ZIG_comptime_value, .ref_addr },
45285157 },
45295158 },
45305159 .packed_struct_field = .{
......@@ -4804,6 +5433,102 @@ const AbbrevCode = enum {
48045433 .{ .location, .exprloc },
48055434 },
48065435 },
5436 .data2_comptime_value = .{
5437 .tag = .ZIG_comptime_value,
5438 .attrs = &.{
5439 .{ .const_value, .data2 },
5440 .{ .type, .ref_addr },
5441 },
5442 },
5443 .data4_comptime_value = .{
5444 .tag = .ZIG_comptime_value,
5445 .attrs = &.{
5446 .{ .const_value, .data4 },
5447 .{ .type, .ref_addr },
5448 },
5449 },
5450 .data8_comptime_value = .{
5451 .tag = .ZIG_comptime_value,
5452 .attrs = &.{
5453 .{ .const_value, .data8 },
5454 .{ .type, .ref_addr },
5455 },
5456 },
5457 .data16_comptime_value = .{
5458 .tag = .ZIG_comptime_value,
5459 .attrs = &.{
5460 .{ .const_value, .data16 },
5461 .{ .type, .ref_addr },
5462 },
5463 },
5464 .sdata_comptime_value = .{
5465 .tag = .ZIG_comptime_value,
5466 .attrs = &.{
5467 .{ .const_value, .sdata },
5468 .{ .type, .ref_addr },
5469 },
5470 },
5471 .udata_comptime_value = .{
5472 .tag = .ZIG_comptime_value,
5473 .attrs = &.{
5474 .{ .const_value, .udata },
5475 .{ .type, .ref_addr },
5476 },
5477 },
5478 .block_comptime_value = .{
5479 .tag = .ZIG_comptime_value,
5480 .attrs = &.{
5481 .{ .const_value, .block },
5482 .{ .type, .ref_addr },
5483 },
5484 },
5485 .string_comptime_value = .{
5486 .tag = .ZIG_comptime_value,
5487 .attrs = &.{
5488 .{ .const_value, .strp },
5489 .{ .type, .ref_addr },
5490 },
5491 },
5492 .location_comptime_value = .{
5493 .tag = .ZIG_comptime_value,
5494 .attrs = &.{
5495 .{ .location, .exprloc },
5496 .{ .type, .ref_addr },
5497 },
5498 },
5499 .aggregate_comptime_value = .{
5500 .tag = .ZIG_comptime_value,
5501 .children = true,
5502 .attrs = &.{
5503 .{ .type, .ref_addr },
5504 },
5505 },
5506 .comptime_value_field_runtime_bits = .{
5507 .tag = .member,
5508 .attrs = &.{
5509 .{ .name, .strp },
5510 .{ .const_value, .block },
5511 },
5512 },
5513 .comptime_value_field_comptime_state = .{
5514 .tag = .member,
5515 .attrs = &.{
5516 .{ .name, .strp },
5517 .{ .ZIG_comptime_value, .ref_addr },
5518 },
5519 },
5520 .comptime_value_elem_runtime_bits = .{
5521 .tag = .member,
5522 .attrs = &.{
5523 .{ .const_value, .block },
5524 },
5525 },
5526 .comptime_value_elem_comptime_state = .{
5527 .tag = .member,
5528 .attrs = &.{
5529 .{ .ZIG_comptime_value, .ref_addr },
5530 },
5531 },
48075532 .null = undefined,
48085533 });
48095534};
tools/lldb_pretty_printers.py+37
......@@ -7,10 +7,28 @@
77import lldb
88import re
99
10# Helpers
11
1012page_size = 1 << 12
1113
1214def log2_int(i): return i.bit_length() - 1
1315
16def create_struct(name, struct_type, **inits):
17 struct_bytes = bytearray(struct_type.size)
18 struct_data = lldb.SBData()
19 for field in struct_type.fields:
20 field_size = field.type.size
21 field_bytes = inits[field.name].data.uint8[:field_size]
22 match struct_data.byte_order:
23 case lldb.eByteOrderLittle:
24 field_start = field.byte_offset
25 struct_bytes[field_start:field_start + len(field_bytes)] = field_bytes
26 case lldb.eByteOrderBig:
27 field_end = field.byte_offset + field_size
28 struct_bytes[field_end - len(field_bytes):field_end] = field_bytes
29 struct_data.SetData(lldb.SBError(), struct_bytes, struct_data.byte_order, struct_data.GetAddressByteSize())
30 return next(iter(inits.values())).CreateValueFromData(name, struct_data, struct_type)
31
1432# Define Zig Language
1533
1634zig_keywords = {
......@@ -678,6 +696,22 @@ value_tag_handlers = {
678696 'lazy_size': lambda payload: '@sizeOf(%s)' % type_Type_SummaryProvider(payload),
679697}
680698
699# Define Zig Stage2 Compiler (compiled with the self-hosted backend)
700
701class root_InternPool_Local_List_SynthProvider:
702 def __init__(self, value, _=None): self.value = value
703 def update(self):
704 capacity = self.value.EvaluateExpression('@as(*@This().Header, @alignCast(@ptrCast(@this().bytes - @This().bytes_offset))).capacity')
705 self.view = create_struct('view', self.value.EvaluateExpression('@This().View').GetValueAsType(), bytes=self.value.GetChildMemberWithName('bytes'), len=capacity, capacity=capacity).GetNonSyntheticValue()
706 def has_children(self): return True
707 def num_children(self): return 1
708 def get_child_index(self, name):
709 try: return ('view',).index(name)
710 except: pass
711 def get_child_at_index(self, index):
712 try: return (self.view,)[index]
713 except: pass
714
681715# Initialize
682716
683717def add(debugger, *, category, regex=False, type, identifier=None, synth=False, inline_children=False, expand=False, summary=False):
......@@ -729,3 +763,6 @@ def __lldb_init_module(debugger, _=None):
729763 add(debugger, category='zig.stage2', type='InternPool.Key.Ptr.Addr', identifier='zig_TaggedUnion', synth=True)
730764 add(debugger, category='zig.stage2', type='InternPool.Key.Aggregate.Storage', identifier='zig_TaggedUnion', synth=True)
731765 add(debugger, category='zig.stage2', type='arch.x86_64.CodeGen.MCValue', identifier='zig_TaggedUnion', synth=True, inline_children=True, summary=True)
766
767 # Initialize Zig Stage2 Compiler (compiled with the self-hosted backend)
768 add(debugger, category='zig', regex=True, type='^root\\.InternPool\\.Local\\.List\\(.*\\)$', identifier='root_InternPool_Local_List', synth=True, expand=True, summary='capacity=${var%#}')