| ... | ... | @@ -18,6 +18,7 @@ const codegen = @import("../codegen.zig"); |
| 18 | 18 | const dev = @import("../dev.zig"); |
| 19 | 19 | const link = @import("../link.zig"); |
| 20 | 20 | const target_info = @import("../target.zig"); |
| 21 | const DebugConstPool = @import("DebugConstPool.zig"); |
| 21 | 22 | |
| 22 | 23 | gpa: Allocator, |
| 23 | 24 | bin_file: *link.File, |
| ... | ... | @@ -25,9 +26,11 @@ format: DW.Format, |
| 25 | 26 | endian: std.builtin.Endian, |
| 26 | 27 | address_size: AddressSize, |
| 27 | 28 | |
| 29 | const_pool: DebugConstPool, |
| 30 | |
| 28 | 31 | mods: std.AutoArrayHashMapUnmanaged(*Module, ModInfo), |
| 29 | | types: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index), |
| 30 | | values: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index), |
| 32 | /// Indices are `DebugConstPool.Index`. |
| 33 | values: std.ArrayList(struct { Unit.Index, Entry.Index }), |
| 31 | 34 | navs: std.AutoArrayHashMapUnmanaged(InternPool.Nav.Index, Entry.Index), |
| 32 | 35 | decls: std.AutoArrayHashMapUnmanaged(InternPool.TrackedInst.Index, Entry.Index), |
| 33 | 36 | |
| ... | ... | @@ -1034,15 +1037,14 @@ const Entry = struct { |
| 1034 | 1037 | }); |
| 1035 | 1038 | const zcu = dwarf.bin_file.comp.zcu.?; |
| 1036 | 1039 | const ip = &zcu.intern_pool; |
| 1037 | | for (dwarf.types.keys(), dwarf.types.values()) |ty, other_entry| { |
| 1038 | | const ty_unit: Unit.Index = if (Type.fromInterned(ty).typeDeclInst(zcu)) |inst_index| |
| 1039 | | dwarf.getUnit(zcu.fileByIndex(inst_index.resolveFile(ip)).mod.?) catch unreachable |
| 1040 | | else |
| 1041 | | .main; |
| 1042 | | if (sec.getUnit(ty_unit) == unit and unit.getEntry(other_entry) == entry) |
| 1043 | | log.err("missing Type({f}({d}))", .{ |
| 1044 | | Type.fromInterned(ty).fmt(.{ .tid = .main, .zcu = zcu }), |
| 1045 | | @intFromEnum(ty), |
| 1040 | for (0.., dwarf.values.items) |raw_index, unit_and_entry| { |
| 1041 | const index: DebugConstPool.Index = @enumFromInt(raw_index); |
| 1042 | const val = index.val(&dwarf.const_pool); |
| 1043 | const val_unit, const val_entry = unit_and_entry; |
| 1044 | if (sec.getUnit(val_unit) == unit and unit.getEntry(val_entry) == entry) |
| 1045 | log.err("missing Value({f}({d}))", .{ |
| 1046 | Value.fromInterned(val).fmtValue(.{ .tid = .main, .zcu = zcu }), |
| 1047 | @intFromEnum(val), |
| 1046 | 1048 | }); |
| 1047 | 1049 | } |
| 1048 | 1050 | for (dwarf.navs.keys(), dwarf.navs.values()) |nav, other_entry| { |
| ... | ... | @@ -1520,7 +1522,6 @@ pub const WipNav = struct { |
| 1520 | 1522 | debug_info: Writer.Allocating, |
| 1521 | 1523 | debug_line: Writer.Allocating, |
| 1522 | 1524 | debug_loclists: Writer.Allocating, |
| 1523 | | pending_lazy: PendingLazy, |
| 1524 | 1525 | |
| 1525 | 1526 | pub fn deinit(wip_nav: *WipNav) void { |
| 1526 | 1527 | const gpa = wip_nav.dwarf.gpa; |
| ... | ... | @@ -1529,8 +1530,6 @@ pub const WipNav = struct { |
| 1529 | 1530 | wip_nav.debug_info.deinit(); |
| 1530 | 1531 | wip_nav.debug_line.deinit(); |
| 1531 | 1532 | wip_nav.debug_loclists.deinit(); |
| 1532 | | wip_nav.pending_lazy.types.deinit(gpa); |
| 1533 | | wip_nav.pending_lazy.values.deinit(gpa); |
| 1534 | 1533 | } |
| 1535 | 1534 | |
| 1536 | 1535 | pub fn genDebugFrame(wip_nav: *WipNav, loc: u32, cfa: Cfa) UpdateError!void { |
| ... | ... | @@ -1945,6 +1944,12 @@ pub const WipNav = struct { |
| 1945 | 1944 | try wip_nav.infoSectionOffset(.debug_str, StringSection.unit, try wip_nav.dwarf.debug_str.addString(wip_nav.dwarf, str), 0); |
| 1946 | 1945 | } |
| 1947 | 1946 | |
| 1947 | fn strpFmt(wip_nav: *WipNav, comptime fmt: []const u8, args: anytype) (UpdateError || Writer.Error)!void { |
| 1948 | const str = try std.fmt.allocPrint(wip_nav.dwarf.gpa, fmt, args); |
| 1949 | defer wip_nav.dwarf.gpa.free(str); |
| 1950 | return wip_nav.strp(str); |
| 1951 | } |
| 1952 | |
| 1948 | 1953 | const ExprLocCounter = struct { |
| 1949 | 1954 | dw: Writer.Discarding, |
| 1950 | 1955 | section_offset_bytes: u32, |
| ... | ... | @@ -2054,74 +2059,16 @@ pub const WipNav = struct { |
| 2054 | 2059 | try dfw.splatByteAll(0, @intFromEnum(wip_nav.dwarf.address_size)); |
| 2055 | 2060 | } |
| 2056 | 2061 | |
| 2057 | | fn getNavEntry( |
| 2058 | | wip_nav: *WipNav, |
| 2059 | | nav_index: InternPool.Nav.Index, |
| 2060 | | ) UpdateError!struct { Unit.Index, Entry.Index } { |
| 2061 | | const zcu = wip_nav.pt.zcu; |
| 2062 | | const ip = &zcu.intern_pool; |
| 2063 | | const nav = ip.getNav(nav_index); |
| 2064 | | const unit = try wip_nav.dwarf.getUnit(zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?); |
| 2065 | | const gop = try wip_nav.dwarf.navs.getOrPut(wip_nav.dwarf.gpa, nav_index); |
| 2066 | | if (gop.found_existing) return .{ unit, gop.value_ptr.* }; |
| 2067 | | const entry = try wip_nav.dwarf.addCommonEntry(unit); |
| 2068 | | gop.value_ptr.* = entry; |
| 2069 | | return .{ unit, entry }; |
| 2070 | | } |
| 2071 | | |
| 2072 | 2062 | fn refNav( |
| 2073 | 2063 | wip_nav: *WipNav, |
| 2074 | 2064 | nav_index: InternPool.Nav.Index, |
| 2075 | 2065 | ) (UpdateError || Writer.Error)!void { |
| 2076 | | const unit, const entry = try wip_nav.getNavEntry(nav_index); |
| 2066 | const unit, const entry = try wip_nav.dwarf.getNavEntry(nav_index); |
| 2077 | 2067 | try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); |
| 2078 | 2068 | } |
| 2079 | 2069 | |
| 2080 | | fn getTypeEntry(wip_nav: *WipNav, ty: Type) UpdateError!struct { Unit.Index, Entry.Index } { |
| 2081 | | const zcu = wip_nav.pt.zcu; |
| 2082 | | const ip = &zcu.intern_pool; |
| 2083 | | const maybe_inst_index = ty.typeDeclInst(zcu); |
| 2084 | | const unit = if (maybe_inst_index) |inst_index| switch (switch (ip.indexToKey(ty.toIntern())) { |
| 2085 | | else => unreachable, |
| 2086 | | .struct_type => ip.loadStructType(ty.toIntern()).name_nav, |
| 2087 | | .union_type => ip.loadUnionType(ty.toIntern()).name_nav, |
| 2088 | | .enum_type => ip.loadEnumType(ty.toIntern()).name_nav, |
| 2089 | | .opaque_type => ip.loadOpaqueType(ty.toIntern()).name_nav, |
| 2090 | | }) { |
| 2091 | | .none => try wip_nav.dwarf.getUnit(zcu.fileByIndex(inst_index.resolveFile(ip)).mod.?), |
| 2092 | | else => |name_nav| return wip_nav.getNavEntry(name_nav.unwrap().?), |
| 2093 | | } else .main; |
| 2094 | | const gop = try wip_nav.dwarf.types.getOrPut(wip_nav.dwarf.gpa, ty.toIntern()); |
| 2095 | | if (gop.found_existing) return .{ unit, gop.value_ptr.* }; |
| 2096 | | const entry = try wip_nav.dwarf.addCommonEntry(unit); |
| 2097 | | gop.value_ptr.* = entry; |
| 2098 | | if (maybe_inst_index == null) try wip_nav.pending_lazy.types.append(wip_nav.dwarf.gpa, ty.toIntern()); |
| 2099 | | return .{ unit, entry }; |
| 2100 | | } |
| 2101 | | |
| 2102 | 2070 | fn refType(wip_nav: *WipNav, ty: Type) (UpdateError || Writer.Error)!void { |
| 2103 | | const unit, const entry = try wip_nav.getTypeEntry(ty); |
| 2104 | | try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); |
| 2105 | | } |
| 2106 | | |
| 2107 | | fn getValueEntry(wip_nav: *WipNav, value: Value) UpdateError!struct { Unit.Index, Entry.Index } { |
| 2108 | | const zcu = wip_nav.pt.zcu; |
| 2109 | | const ip = &zcu.intern_pool; |
| 2110 | | const ty = value.typeOf(zcu); |
| 2111 | | if (std.debug.runtime_safety) assert(ty.comptimeOnly(zcu)); |
| 2112 | | if (ty.toIntern() == .type_type) return wip_nav.getTypeEntry(value.toType()); |
| 2113 | | if (ip.isFunctionType(ty.toIntern()) and !value.isUndef(zcu)) return wip_nav.getNavEntry(switch (ip.indexToKey(value.toIntern())) { |
| 2114 | | else => unreachable, |
| 2115 | | .func => |func| func.owner_nav, |
| 2116 | | .@"extern" => |@"extern"| @"extern".owner_nav, |
| 2117 | | }); |
| 2118 | | const gop = try wip_nav.dwarf.values.getOrPut(wip_nav.dwarf.gpa, value.toIntern()); |
| 2119 | | const unit: Unit.Index = .main; |
| 2120 | | if (gop.found_existing) return .{ unit, gop.value_ptr.* }; |
| 2121 | | const entry = try wip_nav.dwarf.addCommonEntry(unit); |
| 2122 | | gop.value_ptr.* = entry; |
| 2123 | | try wip_nav.pending_lazy.values.append(wip_nav.dwarf.gpa, value.toIntern()); |
| 2124 | | return .{ unit, entry }; |
| 2071 | return wip_nav.refValue(ty.toValue()); |
| 2125 | 2072 | } |
| 2126 | 2073 | |
| 2127 | 2074 | fn refValue(wip_nav: *WipNav, value: Value) (UpdateError || Writer.Error)!void { |
| ... | ... | @@ -2129,6 +2076,15 @@ pub const WipNav = struct { |
| 2129 | 2076 | try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); |
| 2130 | 2077 | } |
| 2131 | 2078 | |
| 2079 | fn getValueEntry(wip_nav: *WipNav, value: Value) UpdateError!struct { Unit.Index, Entry.Index } { |
| 2080 | if (value.typeOf(wip_nav.pt.zcu).toIntern() != .type_type) { |
| 2081 | assert(value.typeOf(wip_nav.pt.zcu).comptimeOnly(wip_nav.pt.zcu)); |
| 2082 | } |
| 2083 | const dwarf = wip_nav.dwarf; |
| 2084 | const index = try dwarf.const_pool.get(wip_nav.pt, .{ .dwarf = dwarf }, value.toIntern()); |
| 2085 | return dwarf.values.items[@intFromEnum(index)]; |
| 2086 | } |
| 2087 | |
| 2132 | 2088 | fn refForward(wip_nav: *WipNav) (Allocator.Error || Writer.Error)!u32 { |
| 2133 | 2089 | const dwarf = wip_nav.dwarf; |
| 2134 | 2090 | const diw = &wip_nav.debug_info.writer; |
| ... | ... | @@ -2156,7 +2112,7 @@ pub const WipNav = struct { |
| 2156 | 2112 | ) (UpdateError || Writer.Error)!void { |
| 2157 | 2113 | const ty = val.typeOf(wip_nav.pt.zcu); |
| 2158 | 2114 | const diw = &wip_nav.debug_info.writer; |
| 2159 | | const size = if (ty.hasRuntimeBits(wip_nav.pt.zcu)) ty.abiSize(wip_nav.pt.zcu) else 0; |
| 2115 | const size = ty.abiSize(wip_nav.pt.zcu); |
| 2160 | 2116 | try diw.writeUleb128(size); |
| 2161 | 2117 | if (size == 0) return; |
| 2162 | 2118 | const old_end = wip_nav.debug_info.writer.end; |
| ... | ... | @@ -2331,22 +2287,6 @@ pub const WipNav = struct { |
| 2331 | 2287 | try wip_nav.refType(parent_type.?); |
| 2332 | 2288 | try wip_nav.infoSectionOffset(.debug_info, wip_nav.unit, generic_decl_entry, 0); |
| 2333 | 2289 | } |
| 2334 | | |
| 2335 | | const PendingLazy = struct { |
| 2336 | | types: std.ArrayList(InternPool.Index), |
| 2337 | | values: std.ArrayList(InternPool.Index), |
| 2338 | | |
| 2339 | | const empty: PendingLazy = .{ .types = .empty, .values = .empty }; |
| 2340 | | }; |
| 2341 | | |
| 2342 | | fn updateLazy(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc) (UpdateError || Writer.Error)!void { |
| 2343 | | while (true) if (wip_nav.pending_lazy.types.pop()) |pending_ty| |
| 2344 | | try wip_nav.dwarf.updateLazyType(wip_nav.pt, src_loc, pending_ty, &wip_nav.pending_lazy) |
| 2345 | | else if (wip_nav.pending_lazy.values.pop()) |pending_val| |
| 2346 | | try wip_nav.dwarf.updateLazyValue(wip_nav.pt, src_loc, pending_val, &wip_nav.pending_lazy) |
| 2347 | | else |
| 2348 | | break; |
| 2349 | | } |
| 2350 | 2290 | }; |
| 2351 | 2291 | |
| 2352 | 2292 | /// When allocating, the ideal_capacity is calculated by |
| ... | ... | @@ -2372,8 +2312,9 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf { |
| 2372 | 2312 | }, |
| 2373 | 2313 | .endian = target.cpu.arch.endian(), |
| 2374 | 2314 | |
| 2315 | .const_pool = .empty, |
| 2316 | |
| 2375 | 2317 | .mods = .empty, |
| 2376 | | .types = .empty, |
| 2377 | 2318 | .values = .empty, |
| 2378 | 2319 | .navs = .empty, |
| 2379 | 2320 | .decls = .empty, |
| ... | ... | @@ -2544,9 +2485,9 @@ pub fn initMetadata(dwarf: *Dwarf) UpdateError!void { |
| 2544 | 2485 | |
| 2545 | 2486 | pub fn deinit(dwarf: *Dwarf) void { |
| 2546 | 2487 | const gpa = dwarf.gpa; |
| 2488 | dwarf.const_pool.deinit(gpa); |
| 2547 | 2489 | for (dwarf.mods.values()) |*mod_info| mod_info.deinit(gpa); |
| 2548 | 2490 | dwarf.mods.deinit(gpa); |
| 2549 | | dwarf.types.deinit(gpa); |
| 2550 | 2491 | dwarf.values.deinit(gpa); |
| 2551 | 2492 | dwarf.navs.deinit(gpa); |
| 2552 | 2493 | dwarf.decls.deinit(gpa); |
| ... | ... | @@ -2562,6 +2503,21 @@ pub fn deinit(dwarf: *Dwarf) void { |
| 2562 | 2503 | dwarf.* = undefined; |
| 2563 | 2504 | } |
| 2564 | 2505 | |
| 2506 | fn getNavEntry( |
| 2507 | dwarf: *Dwarf, |
| 2508 | nav_index: InternPool.Nav.Index, |
| 2509 | ) UpdateError!struct { Unit.Index, Entry.Index } { |
| 2510 | const zcu = dwarf.bin_file.comp.zcu.?; |
| 2511 | const ip = &zcu.intern_pool; |
| 2512 | const nav = ip.getNav(nav_index); |
| 2513 | const unit = try dwarf.getUnit(zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?); |
| 2514 | const gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index); |
| 2515 | if (gop.found_existing) return .{ unit, gop.value_ptr.* }; |
| 2516 | const entry = try dwarf.addCommonEntry(unit); |
| 2517 | gop.value_ptr.* = entry; |
| 2518 | return .{ unit, entry }; |
| 2519 | } |
| 2520 | |
| 2565 | 2521 | fn getUnit(dwarf: *Dwarf, mod: *Module) !Unit.Index { |
| 2566 | 2522 | const mod_gop = try dwarf.mods.getOrPut(dwarf.gpa, mod); |
| 2567 | 2523 | const unit: Unit.Index = @enumFromInt(mod_gop.index); |
| ... | ... | @@ -2622,6 +2578,10 @@ fn getModInfo(dwarf: *Dwarf, unit: Unit.Index) *ModInfo { |
| 2622 | 2578 | return &dwarf.mods.values()[@intFromEnum(unit)]; |
| 2623 | 2579 | } |
| 2624 | 2580 | |
| 2581 | fn getUnitModule(dwarf: *Dwarf, unit: Unit.Index) *Module { |
| 2582 | return dwarf.mods.keys()[@intFromEnum(unit)]; |
| 2583 | } |
| 2584 | |
| 2625 | 2585 | pub fn initWipNav( |
| 2626 | 2586 | dwarf: *Dwarf, |
| 2627 | 2587 | pt: Zcu.PerThread, |
| ... | ... | @@ -2683,7 +2643,6 @@ fn initWipNavInner( |
| 2683 | 2643 | .debug_info = .init(dwarf.gpa), |
| 2684 | 2644 | .debug_line = .init(dwarf.gpa), |
| 2685 | 2645 | .debug_loclists = .init(dwarf.gpa), |
| 2686 | | .pending_lazy = .empty, |
| 2687 | 2646 | }; |
| 2688 | 2647 | errdefer wip_nav.deinit(); |
| 2689 | 2648 | |
| ... | ... | @@ -3050,7 +3009,7 @@ fn finishWipNavWriterError( |
| 3050 | 3009 | } |
| 3051 | 3010 | try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.written()); |
| 3052 | 3011 | |
| 3053 | | try wip_nav.updateLazy(zcu.navSrcLoc(nav_index)); |
| 3012 | try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf }); |
| 3054 | 3013 | } |
| 3055 | 3014 | |
| 3056 | 3015 | pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) error{ OutOfMemory, CodegenFail }!void { |
| ... | ... | @@ -3087,34 +3046,12 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3087 | 3046 | return; |
| 3088 | 3047 | } |
| 3089 | 3048 | |
| 3090 | | var wip_nav: WipNav = .{ |
| 3091 | | .dwarf = dwarf, |
| 3092 | | .pt = pt, |
| 3093 | | .unit = try dwarf.getUnit(file.mod.?), |
| 3094 | | .entry = undefined, |
| 3095 | | .any_children = false, |
| 3096 | | .func = .none, |
| 3097 | | .func_sym_index = undefined, |
| 3098 | | .func_high_pc = undefined, |
| 3099 | | .blocks = undefined, |
| 3100 | | .cfi = undefined, |
| 3101 | | .debug_frame = .init(dwarf.gpa), |
| 3102 | | .debug_info = .init(dwarf.gpa), |
| 3103 | | .debug_line = .init(dwarf.gpa), |
| 3104 | | .debug_loclists = .init(dwarf.gpa), |
| 3105 | | .pending_lazy = .empty, |
| 3106 | | }; |
| 3107 | | defer wip_nav.deinit(); |
| 3108 | | |
| 3109 | | const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index); |
| 3110 | | errdefer _ = if (!nav_gop.found_existing) dwarf.navs.pop(); |
| 3111 | | |
| 3112 | 3049 | const tag: union(enum) { |
| 3113 | | done, |
| 3114 | | decl_alias, |
| 3115 | | decl_var, |
| 3116 | | decl_const, |
| 3117 | | decl_func_alias: InternPool.Nav.Index, |
| 3050 | alias, |
| 3051 | @"var", |
| 3052 | @"const", |
| 3053 | func: Type, |
| 3054 | func_alias: InternPool.Nav.Index, |
| 3118 | 3055 | } = switch (ip.indexToKey(nav_val.toIntern())) { |
| 3119 | 3056 | .int_type, |
| 3120 | 3057 | .ptr_type, |
| ... | ... | @@ -3128,242 +3065,49 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3128 | 3065 | .func_type, |
| 3129 | 3066 | .error_set_type, |
| 3130 | 3067 | .inferred_error_set_type, |
| 3131 | | => .decl_alias, |
| 3068 | => .alias, |
| 3069 | |
| 3132 | 3070 | .struct_type => tag: { |
| 3133 | 3071 | const loaded_struct = ip.loadStructType(nav_val.toIntern()); |
| 3134 | | if (loaded_struct.zir_index.resolveFile(ip) != inst_info.file) break :tag .decl_alias; |
| 3135 | | |
| 3136 | | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern()); |
| 3137 | | if (type_gop.found_existing) { |
| 3138 | | if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias; |
| 3139 | | assert(!nav_gop.found_existing); |
| 3140 | | nav_gop.value_ptr.* = type_gop.value_ptr.*; |
| 3141 | | } else { |
| 3142 | | if (nav_gop.found_existing) |
| 3143 | | dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear() |
| 3144 | | else |
| 3145 | | nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); |
| 3146 | | type_gop.value_ptr.* = nav_gop.value_ptr.*; |
| 3147 | | } |
| 3148 | | wip_nav.entry = nav_gop.value_ptr.*; |
| 3149 | | |
| 3150 | | const diw = &wip_nav.debug_info.writer; |
| 3151 | | |
| 3152 | | switch (loaded_struct.layout) { |
| 3153 | | .auto, .@"extern" => { |
| 3154 | | try wip_nav.declCommon(if (loaded_struct.field_types.len == 0) .{ |
| 3155 | | .decl = .decl_namespace_struct, |
| 3156 | | .generic_decl = .generic_decl_const, |
| 3157 | | .decl_instance = .decl_instance_namespace_struct, |
| 3158 | | } else .{ |
| 3159 | | .decl = .decl_struct, |
| 3160 | | .generic_decl = .generic_decl_const, |
| 3161 | | .decl_instance = .decl_instance_struct, |
| 3162 | | }, &nav, inst_info.file, &decl); |
| 3163 | | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { |
| 3164 | | try diw.writeUleb128(nav_val.toType().abiSize(zcu)); |
| 3165 | | try diw.writeUleb128(nav_val.toType().abiAlignment(zcu).toByteUnits().?); |
| 3166 | | for (0..loaded_struct.field_types.len) |field_index| { |
| 3167 | | const is_comptime = loaded_struct.field_is_comptime_bits.get(ip, field_index); |
| 3168 | | const field_init = loaded_struct.field_defaults.getOrNone(ip, field_index); |
| 3169 | | assert(!(is_comptime and field_init == .none)); |
| 3170 | | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 3171 | | const has_runtime_bits, const has_comptime_state = switch (field_init) { |
| 3172 | | .none => .{ false, false }, |
| 3173 | | else => .{ |
| 3174 | | field_type.hasRuntimeBits(zcu), |
| 3175 | | field_type.comptimeOnly(zcu), |
| 3176 | | }, |
| 3177 | | }; |
| 3178 | | try wip_nav.abbrevCode(if (is_comptime) |
| 3179 | | if (has_comptime_state) |
| 3180 | | .struct_field_comptime_comptime_state |
| 3181 | | else if (has_runtime_bits) |
| 3182 | | .struct_field_comptime_runtime_bits |
| 3183 | | else |
| 3184 | | .struct_field_comptime |
| 3185 | | else if (field_init != .none) |
| 3186 | | if (has_comptime_state) |
| 3187 | | .struct_field_default_comptime_state |
| 3188 | | else if (has_runtime_bits) |
| 3189 | | .struct_field_default_runtime_bits |
| 3190 | | else |
| 3191 | | .struct_field |
| 3192 | | else |
| 3193 | | .struct_field); |
| 3194 | | try wip_nav.strp(loaded_struct.field_names.get(ip)[field_index].toSlice(ip)); |
| 3195 | | try wip_nav.refType(field_type); |
| 3196 | | if (!is_comptime) { |
| 3197 | | try diw.writeUleb128(loaded_struct.field_offsets.get(ip)[field_index]); |
| 3198 | | try diw.writeUleb128(loaded_struct.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse |
| 3199 | | field_type.abiAlignment(zcu).toByteUnits().?); |
| 3200 | | } |
| 3201 | | if (has_comptime_state) |
| 3202 | | try wip_nav.refValue(.fromInterned(field_init)) |
| 3203 | | else if (has_runtime_bits) |
| 3204 | | try wip_nav.blockValue(nav_src_loc, .fromInterned(field_init)); |
| 3205 | | } |
| 3206 | | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3207 | | } |
| 3208 | | }, |
| 3209 | | .@"packed" => { |
| 3210 | | try wip_nav.declCommon(.{ |
| 3211 | | .decl = .decl_packed_struct, |
| 3212 | | .generic_decl = .generic_decl_const, |
| 3213 | | .decl_instance = .decl_instance_packed_struct, |
| 3214 | | }, &nav, inst_info.file, &decl); |
| 3215 | | try wip_nav.refType(.fromInterned(loaded_struct.packed_backing_int_type)); |
| 3216 | | var field_bit_offset: u16 = 0; |
| 3217 | | for (0..loaded_struct.field_types.len) |field_index| { |
| 3218 | | try wip_nav.abbrevCode(.packed_struct_field); |
| 3219 | | try wip_nav.strp(loaded_struct.field_names.get(ip)[field_index].toSlice(ip)); |
| 3220 | | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 3221 | | try wip_nav.refType(field_type); |
| 3222 | | try diw.writeUleb128(field_bit_offset); |
| 3223 | | field_bit_offset += @intCast(field_type.bitSize(zcu)); |
| 3224 | | } |
| 3225 | | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3226 | | }, |
| 3072 | if (nav_index.toOptional() == loaded_struct.name_nav) { |
| 3073 | // This Nav's entry is populated by the type, not the actual Nav. |
| 3074 | _ = try dwarf.const_pool.get(pt, .{ .dwarf = dwarf }, nav_val.toIntern()); |
| 3075 | try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf }); |
| 3076 | return; |
| 3227 | 3077 | } |
| 3228 | | break :tag .done; |
| 3078 | break :tag .alias; |
| 3229 | 3079 | }, |
| 3230 | 3080 | .enum_type => tag: { |
| 3231 | 3081 | const loaded_enum = ip.loadEnumType(nav_val.toIntern()); |
| 3232 | | const type_zir_index = loaded_enum.zir_index.unwrap() orelse break :tag .decl_alias; |
| 3233 | | if (type_zir_index.resolveFile(ip) != inst_info.file) break :tag .decl_alias; |
| 3234 | | |
| 3235 | | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern()); |
| 3236 | | if (type_gop.found_existing) { |
| 3237 | | if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias; |
| 3238 | | assert(!nav_gop.found_existing); |
| 3239 | | nav_gop.value_ptr.* = type_gop.value_ptr.*; |
| 3240 | | } else { |
| 3241 | | if (nav_gop.found_existing) |
| 3242 | | dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear() |
| 3243 | | else |
| 3244 | | nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); |
| 3245 | | type_gop.value_ptr.* = nav_gop.value_ptr.*; |
| 3246 | | } |
| 3247 | | wip_nav.entry = nav_gop.value_ptr.*; |
| 3248 | | const diw = &wip_nav.debug_info.writer; |
| 3249 | | try wip_nav.declCommon(if (loaded_enum.field_names.len > 0) .{ |
| 3250 | | .decl = .decl_enum, |
| 3251 | | .generic_decl = .generic_decl_const, |
| 3252 | | .decl_instance = .decl_instance_enum, |
| 3253 | | } else .{ |
| 3254 | | .decl = .decl_empty_enum, |
| 3255 | | .generic_decl = .generic_decl_const, |
| 3256 | | .decl_instance = .decl_instance_empty_enum, |
| 3257 | | }, &nav, inst_info.file, &decl); |
| 3258 | | try wip_nav.refType(.fromInterned(loaded_enum.int_tag_type)); |
| 3259 | | for (0..loaded_enum.field_names.len) |field_index| { |
| 3260 | | try wip_nav.enumConstValue(loaded_enum, .{ |
| 3261 | | .sdata = .signed_enum_field, |
| 3262 | | .udata = .unsigned_enum_field, |
| 3263 | | .block = .big_enum_field, |
| 3264 | | }, field_index); |
| 3265 | | try wip_nav.strp(loaded_enum.field_names.get(ip)[field_index].toSlice(ip)); |
| 3082 | if (nav_index.toOptional() == loaded_enum.name_nav) { |
| 3083 | // This Nav's entry is populated by the type, not the actual Nav. |
| 3084 | _ = try dwarf.const_pool.get(pt, .{ .dwarf = dwarf }, nav_val.toIntern()); |
| 3085 | try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf }); |
| 3086 | return; |
| 3266 | 3087 | } |
| 3267 | | if (loaded_enum.field_names.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3268 | | break :tag .done; |
| 3088 | break :tag .alias; |
| 3269 | 3089 | }, |
| 3270 | 3090 | .union_type => tag: { |
| 3271 | 3091 | const loaded_union = ip.loadUnionType(nav_val.toIntern()); |
| 3272 | | if (loaded_union.zir_index.resolveFile(ip) != inst_info.file) break :tag .decl_alias; |
| 3273 | | |
| 3274 | | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern()); |
| 3275 | | if (type_gop.found_existing) { |
| 3276 | | if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias; |
| 3277 | | assert(!nav_gop.found_existing); |
| 3278 | | nav_gop.value_ptr.* = type_gop.value_ptr.*; |
| 3279 | | } else { |
| 3280 | | if (nav_gop.found_existing) |
| 3281 | | dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear() |
| 3282 | | else |
| 3283 | | nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); |
| 3284 | | type_gop.value_ptr.* = nav_gop.value_ptr.*; |
| 3285 | | } |
| 3286 | | wip_nav.entry = nav_gop.value_ptr.*; |
| 3287 | | const diw = &wip_nav.debug_info.writer; |
| 3288 | | try wip_nav.declCommon(.{ |
| 3289 | | .decl = .decl_union, |
| 3290 | | .generic_decl = .generic_decl_const, |
| 3291 | | .decl_instance = .decl_instance_union, |
| 3292 | | }, &nav, inst_info.file, &decl); |
| 3293 | | const union_layout = Type.getUnionLayout(loaded_union, zcu); |
| 3294 | | try diw.writeUleb128(union_layout.abi_size); |
| 3295 | | try diw.writeUleb128(union_layout.abi_align.toByteUnits().?); |
| 3296 | | const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type); |
| 3297 | | if (loaded_union.has_runtime_tag) { |
| 3298 | | try wip_nav.abbrevCode(.tagged_union); |
| 3299 | | try wip_nav.infoSectionOffset( |
| 3300 | | .debug_info, |
| 3301 | | wip_nav.unit, |
| 3302 | | wip_nav.entry, |
| 3303 | | @intCast(diw.end + dwarf.sectionOffsetBytes()), |
| 3304 | | ); |
| 3305 | | { |
| 3306 | | try wip_nav.abbrevCode(.generated_field); |
| 3307 | | try wip_nav.strp("tag"); |
| 3308 | | try wip_nav.refType(.fromInterned(loaded_union.enum_tag_type)); |
| 3309 | | try diw.writeUleb128(union_layout.tagOffset()); |
| 3310 | | |
| 3311 | | for (0..loaded_union.field_types.len) |field_index| { |
| 3312 | | try wip_nav.enumConstValue(loaded_tag, .{ |
| 3313 | | .sdata = .signed_tagged_union_field, |
| 3314 | | .udata = .unsigned_tagged_union_field, |
| 3315 | | .block = .big_tagged_union_field, |
| 3316 | | }, field_index); |
| 3317 | | { |
| 3318 | | try wip_nav.abbrevCode(.struct_field); |
| 3319 | | try wip_nav.strp(loaded_tag.field_names.get(ip)[field_index].toSlice(ip)); |
| 3320 | | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 3321 | | try wip_nav.refType(field_type); |
| 3322 | | try diw.writeUleb128(union_layout.payloadOffset()); |
| 3323 | | try diw.writeUleb128(loaded_union.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse |
| 3324 | | if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?); |
| 3325 | | } |
| 3326 | | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3327 | | } |
| 3328 | | } |
| 3329 | | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3330 | | } else for (0..loaded_union.field_types.len) |field_index| { |
| 3331 | | try wip_nav.abbrevCode(.untagged_union_field); |
| 3332 | | try wip_nav.strp(loaded_tag.field_names.get(ip)[field_index].toSlice(ip)); |
| 3333 | | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 3334 | | try wip_nav.refType(field_type); |
| 3335 | | try diw.writeUleb128(loaded_union.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse |
| 3336 | | if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?); |
| 3092 | if (nav_index.toOptional() == loaded_union.name_nav) { |
| 3093 | // This Nav's entry is populated by the type, not the actual Nav. |
| 3094 | _ = try dwarf.const_pool.get(pt, .{ .dwarf = dwarf }, nav_val.toIntern()); |
| 3095 | try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf }); |
| 3096 | return; |
| 3337 | 3097 | } |
| 3338 | | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3339 | | break :tag .done; |
| 3098 | break :tag .alias; |
| 3340 | 3099 | }, |
| 3341 | 3100 | .opaque_type => tag: { |
| 3342 | 3101 | const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern()); |
| 3343 | | if (loaded_opaque.zir_index.resolveFile(ip) != inst_info.file) break :tag .decl_alias; |
| 3344 | | |
| 3345 | | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern()); |
| 3346 | | if (type_gop.found_existing) { |
| 3347 | | if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias; |
| 3348 | | assert(!nav_gop.found_existing); |
| 3349 | | nav_gop.value_ptr.* = type_gop.value_ptr.*; |
| 3350 | | } else { |
| 3351 | | if (nav_gop.found_existing) |
| 3352 | | dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear() |
| 3353 | | else |
| 3354 | | nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); |
| 3355 | | type_gop.value_ptr.* = nav_gop.value_ptr.*; |
| 3102 | if (nav_index.toOptional() == loaded_opaque.name_nav) { |
| 3103 | // This Nav's entry is populated by the type, not the actual Nav. |
| 3104 | _ = try dwarf.const_pool.get(pt, .{ .dwarf = dwarf }, nav_val.toIntern()); |
| 3105 | try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf }); |
| 3106 | return; |
| 3356 | 3107 | } |
| 3357 | | wip_nav.entry = nav_gop.value_ptr.*; |
| 3358 | | const diw = &wip_nav.debug_info.writer; |
| 3359 | | try wip_nav.declCommon(.{ |
| 3360 | | .decl = .decl_namespace_struct, |
| 3361 | | .generic_decl = .generic_decl_const, |
| 3362 | | .decl_instance = .decl_instance_namespace_struct, |
| 3363 | | }, &nav, inst_info.file, &decl); |
| 3364 | | try diw.writeByte(@intFromBool(true)); |
| 3365 | | break :tag .done; |
| 3108 | break :tag .alias; |
| 3366 | 3109 | }, |
| 3110 | |
| 3367 | 3111 | .undef, |
| 3368 | 3112 | .simple_value, |
| 3369 | 3113 | .int, |
| ... | ... | @@ -3378,72 +3122,77 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3378 | 3122 | .aggregate, |
| 3379 | 3123 | .un, |
| 3380 | 3124 | .bitpack, |
| 3381 | | => .decl_const, |
| 3382 | | .variable => .decl_var, |
| 3125 | => .@"const", |
| 3126 | |
| 3127 | .variable => .@"var", |
| 3128 | |
| 3383 | 3129 | .@"extern" => unreachable, |
| 3384 | | .func => |func| tag: { |
| 3385 | | if (func.owner_nav != nav_index) break :tag .{ .decl_func_alias = func.owner_nav }; |
| 3386 | | if (nav_gop.found_existing) switch (try dwarf.debug_info.declAbbrevCode(wip_nav.unit, nav_gop.value_ptr.*)) { |
| 3387 | | .null => {}, |
| 3388 | | else => unreachable, |
| 3389 | | .decl_nullary_func, .decl_func, .decl_instance_nullary_func, .decl_instance_func => return, |
| 3390 | | .decl_nullary_func_generic, |
| 3391 | | .decl_func_generic, |
| 3392 | | .decl_instance_nullary_func_generic, |
| 3393 | | .decl_instance_func_generic, |
| 3394 | | => dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear(), |
| 3395 | | } else nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); |
| 3396 | | wip_nav.entry = nav_gop.value_ptr.*; |
| 3397 | 3130 | |
| 3398 | | const func_type = ip.indexToKey(func.ty).func_type; |
| 3399 | | const is_nullary = !func_type.is_var_args and for (0..func_type.param_types.len) |param_index| { |
| 3400 | | if (!func_type.paramIsComptime(std.math.cast(u5, param_index) orelse break false)) break false; |
| 3401 | | } else true; |
| 3402 | | const diw = &wip_nav.debug_info.writer; |
| 3403 | | try wip_nav.declCommon(if (is_nullary) .{ |
| 3404 | | .decl = .decl_nullary_func_generic, |
| 3405 | | .generic_decl = .generic_decl_func, |
| 3406 | | .decl_instance = .decl_instance_nullary_func_generic, |
| 3407 | | } else .{ |
| 3408 | | .decl = .decl_func_generic, |
| 3409 | | .generic_decl = .generic_decl_func, |
| 3410 | | .decl_instance = .decl_instance_func_generic, |
| 3411 | | }, &nav, inst_info.file, &decl); |
| 3412 | | try wip_nav.refType(.fromInterned(func_type.return_type)); |
| 3413 | | if (!is_nullary) { |
| 3414 | | for (0..func_type.param_types.len) |param_index| { |
| 3415 | | if (std.math.cast(u5, param_index)) |small_param_index| |
| 3416 | | if (func_type.paramIsComptime(small_param_index)) continue; |
| 3417 | | try wip_nav.abbrevCode(.func_type_param); |
| 3418 | | try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index])); |
| 3419 | | } |
| 3420 | | if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args); |
| 3421 | | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3422 | | } |
| 3423 | | break :tag .done; |
| 3131 | .func => |func| tag: { |
| 3132 | if (func.owner_nav != nav_index) break :tag .{ .func_alias = func.owner_nav }; |
| 3133 | break :tag .{ .func = .fromInterned(func.ty) }; |
| 3424 | 3134 | }, |
| 3135 | |
| 3425 | 3136 | // memoization, not types |
| 3426 | 3137 | .memoized_call => unreachable, |
| 3427 | 3138 | }; |
| 3428 | | if (tag != .done) { |
| 3429 | | if (nav_gop.found_existing) |
| 3430 | | dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear() |
| 3431 | | else |
| 3432 | | nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); |
| 3433 | | wip_nav.entry = nav_gop.value_ptr.*; |
| 3139 | |
| 3140 | const unit = try dwarf.getUnit(file.mod.?); |
| 3141 | |
| 3142 | const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index); |
| 3143 | errdefer _ = if (!nav_gop.found_existing) dwarf.navs.pop(); |
| 3144 | |
| 3145 | if (nav_gop.found_existing) { |
| 3146 | if (tag == .func) switch (try dwarf.debug_info.declAbbrevCode(unit, nav_gop.value_ptr.*)) { |
| 3147 | else => unreachable, |
| 3148 | |
| 3149 | .decl_nullary_func, |
| 3150 | .decl_func, |
| 3151 | .decl_instance_nullary_func, |
| 3152 | .decl_instance_func, |
| 3153 | => return, |
| 3154 | |
| 3155 | .null, |
| 3156 | .decl_nullary_func_generic, |
| 3157 | .decl_func_generic, |
| 3158 | .decl_instance_nullary_func_generic, |
| 3159 | .decl_instance_func_generic, |
| 3160 | => {}, |
| 3161 | }; |
| 3162 | dwarf.debug_info.section.getUnit(unit).getEntry(nav_gop.value_ptr.*).clear(); |
| 3163 | } else { |
| 3164 | nav_gop.value_ptr.* = try dwarf.addCommonEntry(unit); |
| 3434 | 3165 | } |
| 3435 | | switch (tag) { |
| 3436 | | .done => {}, |
| 3437 | | .decl_alias => { |
| 3438 | | try wip_nav.declCommon(.{ |
| 3439 | | .decl = .decl_alias, |
| 3440 | | .generic_decl = .generic_decl_const, |
| 3441 | | .decl_instance = .decl_instance_alias, |
| 3442 | | }, &nav, inst_info.file, &decl); |
| 3443 | | try wip_nav.refType(nav_val.toType()); |
| 3444 | | }, |
| 3445 | | .decl_var => { |
| 3446 | | const diw = &wip_nav.debug_info.writer; |
| 3166 | |
| 3167 | var wip_nav: WipNav = .{ |
| 3168 | .dwarf = dwarf, |
| 3169 | .pt = pt, |
| 3170 | .unit = unit, |
| 3171 | .entry = nav_gop.value_ptr.*, |
| 3172 | .any_children = false, |
| 3173 | .func = .none, |
| 3174 | .func_sym_index = undefined, |
| 3175 | .func_high_pc = undefined, |
| 3176 | .blocks = undefined, |
| 3177 | .cfi = undefined, |
| 3178 | .debug_frame = .init(dwarf.gpa), |
| 3179 | .debug_info = .init(dwarf.gpa), |
| 3180 | .debug_line = .init(dwarf.gpa), |
| 3181 | .debug_loclists = .init(dwarf.gpa), |
| 3182 | }; |
| 3183 | defer wip_nav.deinit(); |
| 3184 | const diw = &wip_nav.debug_info.writer; |
| 3185 | |
| 3186 | switch (tag) { |
| 3187 | .alias => { |
| 3188 | try wip_nav.declCommon(.{ |
| 3189 | .decl = .decl_alias, |
| 3190 | .generic_decl = .generic_decl_const, |
| 3191 | .decl_instance = .decl_instance_alias, |
| 3192 | }, &nav, inst_info.file, &decl); |
| 3193 | try wip_nav.refType(nav_val.toType()); |
| 3194 | }, |
| 3195 | .@"var" => { |
| 3447 | 3196 | try wip_nav.declCommon(.{ |
| 3448 | 3197 | .decl = .decl_var, |
| 3449 | 3198 | .generic_decl = .generic_decl_var, |
| ... | ... | @@ -3460,8 +3209,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3460 | 3209 | nav_ty.abiAlignment(zcu).toByteUnits().?); |
| 3461 | 3210 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 3462 | 3211 | }, |
| 3463 | | .decl_const => { |
| 3464 | | const diw = &wip_nav.debug_info.writer; |
| 3212 | .@"const" => { |
| 3465 | 3213 | const nav_ty = nav_val.typeOf(zcu); |
| 3466 | 3214 | const has_runtime_bits = nav_ty.hasRuntimeBits(zcu); |
| 3467 | 3215 | const has_comptime_state = nav_ty.comptimeOnly(zcu); |
| ... | ... | @@ -3496,7 +3244,33 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3496 | 3244 | try wip_nav.abbrevCode(.is_const); |
| 3497 | 3245 | try wip_nav.refType(nav_ty); |
| 3498 | 3246 | }, |
| 3499 | | .decl_func_alias => |owner_nav| { |
| 3247 | .func => |func_ty| { |
| 3248 | const func_type = ip.indexToKey(func_ty.toIntern()).func_type; |
| 3249 | const is_nullary = !func_type.is_var_args and for (0..func_type.param_types.len) |param_index| { |
| 3250 | if (!func_type.paramIsComptime(std.math.cast(u5, param_index) orelse break false)) break false; |
| 3251 | } else true; |
| 3252 | try wip_nav.declCommon(if (is_nullary) .{ |
| 3253 | .decl = .decl_nullary_func_generic, |
| 3254 | .generic_decl = .generic_decl_func, |
| 3255 | .decl_instance = .decl_instance_nullary_func_generic, |
| 3256 | } else .{ |
| 3257 | .decl = .decl_func_generic, |
| 3258 | .generic_decl = .generic_decl_func, |
| 3259 | .decl_instance = .decl_instance_func_generic, |
| 3260 | }, &nav, inst_info.file, &decl); |
| 3261 | try wip_nav.refType(.fromInterned(func_type.return_type)); |
| 3262 | if (!is_nullary) { |
| 3263 | for (0..func_type.param_types.len) |param_index| { |
| 3264 | if (std.math.cast(u5, param_index)) |small_param_index| |
| 3265 | if (func_type.paramIsComptime(small_param_index)) continue; |
| 3266 | try wip_nav.abbrevCode(.func_type_param); |
| 3267 | try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index])); |
| 3268 | } |
| 3269 | if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args); |
| 3270 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3271 | } |
| 3272 | }, |
| 3273 | .func_alias => |owner_nav| { |
| 3500 | 3274 | try wip_nav.declCommon(.{ |
| 3501 | 3275 | .decl = .decl_alias, |
| 3502 | 3276 | .generic_decl = .generic_decl_const, |
| ... | ... | @@ -3505,31 +3279,81 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3505 | 3279 | try wip_nav.refNav(owner_nav); |
| 3506 | 3280 | }, |
| 3507 | 3281 | } |
| 3508 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.written()); |
| 3509 | | try wip_nav.updateLazy(nav_src_loc); |
| 3282 | try dwarf.debug_info.section.replaceEntry(unit, wip_nav.entry, dwarf, wip_nav.debug_info.written()); |
| 3283 | try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf }); |
| 3510 | 3284 | } |
| 3511 | 3285 | |
| 3512 | | fn updateLazyType( |
| 3286 | pub fn updateContainerType( |
| 3513 | 3287 | dwarf: *Dwarf, |
| 3514 | 3288 | pt: Zcu.PerThread, |
| 3515 | | src_loc: Zcu.LazySrcLoc, |
| 3516 | | type_index: InternPool.Index, |
| 3517 | | pending_lazy: *WipNav.PendingLazy, |
| 3518 | | ) (UpdateError || Writer.Error)!void { |
| 3289 | ty: InternPool.Index, |
| 3290 | success: bool, |
| 3291 | ) !void { |
| 3292 | try dwarf.const_pool.updateContainerType(pt, .{ .dwarf = dwarf }, ty, success); |
| 3293 | } |
| 3294 | /// Should only be called by the `DebugConstPool` implementation. |
| 3295 | pub fn addConst(dwarf: *Dwarf, pt: Zcu.PerThread, index: DebugConstPool.Index, val: InternPool.Index) !void { |
| 3519 | 3296 | const zcu = pt.zcu; |
| 3520 | 3297 | const ip = &zcu.intern_pool; |
| 3521 | | assert(ip.typeOf(type_index) == .type_type); |
| 3522 | | const ty: Type = .fromInterned(type_index); |
| 3523 | | switch (type_index) { |
| 3524 | | .generic_poison_type => log.debug("updateLazyType({s})", .{"anytype"}), |
| 3525 | | else => log.debug("updateLazyType({f})", .{ty.fmt(pt)}), |
| 3298 | |
| 3299 | const unit: Unit.Index, const entry: Entry.Index = switch (ip.indexToKey(val)) { |
| 3300 | else => .{ .main, try dwarf.addCommonEntry(.main) }, |
| 3301 | .func => |func| try dwarf.getNavEntry(func.owner_nav), |
| 3302 | .@"extern" => |@"extern"| try dwarf.getNavEntry(@"extern".owner_nav), |
| 3303 | .struct_type, .union_type, .enum_type, .opaque_type => |_, tag| entry: { |
| 3304 | const name_nav = switch (tag) { |
| 3305 | .struct_type => ip.loadStructType(val).name_nav, |
| 3306 | .union_type => ip.loadUnionType(val).name_nav, |
| 3307 | .enum_type => ip.loadEnumType(val).name_nav, |
| 3308 | .opaque_type => ip.loadOpaqueType(val).name_nav, |
| 3309 | else => unreachable, |
| 3310 | }; |
| 3311 | if (name_nav.unwrap()) |nav| { |
| 3312 | break :entry try dwarf.getNavEntry(nav); |
| 3313 | } else { |
| 3314 | const zir_index = Type.fromInterned(val).typeDeclInstAllowGeneratedTag(zcu).?; |
| 3315 | const unit = try dwarf.getUnit(zcu.fileByIndex(zir_index.resolveFile(ip)).mod.?); |
| 3316 | break :entry .{ unit, try dwarf.addCommonEntry(unit) }; |
| 3317 | } |
| 3318 | }, |
| 3319 | }; |
| 3320 | |
| 3321 | assert(@intFromEnum(index) == dwarf.values.items.len); |
| 3322 | try dwarf.values.append(dwarf.gpa, .{ unit, entry }); |
| 3323 | } |
| 3324 | /// Should only be called by the `DebugConstPool` implementation. |
| 3325 | /// |
| 3326 | /// Emits a "dummy" DIE for the given comptime-only value (which may be a type). For types, this is |
| 3327 | /// an opaque type. Otherwise, it is an undefined value of the value's type. |
| 3328 | pub fn updateConstIncomplete(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: DebugConstPool.Index, value_index: InternPool.Index) !void { |
| 3329 | const zcu = pt.zcu; |
| 3330 | |
| 3331 | const val: Value = .fromInterned(value_index); |
| 3332 | |
| 3333 | switch (value_index) { |
| 3334 | .generic_poison_type => log.debug("updateValueIncomplete(anytype)", .{}), |
| 3335 | else => log.debug("updateValueIncomplete(@as({f}, {f}))", .{ |
| 3336 | val.typeOf(zcu).fmt(pt), |
| 3337 | val.fmtValue(pt), |
| 3338 | }), |
| 3526 | 3339 | } |
| 3527 | 3340 | |
| 3341 | const unit, const entry = dwarf.values.items[@intFromEnum(debug_const_index)]; |
| 3342 | |
| 3343 | for ([_]*Section{ |
| 3344 | &dwarf.debug_aranges.section, |
| 3345 | &dwarf.debug_aranges.section, |
| 3346 | &dwarf.debug_info.section, |
| 3347 | &dwarf.debug_line.section, |
| 3348 | &dwarf.debug_loclists.section, |
| 3349 | &dwarf.debug_rnglists.section, |
| 3350 | }) |sec| sec.getUnit(unit).getEntry(entry).clear(); |
| 3351 | |
| 3528 | 3352 | var wip_nav: WipNav = .{ |
| 3529 | 3353 | .dwarf = dwarf, |
| 3530 | 3354 | .pt = pt, |
| 3531 | | .unit = .main, |
| 3532 | | .entry = dwarf.types.get(type_index).?, |
| 3355 | .unit = unit, |
| 3356 | .entry = entry, |
| 3533 | 3357 | .any_children = false, |
| 3534 | 3358 | .func = .none, |
| 3535 | 3359 | .func_sym_index = undefined, |
| ... | ... | @@ -3540,43 +3364,119 @@ fn updateLazyType( |
| 3540 | 3364 | .debug_info = .init(dwarf.gpa), |
| 3541 | 3365 | .debug_line = .init(dwarf.gpa), |
| 3542 | 3366 | .debug_loclists = .init(dwarf.gpa), |
| 3543 | | .pending_lazy = pending_lazy.*, |
| 3544 | 3367 | }; |
| 3545 | | defer { |
| 3546 | | pending_lazy.* = wip_nav.pending_lazy; |
| 3547 | | wip_nav.pending_lazy = .empty; |
| 3548 | | wip_nav.deinit(); |
| 3368 | defer wip_nav.deinit(); |
| 3369 | switch (val.typeOf(zcu).toIntern()) { |
| 3370 | .type_type => { |
| 3371 | try wip_nav.abbrevCode(.generated_empty_struct_type); |
| 3372 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3373 | try wip_nav.debug_info.writer.writeByte(@intFromBool(true)); |
| 3374 | }, |
| 3375 | else => |ty| { |
| 3376 | try wip_nav.abbrevCode(.undefined_comptime_value); |
| 3377 | try wip_nav.refType(.fromInterned(ty)); |
| 3378 | }, |
| 3549 | 3379 | } |
| 3550 | | const diw = &wip_nav.debug_info.writer; |
| 3551 | | const name = switch (type_index) { |
| 3552 | | .generic_poison_type => "", |
| 3553 | | else => try std.fmt.allocPrint(dwarf.gpa, "{f}", .{ty.fmt(pt)}), |
| 3380 | try dwarf.debug_info.section.replaceEntry(unit, entry, dwarf, wip_nav.debug_info.written()); |
| 3381 | try dwarf.debug_loclists.section.replaceEntry(unit, entry, dwarf, wip_nav.debug_loclists.written()); |
| 3382 | } |
| 3383 | /// Should only be called by the `DebugConstPool` implementation. |
| 3384 | /// |
| 3385 | /// Emits a DIE for the given comptime-only value (which may be a type). |
| 3386 | pub fn updateConst(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: DebugConstPool.Index, value_index: InternPool.Index) !void { |
| 3387 | const zcu = pt.zcu; |
| 3388 | const ip = &zcu.intern_pool; |
| 3389 | |
| 3390 | const val: Value = .fromInterned(value_index); |
| 3391 | |
| 3392 | if (val.typeOf(zcu).toIntern() == .type_type and !val.isUndef(zcu)) { |
| 3393 | val.toType().assertHasLayout(zcu); |
| 3394 | } else { |
| 3395 | val.typeOf(zcu).assertHasLayout(zcu); |
| 3396 | } |
| 3397 | |
| 3398 | const value_ip_key = ip.indexToKey(value_index); |
| 3399 | switch (value_ip_key) { |
| 3400 | .func => return, // populated by the Nav instead (`updateComptimeNav` or `initWipNav`) |
| 3401 | .@"extern" => return, // populated by the Nav instead (`initWipNav`) |
| 3402 | else => {}, |
| 3403 | } |
| 3404 | |
| 3405 | switch (value_index) { |
| 3406 | .generic_poison_type => log.debug("updateValue(anytype)", .{}), |
| 3407 | else => log.debug("updateValue(@as({f}, {f}))", .{ |
| 3408 | val.typeOf(zcu).fmt(pt), |
| 3409 | val.fmtValue(pt), |
| 3410 | }), |
| 3411 | } |
| 3412 | |
| 3413 | const unit, const entry = dwarf.values.items[@intFromEnum(debug_const_index)]; |
| 3414 | |
| 3415 | for ([_]*Section{ |
| 3416 | &dwarf.debug_aranges.section, |
| 3417 | &dwarf.debug_info.section, |
| 3418 | &dwarf.debug_line.section, |
| 3419 | &dwarf.debug_loclists.section, |
| 3420 | &dwarf.debug_rnglists.section, |
| 3421 | }) |sec| sec.getUnit(unit).getEntry(entry).clear(); |
| 3422 | |
| 3423 | var wip_nav: WipNav = .{ |
| 3424 | .dwarf = dwarf, |
| 3425 | .pt = pt, |
| 3426 | .unit = unit, |
| 3427 | .entry = entry, |
| 3428 | .any_children = false, |
| 3429 | .func = .none, |
| 3430 | .func_sym_index = undefined, |
| 3431 | .func_high_pc = undefined, |
| 3432 | .blocks = undefined, |
| 3433 | .cfi = undefined, |
| 3434 | .debug_frame = .init(dwarf.gpa), |
| 3435 | .debug_info = .init(dwarf.gpa), |
| 3436 | .debug_line = .init(dwarf.gpa), |
| 3437 | .debug_loclists = .init(dwarf.gpa), |
| 3554 | 3438 | }; |
| 3555 | | defer dwarf.gpa.free(name); |
| 3439 | defer wip_nav.deinit(); |
| 3440 | |
| 3441 | // TODO: we really shouldn't need source locations at this point in the pipeline: we've lost |
| 3442 | // that information by now. If the linker fundamentally cannot lower certain values, that needs |
| 3443 | // to be caught in the frontend; if it can only hit transient failures, they should be reported |
| 3444 | // without trying to tie them to a bogus source location. |
| 3445 | const src_loc: Zcu.LazySrcLoc = .{ |
| 3446 | .base_node_inst = inst: { |
| 3447 | const mod_root_file_index = zcu.module_roots.get(dwarf.getUnitModule(unit)).?.unwrap().?; |
| 3448 | const mod_root_type_index = zcu.fileRootType(mod_root_file_index); |
| 3449 | break :inst ip.loadStructType(mod_root_type_index).zir_index; |
| 3450 | }, |
| 3451 | .offset = .{ .byte_abs = 0 }, |
| 3452 | }; |
| 3453 | |
| 3454 | const diw = &wip_nav.debug_info.writer; |
| 3455 | var big_int_space: Value.BigIntSpace = undefined; |
| 3456 | switch (value_ip_key) { |
| 3457 | .func => unreachable, // handled above |
| 3458 | .@"extern" => unreachable, // handled above |
| 3556 | 3459 | |
| 3557 | | switch (ip.indexToKey(type_index)) { |
| 3558 | | .undef => { |
| 3559 | | try wip_nav.abbrevCode(.undefined_comptime_value); |
| 3560 | | try wip_nav.refType(.type); |
| 3561 | | }, |
| 3562 | 3460 | .int_type => |int_type| { |
| 3563 | 3461 | try wip_nav.abbrevCode(.numeric_type); |
| 3564 | | try wip_nav.strp(name); |
| 3462 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3565 | 3463 | try diw.writeByte(switch (int_type.signedness) { |
| 3566 | 3464 | inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)), |
| 3567 | 3465 | }); |
| 3568 | 3466 | try diw.writeUleb128(int_type.bits); |
| 3569 | | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3570 | | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3467 | try diw.writeUleb128(val.toType().abiSize(zcu)); |
| 3468 | try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?); |
| 3571 | 3469 | }, |
| 3572 | 3470 | .ptr_type => |ptr_type| switch (ptr_type.flags.size) { |
| 3573 | 3471 | .one, .many, .c => { |
| 3574 | 3472 | const ptr_child_type: Type = .fromInterned(ptr_type.child); |
| 3575 | | try wip_nav.abbrevCode(if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type); |
| 3576 | | try wip_nav.strp(name); |
| 3473 | try wip_nav.abbrevCode(switch (ptr_type.flags.alignment) { |
| 3474 | .none => if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type, |
| 3475 | else => if (ptr_type.sentinel == .none) .ptr_aligned_type else .ptr_aligned_sentinel_type, |
| 3476 | }); |
| 3477 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3577 | 3478 | if (ptr_type.sentinel != .none) try wip_nav.blockValue(src_loc, .fromInterned(ptr_type.sentinel)); |
| 3578 | | try diw.writeUleb128(ptr_type.flags.alignment.toByteUnits() orelse |
| 3579 | | ptr_child_type.abiAlignment(zcu).toByteUnits().?); |
| 3479 | if (ptr_type.flags.alignment.toByteUnits()) |a| try diw.writeUleb128(a); |
| 3580 | 3480 | try diw.writeByte(@intFromEnum(ptr_type.flags.address_space)); |
| 3581 | 3481 | if (ptr_type.flags.is_const or ptr_type.flags.is_volatile) try wip_nav.infoSectionOffset( |
| 3582 | 3482 | .debug_info, |
| ... | ... | @@ -3600,12 +3500,12 @@ fn updateLazyType( |
| 3600 | 3500 | }, |
| 3601 | 3501 | .slice => { |
| 3602 | 3502 | try wip_nav.abbrevCode(.generated_struct_type); |
| 3603 | | try wip_nav.strp(name); |
| 3604 | | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3605 | | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3503 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3504 | try diw.writeUleb128(val.toType().abiSize(zcu)); |
| 3505 | try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?); |
| 3606 | 3506 | try wip_nav.abbrevCode(.generated_field); |
| 3607 | 3507 | try wip_nav.strp("ptr"); |
| 3608 | | const ptr_field_type = ty.slicePtrFieldType(zcu); |
| 3508 | const ptr_field_type = val.toType().slicePtrFieldType(zcu); |
| 3609 | 3509 | try wip_nav.refType(ptr_field_type); |
| 3610 | 3510 | try diw.writeUleb128(0); |
| 3611 | 3511 | try wip_nav.abbrevCode(.generated_field); |
| ... | ... | @@ -3619,7 +3519,7 @@ fn updateLazyType( |
| 3619 | 3519 | .array_type => |array_type| { |
| 3620 | 3520 | const array_child_type: Type = .fromInterned(array_type.child); |
| 3621 | 3521 | try wip_nav.abbrevCode(if (array_type.sentinel == .none) .array_type else .array_sentinel_type); |
| 3622 | | try wip_nav.strp(name); |
| 3522 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3623 | 3523 | if (array_type.sentinel != .none) try wip_nav.blockValue(src_loc, .fromInterned(array_type.sentinel)); |
| 3624 | 3524 | try wip_nav.refType(array_child_type); |
| 3625 | 3525 | try wip_nav.abbrevCode(.array_len); |
| ... | ... | @@ -3629,7 +3529,7 @@ fn updateLazyType( |
| 3629 | 3529 | }, |
| 3630 | 3530 | .vector_type => |vector_type| { |
| 3631 | 3531 | try wip_nav.abbrevCode(.vector_type); |
| 3632 | | try wip_nav.strp(name); |
| 3532 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3633 | 3533 | try wip_nav.refType(.fromInterned(vector_type.child)); |
| 3634 | 3534 | try wip_nav.abbrevCode(.array_len); |
| 3635 | 3535 | try wip_nav.refType(.usize); |
| ... | ... | @@ -3640,9 +3540,9 @@ fn updateLazyType( |
| 3640 | 3540 | const opt_child_type: Type = .fromInterned(opt_child_type_index); |
| 3641 | 3541 | const opt_repr = optRepr(opt_child_type, zcu); |
| 3642 | 3542 | try wip_nav.abbrevCode(.generated_union_type); |
| 3643 | | try wip_nav.strp(name); |
| 3644 | | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3645 | | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3543 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3544 | try diw.writeUleb128(val.toType().abiSize(zcu)); |
| 3545 | try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?); |
| 3646 | 3546 | switch (opt_repr) { |
| 3647 | 3547 | .opv_null => { |
| 3648 | 3548 | try wip_nav.abbrevCode(.generated_field); |
| ... | ... | @@ -3720,12 +3620,12 @@ fn updateLazyType( |
| 3720 | 3620 | }; |
| 3721 | 3621 | |
| 3722 | 3622 | try wip_nav.abbrevCode(.generated_union_type); |
| 3723 | | try wip_nav.strp(name); |
| 3623 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3724 | 3624 | if (error_union_type.error_set_type != .generic_poison_type and |
| 3725 | 3625 | error_union_type.payload_type != .generic_poison_type) |
| 3726 | 3626 | { |
| 3727 | | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3728 | | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3627 | try diw.writeUleb128(val.toType().abiSize(zcu)); |
| 3628 | try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?); |
| 3729 | 3629 | } else { |
| 3730 | 3630 | try diw.writeUleb128(0); |
| 3731 | 3631 | try diw.writeUleb128(1); |
| ... | ... | @@ -3791,20 +3691,24 @@ fn updateLazyType( |
| 3791 | 3691 | .bool, |
| 3792 | 3692 | => { |
| 3793 | 3693 | try wip_nav.abbrevCode(.numeric_type); |
| 3794 | | try wip_nav.strp(name); |
| 3795 | | try diw.writeByte(if (type_index == .bool_type) |
| 3694 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3695 | try diw.writeByte(if (value_index == .bool_type) |
| 3796 | 3696 | DW.ATE.boolean |
| 3797 | | else if (ty.isRuntimeFloat()) |
| 3697 | else if (val.toType().isRuntimeFloat()) |
| 3798 | 3698 | DW.ATE.float |
| 3799 | | else if (ty.isSignedInt(zcu)) |
| 3699 | else if (val.toType().isSignedInt(zcu)) |
| 3800 | 3700 | DW.ATE.signed |
| 3801 | | else if (ty.isUnsignedInt(zcu)) |
| 3701 | else if (val.toType().isUnsignedInt(zcu)) |
| 3802 | 3702 | DW.ATE.unsigned |
| 3803 | 3703 | else |
| 3804 | 3704 | unreachable); |
| 3805 | | try diw.writeUleb128(ty.bitSize(zcu)); |
| 3806 | | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3807 | | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3705 | try diw.writeUleb128(val.toType().bitSize(zcu)); |
| 3706 | try diw.writeUleb128(val.toType().abiSize(zcu)); |
| 3707 | try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?); |
| 3708 | }, |
| 3709 | .generic_poison => { |
| 3710 | try wip_nav.abbrevCode(.void_type); |
| 3711 | try wip_nav.strp("anytype"); |
| 3808 | 3712 | }, |
| 3809 | 3713 | .anyopaque, |
| 3810 | 3714 | .void, |
| ... | ... | @@ -3815,37 +3719,29 @@ fn updateLazyType( |
| 3815 | 3719 | .null, |
| 3816 | 3720 | .undefined, |
| 3817 | 3721 | .enum_literal, |
| 3818 | | .generic_poison, |
| 3819 | 3722 | => { |
| 3820 | 3723 | try wip_nav.abbrevCode(.void_type); |
| 3821 | | try wip_nav.strp(if (type_index == .generic_poison_type) "anytype" else name); |
| 3724 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3822 | 3725 | }, |
| 3823 | 3726 | .anyerror => return, // delay until flush |
| 3824 | 3727 | .adhoc_inferred_error_set => unreachable, |
| 3825 | 3728 | }, |
| 3826 | | .struct_type, |
| 3827 | | .union_type, |
| 3828 | | .opaque_type, |
| 3829 | | => unreachable, |
| 3830 | 3729 | .tuple_type => |tuple_type| if (tuple_type.types.len == 0) { |
| 3831 | 3730 | try wip_nav.abbrevCode(.generated_empty_struct_type); |
| 3832 | | try wip_nav.strp(name); |
| 3731 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3833 | 3732 | try diw.writeByte(@intFromBool(false)); |
| 3834 | 3733 | } else { |
| 3835 | 3734 | try wip_nav.abbrevCode(.generated_struct_type); |
| 3836 | | try wip_nav.strp(name); |
| 3837 | | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3838 | | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3735 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3736 | try diw.writeUleb128(val.toType().abiSize(zcu)); |
| 3737 | try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?); |
| 3839 | 3738 | var field_byte_offset: u64 = 0; |
| 3840 | 3739 | for (0..tuple_type.types.len) |field_index| { |
| 3841 | 3740 | const comptime_value = tuple_type.values.get(ip)[field_index]; |
| 3842 | 3741 | const field_type: Type = .fromInterned(tuple_type.types.get(ip)[field_index]); |
| 3843 | 3742 | const has_runtime_bits, const has_comptime_state = switch (comptime_value) { |
| 3844 | 3743 | .none => .{ false, false }, |
| 3845 | | else => .{ |
| 3846 | | field_type.hasRuntimeBits(zcu), |
| 3847 | | field_type.comptimeOnly(zcu), |
| 3848 | | }, |
| 3744 | else => .{ field_type.hasRuntimeBits(zcu), field_type.comptimeOnly(zcu) }, |
| 3849 | 3745 | }; |
| 3850 | 3746 | try wip_nav.abbrevCode(if (has_comptime_state) |
| 3851 | 3747 | .struct_field_comptime_comptime_state |
| ... | ... | @@ -3875,25 +3771,259 @@ fn updateLazyType( |
| 3875 | 3771 | } |
| 3876 | 3772 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3877 | 3773 | }, |
| 3774 | .struct_type => { |
| 3775 | const loaded_struct = ip.loadStructType(value_index); |
| 3776 | const ty = val.toType(); |
| 3777 | const file = loaded_struct.zir_index.resolveFile(ip); |
| 3778 | switch (loaded_struct.layout) { |
| 3779 | .auto, .@"extern" => { |
| 3780 | const struct_is_file: bool = if (loaded_struct.zir_index.resolve(ip)) |inst| f: { |
| 3781 | break :f inst == .main_struct_inst; |
| 3782 | } else false; |
| 3783 | if (loaded_struct.name_nav.unwrap()) |nav_index| { |
| 3784 | assert(!struct_is_file); |
| 3785 | const nav = ip.getNav(nav_index); |
| 3786 | const decl_inst = nav.srcInst(ip).resolve(ip).?; |
| 3787 | const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst); |
| 3788 | try wip_nav.declCommon(if (loaded_struct.field_types.len == 0) .{ |
| 3789 | .decl = .decl_namespace_struct, |
| 3790 | .generic_decl = .generic_decl_const, |
| 3791 | .decl_instance = .decl_instance_namespace_struct, |
| 3792 | } else .{ |
| 3793 | .decl = .decl_struct, |
| 3794 | .generic_decl = .generic_decl_const, |
| 3795 | .decl_instance = .decl_instance_struct, |
| 3796 | }, &nav, file, &decl); |
| 3797 | } else { |
| 3798 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, file); |
| 3799 | try wip_nav.abbrevCode(switch (loaded_struct.field_types.len) { |
| 3800 | 0 => if (struct_is_file) .empty_file else .empty_struct_type, |
| 3801 | else => if (struct_is_file) .file else .struct_type, |
| 3802 | }); |
| 3803 | try diw.writeUleb128(file_gop.index); |
| 3804 | try wip_nav.strp(loaded_struct.name.toSlice(ip)); |
| 3805 | } |
| 3806 | if (loaded_struct.field_types.len == 0) { |
| 3807 | if (!struct_is_file) try diw.writeByte(@intFromBool(false)); |
| 3808 | } else { |
| 3809 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3810 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3811 | for (0..loaded_struct.field_types.len) |field_index| { |
| 3812 | const is_comptime = loaded_struct.field_is_comptime_bits.get(ip, field_index); |
| 3813 | const field_init = loaded_struct.field_defaults.getOrNone(ip, field_index); |
| 3814 | assert(!(is_comptime and field_init == .none)); |
| 3815 | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 3816 | const has_runtime_bits, const has_comptime_state = switch (field_init) { |
| 3817 | .none => .{ false, false }, |
| 3818 | else => .{ |
| 3819 | field_type.hasRuntimeBits(zcu), |
| 3820 | field_type.comptimeOnly(zcu), |
| 3821 | }, |
| 3822 | }; |
| 3823 | try wip_nav.abbrevCode(if (is_comptime) |
| 3824 | if (has_comptime_state) |
| 3825 | .struct_field_comptime_comptime_state |
| 3826 | else if (has_runtime_bits) |
| 3827 | .struct_field_comptime_runtime_bits |
| 3828 | else |
| 3829 | .struct_field_comptime |
| 3830 | else if (field_init != .none) |
| 3831 | if (has_comptime_state) |
| 3832 | .struct_field_default_comptime_state |
| 3833 | else if (has_runtime_bits) |
| 3834 | .struct_field_default_runtime_bits |
| 3835 | else |
| 3836 | .struct_field |
| 3837 | else |
| 3838 | .struct_field); |
| 3839 | try wip_nav.strp(loaded_struct.field_names.get(ip)[field_index].toSlice(ip)); |
| 3840 | try wip_nav.refType(field_type); |
| 3841 | if (!is_comptime) { |
| 3842 | try diw.writeUleb128(loaded_struct.field_offsets.get(ip)[field_index]); |
| 3843 | try diw.writeUleb128(loaded_struct.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse |
| 3844 | field_type.abiAlignment(zcu).toByteUnits().?); |
| 3845 | } |
| 3846 | if (has_comptime_state) |
| 3847 | try wip_nav.refValue(.fromInterned(field_init)) |
| 3848 | else if (has_runtime_bits) |
| 3849 | try wip_nav.blockValue(ty.srcLoc(zcu), .fromInterned(field_init)); |
| 3850 | } |
| 3851 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3852 | } |
| 3853 | }, |
| 3854 | .@"packed" => { |
| 3855 | const need_terminator: bool = if (loaded_struct.name_nav.unwrap()) |nav_index| t: { |
| 3856 | const nav = ip.getNav(nav_index); |
| 3857 | const decl_inst = nav.srcInst(ip).resolve(ip).?; |
| 3858 | const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst); |
| 3859 | try wip_nav.declCommon(.{ |
| 3860 | .decl = .decl_packed_struct, |
| 3861 | .generic_decl = .generic_decl_const, |
| 3862 | .decl_instance = .decl_instance_packed_struct, |
| 3863 | }, &nav, file, &decl); |
| 3864 | break :t true; |
| 3865 | } else t: { |
| 3866 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, file); |
| 3867 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len > 0) .packed_struct_type else .empty_packed_struct_type); |
| 3868 | try diw.writeUleb128(file_gop.index); |
| 3869 | try wip_nav.strp(loaded_struct.name.toSlice(ip)); |
| 3870 | break :t loaded_struct.field_types.len > 0; |
| 3871 | }; |
| 3872 | try wip_nav.refType(.fromInterned(loaded_struct.packed_backing_int_type)); |
| 3873 | var field_bit_offset: u16 = 0; |
| 3874 | for (0..loaded_struct.field_types.len) |field_index| { |
| 3875 | try wip_nav.abbrevCode(.packed_struct_field); |
| 3876 | try wip_nav.strp(loaded_struct.field_names.get(ip)[field_index].toSlice(ip)); |
| 3877 | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 3878 | try wip_nav.refType(field_type); |
| 3879 | try diw.writeUleb128(field_bit_offset); |
| 3880 | field_bit_offset += @intCast(field_type.bitSize(zcu)); |
| 3881 | } |
| 3882 | if (need_terminator) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3883 | }, |
| 3884 | } |
| 3885 | }, |
| 3886 | .union_type => { |
| 3887 | const loaded_union = ip.loadUnionType(value_index); |
| 3888 | const file = loaded_union.zir_index.resolveFile(ip); |
| 3889 | const need_terminator: bool = if (loaded_union.name_nav.unwrap()) |nav_index| t: { |
| 3890 | const nav = ip.getNav(nav_index); |
| 3891 | const decl_inst = nav.srcInst(ip).resolve(ip).?; |
| 3892 | const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst); |
| 3893 | try wip_nav.declCommon(.{ |
| 3894 | .decl = .decl_union, |
| 3895 | .generic_decl = .generic_decl_const, |
| 3896 | .decl_instance = .decl_instance_union, |
| 3897 | }, &nav, file, &decl); |
| 3898 | break :t true; |
| 3899 | } else t: { |
| 3900 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, file); |
| 3901 | try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .union_type else .empty_union_type); |
| 3902 | try diw.writeUleb128(file_gop.index); |
| 3903 | try wip_nav.strp(loaded_union.name.toSlice(ip)); |
| 3904 | break :t loaded_union.field_types.len > 0; |
| 3905 | }; |
| 3906 | const union_layout = Type.getUnionLayout(loaded_union, zcu); |
| 3907 | try diw.writeUleb128(union_layout.abi_size); |
| 3908 | try diw.writeUleb128(union_layout.abi_align.toByteUnits().?); |
| 3909 | const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type); |
| 3910 | if (loaded_union.has_runtime_tag) { |
| 3911 | try wip_nav.abbrevCode(.tagged_union); |
| 3912 | try wip_nav.infoSectionOffset( |
| 3913 | .debug_info, |
| 3914 | wip_nav.unit, |
| 3915 | wip_nav.entry, |
| 3916 | @intCast(diw.end + dwarf.sectionOffsetBytes()), |
| 3917 | ); |
| 3918 | { |
| 3919 | try wip_nav.abbrevCode(.generated_field); |
| 3920 | try wip_nav.strp("tag"); |
| 3921 | try wip_nav.refType(.fromInterned(loaded_union.enum_tag_type)); |
| 3922 | try diw.writeUleb128(union_layout.tagOffset()); |
| 3923 | |
| 3924 | for (0..loaded_union.field_types.len) |field_index| { |
| 3925 | try wip_nav.enumConstValue(loaded_tag, .{ |
| 3926 | .sdata = .signed_tagged_union_field, |
| 3927 | .udata = .unsigned_tagged_union_field, |
| 3928 | .block = .big_tagged_union_field, |
| 3929 | }, field_index); |
| 3930 | { |
| 3931 | try wip_nav.abbrevCode(.struct_field); |
| 3932 | try wip_nav.strp(loaded_tag.field_names.get(ip)[field_index].toSlice(ip)); |
| 3933 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 3934 | try wip_nav.refType(field_type); |
| 3935 | try diw.writeUleb128(union_layout.payloadOffset()); |
| 3936 | try diw.writeUleb128(loaded_union.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse |
| 3937 | if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?); |
| 3938 | } |
| 3939 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3940 | } |
| 3941 | } |
| 3942 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3943 | } else for (0..loaded_union.field_types.len) |field_index| { |
| 3944 | try wip_nav.abbrevCode(.untagged_union_field); |
| 3945 | try wip_nav.strp(loaded_tag.field_names.get(ip)[field_index].toSlice(ip)); |
| 3946 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 3947 | try wip_nav.refType(field_type); |
| 3948 | try diw.writeUleb128(loaded_union.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse |
| 3949 | if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?); |
| 3950 | } |
| 3951 | if (need_terminator) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3952 | }, |
| 3878 | 3953 | .enum_type => { |
| 3879 | | const loaded_enum = ip.loadEnumType(type_index); |
| 3880 | | try wip_nav.abbrevCode(if (loaded_enum.field_names.len == 0) .generated_empty_enum_type else .generated_enum_type); |
| 3881 | | try wip_nav.strp(name); |
| 3882 | | try wip_nav.refType(.fromInterned(loaded_enum.int_tag_type)); |
| 3883 | | for (0..loaded_enum.field_names.len) |field_index| { |
| 3884 | | try wip_nav.enumConstValue(loaded_enum, .{ |
| 3885 | | .sdata = .signed_enum_field, |
| 3886 | | .udata = .unsigned_enum_field, |
| 3887 | | .block = .big_enum_field, |
| 3888 | | }, field_index); |
| 3889 | | try wip_nav.strp(loaded_enum.field_names.get(ip)[field_index].toSlice(ip)); |
| 3954 | const loaded_enum = ip.loadEnumType(value_index); |
| 3955 | if (loaded_enum.zir_index.unwrap()) |zir_index| { |
| 3956 | assert(loaded_enum.owner_union == .none); |
| 3957 | const file = zir_index.resolveFile(ip); |
| 3958 | if (loaded_enum.name_nav.unwrap()) |nav_index| { |
| 3959 | const nav = ip.getNav(nav_index); |
| 3960 | const decl_inst = nav.srcInst(ip).resolve(ip).?; |
| 3961 | const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst); |
| 3962 | try wip_nav.declCommon(if (loaded_enum.field_names.len > 0) .{ |
| 3963 | .decl = .decl_enum, |
| 3964 | .generic_decl = .generic_decl_const, |
| 3965 | .decl_instance = .decl_instance_enum, |
| 3966 | } else .{ |
| 3967 | .decl = .decl_empty_enum, |
| 3968 | .generic_decl = .generic_decl_const, |
| 3969 | .decl_instance = .decl_instance_empty_enum, |
| 3970 | }, &nav, file, &decl); |
| 3971 | } else { |
| 3972 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, file); |
| 3973 | try wip_nav.abbrevCode(if (loaded_enum.field_names.len > 0) .enum_type else .empty_enum_type); |
| 3974 | try diw.writeUleb128(file_gop.index); |
| 3975 | try wip_nav.strp(loaded_enum.name.toSlice(ip)); |
| 3976 | } |
| 3977 | try wip_nav.refType(.fromInterned(loaded_enum.int_tag_type)); |
| 3978 | for (0..loaded_enum.field_names.len) |field_index| { |
| 3979 | try wip_nav.enumConstValue(loaded_enum, .{ |
| 3980 | .sdata = .signed_enum_field, |
| 3981 | .udata = .unsigned_enum_field, |
| 3982 | .block = .big_enum_field, |
| 3983 | }, field_index); |
| 3984 | try wip_nav.strp(loaded_enum.field_names.get(ip)[field_index].toSlice(ip)); |
| 3985 | } |
| 3986 | if (loaded_enum.field_names.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3987 | } else { |
| 3988 | assert(loaded_enum.owner_union != .none); |
| 3989 | try wip_nav.abbrevCode(if (loaded_enum.field_names.len == 0) .generated_empty_enum_type else .generated_enum_type); |
| 3990 | try wip_nav.strp(loaded_enum.name.toSlice(ip)); |
| 3991 | try wip_nav.refType(.fromInterned(loaded_enum.int_tag_type)); |
| 3992 | for (0..loaded_enum.field_names.len) |field_index| { |
| 3993 | try wip_nav.enumConstValue(loaded_enum, .{ |
| 3994 | .sdata = .signed_enum_field, |
| 3995 | .udata = .unsigned_enum_field, |
| 3996 | .block = .big_enum_field, |
| 3997 | }, field_index); |
| 3998 | try wip_nav.strp(loaded_enum.field_names.get(ip)[field_index].toSlice(ip)); |
| 3999 | } |
| 4000 | if (loaded_enum.field_names.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4001 | } |
| 4002 | }, |
| 4003 | .opaque_type => { |
| 4004 | const loaded_opaque = ip.loadOpaqueType(value_index); |
| 4005 | const file = loaded_opaque.zir_index.resolveFile(ip); |
| 4006 | if (loaded_opaque.name_nav.unwrap()) |nav_index| { |
| 4007 | const nav = ip.getNav(nav_index); |
| 4008 | const decl_inst = nav.srcInst(ip).resolve(ip).?; |
| 4009 | const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst); |
| 4010 | try wip_nav.declCommon(.{ |
| 4011 | .decl = .decl_namespace_struct, |
| 4012 | .generic_decl = .generic_decl_const, |
| 4013 | .decl_instance = .decl_instance_namespace_struct, |
| 4014 | }, &nav, file, &decl); |
| 4015 | } else { |
| 4016 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, file); |
| 4017 | try wip_nav.abbrevCode(.empty_struct_type); |
| 4018 | try diw.writeUleb128(file_gop.index); |
| 4019 | try wip_nav.strp(loaded_opaque.name.toSlice(ip)); |
| 3890 | 4020 | } |
| 3891 | | if (loaded_enum.field_names.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4021 | try diw.writeByte(@intFromBool(true)); |
| 3892 | 4022 | }, |
| 3893 | 4023 | .func_type => |func_type| { |
| 3894 | 4024 | const is_nullary = func_type.param_types.len == 0 and !func_type.is_var_args; |
| 3895 | 4025 | try wip_nav.abbrevCode(if (is_nullary) .nullary_func_type else .func_type); |
| 3896 | | try wip_nav.strp(name); |
| 4026 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3897 | 4027 | const cc: DW.CC = cc: { |
| 3898 | 4028 | if (zcu.getTarget().cCallingConvention()) |cc| { |
| 3899 | 4029 | if (@as(std.builtin.CallingConvention.Tag, cc) == func_type.cc) { |
| ... | ... | @@ -3975,7 +4105,7 @@ fn updateLazyType( |
| 3975 | 4105 | }, |
| 3976 | 4106 | .error_set_type => |error_set_type| { |
| 3977 | 4107 | try wip_nav.abbrevCode(if (error_set_type.names.len == 0) .generated_empty_enum_type else .generated_enum_type); |
| 3978 | | try wip_nav.strp(name); |
| 4108 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3979 | 4109 | try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{ |
| 3980 | 4110 | .signedness = .unsigned, |
| 3981 | 4111 | .bits = zcu.errorSetBits(), |
| ... | ... | @@ -3990,100 +4120,28 @@ fn updateLazyType( |
| 3990 | 4120 | }, |
| 3991 | 4121 | .inferred_error_set_type => |func| { |
| 3992 | 4122 | try wip_nav.abbrevCode(.inferred_error_set_type); |
| 3993 | | try wip_nav.strp(name); |
| 4123 | try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); |
| 3994 | 4124 | try wip_nav.refType(.fromInterned(switch (ip.funcIesResolvedUnordered(func)) { |
| 3995 | 4125 | .none => .anyerror_type, |
| 3996 | 4126 | else => |ies| ies, |
| 3997 | 4127 | })); |
| 3998 | 4128 | }, |
| 3999 | 4129 | |
| 4000 | | // values, not types |
| 4001 | | .simple_value, |
| 4002 | | .variable, |
| 4003 | | .@"extern", |
| 4004 | | .func, |
| 4005 | | .int, |
| 4006 | | .err, |
| 4007 | | .error_union, |
| 4008 | | .enum_literal, |
| 4009 | | .enum_tag, |
| 4010 | | .float, |
| 4011 | | .ptr, |
| 4012 | | .slice, |
| 4013 | | .opt, |
| 4014 | | .aggregate, |
| 4015 | | .un, |
| 4016 | | .bitpack, |
| 4017 | | // memoization, not types |
| 4018 | | .memoized_call, |
| 4019 | | => unreachable, |
| 4020 | | } |
| 4021 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.written()); |
| 4022 | | } |
| 4023 | | |
| 4024 | | fn updateLazyValue( |
| 4025 | | dwarf: *Dwarf, |
| 4026 | | pt: Zcu.PerThread, |
| 4027 | | src_loc: Zcu.LazySrcLoc, |
| 4028 | | value_index: InternPool.Index, |
| 4029 | | pending_lazy: *WipNav.PendingLazy, |
| 4030 | | ) (UpdateError || Writer.Error)!void { |
| 4031 | | const zcu = pt.zcu; |
| 4032 | | const ip = &zcu.intern_pool; |
| 4033 | | assert(ip.typeOf(value_index) != .type_type); |
| 4034 | | log.debug("updateLazyValue(@as({f}, {f}))", .{ |
| 4035 | | Value.fromInterned(value_index).typeOf(zcu).fmt(pt), |
| 4036 | | Value.fromInterned(value_index).fmtValue(pt), |
| 4037 | | }); |
| 4038 | | var wip_nav: WipNav = .{ |
| 4039 | | .dwarf = dwarf, |
| 4040 | | .pt = pt, |
| 4041 | | .unit = .main, |
| 4042 | | .entry = dwarf.values.get(value_index).?, |
| 4043 | | .any_children = false, |
| 4044 | | .func = .none, |
| 4045 | | .func_sym_index = undefined, |
| 4046 | | .func_high_pc = undefined, |
| 4047 | | .blocks = undefined, |
| 4048 | | .cfi = undefined, |
| 4049 | | .debug_frame = .init(dwarf.gpa), |
| 4050 | | .debug_info = .init(dwarf.gpa), |
| 4051 | | .debug_line = .init(dwarf.gpa), |
| 4052 | | .debug_loclists = .init(dwarf.gpa), |
| 4053 | | .pending_lazy = pending_lazy.*, |
| 4054 | | }; |
| 4055 | | defer { |
| 4056 | | pending_lazy.* = wip_nav.pending_lazy; |
| 4057 | | wip_nav.pending_lazy = .empty; |
| 4058 | | wip_nav.deinit(); |
| 4059 | | } |
| 4060 | | const diw = &wip_nav.debug_info.writer; |
| 4061 | | var big_int_space: Value.BigIntSpace = undefined; |
| 4062 | | switch (ip.indexToKey(value_index)) { |
| 4063 | | .int_type, |
| 4064 | | .ptr_type, |
| 4065 | | .array_type, |
| 4066 | | .vector_type, |
| 4067 | | .opt_type, |
| 4068 | | .anyframe_type, |
| 4069 | | .error_union_type, |
| 4070 | | .simple_type, |
| 4071 | | .struct_type, |
| 4072 | | .tuple_type, |
| 4073 | | .union_type, |
| 4074 | | .opaque_type, |
| 4075 | | .enum_type, |
| 4076 | | .func_type, |
| 4077 | | .error_set_type, |
| 4078 | | .inferred_error_set_type, |
| 4079 | | => unreachable, // already handled |
| 4080 | 4130 | .undef => |ty| { |
| 4081 | 4131 | try wip_nav.abbrevCode(.undefined_comptime_value); |
| 4082 | 4132 | try wip_nav.refType(.fromInterned(ty)); |
| 4083 | 4133 | }, |
| 4084 | | .simple_value => unreachable, // opv state |
| 4085 | | .variable, .@"extern" => unreachable, // not a value |
| 4086 | | .func => unreachable, // already handled |
| 4134 | .simple_value => |simple_value| switch (simple_value) { |
| 4135 | .void => unreachable, // opv state |
| 4136 | .true, .false => unreachable, // runtime bits |
| 4137 | .@"unreachable" => unreachable, // not a value |
| 4138 | .null => { |
| 4139 | // TODO: proper representation for this |
| 4140 | try wip_nav.abbrevCode(.undefined_comptime_value); |
| 4141 | try wip_nav.refType(.null); |
| 4142 | }, |
| 4143 | }, |
| 4144 | .variable => unreachable, // not a value |
| 4087 | 4145 | .int => |int| { |
| 4088 | 4146 | try wip_nav.bigIntConstValue(.{ |
| 4089 | 4147 | .sdata = .sdata_comptime_value, |
| ... | ... | @@ -4202,7 +4260,7 @@ fn updateLazyValue( |
| 4202 | 4260 | var byte_offset = ptr.byte_offset; |
| 4203 | 4261 | const base_unit, const base_entry = while (true) { |
| 4204 | 4262 | const base_ptr, const access: Access = base_ptr_access: switch (base_addr) { |
| 4205 | | .nav => |nav_index| break try wip_nav.getNavEntry(nav_index), |
| 4263 | .nav => |nav_index| break try dwarf.getNavEntry(nav_index), |
| 4206 | 4264 | .comptime_alloc, .comptime_field => unreachable, |
| 4207 | 4265 | .uav => |uav| { |
| 4208 | 4266 | const uav_ty: Type = .fromInterned(ip.typeOf(uav.val)); |
| ... | ... | @@ -4319,17 +4377,7 @@ fn updateLazyValue( |
| 4319 | 4377 | switch (optRepr(opt_child_type, zcu)) { |
| 4320 | 4378 | .opv_null => try diw.writeUleb128(0), |
| 4321 | 4379 | .unpacked => try wip_nav.blockValue(src_loc, .makeBool(opt.val != .none)), |
| 4322 | | .error_set => try wip_nav.blockValue(src_loc, .fromInterned(value_index)), |
| 4323 | | .pointer => if (opt_child_type.comptimeOnly(zcu)) { |
| 4324 | | var buf: [8]u8 = undefined; |
| 4325 | | const bytes = buf[0..@divExact(zcu.getTarget().ptrBitWidth(), 8)]; |
| 4326 | | dwarf.writeInt(bytes, switch (opt.val) { |
| 4327 | | .none => 0, |
| 4328 | | else => opt_child_type.ptrAlignment(zcu).toByteUnits().?, |
| 4329 | | }); |
| 4330 | | try diw.writeUleb128(bytes.len); |
| 4331 | | try diw.writeAll(bytes); |
| 4332 | | } else try wip_nav.blockValue(src_loc, .fromInterned(value_index)), |
| 4380 | .error_set, .pointer => try wip_nav.blockValue(src_loc, .fromInterned(value_index)), |
| 4333 | 4381 | } |
| 4334 | 4382 | } |
| 4335 | 4383 | if (opt.val != .none) child_field: { |
| ... | ... | @@ -4457,7 +4505,8 @@ fn updateLazyValue( |
| 4457 | 4505 | }, |
| 4458 | 4506 | .memoized_call => unreachable, // not a value |
| 4459 | 4507 | } |
| 4460 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.written()); |
| 4508 | try dwarf.debug_info.section.replaceEntry(unit, entry, dwarf, wip_nav.debug_info.written()); |
| 4509 | try dwarf.debug_loclists.section.replaceEntry(unit, entry, dwarf, wip_nav.debug_loclists.written()); |
| 4461 | 4510 | } |
| 4462 | 4511 | |
| 4463 | 4512 | fn optRepr(opt_child_type: Type, zcu: *const Zcu) enum { unpacked, opv_null, error_set, pointer } { |
| ... | ... | @@ -4472,312 +4521,6 @@ fn optRepr(opt_child_type: Type, zcu: *const Zcu) enum { unpacked, opv_null, err |
| 4472 | 4521 | }; |
| 4473 | 4522 | } |
| 4474 | 4523 | |
| 4475 | | pub fn updateContainerType( |
| 4476 | | dwarf: *Dwarf, |
| 4477 | | pt: Zcu.PerThread, |
| 4478 | | type_index: InternPool.Index, |
| 4479 | | ) UpdateError!void { |
| 4480 | | return dwarf.updateContainerTypeWriterError(pt, type_index) catch |err| switch (err) { |
| 4481 | | error.WriteFailed => error.OutOfMemory, |
| 4482 | | else => |e| e, |
| 4483 | | }; |
| 4484 | | } |
| 4485 | | fn updateContainerTypeWriterError( |
| 4486 | | dwarf: *Dwarf, |
| 4487 | | pt: Zcu.PerThread, |
| 4488 | | type_index: InternPool.Index, |
| 4489 | | ) (UpdateError || Writer.Error)!void { |
| 4490 | | const zcu = pt.zcu; |
| 4491 | | const ip = &zcu.intern_pool; |
| 4492 | | const ty: Type = .fromInterned(type_index); |
| 4493 | | const ty_src_loc = ty.srcLoc(zcu); |
| 4494 | | log.debug("updateContainerType({f})", .{ty.fmt(pt)}); |
| 4495 | | |
| 4496 | | const inst_info = ty.typeDeclInst(zcu).?.resolveFull(ip).?; |
| 4497 | | const file = zcu.fileByIndex(inst_info.file); |
| 4498 | | const unit = try dwarf.getUnit(file.mod.?); |
| 4499 | | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, inst_info.file); |
| 4500 | | if (inst_info.inst == .main_struct_inst) { |
| 4501 | | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, type_index); |
| 4502 | | if (!type_gop.found_existing) type_gop.value_ptr.* = try dwarf.addCommonEntry(unit); |
| 4503 | | var wip_nav: WipNav = .{ |
| 4504 | | .dwarf = dwarf, |
| 4505 | | .pt = pt, |
| 4506 | | .unit = unit, |
| 4507 | | .entry = type_gop.value_ptr.*, |
| 4508 | | .any_children = false, |
| 4509 | | .func = .none, |
| 4510 | | .func_sym_index = undefined, |
| 4511 | | .func_high_pc = undefined, |
| 4512 | | .blocks = undefined, |
| 4513 | | .cfi = undefined, |
| 4514 | | .debug_frame = .init(dwarf.gpa), |
| 4515 | | .debug_info = .init(dwarf.gpa), |
| 4516 | | .debug_line = .init(dwarf.gpa), |
| 4517 | | .debug_loclists = .init(dwarf.gpa), |
| 4518 | | .pending_lazy = .empty, |
| 4519 | | }; |
| 4520 | | defer wip_nav.deinit(); |
| 4521 | | |
| 4522 | | const loaded_struct = ip.loadStructType(type_index); |
| 4523 | | |
| 4524 | | const diw = &wip_nav.debug_info.writer; |
| 4525 | | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .empty_file else .file); |
| 4526 | | try diw.writeUleb128(file_gop.index); |
| 4527 | | try wip_nav.strp(loaded_struct.name.toSlice(ip)); |
| 4528 | | if (loaded_struct.field_types.len > 0) { |
| 4529 | | try diw.writeUleb128(ty.abiSize(zcu)); |
| 4530 | | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 4531 | | for (0..loaded_struct.field_types.len) |field_index| { |
| 4532 | | const is_comptime = loaded_struct.field_is_comptime_bits.get(ip, field_index); |
| 4533 | | const field_init = loaded_struct.field_defaults.getOrNone(ip, field_index); |
| 4534 | | assert(!(is_comptime and field_init == .none)); |
| 4535 | | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 4536 | | const has_runtime_bits, const has_comptime_state = switch (field_init) { |
| 4537 | | .none => .{ false, false }, |
| 4538 | | else => .{ |
| 4539 | | field_type.hasRuntimeBits(zcu), |
| 4540 | | field_type.comptimeOnly(zcu), |
| 4541 | | }, |
| 4542 | | }; |
| 4543 | | try wip_nav.abbrevCode(if (is_comptime) |
| 4544 | | if (has_comptime_state) |
| 4545 | | .struct_field_comptime_comptime_state |
| 4546 | | else if (has_runtime_bits) |
| 4547 | | .struct_field_comptime_runtime_bits |
| 4548 | | else |
| 4549 | | .struct_field_comptime |
| 4550 | | else if (field_init != .none) |
| 4551 | | if (has_comptime_state) |
| 4552 | | .struct_field_default_comptime_state |
| 4553 | | else if (has_runtime_bits) |
| 4554 | | .struct_field_default_runtime_bits |
| 4555 | | else |
| 4556 | | .struct_field |
| 4557 | | else |
| 4558 | | .struct_field); |
| 4559 | | try wip_nav.strp(loaded_struct.field_names.get(ip)[field_index].toSlice(ip)); |
| 4560 | | try wip_nav.refType(field_type); |
| 4561 | | if (!is_comptime) { |
| 4562 | | try diw.writeUleb128(loaded_struct.field_offsets.get(ip)[field_index]); |
| 4563 | | try diw.writeUleb128(loaded_struct.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse |
| 4564 | | field_type.abiAlignment(zcu).toByteUnits().?); |
| 4565 | | } |
| 4566 | | if (has_comptime_state) |
| 4567 | | try wip_nav.refValue(.fromInterned(field_init)) |
| 4568 | | else if (has_runtime_bits) |
| 4569 | | try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init)); |
| 4570 | | } |
| 4571 | | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4572 | | } |
| 4573 | | |
| 4574 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.written()); |
| 4575 | | try wip_nav.updateLazy(ty_src_loc); |
| 4576 | | } else { |
| 4577 | | { |
| 4578 | | // Note that changes to ZIR instruction tracking only need to update this code |
| 4579 | | // if a newly-tracked instruction can be a type's owner `zir_index`. |
| 4580 | | comptime assert(Zir.inst_tracking_version == 0); |
| 4581 | | |
| 4582 | | const decl_inst = file.zir.?.instructions.get(@intFromEnum(inst_info.inst)); |
| 4583 | | const name_strat: Zir.Inst.NameStrategy = switch (decl_inst.tag) { |
| 4584 | | .struct_init, .struct_init_ref, .struct_init_anon => .anon, |
| 4585 | | .extended => switch (decl_inst.data.extended.opcode) { |
| 4586 | | .struct_decl => file.zir.?.getStructDecl(inst_info.inst).name_strategy, |
| 4587 | | .union_decl => file.zir.?.getUnionDecl(inst_info.inst).name_strategy, |
| 4588 | | .enum_decl => file.zir.?.getEnumDecl(inst_info.inst).name_strategy, |
| 4589 | | .opaque_decl => file.zir.?.getOpaqueDecl(inst_info.inst).name_strategy, |
| 4590 | | |
| 4591 | | .reify_enum, |
| 4592 | | .reify_struct, |
| 4593 | | .reify_union, |
| 4594 | | => @enumFromInt(decl_inst.data.extended.small), |
| 4595 | | |
| 4596 | | else => unreachable, |
| 4597 | | }, |
| 4598 | | else => unreachable, |
| 4599 | | }; |
| 4600 | | if (name_strat == .parent) return; |
| 4601 | | } |
| 4602 | | |
| 4603 | | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, type_index); |
| 4604 | | if (!type_gop.found_existing) type_gop.value_ptr.* = try dwarf.addCommonEntry(unit); |
| 4605 | | var wip_nav: WipNav = .{ |
| 4606 | | .dwarf = dwarf, |
| 4607 | | .pt = pt, |
| 4608 | | .unit = unit, |
| 4609 | | .entry = type_gop.value_ptr.*, |
| 4610 | | .any_children = false, |
| 4611 | | .func = .none, |
| 4612 | | .func_sym_index = undefined, |
| 4613 | | .func_high_pc = undefined, |
| 4614 | | .blocks = undefined, |
| 4615 | | .cfi = undefined, |
| 4616 | | .debug_frame = .init(dwarf.gpa), |
| 4617 | | .debug_info = .init(dwarf.gpa), |
| 4618 | | .debug_line = .init(dwarf.gpa), |
| 4619 | | .debug_loclists = .init(dwarf.gpa), |
| 4620 | | .pending_lazy = .empty, |
| 4621 | | }; |
| 4622 | | defer wip_nav.deinit(); |
| 4623 | | const diw = &wip_nav.debug_info.writer; |
| 4624 | | const name = try std.fmt.allocPrint(dwarf.gpa, "{f}", .{ty.fmt(pt)}); |
| 4625 | | defer dwarf.gpa.free(name); |
| 4626 | | |
| 4627 | | switch (ip.indexToKey(type_index)) { |
| 4628 | | .struct_type => { |
| 4629 | | const loaded_struct = ip.loadStructType(type_index); |
| 4630 | | switch (loaded_struct.layout) { |
| 4631 | | .auto, .@"extern" => { |
| 4632 | | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .empty_struct_type else .struct_type); |
| 4633 | | try diw.writeUleb128(file_gop.index); |
| 4634 | | try wip_nav.strp(name); |
| 4635 | | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { |
| 4636 | | try diw.writeUleb128(ty.abiSize(zcu)); |
| 4637 | | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 4638 | | for (0..loaded_struct.field_types.len) |field_index| { |
| 4639 | | const is_comptime = loaded_struct.field_is_comptime_bits.get(ip, field_index); |
| 4640 | | const field_init = loaded_struct.field_defaults.getOrNone(ip, field_index); |
| 4641 | | assert(!(is_comptime and field_init == .none)); |
| 4642 | | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 4643 | | const has_runtime_bits, const has_comptime_state = switch (field_init) { |
| 4644 | | .none => .{ false, false }, |
| 4645 | | else => .{ |
| 4646 | | field_type.hasRuntimeBits(zcu), |
| 4647 | | field_type.comptimeOnly(zcu), |
| 4648 | | }, |
| 4649 | | }; |
| 4650 | | try wip_nav.abbrevCode(if (is_comptime) |
| 4651 | | if (has_comptime_state) |
| 4652 | | .struct_field_comptime_comptime_state |
| 4653 | | else if (has_runtime_bits) |
| 4654 | | .struct_field_comptime_runtime_bits |
| 4655 | | else |
| 4656 | | .struct_field_comptime |
| 4657 | | else if (field_init != .none) |
| 4658 | | if (has_comptime_state) |
| 4659 | | .struct_field_default_comptime_state |
| 4660 | | else if (has_runtime_bits) |
| 4661 | | .struct_field_default_runtime_bits |
| 4662 | | else |
| 4663 | | .struct_field |
| 4664 | | else |
| 4665 | | .struct_field); |
| 4666 | | try wip_nav.strp(loaded_struct.field_names.get(ip)[field_index].toSlice(ip)); |
| 4667 | | try wip_nav.refType(field_type); |
| 4668 | | if (!is_comptime) { |
| 4669 | | try diw.writeUleb128(loaded_struct.field_offsets.get(ip)[field_index]); |
| 4670 | | try diw.writeUleb128(loaded_struct.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse |
| 4671 | | field_type.abiAlignment(zcu).toByteUnits().?); |
| 4672 | | } |
| 4673 | | if (has_comptime_state) |
| 4674 | | try wip_nav.refValue(.fromInterned(field_init)) |
| 4675 | | else if (has_runtime_bits) |
| 4676 | | try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init)); |
| 4677 | | } |
| 4678 | | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4679 | | } |
| 4680 | | }, |
| 4681 | | .@"packed" => { |
| 4682 | | try wip_nav.abbrevCode(if (loaded_struct.field_types.len > 0) .packed_struct_type else .empty_packed_struct_type); |
| 4683 | | try diw.writeUleb128(file_gop.index); |
| 4684 | | try wip_nav.strp(name); |
| 4685 | | try wip_nav.refType(.fromInterned(loaded_struct.packed_backing_int_type)); |
| 4686 | | var field_bit_offset: u16 = 0; |
| 4687 | | for (0..loaded_struct.field_types.len) |field_index| { |
| 4688 | | try wip_nav.abbrevCode(.packed_struct_field); |
| 4689 | | try wip_nav.strp(loaded_struct.field_names.get(ip)[field_index].toSlice(ip)); |
| 4690 | | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 4691 | | try wip_nav.refType(field_type); |
| 4692 | | try diw.writeUleb128(field_bit_offset); |
| 4693 | | field_bit_offset += @intCast(field_type.bitSize(zcu)); |
| 4694 | | } |
| 4695 | | if (loaded_struct.field_types.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4696 | | }, |
| 4697 | | } |
| 4698 | | }, |
| 4699 | | .enum_type => { |
| 4700 | | const loaded_enum = ip.loadEnumType(type_index); |
| 4701 | | try wip_nav.abbrevCode(if (loaded_enum.field_names.len > 0) .enum_type else .empty_enum_type); |
| 4702 | | try diw.writeUleb128(file_gop.index); |
| 4703 | | try wip_nav.strp(name); |
| 4704 | | try wip_nav.refType(.fromInterned(loaded_enum.int_tag_type)); |
| 4705 | | for (0..loaded_enum.field_names.len) |field_index| { |
| 4706 | | try wip_nav.enumConstValue(loaded_enum, .{ |
| 4707 | | .sdata = .signed_enum_field, |
| 4708 | | .udata = .unsigned_enum_field, |
| 4709 | | .block = .big_enum_field, |
| 4710 | | }, field_index); |
| 4711 | | try wip_nav.strp(loaded_enum.field_names.get(ip)[field_index].toSlice(ip)); |
| 4712 | | } |
| 4713 | | if (loaded_enum.field_names.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4714 | | }, |
| 4715 | | .union_type => { |
| 4716 | | const loaded_union = ip.loadUnionType(type_index); |
| 4717 | | try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .union_type else .empty_union_type); |
| 4718 | | try diw.writeUleb128(file_gop.index); |
| 4719 | | try wip_nav.strp(name); |
| 4720 | | const union_layout = Type.getUnionLayout(loaded_union, zcu); |
| 4721 | | try diw.writeUleb128(union_layout.abi_size); |
| 4722 | | try diw.writeUleb128(union_layout.abi_align.toByteUnits().?); |
| 4723 | | const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type); |
| 4724 | | if (loaded_union.has_runtime_tag) { |
| 4725 | | try wip_nav.abbrevCode(.tagged_union); |
| 4726 | | try wip_nav.infoSectionOffset( |
| 4727 | | .debug_info, |
| 4728 | | wip_nav.unit, |
| 4729 | | wip_nav.entry, |
| 4730 | | @intCast(diw.end + dwarf.sectionOffsetBytes()), |
| 4731 | | ); |
| 4732 | | { |
| 4733 | | try wip_nav.abbrevCode(.generated_field); |
| 4734 | | try wip_nav.strp("tag"); |
| 4735 | | try wip_nav.refType(.fromInterned(loaded_union.enum_tag_type)); |
| 4736 | | try diw.writeUleb128(union_layout.tagOffset()); |
| 4737 | | |
| 4738 | | for (0..loaded_union.field_types.len) |field_index| { |
| 4739 | | try wip_nav.enumConstValue(loaded_tag, .{ |
| 4740 | | .sdata = .signed_tagged_union_field, |
| 4741 | | .udata = .unsigned_tagged_union_field, |
| 4742 | | .block = .big_tagged_union_field, |
| 4743 | | }, field_index); |
| 4744 | | { |
| 4745 | | try wip_nav.abbrevCode(.struct_field); |
| 4746 | | try wip_nav.strp(loaded_tag.field_names.get(ip)[field_index].toSlice(ip)); |
| 4747 | | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 4748 | | try wip_nav.refType(field_type); |
| 4749 | | try diw.writeUleb128(union_layout.payloadOffset()); |
| 4750 | | try diw.writeUleb128(loaded_union.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse |
| 4751 | | if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?); |
| 4752 | | } |
| 4753 | | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4754 | | } |
| 4755 | | } |
| 4756 | | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4757 | | } else for (0..loaded_union.field_types.len) |field_index| { |
| 4758 | | try wip_nav.abbrevCode(.untagged_union_field); |
| 4759 | | try wip_nav.strp(loaded_tag.field_names.get(ip)[field_index].toSlice(ip)); |
| 4760 | | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 4761 | | try wip_nav.refType(field_type); |
| 4762 | | try diw.writeUleb128(loaded_union.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse |
| 4763 | | if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?); |
| 4764 | | } |
| 4765 | | if (loaded_union.field_types.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4766 | | }, |
| 4767 | | .opaque_type => { |
| 4768 | | try wip_nav.abbrevCode(.empty_struct_type); |
| 4769 | | try diw.writeUleb128(file_gop.index); |
| 4770 | | try wip_nav.strp(name); |
| 4771 | | try diw.writeByte(@intFromBool(true)); |
| 4772 | | }, |
| 4773 | | else => unreachable, |
| 4774 | | } |
| 4775 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.written()); |
| 4776 | | try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.written()); |
| 4777 | | try wip_nav.updateLazy(ty_src_loc); |
| 4778 | | } |
| 4779 | | } |
| 4780 | | |
| 4781 | 4524 | pub fn updateLineNumber(dwarf: *Dwarf, zcu: *Zcu, zir_index: InternPool.TrackedInst.Index) UpdateError!void { |
| 4782 | 4525 | const comp = dwarf.bin_file.comp; |
| 4783 | 4526 | const io = comp.io; |
| ... | ... | @@ -4840,14 +4583,15 @@ fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (FlushError || Writer.Erro |
| 4840 | 4583 | const comp = dwarf.bin_file.comp; |
| 4841 | 4584 | const io = comp.io; |
| 4842 | 4585 | |
| 4586 | // Update `anyerror` based on the finished global error set. |
| 4843 | 4587 | { |
| 4844 | | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, .anyerror_type); |
| 4845 | | if (!type_gop.found_existing) type_gop.value_ptr.* = try dwarf.addCommonEntry(.main); |
| 4588 | const index = try dwarf.const_pool.get(pt, .{ .dwarf = dwarf }, .anyerror_type); |
| 4589 | const unit, const entry = dwarf.values.items[@intFromEnum(index)]; |
| 4846 | 4590 | var wip_nav: WipNav = .{ |
| 4847 | 4591 | .dwarf = dwarf, |
| 4848 | 4592 | .pt = pt, |
| 4849 | | .unit = .main, |
| 4850 | | .entry = type_gop.value_ptr.*, |
| 4593 | .unit = unit, |
| 4594 | .entry = entry, |
| 4851 | 4595 | .any_children = false, |
| 4852 | 4596 | .func = .none, |
| 4853 | 4597 | .func_sym_index = undefined, |
| ... | ... | @@ -4858,7 +4602,6 @@ fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (FlushError || Writer.Erro |
| 4858 | 4602 | .debug_info = .init(dwarf.gpa), |
| 4859 | 4603 | .debug_line = .init(dwarf.gpa), |
| 4860 | 4604 | .debug_loclists = .init(dwarf.gpa), |
| 4861 | | .pending_lazy = .empty, |
| 4862 | 4605 | }; |
| 4863 | 4606 | defer wip_nav.deinit(); |
| 4864 | 4607 | const diw = &wip_nav.debug_info.writer; |
| ... | ... | @@ -4876,7 +4619,7 @@ fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (FlushError || Writer.Erro |
| 4876 | 4619 | } |
| 4877 | 4620 | if (global_error_set_names.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4878 | 4621 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.written()); |
| 4879 | | try wip_nav.updateLazy(.unneeded); |
| 4622 | try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf }); |
| 4880 | 4623 | } |
| 4881 | 4624 | |
| 4882 | 4625 | for (dwarf.mods.keys(), dwarf.mods.values()) |mod, *mod_info| { |
| ... | ... | @@ -5324,6 +5067,8 @@ const AbbrevCode = enum { |
| 5324 | 5067 | inferred_error_set_type, |
| 5325 | 5068 | ptr_type, |
| 5326 | 5069 | ptr_sentinel_type, |
| 5070 | ptr_aligned_type, |
| 5071 | ptr_aligned_sentinel_type, |
| 5327 | 5072 | is_const, |
| 5328 | 5073 | is_volatile, |
| 5329 | 5074 | array_type, |
| ... | ... | @@ -5960,12 +5705,29 @@ const AbbrevCode = enum { |
| 5960 | 5705 | .tag = .pointer_type, |
| 5961 | 5706 | .attrs = &.{ |
| 5962 | 5707 | .{ .name, .strp }, |
| 5963 | | .{ .alignment, .udata }, |
| 5964 | 5708 | .{ .address_class, .data1 }, |
| 5965 | 5709 | .{ .type, .ref_addr }, |
| 5966 | 5710 | }, |
| 5967 | 5711 | }, |
| 5968 | 5712 | .ptr_sentinel_type = .{ |
| 5713 | .tag = .pointer_type, |
| 5714 | .attrs = &.{ |
| 5715 | .{ .name, .strp }, |
| 5716 | .{ .ZIG_sentinel, .block }, |
| 5717 | .{ .address_class, .data1 }, |
| 5718 | .{ .type, .ref_addr }, |
| 5719 | }, |
| 5720 | }, |
| 5721 | .ptr_aligned_type = .{ |
| 5722 | .tag = .pointer_type, |
| 5723 | .attrs = &.{ |
| 5724 | .{ .name, .strp }, |
| 5725 | .{ .alignment, .udata }, |
| 5726 | .{ .address_class, .data1 }, |
| 5727 | .{ .type, .ref_addr }, |
| 5728 | }, |
| 5729 | }, |
| 5730 | .ptr_aligned_sentinel_type = .{ |
| 5969 | 5731 | .tag = .pointer_type, |
| 5970 | 5732 | .attrs = &.{ |
| 5971 | 5733 | .{ .name, .strp }, |