authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-06 16:19:36-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-07 16:11:00-04:00
logbf68590236d6d7ceb0283cb706d76717755c896a
treef23777b0a46ad8cdc19fb191ceb55da5537e2bef
parent72c64dd1976f7ea87f56ba640181d4f45dda2090

Dwarf2: implement comptime navs


4 files changed, 257 insertions(+), 95 deletions(-)

src/Zcu/PerThread.zig+19-3
......@@ -2657,7 +2657,13 @@ fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool {
26572657 // We've not necessarily generated builtin modules yet, so `doImport` could fail. Instead,
26582658 // create the module here. Then, since we know that `builtin.zig` doesn't have an error and
26592659 // has no imports other than 'std', we can just continue onto the next import.
2660 try pt.updateBuiltinModule(file.mod.?.getBuiltinOptions(comp.config));
2660 const res = try pt.updateBuiltinModule(file.mod.?.getBuiltinOptions(comp.config));
2661 const gop = zcu.alive_files.getOrPutAssumeCapacity(res.file);
2662 if (!gop.found_existing) gop.value_ptr.* = .{ .import = .{
2663 .importer = file_idx,
2664 .tok = item.data.token,
2665 .module = res.module_root,
2666 } };
26612667 continue;
26622668 }
26632669
......@@ -2756,14 +2762,20 @@ fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool {
27562762/// up-to-date, setting a misc failure if updating it fails.
27572763/// Asserts that the imported `builtin.zig` has no ZIR errors, and that it has only one
27582764/// import, which is 'std'.
2759pub fn updateBuiltinModule(pt: Zcu.PerThread, opts: Builtin) Allocator.Error!void {
2765fn updateBuiltinModule(pt: Zcu.PerThread, opts: Builtin) Allocator.Error!struct {
2766 file: Zcu.File.Index,
2767 module_root: *Module,
2768} {
27602769 const zcu = pt.zcu;
27612770 const comp = zcu.comp;
27622771 const gpa = comp.gpa;
27632772 const io = comp.io;
27642773
27652774 const gop = try zcu.builtin_modules.getOrPut(gpa, opts.hash());
2766 if (gop.found_existing) return; // the `File` is up-to-date
2775 if (gop.found_existing) return .{ // the `File` is up-to-date
2776 .file = zcu.module_roots.get(gop.value_ptr.*).?.unwrap().?,
2777 .module_root = gop.value_ptr.*,
2778 };
27672779 errdefer _ = zcu.builtin_modules.pop();
27682780
27692781 const mod: *Module = try .createBuiltin(comp.arena, opts, comp.dirs);
......@@ -2829,6 +2841,10 @@ pub fn updateBuiltinModule(pt: Zcu.PerThread, opts: Builtin) Allocator.Error!voi
28292841 "unable to write '{f}': {s}",
28302842 .{ file.path.fmt(comp), @errorName(err) },
28312843 );
2844 return .{
2845 .file = file_index,
2846 .module_root = mod,
2847 };
28322848}
28332849
28342850pub fn embedFile(
src/link/Dwarf2.zig+202-60
......@@ -81,6 +81,7 @@ pub const Unit = struct {
8181 ui: Unit.Index,
8282 zfi: Zcu.File.Index,
8383 ) std.mem.Allocator.Error!struct { DirIndex, FileIndex } {
84 assert(unit.alive);
8485 try unit.dirs.ensureUnusedCapacity(gpa, 1);
8586 try unit.files.ensureUnusedCapacity(gpa, 1);
8687 const dir_gop = unit.dirs.getOrPutAssumeCapacity(ui);
......@@ -737,8 +738,8 @@ pub const WipNav = struct {
737738 try dl_w.writeByte(DW.LNE.set_address);
738739 try dwarf.addrSym(dl_nw, debug.wip_nav.func_si, 0);
739740
740 const unit = dwarf.getUnit(zf.mod.?);
741 _, const fi = try unit.get(dwarf).getFile(zcu.gpa, unit, inst_info.file);
741 const ui = dwarf.getUnit(zf.mod.?);
742 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, inst_info.file);
742743 try dl_w.writeByte(DW.LNS.set_file);
743744 try dl_w.writeUleb128(@backingInt(fi));
744745
......@@ -1515,7 +1516,6 @@ pub fn getDecl(
15151516 pt: Zcu.PerThread,
15161517 instance_val: InternPool.Index,
15171518) link.Error!link.MappedFile.Node.Index {
1518 assert(dwarf.pending_decl.instance_val == .none);
15191519 const comp = dwarf.lf.comp;
15201520 const gpa = comp.gpa;
15211521 const zcu = pt.zcu;
......@@ -1949,11 +1949,11 @@ pub fn genDebugRnglists(
19491949pub fn updateComptimeNav(
19501950 dwarf: *Dwarf,
19511951 pt: Zcu.PerThread,
1952 nav_index: InternPool.Nav.Index,
1952 ni: InternPool.Nav.Index,
19531953) link.Error!void {
19541954 const zcu = pt.zcu;
19551955 const ip = &zcu.intern_pool;
1956 const nav = ip.getNav(nav_index);
1956 const nav = ip.getNav(ni);
19571957 log.debug("updateComptimeNav({f})", .{nav.fqn.fmt(ip)});
19581958 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
19591959 const nav_val: Value = .fromInterned(nav.resolved.?.value);
......@@ -1964,49 +1964,184 @@ pub fn updateComptimeNav(
19641964 .@"comptime", .@"const", .@"var" => {},
19651965 }
19661966 done: switch (ip.indexToKey(nav_val.toIntern())) {
1967 .int_type,
1968 .ptr_type,
1969 .array_type,
1970 .vector_type,
1971 .opt_type,
1972 .error_union_type,
1973 .anyframe_type,
1974 .simple_type,
1975 .tuple_type,
1976 .func_type,
1977 .error_set_type,
1978 .inferred_error_set_type,
1979 .spirv_type,
1980 => try dwarf.genDeclType(pt, ni, &decl),
19671981 .struct_type => {
19681982 const loaded_struct = ip.loadStructType(nav_val.toIntern());
1969 if (nav_index.toOptional() == loaded_struct.name_nav) {
1970 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1971 break :done;
1972 }
1973 return;
1983 if (ni.toOptional() == loaded_struct.name_nav)
1984 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern())
1985 else
1986 try dwarf.genDeclType(pt, ni, &decl);
19741987 },
19751988 .enum_type => {
19761989 const loaded_enum = ip.loadEnumType(nav_val.toIntern());
1977 if (nav_index.toOptional() == loaded_enum.name_nav) {
1978 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1979 break :done;
1980 }
1981 return;
1990 if (ni.toOptional() == loaded_enum.name_nav)
1991 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern())
1992 else
1993 try dwarf.genDeclType(pt, ni, &decl);
19821994 },
19831995 .union_type => {
19841996 const loaded_union = ip.loadUnionType(nav_val.toIntern());
1985 if (nav_index.toOptional() == loaded_union.name_nav) {
1986 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1987 break :done;
1988 }
1989 return;
1997 if (ni.toOptional() == loaded_union.name_nav)
1998 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern())
1999 else
2000 try dwarf.genDeclType(pt, ni, &decl);
19902001 },
19912002 .opaque_type => {
19922003 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());
1993 if (nav_index.toOptional() == loaded_opaque.name_nav) {
1994 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1995 break :done;
1996 }
1997 return;
1998 },
1999 .func => |func| if (func.owner_nav == nav_index and func.generic_owner == .none) {
2004 if (ni.toOptional() == loaded_opaque.name_nav)
2005 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern())
2006 else
2007 try dwarf.genDeclType(pt, ni, &decl);
2008 },
2009 .undef,
2010 .simple_value,
2011 .int,
2012 .err,
2013 .error_union,
2014 .enum_literal,
2015 .enum_tag,
2016 .float,
2017 .ptr,
2018 .slice,
2019 .opt,
2020 .aggregate,
2021 .un,
2022 .bitpack,
2023 => try dwarf.genDeclValue(pt, ni, &decl),
2024 .@"extern" => unreachable,
2025 .func => |func| if (func.owner_nav == ni and func.generic_owner == .none) {
20002026 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
20012027 break :done;
20022028 } else return,
2003
2004 else => return,
2005
20062029 // memoization, not values
20072030 .memoized_call => unreachable,
20082031 }
2009 try dwarf.const_pool.flushPending(pt, dwarf.constPoolUser());
2032}
2033
2034fn genDeclType(
2035 dwarf: *Dwarf,
2036 pt: Zcu.PerThread,
2037 ni: InternPool.Nav.Index,
2038 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,
2039) link.Error!void {
2040 const gi = try dwarf.getGlobal(ni);
2041 const debug_info_ni = gi.get(dwarf).debug_info_ni.unwrap().?;
2042 var di_nw: link.MappedFile.Node.Writer = undefined;
2043 if (dwarf.lf.cast(.elf2)) |elf| {
2044 debug_info_ni.writer(pt.zcu.gpa, &elf.mf, &di_nw);
2045 elf.resetNodeRelocs(debug_info_ni);
2046 } else unreachable;
2047 defer di_nw.deinit();
2048 dwarf.genDeclTypeInner(pt, &di_nw, ni, decl) catch |err| switch (err) {
2049 error.WriteFailed => return dwarf.reportWriteError(&di_nw),
2050 else => |e| return e,
2051 };
2052}
2053fn genDeclTypeInner(
2054 dwarf: *Dwarf,
2055 pt: Zcu.PerThread,
2056 di_nw: *link.MappedFile.Node.Writer,
2057 ni: InternPool.Nav.Index,
2058 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,
2059) link.EmitError!void {
2060 const ip = &pt.zcu.intern_pool;
2061 const nav = ip.getNav(ni);
2062 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(nav.analysis.?.namespace).owner_type);
2063 const di_w = &di_nw.interface;
2064 try dwarf.abbrevCode(di_nw, .decl_type);
2065 try dwarf.secOffset(di_nw, parent_ni, 0);
2066 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2067 try di_w.writeUleb128(decl.src_column + 1);
2068 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2069 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
2070 try dwarf.refConst(pt, di_nw, .fromInterned(nav.resolved.?.value));
2071 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
2072}
2073
2074fn genDeclValue(
2075 dwarf: *Dwarf,
2076 pt: Zcu.PerThread,
2077 ni: InternPool.Nav.Index,
2078 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,
2079) link.Error!void {
2080 const gi = try dwarf.getGlobal(ni);
2081 const debug_info_ni = gi.get(dwarf).debug_info_ni.unwrap().?;
2082 var di_nw: link.MappedFile.Node.Writer = undefined;
2083 if (dwarf.lf.cast(.elf2)) |elf| {
2084 debug_info_ni.writer(pt.zcu.gpa, &elf.mf, &di_nw);
2085 elf.resetNodeRelocs(debug_info_ni);
2086 } else unreachable;
2087 defer di_nw.deinit();
2088 dwarf.genDeclValueInner(pt, &di_nw, ni, decl) catch |err| switch (err) {
2089 error.WriteFailed => return dwarf.reportWriteError(&di_nw),
2090 else => |e| return e,
2091 };
2092}
2093fn genDeclValueInner(
2094 dwarf: *Dwarf,
2095 pt: Zcu.PerThread,
2096 di_nw: *link.MappedFile.Node.Writer,
2097 ni: InternPool.Nav.Index,
2098 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,
2099) link.EmitError!void {
2100 const zcu = pt.zcu;
2101 const ip = &zcu.intern_pool;
2102 const nav = ip.getNav(ni);
2103 const nav_const, const nav_ty: Type, const nav_align, const nav_val: Value = resolved: {
2104 const resolved = nav.resolved.?;
2105 break :resolved .{
2106 resolved.@"const",
2107 .fromInterned(resolved.type),
2108 resolved.@"align",
2109 .fromInterned(resolved.value),
2110 };
2111 };
2112 const nav_class = nav_ty.classify(zcu);
2113 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(nav.analysis.?.namespace).owner_type);
2114 const di_w = &di_nw.interface;
2115 try dwarf.abbrevCode(di_nw, if (nav_const) switch (nav_class) {
2116 .no_possible_value, .one_possible_value => .decl_const,
2117 .runtime => .decl_const_fully_runtime,
2118 .partially_comptime => .decl_const_partially_comptime,
2119 .fully_comptime => .decl_const_fully_comptime,
2120 } else .decl_var);
2121 try dwarf.secOffset(di_nw, parent_ni, 0);
2122 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2123 try di_w.writeUleb128(decl.src_column + 1);
2124 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2125 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
2126 try dwarf.strp(&dwarf.debug_str, di_nw, switch (decl.linkage) {
2127 .normal => nav.fqn,
2128 .@"extern", .@"export" => nav.name,
2129 }.toSlice(ip));
2130 const type_offset = di_w.end;
2131 if (nav_const) try dwarf.secOffsetPlaceholder(di_w) else {
2132 try dwarf.refType(pt, di_nw, nav_ty);
2133 try dwarf.blockConst(pt, di_nw, nav_val);
2134 }
2135 try di_w.writeUleb128(nav_align.toByteUnits() orelse nav_ty.abiAlignment(zcu).toByteUnits().?);
2136 try di_w.writeByte(@intFromBool(decl.linkage != .normal));
2137 if (nav_const) {
2138 if (nav_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, nav_val);
2139 if (nav_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, nav_val);
2140 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2141 try dwarf.abbrevCode(di_nw, .is_const);
2142 try dwarf.refType(pt, di_nw, nav_ty);
2143 }
2144 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
20102145}
20112146
20122147pub fn addConst(
......@@ -2044,9 +2179,11 @@ pub fn addConst(
20442179 const name_gi = try dwarf.getGlobal(name_nav);
20452180 break :debug_info_ni name_gi.get(dwarf).debug_info_ni.unwrap().?;
20462181 }
2047 break :debug_info_ni try addConstNode(dwarf.lf, dwarf.getUnit(zcu.fileByIndex(
2182 const mod = zcu.fileByIndex(
20482183 Type.fromInterned(val).typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip),
2049 ).mod.?), cpi);
2184 ).mod.?;
2185 assert(!mod.strip);
2186 break :debug_info_ni try addConstNode(dwarf.lf, dwarf.getUnit(mod), cpi);
20502187 },
20512188 }.toOptional(),
20522189 });
......@@ -2456,9 +2593,8 @@ fn updateConstInner(
24562593 } else if (loaded_struct.name_nav.unwrap()) |name_ni| {
24572594 const name_nav = ip.getNav(name_ni);
24582595 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2459 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2460 name_nav.analysis.?.namespace,
2461 ).owner_type);
2596 const parent_ni =
2597 try dwarf.getDecl(pt, ip.namespacePtr(name_nav.analysis.?.namespace).owner_type);
24622598 try dwarf.abbrevCode(di_nw, if (loaded_struct.field_types.len > 0)
24632599 switch (loaded_struct.layout) {
24642600 .auto, .@"extern" => .decl_struct,
......@@ -2589,9 +2725,8 @@ fn updateConstInner(
25892725 } else if (loaded_union.name_nav.unwrap()) |name_ni| {
25902726 const name_nav = ip.getNav(name_ni);
25912727 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2592 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2593 name_nav.analysis.?.namespace,
2594 ).owner_type);
2728 const parent_ni =
2729 try dwarf.getDecl(pt, ip.namespacePtr(name_nav.analysis.?.namespace).owner_type);
25952730 try dwarf.abbrevCode(di_nw, if (loaded_union.field_types.len > 0)
25962731 switch (loaded_union.layout) {
25972732 .auto, .@"extern" => .decl_union,
......@@ -3137,9 +3272,8 @@ fn updateConstIncompleteInner(
31373272 } else if (maybe_name_nav.unwrap()) |name_ni| {
31383273 const name_nav = ip.getNav(name_ni);
31393274 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
3140 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
3141 name_nav.analysis.?.namespace,
3142 ).owner_type);
3275 const parent_ni =
3276 try dwarf.getDecl(pt, ip.namespacePtr(name_nav.analysis.?.namespace).owner_type);
31433277 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {
31443278 .@"struct" => .decl_incomplete_struct,
31453279 .@"union" => .decl_incomplete_union,
......@@ -3399,9 +3533,8 @@ fn genDeclInner(
33993533 if (maybe_name_nav.unwrap()) |name_ni| {
34003534 const name_nav = ip.getNav(name_ni);
34013535 const decl = zir.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
3402 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
3403 name_nav.analysis.?.namespace,
3404 ).owner_type);
3536 const parent_ni =
3537 try dwarf.getDecl(pt, ip.namespacePtr(name_nav.analysis.?.namespace).owner_type);
34053538 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {
34063539 .@"struct" => .decl_specification_struct,
34073540 .@"union" => .decl_specification_union,
......@@ -3537,9 +3670,6 @@ pub fn secOffsetSize(dwarf: *Dwarf) usize {
35373670 .@"64" => 8,
35383671 };
35393672}
3540fn secOffsetPlaceholder(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void {
3541 @memset(try w.writableSlice(dwarf.secOffsetSize()), undefined);
3542}
35433673fn secOffset(
35443674 dwarf: *Dwarf,
35453675 nw: *link.MappedFile.Node.Writer,
......@@ -3548,6 +3678,18 @@ fn secOffset(
35483678) link.EmitError!void {
35493679 const offset = nw.interface.end;
35503680 try dwarf.secOffsetPlaceholder(&nw.interface);
3681 try dwarf.secOffsetFinish(nw, offset, target_ni, addend);
3682}
3683fn secOffsetPlaceholder(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void {
3684 @memset(try w.writableSlice(dwarf.secOffsetSize()), undefined);
3685}
3686fn secOffsetFinish(
3687 dwarf: *Dwarf,
3688 nw: *link.MappedFile.Node.Writer,
3689 offset: usize,
3690 target_ni: link.MappedFile.Node.Index,
3691 addend: usize,
3692) link.Error!void {
35513693 if (dwarf.lf.cast(.elf2)) |elf| try elf.addNodeReloc(
35523694 nw.ni,
35533695 offset,
......@@ -3745,7 +3887,7 @@ pub const AbbrevCode = enum {
37453887 pad_n,
37463888 // decl, specification, and instance codes are assumed to all have the same uleb128 size
37473889 decl_lost,
3748 decl_alias,
3890 decl_type,
37493891 decl_empty_incomplete_enum,
37503892 decl_incomplete_enum,
37513893 decl_empty_enum,
......@@ -3780,9 +3922,9 @@ pub const AbbrevCode = enum {
37803922 type_decl_packed_union,
37813923 decl_var,
37823924 decl_const,
3783 decl_const_runtime_bits,
3784 decl_const_comptime_state,
3785 decl_const_runtime_bits_comptime_state,
3925 decl_const_fully_runtime,
3926 decl_const_partially_comptime,
3927 decl_const_fully_comptime,
37863928 decl_empty_func,
37873929 decl_func,
37883930 decl_empty_func_generic,
......@@ -3802,7 +3944,7 @@ pub const AbbrevCode = enum {
38023944 type_decl_specification_empty_union,
38033945 type_decl_specification_union,
38043946 decl_specification_func,
3805 decl_instance_alias,
3947 decl_instance_type,
38063948 decl_instance_empty_incomplete_enum,
38073949 decl_instance_incomplete_enum,
38083950 decl_instance_empty_enum,
......@@ -3921,7 +4063,7 @@ pub const AbbrevCode = enum {
39214063 comptime {
39224064 assert(uleb128Size(@backingInt(AbbrevCode.pad_1)) == 1);
39234065 assert(uleb128Size(@backingInt(AbbrevCode.pad_n)) == 1);
3924 assert(uleb128Size(@backingInt(AbbrevCode.decl_alias)) == decl_size);
4066 assert(uleb128Size(@backingInt(AbbrevCode.decl_type)) == decl_size);
39254067 }
39264068
39274069 const Attr = struct {
......@@ -3969,7 +4111,7 @@ pub const AbbrevCode = enum {
39694111 .decl_lost = .{
39704112 .tag = .ZIG_lost_declaration,
39714113 },
3972 .decl_alias = .{
4114 .decl_type = .{
39734115 .tag = .imported_declaration,
39744116 .attrs = decl_attrs ++ .{
39754117 .{ .import, .ref_addr },
......@@ -4186,7 +4328,7 @@ pub const AbbrevCode = enum {
41864328 .{ .external, .flag },
41874329 },
41884330 },
4189 .decl_const_runtime_bits = .{
4331 .decl_const_fully_runtime = .{
41904332 .tag = .constant,
41914333 .attrs = decl_attrs ++ .{
41924334 .{ .linkage_name, .strp },
......@@ -4196,24 +4338,24 @@ pub const AbbrevCode = enum {
41964338 .{ .const_value, .block },
41974339 },
41984340 },
4199 .decl_const_comptime_state = .{
4341 .decl_const_partially_comptime = .{
42004342 .tag = .constant,
42014343 .attrs = decl_attrs ++ .{
42024344 .{ .linkage_name, .strp },
42034345 .{ .type, .ref_addr },
42044346 .{ .alignment, .udata },
42054347 .{ .external, .flag },
4348 .{ .const_value, .block },
42064349 .{ .ZIG_comptime_value, .ref_addr },
42074350 },
42084351 },
4209 .decl_const_runtime_bits_comptime_state = .{
4352 .decl_const_fully_comptime = .{
42104353 .tag = .constant,
42114354 .attrs = decl_attrs ++ .{
42124355 .{ .linkage_name, .strp },
42134356 .{ .type, .ref_addr },
42144357 .{ .alignment, .udata },
42154358 .{ .external, .flag },
4216 .{ .const_value, .block },
42174359 .{ .ZIG_comptime_value, .ref_addr },
42184360 },
42194361 },
......@@ -4334,7 +4476,7 @@ pub const AbbrevCode = enum {
43344476 .tag = .subprogram,
43354477 .attrs = decl_specification_attrs,
43364478 },
4337 .decl_instance_alias = .{
4479 .decl_instance_type = .{
43384480 .tag = .imported_declaration,
43394481 .attrs = decl_instance_attrs ++ .{
43404482 .{ .import, .ref_addr },
src/link/Elf2.zig+35-31
......@@ -7197,7 +7197,7 @@ fn prelinkInner(elf: *Elf) Error!void {
71977197 };
71987198 elf.input_pending_index += 1;
71997199
7200 try elf.nodes.ensureUnusedCapacity(gpa, 5 + 4);
7200 try elf.nodes.ensureUnusedCapacity(gpa, 4 + 5);
72017201
72027202 switch (elf.shndx.debug_abbrev) {
72037203 .UNDEF => {},
......@@ -7301,7 +7301,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {
73017301 });
73027302 }
73037303 if (!try elf.dwarf.updateUnits(zcu)) return;
7304 try elf.nodes.ensureUnusedCapacity(gpa, 5 * units_len);
7304 try elf.nodes.ensureUnusedCapacity(gpa, 6 * units_len);
73057305 for (0..units_len) |unit_index| {
73067306 const ui: Dwarf.Unit.Index = @fromBackingInt(@intCast(unit_index));
73077307 const unit = ui.get(&elf.dwarf);
......@@ -8633,37 +8633,37 @@ fn updateNavInner(elf: *Elf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index)
86338633
86348634 const nav = ip.getNav(nav_index);
86358635 if (ip.indexToKey(nav.resolved.?.value) == .@"extern") return;
8636 if (!Type.fromInterned(nav.resolved.?.type).hasRuntimeBits(zcu)) {
8637 if (elf.ehdrMachine() != .X86_64) return;
8638 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;
8639 return if (!mod.strip) elf.dwarf.updateComptimeNav(pt, nav_index);
8640 }
8641
8642 const nmi = try elf.navMapIndex(zcu, nav_index);
8643 const ni = nmi.symbol(elf).index().ptr(elf).node.unwrap().?;
8636 if (Type.fromInterned(nav.resolved.?.type).hasRuntimeBits(zcu)) {
8637 const nmi = try elf.navMapIndex(zcu, nav_index);
8638 const ni = nmi.symbol(elf).index().ptr(elf).node.unwrap().?;
86448639
8645 // Ensure the NAV is marked as moved so that once we're done, `flushMoved` will eventually be
8646 // called to apply the NAV's new relocations.
8647 try ni.moved(gpa, &elf.mf);
8640 // Ensure the NAV is marked as moved so that once we're done, `flushMoved` will eventually be
8641 // called to apply the NAV's new relocations.
8642 try ni.moved(gpa, &elf.mf);
86488643
8649 {
8650 var nw: MappedFile.Node.Writer = undefined;
8651 ni.writer(gpa, &elf.mf, &nw);
8652 defer nw.deinit();
8653 elf.resetNodeRelocs(ni);
8654 codegen.generateSymbol(
8655 &elf.base,
8656 pt,
8657 .fromInterned(nav.resolved.?.value),
8658 &nw.interface,
8659 .{ .atom_index = Node.toAtom(ni) },
8660 ) catch |err| switch (err) {
8661 else => |e| return e,
8662 error.WriteFailed => return nw.err.?,
8663 };
8664 switch (elf.symPtr(nmi.symbol(elf).index())) {
8665 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),
8644 {
8645 var nw: MappedFile.Node.Writer = undefined;
8646 ni.writer(gpa, &elf.mf, &nw);
8647 defer nw.deinit();
8648 elf.resetNodeRelocs(ni);
8649 codegen.generateSymbol(
8650 &elf.base,
8651 pt,
8652 .fromInterned(nav.resolved.?.value),
8653 &nw.interface,
8654 .{ .atom_index = Node.toAtom(ni) },
8655 ) catch |err| switch (err) {
8656 else => |e| return e,
8657 error.WriteFailed => return nw.err.?,
8658 };
8659 switch (elf.symPtr(nmi.symbol(elf).index())) {
8660 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),
8661 }
86668662 }
8663 } else {
8664 if (elf.ehdrMachine() != .X86_64) return;
8665 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;
8666 if (!mod.strip) try elf.dwarf.updateComptimeNav(pt, nav_index);
86678667 }
86688668
86698669 // The NAV's node is done---now generate any UAVs or lazy code/data which the NAV needs.
......@@ -8726,7 +8726,11 @@ pub fn addConst(
87268726 .code_view => unreachable,
87278727 }
87288728}
8729fn addConstNode(lf: *link.File, ui: Dwarf.Unit.Index, cpi: link.ConstPool.Index) link.Error!MappedFile.Node.Index {
8729fn addConstNode(
8730 lf: *link.File,
8731 ui: Dwarf.Unit.Index,
8732 cpi: link.ConstPool.Index,
8733) link.Error!MappedFile.Node.Index {
87308734 const elf = lf.cast(.elf2).?;
87318735 const unit = ui.get(&elf.dwarf);
87328736 const debug_info_ni = elf.addNodeAssumeCapacity(
test/src/Debugger.zig+1-1
......@@ -629,7 +629,7 @@ pub fn addTests(db: *Debugger) void {
629629 \\(lldb) breakpoint delete --force 1
630630 \\1 breakpoints deleted; 0 breakpoint locations disabled.
631631 },
632 .{ .skip_new_linker = true },
632 .{ .skip_new_linker = true }, // passes, but prints errors
633633 );
634634 db.addLldbTest(
635635 "optionals",