authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-12-16 15:11:15-05:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-12-16 17:25:52-05:00
log8c0628d0e290c7c1168c52c3adb408b48b48f8d0
tree6af53c90432621a72e37062e2e11e528a621b0b7
parent5af740465597c3bcee3d26adbc7b1994d40df0f1

Dwarf: include comptime-only values in debug info


5 files changed, 1001 insertions(+), 203 deletions(-)

lib/std/dwarf/AT.zig+2
...@@ -224,6 +224,8 @@ pub const ZIG_parent = 0x2ccd;...@@ -224,6 +224,8 @@ pub const ZIG_parent = 0x2ccd;
224pub const ZIG_padding = 0x2cce;224pub const ZIG_padding = 0x2cce;
225pub const ZIG_relative_decl = 0x2cd0;225pub const ZIG_relative_decl = 0x2cd0;
226pub const ZIG_decl_line_relative = 0x2cd1;226pub const ZIG_decl_line_relative = 0x2cd1;
227pub const ZIG_comptime_value = 0x2cd2;
228pub const ZIG_comptime_default_value = 0x2cd3;
227pub const ZIG_sentinel = 0x2ce2;229pub const ZIG_sentinel = 0x2ce2;
228230
229// UPC extension.231// UPC extension.
lib/std/dwarf/TAG.zig+1
...@@ -119,3 +119,4 @@ pub const PGI_interface_block = 0xA020;...@@ -119,3 +119,4 @@ pub const PGI_interface_block = 0xA020;
119119
120// ZIG extensions.120// ZIG extensions.
121pub const ZIG_padding = 0xfdb1;121pub const ZIG_padding = 0xfdb1;
122pub const ZIG_comptime_value = 0xfdb2;
src/InternPool.zig+72-3
...@@ -4704,9 +4704,45 @@ pub const Index = enum(u32) {...@@ -4704,9 +4704,45 @@ pub const Index = enum(u32) {
4704 }4704 }
47054705
4706 comptime {4706 comptime {
4707 if (builtin.zig_backend == .stage2_llvm and !builtin.strip_debug_info) {4707 if (!builtin.strip_debug_info) switch (builtin.zig_backend) {
4708 _ = &dbHelper;4708 .stage2_llvm => _ = &dbHelper,
4709 }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 };
4710 }4746 }
4711};4747};
47124748
...@@ -5302,6 +5338,39 @@ pub const Tag = enum(u8) {...@@ -5302,6 +5338,39 @@ pub const Tag = enum(u8) {
5302 };5338 };
5303 }5339 }
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
5305 pub const Variable = struct {5374 pub const Variable = struct {
5306 ty: Index,5375 ty: Index,
5307 /// May be `none`.5376 /// May be `none`.
src/Type.zig+1
...@@ -4126,6 +4126,7 @@ pub const @"anyframe": Type = .{ .ip_index = .anyframe_type };...@@ -4126,6 +4126,7 @@ pub const @"anyframe": Type = .{ .ip_index = .anyframe_type };
4126pub const @"null": Type = .{ .ip_index = .null_type };4126pub const @"null": Type = .{ .ip_index = .null_type };
4127pub const @"undefined": Type = .{ .ip_index = .undefined_type };4127pub const @"undefined": Type = .{ .ip_index = .undefined_type };
4128pub const @"noreturn": Type = .{ .ip_index = .noreturn_type };4128pub const @"noreturn": Type = .{ .ip_index = .noreturn_type };
4129pub const enum_literal: Type = .{ .ip_index = .enum_literal_type };
41294130
4130pub const @"c_char": Type = .{ .ip_index = .c_char_type };4131pub const @"c_char": Type = .{ .ip_index = .c_char_type };
4131pub const @"c_short": Type = .{ .ip_index = .c_short_type };4132pub const @"c_short": Type = .{ .ip_index = .c_short_type };
src/link/Dwarf.zig+925-200
...@@ -6,6 +6,7 @@ address_size: AddressSize,...@@ -6,6 +6,7 @@ address_size: AddressSize,
66
7mods: std.AutoArrayHashMapUnmanaged(*Module, ModInfo),7mods: std.AutoArrayHashMapUnmanaged(*Module, ModInfo),
8types: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index),8types: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index),
9values: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index),
9navs: std.AutoArrayHashMapUnmanaged(InternPool.Nav.Index, Entry.Index),10navs: std.AutoArrayHashMapUnmanaged(InternPool.Nav.Index, Entry.Index),
1011
11debug_abbrev: DebugAbbrev,12debug_abbrev: DebugAbbrev,
...@@ -1055,6 +1056,11 @@ pub const Loc = union(enum) {...@@ -1055,6 +1056,11 @@ pub const Loc = union(enum) {
1055 form_tls_address: *const Loc,1056 form_tls_address: *const Loc,
1056 implicit_value: []const u8,1057 implicit_value: []const u8,
1057 stack_value: *const Loc,1058 stack_value: *const Loc,
1059 implicit_pointer: struct {
1060 unit: Unit.Index,
1061 entry: Entry.Index,
1062 offset: i65,
1063 },
1058 wasm_ext: union(enum) {1064 wasm_ext: union(enum) {
1059 local: u32,1065 local: u32,
1060 global: u32,1066 global: u32,
...@@ -1193,6 +1199,11 @@ pub const Loc = union(enum) {...@@ -1193,6 +1199,11 @@ pub const Loc = union(enum) {
1193 try value.write(adapter);1199 try value.write(adapter);
1194 try writer.writeByte(DW.OP.stack_value);1200 try writer.writeByte(DW.OP.stack_value);
1195 },1201 },
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 },
1196 .wasm_ext => |wasm_ext| {1207 .wasm_ext => |wasm_ext| {
1197 try writer.writeByte(DW.OP.WASM_location);1208 try writer.writeByte(DW.OP.WASM_location);
1198 switch (wasm_ext) {1209 switch (wasm_ext) {
...@@ -1386,7 +1397,7 @@ pub const WipNav = struct {...@@ -1386,7 +1397,7 @@ pub const WipNav = struct {
1386 debug_info: std.ArrayListUnmanaged(u8),1397 debug_info: std.ArrayListUnmanaged(u8),
1387 debug_line: std.ArrayListUnmanaged(u8),1398 debug_line: std.ArrayListUnmanaged(u8),
1388 debug_loclists: std.ArrayListUnmanaged(u8),1399 debug_loclists: std.ArrayListUnmanaged(u8),
1389 pending_types: std.ArrayListUnmanaged(InternPool.Index),1400 pending_lazy: std.ArrayListUnmanaged(InternPool.Index),
13901401
1391 pub fn deinit(wip_nav: *WipNav) void {1402 pub fn deinit(wip_nav: *WipNav) void {
1392 const gpa = wip_nav.dwarf.gpa;1403 const gpa = wip_nav.dwarf.gpa;
...@@ -1395,7 +1406,7 @@ pub const WipNav = struct {...@@ -1395,7 +1406,7 @@ pub const WipNav = struct {
1395 wip_nav.debug_info.deinit(gpa);1406 wip_nav.debug_info.deinit(gpa);
1396 wip_nav.debug_line.deinit(gpa);1407 wip_nav.debug_line.deinit(gpa);
1397 wip_nav.debug_loclists.deinit(gpa);1408 wip_nav.debug_loclists.deinit(gpa);
1398 wip_nav.pending_types.deinit(gpa);1409 wip_nav.pending_lazy.deinit(gpa);
1399 }1410 }
14001411
1401 pub fn genDebugFrame(wip_nav: *WipNav, loc: u32, cfa: Cfa) UpdateError!void {1412 pub fn genDebugFrame(wip_nav: *WipNav, loc: u32, cfa: Cfa) UpdateError!void {
...@@ -1420,7 +1431,7 @@ pub const WipNav = struct {...@@ -1420,7 +1431,7 @@ pub const WipNav = struct {
1420 });1431 });
1421 try wip_nav.strp(name);1432 try wip_nav.strp(name);
1422 try wip_nav.refType(ty);1433 try wip_nav.refType(ty);
1423 try wip_nav.exprloc(loc);1434 try wip_nav.infoExprloc(loc);
1424 wip_nav.any_children = true;1435 wip_nav.any_children = true;
1425 }1436 }
14261437
...@@ -1627,33 +1638,39 @@ pub const WipNav = struct {...@@ -1627,33 +1638,39 @@ pub const WipNav = struct {
1627 try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), try wip_nav.dwarf.refAbbrevCode(abbrev_code));1638 try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), try wip_nav.dwarf.refAbbrevCode(abbrev_code));
1628 }1639 }
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 {
1631 const dwarf = wip_nav.dwarf;1642 const dwarf = wip_nav.dwarf;
1632 const gpa = dwarf.gpa;1643 const gpa = dwarf.gpa;
1633 const entry_ptr = dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry);1644 const entry_ptr = @field(dwarf, @tagName(sec)).section.getUnit(wip_nav.unit).getEntry(wip_nav.entry);
1634 if (sec != .debug_info) {1645 const bytes = &@field(wip_nav, @tagName(sec));
1646 const source_off: u32 = @intCast(bytes.items.len);
1647 if (target_sec != sec) {
1635 try entry_ptr.cross_section_relocs.append(gpa, .{1648 try entry_ptr.cross_section_relocs.append(gpa, .{
1636 .source_off = @intCast(wip_nav.debug_info.items.len),1649 .source_off = source_off,
1637 .target_sec = sec,1650 .target_sec = target_sec,
1638 .target_unit = unit,1651 .target_unit = target_unit,
1639 .target_entry = entry.toOptional(),1652 .target_entry = target_entry.toOptional(),
1640 .target_off = off,1653 .target_off = target_off,
1641 });1654 });
1642 } else if (unit != wip_nav.unit) {1655 } else if (target_unit != wip_nav.unit) {
1643 try entry_ptr.cross_unit_relocs.append(gpa, .{1656 try entry_ptr.cross_unit_relocs.append(gpa, .{
1644 .source_off = @intCast(wip_nav.debug_info.items.len),1657 .source_off = source_off,
1645 .target_unit = unit,1658 .target_unit = target_unit,
1646 .target_entry = entry.toOptional(),1659 .target_entry = target_entry.toOptional(),
1647 .target_off = off,1660 .target_off = target_off,
1648 });1661 });
1649 } else {1662 } else {
1650 try entry_ptr.cross_entry_relocs.append(gpa, .{1663 try entry_ptr.cross_entry_relocs.append(gpa, .{
1651 .source_off = @intCast(wip_nav.debug_info.items.len),1664 .source_off = source_off,
1652 .target_entry = entry.toOptional(),1665 .target_entry = target_entry.toOptional(),
1653 .target_off = off,1666 .target_off = target_off,
1654 });1667 });
1655 }1668 }
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);
1657 }1674 }
16581675
1659 fn strp(wip_nav: *WipNav, str: []const u8) UpdateError!void {1676 fn strp(wip_nav: *WipNav, str: []const u8) UpdateError!void {
...@@ -1663,7 +1680,15 @@ pub const WipNav = struct {...@@ -1663,7 +1680,15 @@ pub const WipNav = struct {
1663 const ExprLocCounter = struct {1680 const ExprLocCounter = struct {
1664 const Stream = std.io.CountingWriter(std.io.NullWriter);1681 const Stream = std.io.CountingWriter(std.io.NullWriter);
1665 stream: Stream,1682 stream: Stream,
1683 section_offset_bytes: u32,
1666 address_size: AddressSize,1684 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 }
1667 fn writer(counter: *ExprLocCounter) Stream.Writer {1692 fn writer(counter: *ExprLocCounter) Stream.Writer {
1668 return counter.stream.writer();1693 return counter.stream.writer();
1669 }1694 }
...@@ -1673,13 +1698,13 @@ pub const WipNav = struct {...@@ -1673,13 +1698,13 @@ pub const WipNav = struct {
1673 fn addrSym(counter: *ExprLocCounter, _: u32) error{}!void {1698 fn addrSym(counter: *ExprLocCounter, _: u32) error{}!void {
1674 counter.stream.bytes_written += @intFromEnum(counter.address_size);1699 counter.stream.bytes_written += @intFromEnum(counter.address_size);
1675 }1700 }
1701 fn infoEntry(counter: *ExprLocCounter, _: Unit.Index, _: Entry.Index) error{}!void {
1702 counter.stream.bytes_written += counter.section_offset_bytes;
1703 }
1676 };1704 };
16771705
1678 fn exprloc(wip_nav: *WipNav, loc: Loc) UpdateError!void {1706 fn infoExprloc(wip_nav: *WipNav, loc: Loc) UpdateError!void {
1679 var counter: ExprLocCounter = .{1707 var counter: ExprLocCounter = .init(wip_nav.dwarf);
1680 .stream = std.io.countingWriter(std.io.null_writer),
1681 .address_size = wip_nav.dwarf.address_size,
1682 };
1683 try loc.write(&counter);1708 try loc.write(&counter);
16841709
1685 const adapter: struct {1710 const adapter: struct {
...@@ -1693,6 +1718,9 @@ pub const WipNav = struct {...@@ -1693,6 +1718,9 @@ pub const WipNav = struct {
1693 fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void {1718 fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void {
1694 try ctx.wip_nav.infoAddrSym(sym_index, 0);1719 try ctx.wip_nav.infoAddrSym(sym_index, 0);
1695 }1720 }
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 }
1696 } = .{ .wip_nav = wip_nav };1724 } = .{ .wip_nav = wip_nav };
1697 try uleb128(adapter.writer(), counter.stream.bytes_written);1725 try uleb128(adapter.writer(), counter.stream.bytes_written);
1698 try loc.write(adapter);1726 try loc.write(adapter);
...@@ -1708,10 +1736,7 @@ pub const WipNav = struct {...@@ -1708,10 +1736,7 @@ pub const WipNav = struct {
1708 }1736 }
17091737
1710 fn frameExprloc(wip_nav: *WipNav, loc: Loc) UpdateError!void {1738 fn frameExprloc(wip_nav: *WipNav, loc: Loc) UpdateError!void {
1711 var counter: ExprLocCounter = .{1739 var counter: ExprLocCounter = .init(wip_nav.dwarf);
1712 .stream = std.io.countingWriter(std.io.null_writer),
1713 .address_size = wip_nav.dwarf.address_size,
1714 };
1715 try loc.write(&counter);1740 try loc.write(&counter);
17161741
1717 const adapter: struct {1742 const adapter: struct {
...@@ -1725,6 +1750,9 @@ pub const WipNav = struct {...@@ -1725,6 +1750,9 @@ pub const WipNav = struct {
1725 fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void {1750 fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void {
1726 try ctx.wip_nav.frameAddrSym(sym_index, 0);1751 try ctx.wip_nav.frameAddrSym(sym_index, 0);
1727 }1752 }
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 }
1728 } = .{ .wip_nav = wip_nav };1756 } = .{ .wip_nav = wip_nav };
1729 try uleb128(adapter.writer(), counter.stream.bytes_written);1757 try uleb128(adapter.writer(), counter.stream.bytes_written);
1730 try loc.write(adapter);1758 try loc.write(adapter);
...@@ -1739,6 +1767,22 @@ pub const WipNav = struct {...@@ -1739,6 +1767,22 @@ pub const WipNav = struct {
1739 try wip_nav.debug_frame.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size));1767 try wip_nav.debug_frame.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size));
1740 }1768 }
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
1742 fn getTypeEntry(wip_nav: *WipNav, ty: Type) UpdateError!struct { Unit.Index, Entry.Index } {1786 fn getTypeEntry(wip_nav: *WipNav, ty: Type) UpdateError!struct { Unit.Index, Entry.Index } {
1743 const zcu = wip_nav.pt.zcu;1787 const zcu = wip_nav.pt.zcu;
1744 const ip = &zcu.intern_pool;1788 const ip = &zcu.intern_pool;
...@@ -1751,7 +1795,7 @@ pub const WipNav = struct {...@@ -1751,7 +1795,7 @@ pub const WipNav = struct {
1751 if (gop.found_existing) return .{ unit, gop.value_ptr.* };1795 if (gop.found_existing) return .{ unit, gop.value_ptr.* };
1752 const entry = try wip_nav.dwarf.addCommonEntry(unit);1796 const entry = try wip_nav.dwarf.addCommonEntry(unit);
1753 gop.value_ptr.* = entry;1797 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());
1755 return .{ unit, entry };1799 return .{ unit, entry };
1756 }1800 }
17571801
...@@ -1760,13 +1804,25 @@ pub const WipNav = struct {...@@ -1760,13 +1804,25 @@ pub const WipNav = struct {
1760 try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0);1804 try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0);
1761 }1805 }
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 } {
1764 const zcu = wip_nav.pt.zcu;1808 const zcu = wip_nav.pt.zcu;
1765 const ip = &zcu.intern_pool;1809 const ip = &zcu.intern_pool;
1766 const unit = try wip_nav.dwarf.getUnit(zcu.fileByIndex(ip.getNav(nav_index).srcInst(ip).resolveFile(ip)).mod);1810 const ty = value.typeOf(zcu);
1767 const nav_gop = try wip_nav.dwarf.navs.getOrPut(wip_nav.dwarf.gpa, nav_index);1811 if (std.debug.runtime_safety) assert(ty.comptimeOnly(zcu) and try ty.onePossibleValue(wip_nav.pt) == null);
1768 if (!nav_gop.found_existing) nav_gop.value_ptr.* = try wip_nav.dwarf.addCommonEntry(unit);1812 if (ty.toIntern() == .type_type) return wip_nav.getTypeEntry(value.toType());
1769 try wip_nav.infoSectionOffset(.debug_info, unit, nav_gop.value_ptr.*, 0);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);
1770 }1826 }
17711827
1772 fn refForward(wip_nav: *WipNav) std.mem.Allocator.Error!u32 {1828 fn refForward(wip_nav: *WipNav) std.mem.Allocator.Error!u32 {
...@@ -1809,73 +1865,81 @@ pub const WipNav = struct {...@@ -1809,73 +1865,81 @@ pub const WipNav = struct {
1809 }1865 }
1810 }1866 }
18111867
1812 fn enumConstValue(1868 const AbbrevCodeForForm = struct {
1869 sdata: AbbrevCode,
1870 udata: AbbrevCode,
1871 block: AbbrevCode,
1872 };
1873
1874 fn bigIntConstValue(
1813 wip_nav: *WipNav,1875 wip_nav: *WipNav,
1814 loaded_enum: InternPool.LoadedEnumType,1876 abbrev_code: AbbrevCodeForForm,
1815 abbrev_code: struct {1877 ty: Type,
1816 sdata: AbbrevCode,1878 big_int: std.math.big.int.Const,
1817 udata: AbbrevCode,
1818 block: AbbrevCode,
1819 },
1820 field_index: usize,
1821 ) UpdateError!void {1879 ) UpdateError!void {
1822 const zcu = wip_nav.pt.zcu;1880 const zcu = wip_nav.pt.zcu;
1823 const ip = &zcu.intern_pool;
1824 const diw = wip_nav.debug_info.writer(wip_nav.dwarf.gpa);1881 const diw = wip_nav.debug_info.writer(wip_nav.dwarf.gpa);
1825 const signedness = switch (loaded_enum.tag_ty) {1882 const signedness = switch (ty.toIntern()) {
1826 .comptime_int_type => .signed,1883 .comptime_int_type, .comptime_float_type => .signed,
1827 else => Type.fromInterned(loaded_enum.tag_ty).intInfo(zcu).signedness,1884 else => ty.intInfo(zcu).signedness,
1828 };1885 };
1829 if (loaded_enum.values.len > 0) {1886 const bits = @max(1, big_int.bitCountTwosCompForSignedness(signedness));
1830 var big_int_space: Value.BigIntSpace = undefined;1887 if (bits <= 64) {
1831 const big_int = ip.indexToKey(loaded_enum.values.get(ip)[field_index]).int.storage.toBigInt(&big_int_space);1888 try wip_nav.abbrevCode(switch (signedness) {
1832 const bits = @max(1, big_int.bitCountTwosCompForSignedness(signedness));1889 .signed => abbrev_code.sdata,
1833 if (bits <= 64) {1890 .unsigned => abbrev_code.udata,
1834 try wip_nav.abbrevCode(switch (signedness) {1891 });
1835 .signed => abbrev_code.sdata,1892 try wip_nav.debug_info.ensureUnusedCapacity(wip_nav.dwarf.gpa, std.math.divCeil(usize, bits, 7) catch unreachable);
1836 .unsigned => abbrev_code.udata,1893 var bit: usize = 0;
1837 });1894 var carry: u1 = 1;
1838 try wip_nav.debug_info.ensureUnusedCapacity(wip_nav.dwarf.gpa, std.math.divCeil(usize, bits, 7) catch unreachable);1895 while (bit < bits) {
1839 var bit: usize = 0;1896 const limb_bits = @typeInfo(std.math.big.Limb).int.bits;
1840 var carry: u1 = 1;1897 const limb_index = bit / limb_bits;
1841 while (bit < bits) : (bit += 7) {1898 const limb_shift: std.math.Log2Int(std.math.big.Limb) = @intCast(bit % limb_bits);
1842 const limb_bits = @typeInfo(std.math.big.Limb).int.bits;1899 const low_abs_part: u7 = @truncate(big_int.limbs[limb_index] >> limb_shift);
1843 const limb_index = bit / limb_bits;1900 const abs_part = if (limb_shift > limb_bits - 7 and limb_index + 1 < big_int.limbs.len) abs_part: {
1844 const limb_shift: std.math.Log2Int(std.math.big.Limb) = @intCast(bit % limb_bits);1901 const high_abs_part: u7 = @truncate(big_int.limbs[limb_index + 1] << -%limb_shift);
1845 const low_abs_part: u7 = @truncate(big_int.limbs[limb_index] >> limb_shift);1902 break :abs_part high_abs_part | low_abs_part;
1846 const abs_part = if (limb_shift > limb_bits - 7 and limb_index + 1 < big_int.limbs.len) abs_part: {1903 } else low_abs_part;
1847 const high_abs_part: u7 = @truncate(big_int.limbs[limb_index + 1] << -%limb_shift);1904 const twos_comp_part = if (big_int.positive) abs_part else twos_comp_part: {
1848 break :abs_part high_abs_part | low_abs_part;1905 const twos_comp_part, carry = @addWithOverflow(~abs_part, carry);
1849 } else low_abs_part;1906 break :twos_comp_part twos_comp_part;
1850 const twos_comp_part = if (big_int.positive) abs_part else twos_comp_part: {1907 };
1851 const twos_comp_part, carry = @addWithOverflow(~abs_part, carry);1908 bit += 7;
1852 break :twos_comp_part twos_comp_part;1909 wip_nav.debug_info.appendAssumeCapacity(@as(u8, if (bit < bits) 0x80 else 0x00) | 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 );
1864 }1910 }
1865 } else switch (signedness) {1911 } else {
1866 .signed => {1912 try wip_nav.abbrevCode(abbrev_code.block);
1867 try wip_nav.abbrevCode(abbrev_code.sdata);1913 const bytes = @max(ty.abiSize(zcu), std.math.divCeil(usize, bits, 8) catch unreachable);
1868 try sleb128(diw, field_index);1914 try uleb128(diw, bytes);
1869 },1915 big_int.writeTwosComplement(
1870 .unsigned => {1916 try wip_nav.debug_info.addManyAsSlice(wip_nav.dwarf.gpa, @intCast(bytes)),
1871 try wip_nav.abbrevCode(abbrev_code.udata);1917 wip_nav.dwarf.endian,
1872 try uleb128(diw, field_index);1918 );
1873 },
1874 }1919 }
1875 }1920 }
18761921
1877 fn flush(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc) UpdateError!void {1922 fn enumConstValue(
1878 while (wip_nav.pending_types.popOrNull()) |ty| try wip_nav.dwarf.updateType(wip_nav.pt, src_loc, ty, &wip_nav.pending_types);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 };
1879 }1943 }
1880};1944};
18811945
...@@ -1904,6 +1968,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {...@@ -1904,6 +1968,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {
19041968
1905 .mods = .{},1969 .mods = .{},
1906 .types = .{},1970 .types = .{},
1971 .values = .{},
1907 .navs = .{},1972 .navs = .{},
19081973
1909 .debug_abbrev = .{ .section = Section.init },1974 .debug_abbrev = .{ .section = Section.init },
...@@ -2075,6 +2140,7 @@ pub fn deinit(dwarf: *Dwarf) void {...@@ -2075,6 +2140,7 @@ pub fn deinit(dwarf: *Dwarf) void {
2075 for (dwarf.mods.values()) |*mod_info| mod_info.deinit(gpa);2140 for (dwarf.mods.values()) |*mod_info| mod_info.deinit(gpa);
2076 dwarf.mods.deinit(gpa);2141 dwarf.mods.deinit(gpa);
2077 dwarf.types.deinit(gpa);2142 dwarf.types.deinit(gpa);
2143 dwarf.values.deinit(gpa);
2078 dwarf.navs.deinit(gpa);2144 dwarf.navs.deinit(gpa);
2079 dwarf.debug_abbrev.section.deinit(gpa);2145 dwarf.debug_abbrev.section.deinit(gpa);
2080 dwarf.debug_aranges.section.deinit(gpa);2146 dwarf.debug_aranges.section.deinit(gpa);
...@@ -2186,7 +2252,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2186,7 +2252,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
2186 .debug_info = .{},2252 .debug_info = .{},
2187 .debug_line = .{},2253 .debug_line = .{},
2188 .debug_loclists = .{},2254 .debug_loclists = .{},
2189 .pending_types = .{},2255 .pending_lazy = .{},
2190 };2256 };
2191 errdefer wip_nav.deinit();2257 errdefer wip_nav.deinit();
21922258
...@@ -2223,7 +2289,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2223,7 +2289,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
22232289
2224 const diw = wip_nav.debug_info.writer(dwarf.gpa);2290 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2225 try wip_nav.abbrevCode(.decl_var);2291 try wip_nav.abbrevCode(.decl_var);
2226 try wip_nav.refType(Type.fromInterned(parent_type));2292 try wip_nav.refType(.fromInterned(parent_type));
2227 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2293 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2228 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2294 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2229 try uleb128(diw, loc.column + 1);2295 try uleb128(diw, loc.column + 1);
...@@ -2232,7 +2298,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2232,7 +2298,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
2232 try wip_nav.strp(nav.fqn.toSlice(ip));2298 try wip_nav.strp(nav.fqn.toSlice(ip));
2233 const nav_ty = nav_val.typeOf(zcu);2299 const nav_ty = nav_val.typeOf(zcu);
2234 const nav_ty_reloc_index = try wip_nav.refForward();2300 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 } });
2236 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse2302 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
2237 nav_ty.abiAlignment(zcu).toByteUnits().?);2303 nav_ty.abiAlignment(zcu).toByteUnits().?);
2238 try diw.writeByte(@intFromBool(false));2304 try diw.writeByte(@intFromBool(false));
...@@ -2272,17 +2338,17 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2272,17 +2338,17 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
22722338
2273 const diw = wip_nav.debug_info.writer(dwarf.gpa);2339 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2274 try wip_nav.abbrevCode(.decl_var);2340 try wip_nav.abbrevCode(.decl_var);
2275 try wip_nav.refType(Type.fromInterned(parent_type));2341 try wip_nav.refType(.fromInterned(parent_type));
2276 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2342 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2277 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2343 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2278 try uleb128(diw, loc.column + 1);2344 try uleb128(diw, loc.column + 1);
2279 try diw.writeByte(accessibility);2345 try diw.writeByte(accessibility);
2280 try wip_nav.strp(nav.name.toSlice(ip));2346 try wip_nav.strp(nav.name.toSlice(ip));
2281 try wip_nav.strp(nav.fqn.toSlice(ip));2347 try wip_nav.strp(nav.fqn.toSlice(ip));
2282 const ty = Type.fromInterned(variable.ty);2348 const ty: Type = .fromInterned(variable.ty);
2283 try wip_nav.refType(ty);2349 try wip_nav.refType(ty);
2284 const addr: Loc = .{ .addr = .{ .sym = sym_index } };2350 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);
2286 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse2352 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
2287 ty.abiAlignment(zcu).toByteUnits().?);2353 ty.abiAlignment(zcu).toByteUnits().?);
2288 try diw.writeByte(@intFromBool(false));2354 try diw.writeByte(@intFromBool(false));
...@@ -2364,14 +2430,14 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2364,14 +2430,14 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
23642430
2365 const diw = wip_nav.debug_info.writer(dwarf.gpa);2431 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2366 try wip_nav.abbrevCode(.decl_func);2432 try wip_nav.abbrevCode(.decl_func);
2367 try wip_nav.refType(Type.fromInterned(parent_type));2433 try wip_nav.refType(.fromInterned(parent_type));
2368 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2434 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2369 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2435 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2370 try uleb128(diw, loc.column + 1);2436 try uleb128(diw, loc.column + 1);
2371 try diw.writeByte(accessibility);2437 try diw.writeByte(accessibility);
2372 try wip_nav.strp(nav.name.toSlice(ip));2438 try wip_nav.strp(nav.name.toSlice(ip));
2373 try wip_nav.strp(nav.fqn.toSlice(ip));2439 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));
2375 try wip_nav.infoAddrSym(sym_index, 0);2441 try wip_nav.infoAddrSym(sym_index, 0);
2376 wip_nav.func_high_pc = @intCast(wip_nav.debug_info.items.len);2442 wip_nav.func_high_pc = @intCast(wip_nav.debug_info.items.len);
2377 try diw.writeInt(u32, 0, dwarf.endian);2443 try diw.writeInt(u32, 0, dwarf.endian);
...@@ -2525,7 +2591,7 @@ pub fn finishWipNav(...@@ -2525,7 +2591,7 @@ pub fn finishWipNav(
2525 }2591 }
2526 try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.items);2592 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));
2529}2595}
25302596
2531pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) UpdateError!void {2597pub 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...@@ -2586,7 +2652,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2586 .debug_info = .{},2652 .debug_info = .{},
2587 .debug_line = .{},2653 .debug_line = .{},
2588 .debug_loclists = .{},2654 .debug_loclists = .{},
2589 .pending_types = .{},2655 .pending_lazy = .{},
2590 };2656 };
2591 defer wip_nav.deinit();2657 defer wip_nav.deinit();
25922658
...@@ -2648,7 +2714,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2648,7 +2714,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2648 switch (loaded_struct.layout) {2714 switch (loaded_struct.layout) {
2649 .auto, .@"extern" => {2715 .auto, .@"extern" => {
2650 try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .decl_namespace_struct else .decl_struct);2716 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));
2652 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2718 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2653 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2719 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2654 try uleb128(diw, loc.column + 1);2720 try uleb128(diw, loc.column + 1);
...@@ -2661,43 +2727,65 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2661,43 +2727,65 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2661 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);2727 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
2662 const field_init = loaded_struct.fieldInit(ip, field_index);2728 const field_init = loaded_struct.fieldInit(ip, field_index);
2663 assert(!(is_comptime and field_init == .none));2729 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 };
2664 try wip_nav.abbrevCode(if (is_comptime)2738 try wip_nav.abbrevCode(if (is_comptime)
2665 .struct_field_comptime2739 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
2666 else if (field_init != .none)2747 else if (field_init != .none)
2667 .struct_field_default2748 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
2668 else2756 else
2669 .struct_field);2757 .struct_field);
2670 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {2758 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});2759 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
2672 defer dwarf.gpa.free(field_name);2760 const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{field_index}) catch unreachable;
2673 try wip_nav.strp(field_name);2761 try wip_nav.strp(field_name);
2674 }2762 }
2675 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2676 try wip_nav.refType(field_type);2763 try wip_nav.refType(field_type);
2677 if (!is_comptime) {2764 if (!is_comptime) {
2678 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);2765 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
2679 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse2766 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
2680 field_type.abiAlignment(zcu).toByteUnits().?);2767 field_type.abiAlignment(zcu).toByteUnits().?);
2681 }2768 }
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));
2683 }2771 }
2684 try uleb128(diw, @intFromEnum(AbbrevCode.null));2772 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2685 }2773 }
2686 },2774 },
2687 .@"packed" => {2775 .@"packed" => {
2688 try wip_nav.abbrevCode(.decl_packed_struct);2776 try wip_nav.abbrevCode(.decl_packed_struct);
2689 try wip_nav.refType(Type.fromInterned(parent_type));2777 try wip_nav.refType(.fromInterned(parent_type));
2690 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2778 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2691 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2779 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2692 try uleb128(diw, loc.column + 1);2780 try uleb128(diw, loc.column + 1);
2693 try diw.writeByte(accessibility);2781 try diw.writeByte(accessibility);
2694 try wip_nav.strp(nav.name.toSlice(ip));2782 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)));
2696 var field_bit_offset: u16 = 0;2784 var field_bit_offset: u16 = 0;
2697 for (0..loaded_struct.field_types.len) |field_index| {2785 for (0..loaded_struct.field_types.len) |field_index| {
2698 try wip_nav.abbrevCode(.packed_struct_field);2786 try wip_nav.abbrevCode(.packed_struct_field);
2699 try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip));2787 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]);
2701 try wip_nav.refType(field_type);2789 try wip_nav.refType(field_type);
2702 try uleb128(diw, field_bit_offset);2790 try uleb128(diw, field_bit_offset);
2703 field_bit_offset += @intCast(field_type.bitSize(zcu));2791 field_bit_offset += @intCast(field_type.bitSize(zcu));
...@@ -2745,13 +2833,13 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2745,13 +2833,13 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2745 wip_nav.entry = nav_gop.value_ptr.*;2833 wip_nav.entry = nav_gop.value_ptr.*;
2746 const diw = wip_nav.debug_info.writer(dwarf.gpa);2834 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2747 try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .decl_enum else .decl_empty_enum);2835 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));
2749 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2837 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2750 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2838 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2751 try uleb128(diw, loc.column + 1);2839 try uleb128(diw, loc.column + 1);
2752 try diw.writeByte(accessibility);2840 try diw.writeByte(accessibility);
2753 try wip_nav.strp(nav.name.toSlice(ip));2841 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));
2755 for (0..loaded_enum.names.len) |field_index| {2843 for (0..loaded_enum.names.len) |field_index| {
2756 try wip_nav.enumConstValue(loaded_enum, .{2844 try wip_nav.enumConstValue(loaded_enum, .{
2757 .sdata = .signed_enum_field,2845 .sdata = .signed_enum_field,
...@@ -2800,7 +2888,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2800,7 +2888,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2800 wip_nav.entry = nav_gop.value_ptr.*;2888 wip_nav.entry = nav_gop.value_ptr.*;
2801 const diw = wip_nav.debug_info.writer(dwarf.gpa);2889 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2802 try wip_nav.abbrevCode(.decl_union);2890 try wip_nav.abbrevCode(.decl_union);
2803 try wip_nav.refType(Type.fromInterned(parent_type));2891 try wip_nav.refType(.fromInterned(parent_type));
2804 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2892 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2805 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2893 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2806 try uleb128(diw, loc.column + 1);2894 try uleb128(diw, loc.column + 1);
...@@ -2821,7 +2909,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2821,7 +2909,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2821 {2909 {
2822 try wip_nav.abbrevCode(.generated_field);2910 try wip_nav.abbrevCode(.generated_field);
2823 try wip_nav.strp("tag");2911 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));
2825 try uleb128(diw, union_layout.tagOffset());2913 try uleb128(diw, union_layout.tagOffset());
28262914
2827 for (0..loaded_union.field_types.len) |field_index| {2915 for (0..loaded_union.field_types.len) |field_index| {
...@@ -2833,7 +2921,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2833,7 +2921,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2833 {2921 {
2834 try wip_nav.abbrevCode(.struct_field);2922 try wip_nav.abbrevCode(.struct_field);
2835 try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip));2923 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]);
2837 try wip_nav.refType(field_type);2925 try wip_nav.refType(field_type);
2838 try uleb128(diw, union_layout.payloadOffset());2926 try uleb128(diw, union_layout.payloadOffset());
2839 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse2927 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...@@ -2846,7 +2934,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2846 } else for (0..loaded_union.field_types.len) |field_index| {2934 } else for (0..loaded_union.field_types.len) |field_index| {
2847 try wip_nav.abbrevCode(.untagged_union_field);2935 try wip_nav.abbrevCode(.untagged_union_field);
2848 try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip));2936 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]);
2850 try wip_nav.refType(field_type);2938 try wip_nav.refType(field_type);
2851 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse2939 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
2852 field_type.abiAlignment(zcu).toByteUnits().?);2940 field_type.abiAlignment(zcu).toByteUnits().?);
...@@ -2891,7 +2979,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2891,7 +2979,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2891 wip_nav.entry = nav_gop.value_ptr.*;2979 wip_nav.entry = nav_gop.value_ptr.*;
2892 const diw = wip_nav.debug_info.writer(dwarf.gpa);2980 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2893 try wip_nav.abbrevCode(.decl_namespace_struct);2981 try wip_nav.abbrevCode(.decl_namespace_struct);
2894 try wip_nav.refType(Type.fromInterned(parent_type));2982 try wip_nav.refType(.fromInterned(parent_type));
2895 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2983 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2896 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2984 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2897 try uleb128(diw, loc.column + 1);2985 try uleb128(diw, loc.column + 1);
...@@ -2947,17 +3035,17 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2947,17 +3035,17 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2947 .decl_func_generic3035 .decl_func_generic
2948 else3036 else
2949 .decl_empty_func_generic);3037 .decl_empty_func_generic);
2950 try wip_nav.refType(Type.fromInterned(parent_type));3038 try wip_nav.refType(.fromInterned(parent_type));
2951 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));3039 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2952 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);3040 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2953 try uleb128(diw, loc.column + 1);3041 try uleb128(diw, loc.column + 1);
2954 try diw.writeByte(accessibility);3042 try diw.writeByte(accessibility);
2955 try wip_nav.strp(nav.name.toSlice(ip));3043 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));
2957 if (func_type.param_types.len > 0 or func_type.is_var_args) {3045 if (func_type.param_types.len > 0 or func_type.is_var_args) {
2958 for (0..func_type.param_types.len) |param_index| {3046 for (0..func_type.param_types.len) |param_index| {
2959 try wip_nav.abbrevCode(.func_type_param);3047 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]));
2961 }3049 }
2962 if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args);3050 if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args);
2963 try uleb128(diw, @intFromEnum(AbbrevCode.null));3051 try uleb128(diw, @intFromEnum(AbbrevCode.null));
...@@ -2979,7 +3067,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2979,7 +3067,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2979 .decl_alias => {3067 .decl_alias => {
2980 const diw = wip_nav.debug_info.writer(dwarf.gpa);3068 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2981 try wip_nav.abbrevCode(.decl_alias);3069 try wip_nav.abbrevCode(.decl_alias);
2982 try wip_nav.refType(Type.fromInterned(parent_type));3070 try wip_nav.refType(.fromInterned(parent_type));
2983 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));3071 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2984 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);3072 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2985 try uleb128(diw, loc.column + 1);3073 try uleb128(diw, loc.column + 1);
...@@ -2990,7 +3078,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2990,7 +3078,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2990 .decl_var => {3078 .decl_var => {
2991 const diw = wip_nav.debug_info.writer(dwarf.gpa);3079 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2992 try wip_nav.abbrevCode(.decl_var);3080 try wip_nav.abbrevCode(.decl_var);
2993 try wip_nav.refType(Type.fromInterned(parent_type));3081 try wip_nav.refType(.fromInterned(parent_type));
2994 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));3082 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2995 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);3083 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2996 try uleb128(diw, loc.column + 1);3084 try uleb128(diw, loc.column + 1);
...@@ -3006,42 +3094,52 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -3006,42 +3094,52 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
3006 },3094 },
3007 .decl_const => {3095 .decl_const => {
3008 const diw = wip_nav.debug_info.writer(dwarf.gpa);3096 const diw = wip_nav.debug_info.writer(dwarf.gpa);
3009 try wip_nav.abbrevCode(.decl_const);3097 const nav_ty = nav_val.typeOf(zcu);
3010 try wip_nav.refType(Type.fromInterned(parent_type));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));
3011 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));3109 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
3012 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);3110 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
3013 try uleb128(diw, loc.column + 1);3111 try uleb128(diw, loc.column + 1);
3014 try diw.writeByte(accessibility);3112 try diw.writeByte(accessibility);
3015 try wip_nav.strp(nav.name.toSlice(ip));3113 try wip_nav.strp(nav.name.toSlice(ip));
3016 try wip_nav.strp(nav.fqn.toSlice(ip));3114 try wip_nav.strp(nav.fqn.toSlice(ip));
3017 const nav_ty = nav_val.typeOf(zcu);
3018 const nav_ty_reloc_index = try wip_nav.refForward();3115 const nav_ty_reloc_index = try wip_nav.refForward();
3019 try wip_nav.blockValue(nav_src_loc, nav_val);
3020 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse3116 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
3021 nav_ty.abiAlignment(zcu).toByteUnits().?);3117 nav_ty.abiAlignment(zcu).toByteUnits().?);
3022 try diw.writeByte(@intFromBool(false));3118 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);
3023 wip_nav.finishForward(nav_ty_reloc_index);3121 wip_nav.finishForward(nav_ty_reloc_index);
3024 try wip_nav.abbrevCode(.is_const);3122 try wip_nav.abbrevCode(.is_const);
3025 try wip_nav.refType(nav_ty);3123 try wip_nav.refType(nav_ty);
3026 },3124 },
3027 }3125 }
3028 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);3126 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);
3030}3128}
30313129
3032fn updateType(3130fn updateLazyType(
3033 dwarf: *Dwarf,3131 dwarf: *Dwarf,
3034 pt: Zcu.PerThread,3132 pt: Zcu.PerThread,
3035 src_loc: Zcu.LazySrcLoc,3133 src_loc: Zcu.LazySrcLoc,
3036 type_index: InternPool.Index,3134 type_index: InternPool.Index,
3037 pending_types: *std.ArrayListUnmanaged(InternPool.Index),3135 pending_lazy: *std.ArrayListUnmanaged(InternPool.Index),
3038) UpdateError!void {3136) UpdateError!void {
3039 const zcu = pt.zcu;3137 const zcu = pt.zcu;
3040 const ip = &zcu.intern_pool;3138 const ip = &zcu.intern_pool;
3041 const ty = Type.fromInterned(type_index);3139 const ty: Type = .fromInterned(type_index);
3042 switch (type_index) {3140 switch (type_index) {
3043 .generic_poison_type => log.debug("updateType({s})", .{"anytype"}),3141 .generic_poison_type => log.debug("updateLazyType({s})", .{"anytype"}),
3044 else => log.debug("updateType({})", .{ty.fmt(pt)}),3142 else => log.debug("updateLazyType({})", .{ty.fmt(pt)}),
3045 }3143 }
30463144
3047 var wip_nav: WipNav = .{3145 var wip_nav: WipNav = .{
...@@ -3059,11 +3157,11 @@ fn updateType(...@@ -3059,11 +3157,11 @@ fn updateType(
3059 .debug_info = .{},3157 .debug_info = .{},
3060 .debug_line = .{},3158 .debug_line = .{},
3061 .debug_loclists = .{},3159 .debug_loclists = .{},
3062 .pending_types = pending_types.*,3160 .pending_lazy = pending_lazy.*,
3063 };3161 };
3064 defer {3162 defer {
3065 pending_types.* = wip_nav.pending_types;3163 pending_lazy.* = wip_nav.pending_lazy;
3066 wip_nav.pending_types = .{};3164 wip_nav.pending_lazy = .{};
3067 wip_nav.deinit();3165 wip_nav.deinit();
3068 }3166 }
3069 const diw = wip_nav.debug_info.writer(dwarf.gpa);3167 const diw = wip_nav.debug_info.writer(dwarf.gpa);
...@@ -3086,13 +3184,10 @@ fn updateType(...@@ -3086,13 +3184,10 @@ fn updateType(
3086 },3184 },
3087 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {3185 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
3088 .One, .Many, .C => {3186 .One, .Many, .C => {
3089 const ptr_child_type = Type.fromInterned(ptr_type.child);3187 const ptr_child_type: Type = .fromInterned(ptr_type.child);
3090 try wip_nav.abbrevCode(if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type);3188 try wip_nav.abbrevCode(if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type);
3091 try wip_nav.strp(name);3189 try wip_nav.strp(name);
3092 if (ptr_type.sentinel != .none) try wip_nav.blockValue(3190 if (ptr_type.sentinel != .none) try wip_nav.blockValue(src_loc, .fromInterned(ptr_type.sentinel));
3093 src_loc,
3094 Value.fromInterned(ptr_type.sentinel),
3095 );
3096 try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse3191 try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse
3097 ptr_child_type.abiAlignment(zcu).toByteUnits().?);3192 ptr_child_type.abiAlignment(zcu).toByteUnits().?);
3098 try diw.writeByte(@intFromEnum(ptr_type.flags.address_space));3193 try diw.writeByte(@intFromEnum(ptr_type.flags.address_space));
...@@ -3128,37 +3223,34 @@ fn updateType(...@@ -3128,37 +3223,34 @@ fn updateType(
3128 try uleb128(diw, 0);3223 try uleb128(diw, 0);
3129 try wip_nav.abbrevCode(.generated_field);3224 try wip_nav.abbrevCode(.generated_field);
3130 try wip_nav.strp("len");3225 try wip_nav.strp("len");
3131 const len_field_type = Type.usize;3226 const len_field_type: Type = .usize;
3132 try wip_nav.refType(len_field_type);3227 try wip_nav.refType(len_field_type);
3133 try uleb128(diw, len_field_type.abiAlignment(zcu).forward(ptr_field_type.abiSize(zcu)));3228 try uleb128(diw, len_field_type.abiAlignment(zcu).forward(ptr_field_type.abiSize(zcu)));
3134 try uleb128(diw, @intFromEnum(AbbrevCode.null));3229 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3135 },3230 },
3136 },3231 },
3137 .array_type => |array_type| {3232 .array_type => |array_type| {
3138 const array_child_type = Type.fromInterned(array_type.child);3233 const array_child_type: Type = .fromInterned(array_type.child);
3139 try wip_nav.abbrevCode(if (array_type.sentinel == .none) .array_type else .array_sentinel_type);3234 try wip_nav.abbrevCode(if (array_type.sentinel == .none) .array_type else .array_sentinel_type);
3140 try wip_nav.strp(name);3235 try wip_nav.strp(name);
3141 if (array_type.sentinel != .none) try wip_nav.blockValue(3236 if (array_type.sentinel != .none) try wip_nav.blockValue(src_loc, .fromInterned(array_type.sentinel));
3142 src_loc,
3143 Value.fromInterned(array_type.sentinel),
3144 );
3145 try wip_nav.refType(array_child_type);3237 try wip_nav.refType(array_child_type);
3146 try wip_nav.abbrevCode(.array_index);3238 try wip_nav.abbrevCode(.array_index);
3147 try wip_nav.refType(Type.usize);3239 try wip_nav.refType(.usize);
3148 try uleb128(diw, array_type.len);3240 try uleb128(diw, array_type.len);
3149 try uleb128(diw, @intFromEnum(AbbrevCode.null));3241 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3150 },3242 },
3151 .vector_type => |vector_type| {3243 .vector_type => |vector_type| {
3152 try wip_nav.abbrevCode(.vector_type);3244 try wip_nav.abbrevCode(.vector_type);
3153 try wip_nav.strp(name);3245 try wip_nav.strp(name);
3154 try wip_nav.refType(Type.fromInterned(vector_type.child));3246 try wip_nav.refType(.fromInterned(vector_type.child));
3155 try wip_nav.abbrevCode(.array_index);3247 try wip_nav.abbrevCode(.array_index);
3156 try wip_nav.refType(Type.usize);3248 try wip_nav.refType(.usize);
3157 try uleb128(diw, vector_type.len);3249 try uleb128(diw, vector_type.len);
3158 try uleb128(diw, @intFromEnum(AbbrevCode.null));3250 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3159 },3251 },
3160 .opt_type => |opt_child_type_index| {3252 .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);
3162 try wip_nav.abbrevCode(.union_type);3254 try wip_nav.abbrevCode(.union_type);
3163 try wip_nav.strp(name);3255 try wip_nav.strp(name);
3164 try uleb128(diw, ty.abiSize(zcu));3256 try uleb128(diw, ty.abiSize(zcu));
...@@ -3166,7 +3258,7 @@ fn updateType(...@@ -3166,7 +3258,7 @@ fn updateType(
3166 if (opt_child_type.isNoReturn(zcu)) {3258 if (opt_child_type.isNoReturn(zcu)) {
3167 try wip_nav.abbrevCode(.generated_field);3259 try wip_nav.abbrevCode(.generated_field);
3168 try wip_nav.strp("null");3260 try wip_nav.strp("null");
3169 try wip_nav.refType(Type.null);3261 try wip_nav.refType(.null);
3170 try uleb128(diw, 0);3262 try uleb128(diw, 0);
3171 } else {3263 } else {
3172 try wip_nav.abbrevCode(.tagged_union);3264 try wip_nav.abbrevCode(.tagged_union);
...@@ -3189,21 +3281,21 @@ fn updateType(...@@ -3189,21 +3281,21 @@ fn updateType(
3189 };3281 };
3190 switch (repr) {3282 switch (repr) {
3191 .unpacked => {3283 .unpacked => {
3192 try wip_nav.refType(Type.bool);3284 try wip_nav.refType(.bool);
3193 try uleb128(diw, if (opt_child_type.hasRuntimeBits(zcu))3285 try uleb128(diw, if (opt_child_type.hasRuntimeBits(zcu))
3194 opt_child_type.abiSize(zcu)3286 opt_child_type.abiSize(zcu)
3195 else3287 else
3196 0);3288 0);
3197 },3289 },
3198 .error_set => {3290 .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 = .{
3200 .signedness = .unsigned,3292 .signedness = .unsigned,
3201 .bits = zcu.errorSetBits(),3293 .bits = zcu.errorSetBits(),
3202 } })));3294 } })));
3203 try uleb128(diw, 0);3295 try uleb128(diw, 0);
3204 },3296 },
3205 .pointer => {3297 .pointer => {
3206 try wip_nav.refType(Type.usize);3298 try wip_nav.refType(.usize);
3207 try uleb128(diw, 0);3299 try uleb128(diw, 0);
3208 },3300 },
3209 }3301 }
...@@ -3213,7 +3305,7 @@ fn updateType(...@@ -3213,7 +3305,7 @@ fn updateType(
3213 {3305 {
3214 try wip_nav.abbrevCode(.generated_field);3306 try wip_nav.abbrevCode(.generated_field);
3215 try wip_nav.strp("null");3307 try wip_nav.strp("null");
3216 try wip_nav.refType(Type.null);3308 try wip_nav.refType(.null);
3217 try uleb128(diw, 0);3309 try uleb128(diw, 0);
3218 }3310 }
3219 try uleb128(diw, @intFromEnum(AbbrevCode.null));3311 try uleb128(diw, @intFromEnum(AbbrevCode.null));
...@@ -3233,8 +3325,8 @@ fn updateType(...@@ -3233,8 +3325,8 @@ fn updateType(
3233 },3325 },
3234 .anyframe_type => unreachable,3326 .anyframe_type => unreachable,
3235 .error_union_type => |error_union_type| {3327 .error_union_type => |error_union_type| {
3236 const error_union_error_set_type = Type.fromInterned(error_union_type.error_set_type);3328 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);3329 const error_union_payload_type: Type = .fromInterned(error_union_type.payload_type);
3238 const error_union_error_set_offset, const error_union_payload_offset = switch (error_union_type.payload_type) {3330 const error_union_error_set_offset, const error_union_payload_offset = switch (error_union_type.payload_type) {
3239 .generic_poison_type => .{ 0, 0 },3331 .generic_poison_type => .{ 0, 0 },
3240 else => .{3332 else => .{
...@@ -3265,7 +3357,7 @@ fn updateType(...@@ -3265,7 +3357,7 @@ fn updateType(
3265 {3357 {
3266 try wip_nav.abbrevCode(.generated_field);3358 try wip_nav.abbrevCode(.generated_field);
3267 try wip_nav.strp("is_error");3359 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 = .{
3269 .signedness = .unsigned,3361 .signedness = .unsigned,
3270 .bits = zcu.errorSetBits(),3362 .bits = zcu.errorSetBits(),
3271 } })));3363 } })));
...@@ -3363,24 +3455,39 @@ fn updateType(...@@ -3363,24 +3455,39 @@ fn updateType(
3363 var field_byte_offset: u64 = 0;3455 var field_byte_offset: u64 = 0;
3364 for (0..tuple_type.types.len) |field_index| {3456 for (0..tuple_type.types.len) |field_index| {
3365 const comptime_value = tuple_type.values.get(ip)[field_index];3457 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);
3367 {3476 {
3368 var name_buf: [32]u8 = undefined;3477 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
3369 const field_name = std.fmt.bufPrint(&name_buf, "{d}", .{field_index}) catch unreachable;3478 const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{field_index}) catch unreachable;
3370 try wip_nav.strp(field_name);3479 try wip_nav.strp(field_name);
3371 }3480 }
3372 const field_type = Type.fromInterned(tuple_type.types.get(ip)[field_index]);
3373 try wip_nav.refType(field_type);3481 try wip_nav.refType(field_type);
3374 if (comptime_value != .none) try wip_nav.blockValue(3482 if (comptime_value == .none) {
3375 src_loc,
3376 Value.fromInterned(comptime_value),
3377 ) else {
3378 const field_align = field_type.abiAlignment(zcu);3483 const field_align = field_type.abiAlignment(zcu);
3379 field_byte_offset = field_align.forward(field_byte_offset);3484 field_byte_offset = field_align.forward(field_byte_offset);
3380 try uleb128(diw, field_byte_offset);3485 try uleb128(diw, field_byte_offset);
3381 try uleb128(diw, field_type.abiAlignment(zcu).toByteUnits().?);3486 try uleb128(diw, field_type.abiAlignment(zcu).toByteUnits().?);
3382 field_byte_offset += field_type.abiSize(zcu);3487 field_byte_offset += field_type.abiSize(zcu);
3383 }3488 }
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));
3384 }3491 }
3385 try uleb128(diw, @intFromEnum(AbbrevCode.null));3492 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3386 },3493 },
...@@ -3388,7 +3495,7 @@ fn updateType(...@@ -3388,7 +3495,7 @@ fn updateType(
3388 const loaded_enum = ip.loadEnumType(type_index);3495 const loaded_enum = ip.loadEnumType(type_index);
3389 try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type);3496 try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type);
3390 try wip_nav.strp(name);3497 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));
3392 for (0..loaded_enum.names.len) |field_index| {3499 for (0..loaded_enum.names.len) |field_index| {
3393 try wip_nav.enumConstValue(loaded_enum, .{3500 try wip_nav.enumConstValue(loaded_enum, .{
3394 .sdata = .signed_enum_field,3501 .sdata = .signed_enum_field,
...@@ -3469,10 +3576,10 @@ fn updateType(...@@ -3469,10 +3576,10 @@ fn updateType(
3469 };3576 };
3470 };3577 };
3471 try diw.writeByte(@intFromEnum(cc));3578 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));
3473 for (0..func_type.param_types.len) |param_index| {3580 for (0..func_type.param_types.len) |param_index| {
3474 try wip_nav.abbrevCode(.func_type_param);3581 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]));
3476 }3583 }
3477 if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args);3584 if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args);
3478 if (!is_nullary) try uleb128(diw, @intFromEnum(AbbrevCode.null));3585 if (!is_nullary) try uleb128(diw, @intFromEnum(AbbrevCode.null));
...@@ -3480,7 +3587,7 @@ fn updateType(...@@ -3480,7 +3587,7 @@ fn updateType(
3480 .error_set_type => |error_set_type| {3587 .error_set_type => |error_set_type| {
3481 try wip_nav.abbrevCode(if (error_set_type.names.len > 0) .enum_type else .empty_enum_type);3588 try wip_nav.abbrevCode(if (error_set_type.names.len > 0) .enum_type else .empty_enum_type);
3482 try wip_nav.strp(name);3589 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 = .{
3484 .signedness = .unsigned,3591 .signedness = .unsigned,
3485 .bits = zcu.errorSetBits(),3592 .bits = zcu.errorSetBits(),
3486 } })));3593 } })));
...@@ -3495,7 +3602,7 @@ fn updateType(...@@ -3495,7 +3602,7 @@ fn updateType(
3495 .inferred_error_set_type => |func| {3602 .inferred_error_set_type => |func| {
3496 try wip_nav.abbrevCode(.inferred_error_set_type);3603 try wip_nav.abbrevCode(.inferred_error_set_type);
3497 try wip_nav.strp(name);3604 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)) {
3499 .none => .anyerror_type,3606 .none => .anyerror_type,
3500 else => |ies| ies,3607 else => |ies| ies,
3501 }));3608 }));
...@@ -3526,10 +3633,378 @@ fn updateType(...@@ -3526,10 +3633,378 @@ fn updateType(
3526 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);3633 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);
3527}3634}
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
3529pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternPool.Index) UpdateError!void {4004pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternPool.Index) UpdateError!void {
3530 const zcu = pt.zcu;4005 const zcu = pt.zcu;
3531 const ip = &zcu.intern_pool;4006 const ip = &zcu.intern_pool;
3532 const ty = Type.fromInterned(type_index);4007 const ty: Type = .fromInterned(type_index);
3533 const ty_src_loc = ty.srcLoc(zcu);4008 const ty_src_loc = ty.srcLoc(zcu);
3534 log.debug("updateContainerType({}({d}))", .{ ty.fmt(pt), @intFromEnum(type_index) });4009 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...@@ -3554,7 +4029,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3554 .debug_info = .{},4029 .debug_info = .{},
3555 .debug_line = .{},4030 .debug_line = .{},
3556 .debug_loclists = .{},4031 .debug_loclists = .{},
3557 .pending_types = .{},4032 .pending_lazy = .{},
3558 };4033 };
3559 defer wip_nav.deinit();4034 defer wip_nav.deinit();
35604035
...@@ -3572,31 +4047,53 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -3572,31 +4047,53 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3572 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);4047 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
3573 const field_init = loaded_struct.fieldInit(ip, field_index);4048 const field_init = loaded_struct.fieldInit(ip, field_index);
3574 assert(!(is_comptime and field_init == .none));4049 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 };
3575 try wip_nav.abbrevCode(if (is_comptime)4058 try wip_nav.abbrevCode(if (is_comptime)
3576 .struct_field_comptime4059 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
3577 else if (field_init != .none)4067 else if (field_init != .none)
3578 .struct_field_default4068 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
3579 else4076 else
3580 .struct_field);4077 .struct_field);
3581 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {4078 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});4079 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
3583 defer dwarf.gpa.free(field_name);4080 const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{field_index}) catch unreachable;
3584 try wip_nav.strp(field_name);4081 try wip_nav.strp(field_name);
3585 }4082 }
3586 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
3587 try wip_nav.refType(field_type);4083 try wip_nav.refType(field_type);
3588 if (!is_comptime) {4084 if (!is_comptime) {
3589 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);4085 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
3590 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse4086 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
3591 field_type.abiAlignment(zcu).toByteUnits().?);4087 field_type.abiAlignment(zcu).toByteUnits().?);
3592 }4088 }
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));
3594 }4091 }
3595 try uleb128(diw, @intFromEnum(AbbrevCode.null));4092 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3596 }4093 }
35974094
3598 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);4095 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);
3600 } else {4097 } else {
3601 {4098 {
3602 // Note that changes to ZIR instruction tracking only need to update this code4099 // 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...@@ -3637,7 +4134,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3637 .debug_info = .{},4134 .debug_info = .{},
3638 .debug_line = .{},4135 .debug_line = .{},
3639 .debug_loclists = .{},4136 .debug_loclists = .{},
3640 .pending_types = .{},4137 .pending_lazy = .{},
3641 };4138 };
3642 defer wip_nav.deinit();4139 defer wip_nav.deinit();
3643 const diw = wip_nav.debug_info.writer(dwarf.gpa);4140 const diw = wip_nav.debug_info.writer(dwarf.gpa);
...@@ -3658,25 +4155,47 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -3658,25 +4155,47 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3658 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);4155 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
3659 const field_init = loaded_struct.fieldInit(ip, field_index);4156 const field_init = loaded_struct.fieldInit(ip, field_index);
3660 assert(!(is_comptime and field_init == .none));4157 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 };
3661 try wip_nav.abbrevCode(if (is_comptime)4166 try wip_nav.abbrevCode(if (is_comptime)
3662 .struct_field_comptime4167 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
3663 else if (field_init != .none)4175 else if (field_init != .none)
3664 .struct_field_default4176 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
3665 else4184 else
3666 .struct_field);4185 .struct_field);
3667 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {4186 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});4187 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
3669 defer dwarf.gpa.free(field_name);4188 const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{field_index}) catch unreachable;
3670 try wip_nav.strp(field_name);4189 try wip_nav.strp(field_name);
3671 }4190 }
3672 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
3673 try wip_nav.refType(field_type);4191 try wip_nav.refType(field_type);
3674 if (!is_comptime) {4192 if (!is_comptime) {
3675 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);4193 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
3676 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse4194 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
3677 field_type.abiAlignment(zcu).toByteUnits().?);4195 field_type.abiAlignment(zcu).toByteUnits().?);
3678 }4196 }
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));
3680 }4199 }
3681 try uleb128(diw, @intFromEnum(AbbrevCode.null));4200 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3682 }4201 }
...@@ -3684,12 +4203,12 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -3684,12 +4203,12 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3684 .@"packed" => {4203 .@"packed" => {
3685 try wip_nav.abbrevCode(if (loaded_struct.field_types.len > 0) .packed_struct_type else .empty_packed_struct_type);4204 try wip_nav.abbrevCode(if (loaded_struct.field_types.len > 0) .packed_struct_type else .empty_packed_struct_type);
3686 try wip_nav.strp(name);4205 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)));
3688 var field_bit_offset: u16 = 0;4207 var field_bit_offset: u16 = 0;
3689 for (0..loaded_struct.field_types.len) |field_index| {4208 for (0..loaded_struct.field_types.len) |field_index| {
3690 try wip_nav.abbrevCode(.packed_struct_field);4209 try wip_nav.abbrevCode(.packed_struct_field);
3691 try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip));4210 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]);
3693 try wip_nav.refType(field_type);4212 try wip_nav.refType(field_type);
3694 try uleb128(diw, field_bit_offset);4213 try uleb128(diw, field_bit_offset);
3695 field_bit_offset += @intCast(field_type.bitSize(zcu));4214 field_bit_offset += @intCast(field_type.bitSize(zcu));
...@@ -3702,7 +4221,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -3702,7 +4221,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3702 const loaded_enum = ip.loadEnumType(type_index);4221 const loaded_enum = ip.loadEnumType(type_index);
3703 try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type);4222 try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type);
3704 try wip_nav.strp(name);4223 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));
3706 for (0..loaded_enum.names.len) |field_index| {4225 for (0..loaded_enum.names.len) |field_index| {
3707 try wip_nav.enumConstValue(loaded_enum, .{4226 try wip_nav.enumConstValue(loaded_enum, .{
3708 .sdata = .signed_enum_field,4227 .sdata = .signed_enum_field,
...@@ -3732,7 +4251,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -3732,7 +4251,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3732 {4251 {
3733 try wip_nav.abbrevCode(.generated_field);4252 try wip_nav.abbrevCode(.generated_field);
3734 try wip_nav.strp("tag");4253 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));
3736 try uleb128(diw, union_layout.tagOffset());4255 try uleb128(diw, union_layout.tagOffset());
37374256
3738 for (0..loaded_union.field_types.len) |field_index| {4257 for (0..loaded_union.field_types.len) |field_index| {
...@@ -3744,7 +4263,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -3744,7 +4263,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3744 {4263 {
3745 try wip_nav.abbrevCode(.struct_field);4264 try wip_nav.abbrevCode(.struct_field);
3746 try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip));4265 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]);
3748 try wip_nav.refType(field_type);4267 try wip_nav.refType(field_type);
3749 try uleb128(diw, union_layout.payloadOffset());4268 try uleb128(diw, union_layout.payloadOffset());
3750 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse4269 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...@@ -3757,7 +4276,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3757 } else for (0..loaded_union.field_types.len) |field_index| {4276 } else for (0..loaded_union.field_types.len) |field_index| {
3758 try wip_nav.abbrevCode(.untagged_union_field);4277 try wip_nav.abbrevCode(.untagged_union_field);
3759 try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip));4278 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]);
3761 try wip_nav.refType(field_type);4280 try wip_nav.refType(field_type);
3762 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse4281 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
3763 field_type.abiAlignment(zcu).toByteUnits().?);4282 field_type.abiAlignment(zcu).toByteUnits().?);
...@@ -3773,7 +4292,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -3773,7 +4292,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3773 }4292 }
3774 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);4293 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);
3775 try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.items);4294 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);
3777 }4296 }
3778}4297}
37794298
...@@ -3840,14 +4359,14 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {...@@ -3840,14 +4359,14 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
3840 .debug_info = .{},4359 .debug_info = .{},
3841 .debug_line = .{},4360 .debug_line = .{},
3842 .debug_loclists = .{},4361 .debug_loclists = .{},
3843 .pending_types = .{},4362 .pending_lazy = .{},
3844 };4363 };
3845 defer wip_nav.deinit();4364 defer wip_nav.deinit();
3846 const diw = wip_nav.debug_info.writer(dwarf.gpa);4365 const diw = wip_nav.debug_info.writer(dwarf.gpa);
3847 const global_error_set_names = ip.global_error_set.getNamesFromMainThread();4366 const global_error_set_names = ip.global_error_set.getNamesFromMainThread();
3848 try wip_nav.abbrevCode(if (global_error_set_names.len > 0) .enum_type else .empty_enum_type);4367 try wip_nav.abbrevCode(if (global_error_set_names.len > 0) .enum_type else .empty_enum_type);
3849 try wip_nav.strp("anyerror");4368 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 = .{
3851 .signedness = .unsigned,4370 .signedness = .unsigned,
3852 .bits = zcu.errorSetBits(),4371 .bits = zcu.errorSetBits(),
3853 } })));4372 } })));
...@@ -3858,7 +4377,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {...@@ -3858,7 +4377,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
3858 }4377 }
3859 if (global_error_set_names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));4378 if (global_error_set_names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));
3860 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);4379 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);
3862 }4381 }
38634382
3864 {4383 {
...@@ -4244,6 +4763,9 @@ const AbbrevCode = enum {...@@ -4244,6 +4763,9 @@ const AbbrevCode = enum {
4244 decl_union,4763 decl_union,
4245 decl_var,4764 decl_var,
4246 decl_const,4765 decl_const,
4766 decl_const_runtime_bits,
4767 decl_const_comptime_state,
4768 decl_const_runtime_bits_comptime_state,
4247 decl_func,4769 decl_func,
4248 decl_empty_func,4770 decl_empty_func,
4249 decl_func_generic,4771 decl_func_generic,
...@@ -4259,7 +4781,13 @@ const AbbrevCode = enum {...@@ -4259,7 +4781,13 @@ const AbbrevCode = enum {
4259 generated_field,4781 generated_field,
4260 struct_field,4782 struct_field,
4261 struct_field_default,4783 struct_field_default,
4784 struct_field_default_runtime_bits,
4785 struct_field_default_comptime_state,
4786 struct_field_default_runtime_bits_comptime_state,
4262 struct_field_comptime,4787 struct_field_comptime,
4788 struct_field_comptime_runtime_bits,
4789 struct_field_comptime_comptime_state,
4790 struct_field_comptime_runtime_bits_comptime_state,
4263 packed_struct_field,4791 packed_struct_field,
4264 untagged_union_field,4792 untagged_union_field,
4265 tagged_union,4793 tagged_union,
...@@ -4296,6 +4824,20 @@ const AbbrevCode = enum {...@@ -4296,6 +4824,20 @@ const AbbrevCode = enum {
4296 inlined_func,4824 inlined_func,
4297 local_arg,4825 local_arg,
4298 local_var,4826 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
4300 const decl_bytes = uleb128Bytes(@intFromEnum(AbbrevCode.decl_empty_func_generic));4842 const decl_bytes = uleb128Bytes(@intFromEnum(AbbrevCode.decl_empty_func_generic));
43014843
...@@ -4387,9 +4929,39 @@ const AbbrevCode = enum {...@@ -4387,9 +4929,39 @@ const AbbrevCode = enum {
4387 .attrs = decl_abbrev_common_attrs ++ .{4929 .attrs = decl_abbrev_common_attrs ++ .{
4388 .{ .linkage_name, .strp },4930 .{ .linkage_name, .strp },
4389 .{ .type, .ref_addr },4931 .{ .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 },
4390 .{ .const_value, .block },4943 .{ .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 },
4391 .{ .alignment, .udata },4961 .{ .alignment, .udata },
4392 .{ .external, .flag },4962 .{ .external, .flag },
4963 .{ .const_value, .block },
4964 .{ .ZIG_comptime_value, .ref_addr },
4393 },4965 },
4394 },4966 },
4395 .decl_func = .{4967 .decl_func = .{
...@@ -4509,6 +5081,15 @@ const AbbrevCode = enum {...@@ -4509,6 +5081,15 @@ const AbbrevCode = enum {
4509 },5081 },
4510 },5082 },
4511 .struct_field_default = .{5083 .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 = .{
4512 .tag = .member,5093 .tag = .member,
4513 .attrs = &.{5094 .attrs = &.{
4514 .{ .name, .strp },5095 .{ .name, .strp },
...@@ -4518,13 +5099,61 @@ const AbbrevCode = enum {...@@ -4518,13 +5099,61 @@ const AbbrevCode = enum {
4518 .{ .default_value, .block },5099 .{ .default_value, .block },
4519 },5100 },
4520 },5101 },
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 },
4521 .struct_field_comptime = .{5123 .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 = .{
4522 .tag = .member,5150 .tag = .member,
4523 .attrs = &.{5151 .attrs = &.{
4524 .{ .const_expr, .flag_present },5152 .{ .const_expr, .flag_present },
4525 .{ .name, .strp },5153 .{ .name, .strp },
4526 .{ .type, .ref_addr },5154 .{ .type, .ref_addr },
4527 .{ .const_value, .block },5155 .{ .const_value, .block },
5156 .{ .ZIG_comptime_value, .ref_addr },
4528 },5157 },
4529 },5158 },
4530 .packed_struct_field = .{5159 .packed_struct_field = .{
...@@ -4804,6 +5433,102 @@ const AbbrevCode = enum {...@@ -4804,6 +5433,102 @@ const AbbrevCode = enum {
4804 .{ .location, .exprloc },5433 .{ .location, .exprloc },
4805 },5434 },
4806 },5435 },
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 },
4807 .null = undefined,5532 .null = undefined,
4808 });5533 });
4809};5534};