authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-08-31 05:02:04-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-03 12:59:38-04:00
log566b6a6ec0ac2aa847fc3c8572c2404dcb67b51e
tree588362cf975be66161ca1aa4c688c59ee6fb83e4
parentf9ae1f808b9e8c1d9a0394505be222f8becf4259

Dwarf2: finish type debug info


10 files changed, 1466 insertions(+), 460 deletions(-)

lib/std/zig/AstGen.zig+42-6
......@@ -1884,7 +1884,8 @@ fn structInitExprAnon(
18841884
18851885 const payload_index = try addExtra(astgen, Zir.Inst.StructInitAnon{
18861886 .abs_node = node,
1887 .abs_line = astgen.source_line,
1887 .src_line = astgen.source_line,
1888 .src_column = astgen.source_column,
18881889 .fields_len = @intCast(struct_init.ast.fields.len),
18891890 });
18901891 const field_size = @typeInfo(Zir.Inst.StructInitAnon.Item).@"struct".field_names.len;
......@@ -1917,7 +1918,8 @@ fn structInitExprTyped(
19171918
19181919 const payload_index = try addExtra(astgen, Zir.Inst.StructInit{
19191920 .abs_node = node,
1920 .abs_line = astgen.source_line,
1921 .src_line = astgen.source_line,
1922 .src_column = astgen.source_column,
19211923 .fields_len = @intCast(struct_init.ast.fields.len),
19221924 });
19231925 const field_size = @typeInfo(Zir.Inst.StructInit.Item).@"struct".field_names.len;
......@@ -4846,9 +4848,13 @@ fn structDeclInner(
48464848 astgen.advanceSourceCursorToNode(node);
48474849
48484850 const decl_inst = try gz.reserveInstructionIndex();
4851 const src_line = astgen.source_line;
4852 const src_column = astgen.source_column;
48494853
48504854 if (container_decl.ast.members.len == 0 and maybe_backing_int_node == .none) {
48514855 try gz.setStruct(decl_inst, .{
4856 .src_line = src_line,
4857 .src_column = src_column,
48524858 .src_node = node,
48534859 .name_strat = name_strat,
48544860 .layout = layout,
......@@ -5003,6 +5009,8 @@ fn structDeclInner(
50035009 astgen.src_hasher.final(&fields_hash);
50045010
50055011 try gz.setStruct(decl_inst, .{
5012 .src_line = src_line,
5013 .src_column = src_column,
50065014 .src_node = node,
50075015 .name_strat = name_strat,
50085016 .layout = layout,
......@@ -5151,6 +5159,8 @@ fn unionDeclInner(
51515159 astgen.advanceSourceCursorToNode(node);
51525160
51535161 const decl_inst = try gz.reserveInstructionIndex();
5162 const src_line = astgen.source_line;
5163 const src_column = astgen.source_column;
51545164
51555165 var namespace: Scope.Namespace = .{
51565166 .parent = scope,
......@@ -5284,6 +5294,8 @@ fn unionDeclInner(
52845294 astgen.src_hasher.final(&fields_hash);
52855295
52865296 try gz.setUnion(decl_inst, .{
5297 .src_line = src_line,
5298 .src_column = src_column,
52875299 .src_node = node,
52885300 .name_strat = name_strat,
52895301 .kind = switch (layout) {
......@@ -5358,6 +5370,8 @@ fn containerDecl(
53585370 astgen.advanceSourceCursorToNode(node);
53595371
53605372 const decl_inst = try gz.reserveInstructionIndex();
5373 const src_line = astgen.source_line;
5374 const src_column = astgen.source_column;
53615375
53625376 var namespace: Scope.Namespace = .{
53635377 .parent = scope,
......@@ -5482,6 +5496,8 @@ fn containerDecl(
54825496 astgen.src_hasher.final(&fields_hash);
54835497
54845498 try gz.setEnum(decl_inst, .{
5499 .src_line = src_line,
5500 .src_column = src_column,
54855501 .src_node = node,
54865502 .name_strat = name_strat,
54875503 .tag_type_body_len = tag_type_body_len,
......@@ -5504,6 +5520,8 @@ fn containerDecl(
55045520 astgen.advanceSourceCursorToNode(node);
55055521
55065522 const decl_inst = try gz.reserveInstructionIndex();
5523 const src_line = astgen.source_line;
5524 const src_column = astgen.source_column;
55075525
55085526 var namespace: Scope.Namespace = .{
55095527 .parent = scope,
......@@ -5545,6 +5563,8 @@ fn containerDecl(
55455563 wip_decls.finish();
55465564
55475565 try gz.setOpaque(decl_inst, .{
5566 .src_line = src_line,
5567 .src_column = src_column,
55485568 .src_node = node,
55495569 .name_strat = name_strat,
55505570 .decls_len = scan_result.decls_len,
......@@ -9302,6 +9322,7 @@ fn builtinCall(
93029322 const field_attrs = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = field_attrs_ty } }, params[4], .struct_field_attrs);
93039323 const result = try gz.addExtendedPayloadSmall(.reify_struct, @backingInt(reify_name_strat), Zir.Inst.ReifyStruct{
93049324 .src_line = gz.astgen.source_line,
9325 .src_column = gz.astgen.source_column,
93059326 .node = node,
93069327 .layout = layout,
93079328 .backing_ty = backing_ty,
......@@ -9330,6 +9351,7 @@ fn builtinCall(
93309351 const field_attrs = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = field_attrs_ty } }, params[4], .union_field_attrs);
93319352 const result = try gz.addExtendedPayloadSmall(.reify_union, @backingInt(reify_name_strat), Zir.Inst.ReifyUnion{
93329353 .src_line = gz.astgen.source_line,
9354 .src_column = gz.astgen.source_column,
93339355 .node = node,
93349356 .layout = layout,
93359357 .arg_ty = arg_ty,
......@@ -9352,6 +9374,7 @@ fn builtinCall(
93529374 const field_values = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = field_values_ty } }, params[3], .enum_field_values);
93539375 const result = try gz.addExtendedPayloadSmall(.reify_enum, @backingInt(reify_name_strat), Zir.Inst.ReifyEnum{
93549376 .src_line = gz.astgen.source_line,
9377 .src_column = gz.astgen.source_column,
93559378 .node = node,
93569379 .tag_ty = tag_ty,
93579380 .mode = mode,
......@@ -9365,6 +9388,7 @@ fn builtinCall(
93659388 const operand = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = spirv_type_options_ty } }, params[0], .type);
93669389 const result = try gz.addExtendedPayload(.reify_spirv_type, Zir.Inst.ReifySpirvType{
93679390 .src_line = gz.astgen.source_line,
9391 .src_column = gz.astgen.source_column,
93689392 .node = node,
93699393 .operand = operand,
93709394 });
......@@ -12392,6 +12416,8 @@ const GenZir = struct {
1239212416 }
1239312417
1239412418 fn setStruct(gz: *GenZir, inst: Zir.Inst.Index, args: struct {
12419 src_line: u32,
12420 src_column: u32,
1239512421 src_node: Ast.Node.Index,
1239612422 name_strat: Zir.Inst.NameStrategy,
1239712423 layout: std.lang.Type.ContainerLayout,
......@@ -12428,7 +12454,8 @@ const GenZir = struct {
1242812454 .fields_hash_1 = fields_hash_arr[1],
1242912455 .fields_hash_2 = fields_hash_arr[2],
1243012456 .fields_hash_3 = fields_hash_arr[3],
12431 .src_line = astgen.source_line,
12457 .src_line = args.src_line,
12458 .src_column = args.src_column,
1243212459 .src_node = args.src_node,
1243312460 });
1243412461
......@@ -12461,6 +12488,8 @@ const GenZir = struct {
1246112488 }
1246212489
1246312490 fn setUnion(gz: *GenZir, inst: Zir.Inst.Index, args: struct {
12491 src_line: u32,
12492 src_column: u32,
1246412493 src_node: Ast.Node.Index,
1246512494 name_strat: Zir.Inst.NameStrategy,
1246612495 kind: Zir.Inst.UnionDecl.Kind,
......@@ -12495,7 +12524,8 @@ const GenZir = struct {
1249512524 .fields_hash_1 = fields_hash_arr[1],
1249612525 .fields_hash_2 = fields_hash_arr[2],
1249712526 .fields_hash_3 = fields_hash_arr[3],
12498 .src_line = astgen.source_line,
12527 .src_line = args.src_line,
12528 .src_column = args.src_column,
1249912529 .src_node = args.src_node,
1250012530 });
1250112531
......@@ -12530,6 +12560,8 @@ const GenZir = struct {
1253012560 }
1253112561
1253212562 fn setEnum(gz: *GenZir, inst: Zir.Inst.Index, args: struct {
12563 src_line: u32,
12564 src_column: u32,
1253312565 src_node: Ast.Node.Index,
1253412566 name_strat: Zir.Inst.NameStrategy,
1253512567 tag_type_body_len: ?u32,
......@@ -12563,7 +12595,8 @@ const GenZir = struct {
1256312595 .fields_hash_1 = fields_hash_arr[1],
1256412596 .fields_hash_2 = fields_hash_arr[2],
1256512597 .fields_hash_3 = fields_hash_arr[3],
12566 .src_line = astgen.source_line,
12598 .src_line = args.src_line,
12599 .src_column = args.src_column,
1256712600 .src_node = args.src_node,
1256812601 });
1256912602
......@@ -12594,6 +12627,8 @@ const GenZir = struct {
1259412627 }
1259512628
1259612629 fn setOpaque(gz: *GenZir, inst: Zir.Inst.Index, args: struct {
12630 src_line: u32,
12631 src_column: u32,
1259712632 src_node: Ast.Node.Index,
1259812633 name_strat: Zir.Inst.NameStrategy,
1259912634 decls_len: u32,
......@@ -12615,7 +12650,8 @@ const GenZir = struct {
1261512650 args.decls.len);
1261612651
1261712652 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.OpaqueDecl{
12618 .src_line = astgen.source_line,
12653 .src_line = args.src_line,
12654 .src_column = args.src_column,
1261912655 .src_node = args.src_node,
1262012656 });
1262112657 if (captures_len != 0) astgen.extra.appendAssumeCapacity(captures_len);
lib/std/zig/Zir.zig+20-4
......@@ -3277,6 +3277,7 @@ pub const Inst = struct {
32773277
32783278 pub const ReifyStruct = struct {
32793279 src_line: u32,
3280 src_column: u32,
32803281 /// This node is absolute, because `reify` instructions are tracked across updates, and
32813282 /// this simplifies the logic for getting source locations for types.
32823283 node: Ast.Node.Index,
......@@ -3289,6 +3290,7 @@ pub const Inst = struct {
32893290
32903291 pub const ReifyUnion = struct {
32913292 src_line: u32,
3293 src_column: u32,
32923294 /// This node is absolute, because `reify` instructions are tracked across updates, and
32933295 /// this simplifies the logic for getting source locations for types.
32943296 node: Ast.Node.Index,
......@@ -3301,6 +3303,7 @@ pub const Inst = struct {
33013303
33023304 pub const ReifyEnum = struct {
33033305 src_line: u32,
3306 src_column: u32,
33043307 /// This node is absolute, because `reify` instructions are tracked across updates, and
33053308 /// this simplifies the logic for getting source locations for types.
33063309 node: Ast.Node.Index,
......@@ -3312,6 +3315,7 @@ pub const Inst = struct {
33123315
33133316 pub const ReifySpirvType = struct {
33143317 src_line: u32,
3318 src_column: u32,
33153319 /// This node is absolute, because `reify` instructions are tracked across updates, and
33163320 /// this simplifies the logic for getting source locations for types.
33173321 node: Ast.Node.Index,
......@@ -3509,6 +3513,7 @@ pub const Inst = struct {
35093513 fields_hash_2: u32,
35103514 fields_hash_3: u32,
35113515 src_line: u32,
3516 src_column: u32,
35123517 /// This node provides a new absolute baseline node for all instructions within this struct.
35133518 src_node: Ast.Node.Index,
35143519
......@@ -3664,6 +3669,7 @@ pub const Inst = struct {
36643669 fields_hash_2: u32,
36653670 fields_hash_3: u32,
36663671 src_line: u32,
3672 src_column: u32,
36673673 /// This node provides a new absolute baseline node for all instructions within this struct.
36683674 src_node: Ast.Node.Index,
36693675
......@@ -3701,6 +3707,7 @@ pub const Inst = struct {
37013707 fields_hash_2: u32,
37023708 fields_hash_3: u32,
37033709 src_line: u32,
3710 src_column: u32,
37043711 /// This node provides a new absolute baseline node for all instructions within this struct.
37053712 src_node: Ast.Node.Index,
37063713
......@@ -3756,6 +3763,7 @@ pub const Inst = struct {
37563763 /// 4. decl: Index, // for every decls_len; points to a `declaration` instruction
37573764 pub const OpaqueDecl = struct {
37583765 src_line: u32,
3766 src_column: u32,
37593767 /// This node provides a new absolute baseline node for all instructions within this struct.
37603768 src_node: Ast.Node.Index,
37613769
......@@ -3803,8 +3811,8 @@ pub const Inst = struct {
38033811 /// If this is an anonymous initialization (the operand is poison), this instruction becomes the owner of a type.
38043812 /// To resolve source locations, we need an absolute source node.
38053813 abs_node: Ast.Node.Index,
3806 /// Likewise, we need an absolute line number.
3807 abs_line: u32,
3814 src_line: u32,
3815 src_column: u32,
38083816 fields_len: u32,
38093817
38103818 pub const Item = struct {
......@@ -3823,8 +3831,8 @@ pub const Inst = struct {
38233831 /// This is an anonymous initialization, meaning this instruction becomes the owner of a type.
38243832 /// To resolve source locations, we need an absolute source node.
38253833 abs_node: Ast.Node.Index,
3826 /// Likewise, we need an absolute line number.
3827 abs_line: u32,
3834 src_line: u32,
3835 src_column: u32,
38283836 fields_len: u32,
38293837
38303838 pub const Item = struct {
......@@ -5318,6 +5326,7 @@ pub fn getStructDecl(zir: *const Zir, struct_decl: Inst.Index) UnwrappedStructDe
53185326 const field_bodies_overlong: []const Inst.Index = @ptrCast(zir.extra[extra_index..]);
53195327 return .{
53205328 .src_line = extra.data.src_line,
5329 .src_column = extra.data.src_column,
53215330 .src_node = extra.data.src_node,
53225331 .name_strategy = small.name_strategy,
53235332 .captures = captures,
......@@ -5335,6 +5344,7 @@ pub fn getStructDecl(zir: *const Zir, struct_decl: Inst.Index) UnwrappedStructDe
53355344}
53365345pub const UnwrappedStructDecl = struct {
53375346 src_line: u32,
5347 src_column: u32,
53385348 src_node: Ast.Node.Index,
53395349 name_strategy: Inst.NameStrategy,
53405350
......@@ -5463,6 +5473,7 @@ pub fn getUnionDecl(zir: *const Zir, union_decl: Inst.Index) UnwrappedUnionDecl
54635473 const field_bodies_overlong: []const Inst.Index = @ptrCast(zir.extra[extra_index..]);
54645474 return .{
54655475 .src_line = extra.data.src_line,
5476 .src_column = extra.data.src_column,
54665477 .src_node = extra.data.src_node,
54675478 .name_strategy = small.name_strategy,
54685479 .captures = captures,
......@@ -5479,6 +5490,7 @@ pub fn getUnionDecl(zir: *const Zir, union_decl: Inst.Index) UnwrappedUnionDecl
54795490}
54805491pub const UnwrappedUnionDecl = struct {
54815492 src_line: u32,
5493 src_column: u32,
54825494 src_node: Ast.Node.Index,
54835495 name_strategy: Inst.NameStrategy,
54845496
......@@ -5590,6 +5602,7 @@ pub fn getEnumDecl(zir: *const Zir, enum_decl: Inst.Index) UnwrappedEnumDecl {
55905602 const field_bodies_overlong: []const Inst.Index = @ptrCast(zir.extra[extra_index..]);
55915603 return .{
55925604 .src_line = extra.data.src_line,
5605 .src_column = extra.data.src_column,
55935606 .src_node = extra.data.src_node,
55945607 .name_strategy = small.name_strategy,
55955608 .captures = captures,
......@@ -5604,6 +5617,7 @@ pub fn getEnumDecl(zir: *const Zir, enum_decl: Inst.Index) UnwrappedEnumDecl {
56045617}
56055618pub const UnwrappedEnumDecl = struct {
56065619 src_line: u32,
5620 src_column: u32,
56075621 src_node: Ast.Node.Index,
56085622 name_strategy: Inst.NameStrategy,
56095623
......@@ -5682,6 +5696,7 @@ pub fn getOpaqueDecl(zir: *const Zir, opaque_decl: Inst.Index) UnwrappedOpaqueDe
56825696 extra_index += decls_len;
56835697 return .{
56845698 .src_line = extra.data.src_line,
5699 .src_column = extra.data.src_column,
56855700 .src_node = extra.data.src_node,
56865701 .name_strategy = small.name_strategy,
56875702 .captures = captures,
......@@ -5691,6 +5706,7 @@ pub fn getOpaqueDecl(zir: *const Zir, opaque_decl: Inst.Index) UnwrappedOpaqueDe
56915706}
56925707pub const UnwrappedOpaqueDecl = struct {
56935708 src_line: u32,
5709 src_column: u32,
56945710 src_node: Ast.Node.Index,
56955711 name_strategy: Inst.NameStrategy,
56965712 captures: []const Inst.Capture,
src/Type.zig+2-2
......@@ -2693,8 +2693,8 @@ pub fn typeDeclSrcLine(ty: Type, zcu: *Zcu) ?u32 {
26932693 };
26942694 const inst = zir.instructions.get(@backingInt(info.inst));
26952695 return switch (inst.tag) {
2696 .struct_init, .struct_init_ref => zir.extraData(Zir.Inst.StructInit, inst.data.pl_node.payload_index).data.abs_line,
2697 .struct_init_anon => zir.extraData(Zir.Inst.StructInitAnon, inst.data.pl_node.payload_index).data.abs_line,
2696 .struct_init, .struct_init_ref => zir.extraData(Zir.Inst.StructInit, inst.data.pl_node.payload_index).data.src_line,
2697 .struct_init_anon => zir.extraData(Zir.Inst.StructInitAnon, inst.data.pl_node.payload_index).data.src_line,
26982698 .extended => switch (inst.data.extended.opcode) {
26992699 .struct_decl => zir.getStructDecl(info.inst).src_line,
27002700 .union_decl => zir.getUnionDecl(info.inst).src_line,
src/Zcu/PerThread.zig+49-15
......@@ -864,26 +864,60 @@ fn updateZirRefs(pt: Zcu.PerThread) (Io.Cancelable || Allocator.Error)!void {
864864 try comp.link_queue.enqueueZcu(comp, pt.tid, .{ .lost_tracking = tracked_inst_index });
865865 continue;
866866 };
867 tracked_inst.inst = InternPool.TrackedInst.MaybeLost.ZirIndex.wrap(new_inst);
867 tracked_inst.inst = .wrap(new_inst);
868868
869869 const old_zir = file.prev_zir.?.*;
870 const new_zir = file.zir.?;
871870 const old_tag = old_zir.instructions.items(.tag)[@backingInt(old_inst)];
872871 const old_data = old_zir.instructions.items(.data)[@backingInt(old_inst)];
873872
874 switch (old_tag) {
875 .declaration => {
876 const old_line = old_zir.getDeclaration(old_inst).src_line;
877 const new_line = new_zir.getDeclaration(new_inst).src_line;
878 if (old_line != new_line) {
879 comp.link_prog_node.increaseEstimatedTotalItems(1);
880 try comp.link_queue.enqueueZcu(comp, pt.tid, .{ .debug_update_line_number = .{
881 .inst = tracked_inst_index,
882 .line = new_line,
883 } });
884 }
885 },
886 else => {},
873 const new_zir = file.zir.?;
874 const new_data = new_zir.instructions.items(.data)[@backingInt(new_inst)];
875
876 debug_update_line_number: {
877 const old_line, const new_line = switch (old_tag) {
878 .declaration => .{
879 old_zir.getDeclaration(old_inst).src_line,
880 new_zir.getDeclaration(new_inst).src_line,
881 },
882 .extended => switch (old_data.extended.opcode) {
883 .struct_decl => .{
884 old_zir.getStructDecl(old_inst).src_line,
885 new_zir.getStructDecl(new_inst).src_line,
886 },
887 .union_decl => .{
888 old_zir.getUnionDecl(old_inst).src_line,
889 new_zir.getUnionDecl(new_inst).src_line,
890 },
891 .enum_decl => .{
892 old_zir.getEnumDecl(old_inst).src_line,
893 new_zir.getEnumDecl(new_inst).src_line,
894 },
895 .opaque_decl => .{
896 old_zir.getOpaqueDecl(old_inst).src_line,
897 new_zir.getOpaqueDecl(new_inst).src_line,
898 },
899 .reify_enum => .{
900 old_zir.extraData(Zir.Inst.ReifyEnum, old_data.extended.operand).data.src_line,
901 new_zir.extraData(Zir.Inst.ReifyEnum, new_data.extended.operand).data.src_line,
902 },
903 .reify_struct => .{
904 old_zir.extraData(Zir.Inst.ReifyStruct, old_data.extended.operand).data.src_line,
905 new_zir.extraData(Zir.Inst.ReifyStruct, new_data.extended.operand).data.src_line,
906 },
907 .reify_union => .{
908 old_zir.extraData(Zir.Inst.ReifyUnion, old_data.extended.operand).data.src_line,
909 new_zir.extraData(Zir.Inst.ReifyUnion, new_data.extended.operand).data.src_line,
910 },
911 else => break :debug_update_line_number,
912 },
913 else => break :debug_update_line_number,
914 };
915 if (old_line == new_line) break :debug_update_line_number;
916 comp.link_prog_node.increaseEstimatedTotalItems(1);
917 try comp.link_queue.enqueueZcu(comp, pt.tid, .{ .debug_update_line_number = .{
918 .inst = tracked_inst_index,
919 .line = new_line,
920 } });
887921 }
888922
889923 if (old_zir.getAssociatedSrcHash(old_inst)) |old_hash| hash_changed: {
src/link.zig+15-2
......@@ -875,10 +875,23 @@ pub const File = struct {
875875 assert(pt.zcu.llvm_object == null);
876876 {
877877 const ti = ti_id.resolveFull(&pt.zcu.intern_pool).?;
878 assert(ti.inst != .main_struct_inst);
879878 const file = pt.zcu.fileByIndex(ti.file);
880879 const inst = file.zir.?.instructions.get(@backingInt(ti.inst));
881 assert(inst.tag == .declaration);
880 switch (inst.tag) {
881 .declaration => {},
882 .extended => switch (inst.data.extended.opcode) {
883 .struct_decl,
884 .union_decl,
885 .enum_decl,
886 .opaque_decl,
887 .reify_enum,
888 .reify_struct,
889 .reify_union,
890 => {},
891 else => unreachable,
892 },
893 else => unreachable,
894 }
882895 }
883896 switch (base.tag) {
884897 .lld => unreachable,
src/link/Dwarf.zig+2-1
......@@ -4627,6 +4627,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
46274627 }
46284628 try diw.writeUleb128(@backingInt(AbbrevCode.null));
46294629 },
4630
46304631 .memoized_call => unreachable, // not a value
46314632 }
46324633 try dwarf.debug_info.section.replaceEntry(unit, entry, dwarf, wip_nav.debug_info.written());
......@@ -4651,7 +4652,7 @@ pub fn updateLineNumber(dwarf: *Dwarf, zcu: *Zcu, zir_index: InternPool.TrackedI
46514652 const ip = &zcu.intern_pool;
46524653
46534654 const inst_info = zir_index.resolveFull(ip).?;
4654 assert(inst_info.inst != .main_struct_inst);
4655 if (inst_info.inst == .main_struct_inst) return;
46554656 const file = zcu.fileByIndex(inst_info.file);
46564657
46574658 var line_buf: [4]u8 = undefined;
src/link/Dwarf2.zig+1316-421
......@@ -10,10 +10,7 @@ consts: std.ArrayList(Const),
1010globals: std.array_hash_map.Auto(InternPool.Nav.Index, Global),
1111funcs: std.array_hash_map.Auto(InternPool.Nav.Index, Func),
1212decls: std.array_hash_map.Auto(InternPool.TrackedInst.Index, Decl),
13pending_decl: ?struct {
14 di: Decl.Index,
15 instance_val: InternPool.Index,
16},
13pending_decl: struct { di: Decl.Index, instance_val: InternPool.Index },
1714
1815debug_abbrev: Abbrev,
1916frame: Frame,
......@@ -680,7 +677,7 @@ pub const WipNav = struct {
680677 const di_nw = &debug.info_writer;
681678 const diw = &di_nw.interface;
682679 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_func));
683 try dwarf.refConst(pt, di_nw, .fromInterned(ip.namespacePtr(switch (func.generic_owner) {
680 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(switch (func.generic_owner) {
684681 .none => nav,
685682 else => |generic_owner| ip.getNav(zcu.funcInfo(generic_owner).owner_nav),
686683 }.analysis.?.namespace).owner_type));
......@@ -692,7 +689,7 @@ pub const WipNav = struct {
692689 .normal => nav.fqn,
693690 .@"extern", .@"export" => nav.name,
694691 }.toSlice(ip));
695 try dwarf.refConst(pt, di_nw, .fromInterned(func_type.return_type));
692 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
696693 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, 0);
697694 debug.info_func_length_offset = diw.end;
698695 try diw.writeInt(u32, undefined, dwarf.endian);
......@@ -802,7 +799,7 @@ pub const WipNav = struct {
802799 .local_var => if (opt_name) |_| .local_var else unreachable,
803800 }));
804801 if (opt_name) |name| try dwarf.strp(&dwarf.debug_str, di_nw, name);
805 try dwarf.refConst(debug.pt, di_nw, ty.toValue());
802 try dwarf.refType(debug.pt, di_nw, ty);
806803 try dwarf.exprLoc(&debug.info_writer, loc);
807804 debug.any_children = true;
808805 }
......@@ -855,7 +852,7 @@ pub const WipNav = struct {
855852 } else unreachable,
856853 }));
857854 if (opt_name) |name| try dwarf.strp(&dwarf.debug_str, di_nw, name);
858 try dwarf.refConst(pt, di_nw, ty.toValue());
855 try dwarf.refType(pt, di_nw, ty);
859856 if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, val);
860857 if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, val);
861858 debug.any_children = true;
......@@ -1251,7 +1248,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {
12511248 .globals = .empty,
12521249 .funcs = .empty,
12531250 .decls = .empty,
1254 .pending_decl = null,
1251 .pending_decl = .{ .di = undefined, .instance_val = .none },
12551252
12561253 .debug_abbrev = .{
12571254 .ni = .none,
......@@ -1457,33 +1454,42 @@ pub fn getFuncIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Func.Index {
14571454 return @fromBackingInt(@intCast(dwarf.funcs.getIndex(nav) orelse return null));
14581455}
14591456
1460pub fn getDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedInst.Index {
1457fn getDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedInst.Index {
14611458 const ip = &dwarf.lf.comp.zcu.?.intern_pool;
14621459 switch (ip.indexToKey(val)) {
14631460 else => unreachable,
1464 .struct_type => {
1465 const loaded_struct = ip.loadStructType(val);
1466 if (loaded_struct.captures.len == 0) return null;
1467 return ip.getNav(loaded_struct.name_nav.unwrap() orelse
1468 return loaded_struct.zir_index).srcInst(ip);
1469 },
1470 .enum_type => {
1471 const loaded_enum = ip.loadEnumType(val);
1472 if (loaded_enum.captures.len == 0) return null;
1473 return ip.getNav(loaded_enum.name_nav.unwrap() orelse
1474 return loaded_enum.zir_index.unwrap().?).srcInst(ip);
1475 },
1476 .union_type => {
1477 const loaded_union = ip.loadUnionType(val);
1478 if (loaded_union.captures.len == 0) return null;
1479 return ip.getNav(loaded_union.name_nav.unwrap() orelse
1480 return loaded_union.zir_index).srcInst(ip);
1481 },
1482 .opaque_type => {
1483 const loaded_opaque = ip.loadOpaqueType(val);
1484 if (loaded_opaque.captures.len == 0) return null;
1485 return ip.getNav(loaded_opaque.name_nav.unwrap() orelse
1486 return loaded_opaque.zir_index).srcInst(ip);
1461 .struct_type, .union_type, .enum_type, .opaque_type => |container, tag| switch (container) {
1462 .declared => |declared| switch (declared.captures.owned.len) {
1463 0 => return null,
1464 else => switch (tag) {
1465 else => unreachable,
1466 .struct_type => {
1467 const loaded_struct = ip.loadStructType(val);
1468 return ip.getNav(loaded_struct.name_nav.unwrap() orelse
1469 return loaded_struct.zir_index).srcInst(ip);
1470 },
1471 .union_type => {
1472 const loaded_union = ip.loadUnionType(val);
1473 return ip.getNav(loaded_union.name_nav.unwrap() orelse
1474 return loaded_union.zir_index).srcInst(ip);
1475 },
1476 .enum_type => {
1477 const loaded_enum = ip.loadEnumType(val);
1478 return ip.getNav(loaded_enum.name_nav.unwrap() orelse
1479 return loaded_enum.zir_index.unwrap().?).srcInst(ip);
1480 },
1481 .opaque_type => {
1482 const loaded_opaque = ip.loadOpaqueType(val);
1483 return ip.getNav(loaded_opaque.name_nav.unwrap() orelse
1484 return loaded_opaque.zir_index).srcInst(ip);
1485 },
1486 },
1487 },
1488 .reified => |reified| {
1489 assert(reified.zir_index.resolve(ip).? != .main_struct_inst);
1490 return reified.zir_index;
1491 },
1492 .generated_union_tag => unreachable,
14871493 },
14881494 .func => |func| return ip.getNav(switch (func.generic_owner) {
14891495 .none => func.owner_nav,
......@@ -1496,7 +1502,7 @@ pub fn getDecl(
14961502 pt: Zcu.PerThread,
14971503 instance_val: InternPool.Index,
14981504) link.Error!MappedFile.Node.Index {
1499 assert(dwarf.pending_decl == null);
1505 assert(dwarf.pending_decl.instance_val == .none);
15001506 const comp = dwarf.lf.comp;
15011507 const gpa = comp.gpa;
15021508 const zcu = pt.zcu;
......@@ -2003,13 +2009,15 @@ fn genDeclFuncGeneric(
20032009 name: []const u8,
20042010 param_body: []const std.zig.Zir.Inst.Index,
20052011) link.EmitError!void {
2012 const zcu = pt.zcu;
20062013 const diw = &di_nw.interface;
20072014 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_func_generic));
2008 try dwarf.refConst(pt, di_nw, parent_ty.toValue());
2015 try dwarf.refType(pt, di_nw, parent_ty);
20092016 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
20102017 try diw.writeUleb128(decl.src_column + 1);
20112018 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
20122019 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2020 try dwarf.refType(pt, di_nw, .fromInterned(fn_ty.return_type));
20132021 var param_index: u32 = 0;
20142022 for (param_body) |param_inst| {
20152023 switch (zir.getParamName(param_inst) orelse break) {
......@@ -2019,7 +2027,7 @@ fn genDeclFuncGeneric(
20192027 try dwarf.strp(&dwarf.debug_str, di_nw, zir.nullTerminatedString(param_name));
20202028 },
20212029 }
2022 try dwarf.refConst(pt, di_nw, .fromInterned(fn_ty.param_types.get(&pt.zcu.intern_pool)[param_index]));
2030 try dwarf.refType(pt, di_nw, .fromInterned(fn_ty.param_types.get(&zcu.intern_pool)[param_index]));
20232031 param_index += 1;
20242032 }
20252033 if (fn_ty.is_var_args) try diw.writeUleb128(try dwarf.refAbbrevCode(.is_var_args));
......@@ -2095,7 +2103,6 @@ fn updateConstInner(
20952103 const ip = &zcu.intern_pool;
20962104 const diw = &di_nw.interface;
20972105 switch (ip.indexToKey(val)) {
2098 else => return,
20992106 .int_type => |int_type| {
21002107 const ty: Type = .fromInterned(val);
21012108 try diw.writeUleb128(try dwarf.refAbbrevCode(.numeric_type));
......@@ -2111,17 +2118,13 @@ fn updateConstInner(
21112118 },
21122119 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
21132120 .one, .many, .c => {
2114 const ty: Type = .fromInterned(val);
2115 const ptr_child_ty: Type = .fromInterned(ptr_type.child);
2121 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
2122 defer zcu.gpa.free(name);
21162123 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (ptr_type.flags.alignment) {
21172124 .none => if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type,
21182125 else => if (ptr_type.sentinel == .none) .ptr_aligned_type else .ptr_aligned_sentinel_type,
21192126 }));
2120 {
2121 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
2122 defer zcu.gpa.free(name);
2123 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2124 }
2127 try dwarf.strp(&dwarf.debug_str, di_nw, name);
21252128 if (ptr_type.sentinel != .none) try dwarf.blockConst(pt, di_nw, .fromInterned(ptr_type.sentinel));
21262129 if (ptr_type.flags.alignment.toByteUnits()) |a| try diw.writeUleb128(a);
21272130 try diw.writeByte(@backingInt(ptr_type.flags.address_space));
......@@ -2139,31 +2142,181 @@ fn updateConstInner(
21392142 );
21402143 }
21412144 if (ptr_type.flags.is_volatile) try diw.writeUleb128(try dwarf.refAbbrevCode(.is_volatile));
2142 try dwarf.refConst(pt, di_nw, ptr_child_ty.toValue());
2145 try dwarf.refType(pt, di_nw, .fromInterned(ptr_type.child));
21432146 },
21442147 .slice => {
21452148 const ty: Type = .fromInterned(val);
2149 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
2150 defer zcu.gpa.free(name);
21462151 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_struct_type));
2147 {
2148 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
2149 defer zcu.gpa.free(name);
2150 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2151 }
2152 try dwarf.strp(&dwarf.debug_str, di_nw, name);
21522153 try diw.writeUleb128(ty.abiSize(zcu));
21532154 try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
21542155 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
21552156 try dwarf.strp(&dwarf.debug_str, di_nw, "ptr");
21562157 const ptr_field_ty = ty.slicePtrFieldType(zcu);
2157 try dwarf.refConst(pt, di_nw, ptr_field_ty.toValue());
2158 try dwarf.refType(pt, di_nw, ptr_field_ty);
21582159 try diw.writeUleb128(0);
21592160 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
21602161 try dwarf.strp(&dwarf.debug_str, di_nw, "len");
21612162 const len_field_ty: Type = .usize;
2162 try dwarf.refConst(pt, di_nw, len_field_ty.toValue());
2163 try dwarf.refType(pt, di_nw, len_field_ty);
21632164 try diw.writeUleb128(len_field_ty.abiAlignment(zcu).forward(ptr_field_ty.abiSize(zcu)));
21642165 try diw.writeUleb128(@backingInt(AbbrevCode.null));
21652166 },
21662167 },
2168 .array_type => |array_type| {
2169 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
2170 defer zcu.gpa.free(name);
2171 try diw.writeUleb128(try dwarf.refAbbrevCode(
2172 if (array_type.sentinel == .none) .array_type else .array_sentinel_type,
2173 ));
2174 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2175 if (array_type.sentinel != .none)
2176 try dwarf.blockConst(pt, di_nw, .fromInterned(array_type.sentinel));
2177 try dwarf.refType(pt, di_nw, .fromInterned(array_type.child));
2178 try diw.writeUleb128(try dwarf.refAbbrevCode(.array_len));
2179 try dwarf.refType(pt, di_nw, .usize);
2180 try diw.writeUleb128(array_type.len);
2181 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2182 },
2183 .vector_type => |vector_type| {
2184 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
2185 defer zcu.gpa.free(name);
2186 try diw.writeUleb128(try dwarf.refAbbrevCode(.vector_type));
2187 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2188 try dwarf.refType(pt, di_nw, .fromInterned(vector_type.child));
2189 try diw.writeUleb128(try dwarf.refAbbrevCode(.array_len));
2190 try dwarf.refType(pt, di_nw, .usize);
2191 try diw.writeUleb128(vector_type.len);
2192 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2193 },
2194 .opt_type => |opt_child_type_index| {
2195 const opt_ty: Type = .fromInterned(val);
2196 const opt_child_ty: Type = .fromInterned(opt_child_type_index);
2197 const opt_repr = optRepr(opt_child_ty, zcu);
2198 const name = try zcu.gpa.print("{f}", .{opt_ty.fmt(pt)});
2199 defer zcu.gpa.free(name);
2200 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_union_type));
2201 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2202 try diw.writeUleb128(opt_ty.abiSize(zcu));
2203 try diw.writeUleb128(opt_ty.abiAlignment(zcu).toByteUnits().?);
2204 switch (opt_repr) {
2205 .opv_null => {
2206 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
2207 try dwarf.strp(&dwarf.debug_str, di_nw, "null");
2208 try dwarf.refType(pt, di_nw, .null);
2209 try diw.writeUleb128(0);
2210 },
2211 .unpacked, .error_set, .pointer => {
2212 try diw.writeUleb128(try dwarf.refAbbrevCode(.tagged_union));
2213 try dwarf.secOffset(di_nw, di_nw.ni, diw.end + dwarf.secOffsetSize());
2214 {
2215 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
2216 try dwarf.strp(&dwarf.debug_str, di_nw, "has_value");
2217 switch (opt_repr) {
2218 .opv_null => unreachable,
2219 .unpacked => {
2220 try dwarf.refType(pt, di_nw, .bool);
2221 try diw.writeUleb128(if (opt_child_ty.hasRuntimeBits(zcu))
2222 opt_child_ty.abiSize(zcu)
2223 else
2224 0);
2225 },
2226 .error_set => {
2227 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
2228 try diw.writeUleb128(0);
2229 },
2230 .pointer => {
2231 try dwarf.refType(pt, di_nw, .usize);
2232 try diw.writeUleb128(0);
2233 },
2234 }
2235
2236 try diw.writeUleb128(try dwarf.refAbbrevCode(.tagged_union_field));
2237 try diw.writeUleb128(DW.FORM.data1);
2238 try diw.writeByte(0);
2239 {
2240 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
2241 try dwarf.strp(&dwarf.debug_str, di_nw, "null");
2242 try dwarf.refType(pt, di_nw, .null);
2243 try diw.writeUleb128(0);
2244 }
2245 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2246
2247 try diw.writeUleb128(try dwarf.refAbbrevCode(.tagged_union_default_field));
2248 {
2249 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
2250 try dwarf.strp(&dwarf.debug_str, di_nw, "?");
2251 try dwarf.refType(pt, di_nw, opt_child_ty);
2252 try diw.writeUleb128(0);
2253 }
2254 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2255 }
2256 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2257 },
2258 }
2259 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2260 },
2261 .anyframe_type => unreachable,
2262 .error_union_type => |error_union_type| {
2263 const eu_ty: Type = .fromInterned(val);
2264 const eu_error_set_ty: Type = .fromInterned(error_union_type.error_set_type);
2265 const eu_payload_ty: Type = .fromInterned(error_union_type.payload_type);
2266 const eu_error_set_offset, const eu_payload_offset = switch (error_union_type.payload_type) {
2267 .generic_poison_type => .{ 0, 0 },
2268 else => .{
2269 codegen.errUnionErrorOffset(eu_payload_ty, zcu),
2270 codegen.errUnionPayloadOffset(eu_payload_ty, zcu),
2271 },
2272 };
2273 const name = try zcu.gpa.print("{f}", .{eu_ty.fmt(pt)});
2274 defer zcu.gpa.free(name);
2275
2276 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_union_type));
2277 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2278 if (error_union_type.error_set_type != .generic_poison_type and
2279 error_union_type.payload_type != .generic_poison_type)
2280 {
2281 try diw.writeUleb128(eu_ty.abiSize(zcu));
2282 try diw.writeUleb128(eu_ty.abiAlignment(zcu).toByteUnits().?);
2283 } else {
2284 try diw.writeUleb128(0);
2285 try diw.writeUleb128(1);
2286 }
2287 {
2288 try diw.writeUleb128(try dwarf.refAbbrevCode(.tagged_union));
2289 try dwarf.secOffset(di_nw, di_nw.ni, diw.end + dwarf.secOffsetSize());
2290 {
2291 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
2292 try dwarf.strp(&dwarf.debug_str, di_nw, "is_error");
2293 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
2294 try diw.writeUleb128(eu_error_set_offset);
2295
2296 try diw.writeUleb128(try dwarf.refAbbrevCode(.tagged_union_field));
2297 try diw.writeUleb128(DW.FORM.udata);
2298 try diw.writeUleb128(0);
2299 {
2300 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
2301 try dwarf.strp(&dwarf.debug_str, di_nw, "value");
2302 try dwarf.refType(pt, di_nw, eu_payload_ty);
2303 try diw.writeUleb128(eu_payload_offset);
2304 }
2305 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2306
2307 try diw.writeUleb128(try dwarf.refAbbrevCode(.tagged_union_default_field));
2308 {
2309 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
2310 try dwarf.strp(&dwarf.debug_str, di_nw, "error");
2311 try dwarf.refType(pt, di_nw, eu_error_set_ty);
2312 try diw.writeUleb128(eu_error_set_offset);
2313 }
2314 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2315 }
2316 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2317 }
2318 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2319 },
21672320 .simple_type => |simple_type| switch (simple_type) {
21682321 .f16,
21692322 .f32,
......@@ -2220,25 +2373,315 @@ fn updateConstInner(
22202373 var name_buf: ["@TypeOf(undefined)".len]u8 = undefined;
22212374 try dwarf.strp(&dwarf.debug_str, di_nw, std.mem.print(&name_buf, "{f}", .{ty.fmt(pt)}) catch unreachable);
22222375 },
2223 .anyerror => return,
2376 .anyerror => {
2377 const global_error_set_names = ip.global_error_set.getNamesFromMainThread();
2378 try diw.writeUleb128(try dwarf.refAbbrevCode(
2379 if (global_error_set_names.len > 0) .generated_enum_type else .generated_empty_enum_type,
2380 ));
2381 try dwarf.strp(&dwarf.debug_str, di_nw, "anyerror");
2382 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
2383 for (global_error_set_names, 1..) |name, value| {
2384 try diw.writeUleb128(try dwarf.refAbbrevCode(.enum_field));
2385 try diw.writeUleb128(DW.FORM.udata);
2386 try diw.writeUleb128(value);
2387 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
2388 }
2389 if (global_error_set_names.len > 0) try diw.writeUleb128(@backingInt(AbbrevCode.null));
2390 },
22242391 .adhoc_inferred_error_set => unreachable,
22252392 },
2393 .tuple_type => |tuple_type| {
2394 const ty: Type = .fromInterned(val);
2395 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
2396 defer zcu.gpa.free(name);
2397 if (tuple_type.types.len == 0) {
2398 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_empty_struct_type));
2399 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2400 try diw.writeByte(@intFromBool(false));
2401 } else {
2402 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_struct_type));
2403 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2404 try diw.writeUleb128(ty.abiSize(zcu));
2405 try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
2406 var field_byte_offset: u64 = 0;
2407 for (0..tuple_type.types.len) |field_index| {
2408 const comptime_value = tuple_type.values.get(ip)[field_index];
2409 const field_ty: Type = .fromInterned(tuple_type.types.get(ip)[field_index]);
2410 const comptime_value_class = switch (comptime_value) {
2411 .none => .no_possible_value,
2412 else => field_ty.classify(zcu),
2413 };
2414 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (comptime_value) {
2415 .none => .field,
2416 else => switch (comptime_value_class) {
2417 .no_possible_value, .one_possible_value => .field_comptime,
2418 .runtime => .field_comptime_fully_runtime,
2419 .partially_comptime => .field_comptime_partially_comptime,
2420 .fully_comptime => .field_comptime_fully_comptime,
2421 },
2422 }));
2423 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
2424 try dwarf.strp(
2425 &dwarf.debug_str,
2426 di_nw,
2427 std.mem.print(&field_name_buf, "{d}", .{field_index}) catch unreachable,
2428 );
2429 try dwarf.refType(pt, di_nw, field_ty);
2430 if (comptime_value == .none) {
2431 const field_align = field_ty.abiAlignment(zcu);
2432 field_byte_offset = field_align.forward(field_byte_offset);
2433 try diw.writeUleb128(field_byte_offset);
2434 try diw.writeUleb128(field_ty.abiAlignment(zcu).toByteUnits().?);
2435 field_byte_offset += field_ty.abiSize(zcu);
2436 }
2437 if (comptime_value_class.hasRuntimeBits())
2438 try dwarf.blockConst(pt, di_nw, .fromInterned(comptime_value));
2439 if (comptime_value_class.comptimeOnly())
2440 try dwarf.refConst(pt, di_nw, .fromInterned(comptime_value));
2441 }
2442 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2443 }
2444 },
22262445 .struct_type => {
22272446 const loaded_struct = ip.loadStructType(val);
22282447 const zfi = loaded_struct.zir_index.resolveFile(ip);
22292448 const zf = zcu.fileByIndex(zfi);
2449 const src_inst = loaded_struct.zir_index.resolve(ip);
2450 if (src_inst == .main_struct_inst) {
2451 assert(loaded_struct.captures.len == 0);
2452 const ui = dwarf.getUnit(zf.mod.?);
2453 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, zfi);
2454 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (loaded_struct.layout) {
2455 .auto => if (loaded_struct.field_types.len > 0) .file else .empty_file,
2456 .@"extern", .@"packed" => unreachable,
2457 }));
2458 try diw.writeUleb128(@backingInt(fi));
2459 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));
2460 } else if (loaded_struct.captures.len > 0 or loaded_struct.is_reified) {
2461 try diw.writeUleb128(try dwarf.refAbbrevCode(
2462 if (loaded_struct.captures.len > 0 or loaded_struct.field_types.len > 0) switch (loaded_struct.layout) {
2463 .auto, .@"extern" => .decl_instance_struct,
2464 .@"packed" => .decl_instance_packed_struct,
2465 } else switch (loaded_struct.layout) {
2466 .auto, .@"extern" => .decl_instance_empty_struct,
2467 .@"packed" => .decl_instance_empty_packed_struct,
2468 },
2469 ));
2470 try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0);
2471 } else if (loaded_struct.name_nav.unwrap()) |name_ni| {
2472 const name_nav = ip.getNav(name_ni);
2473 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2474 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2475 name_nav.analysis.?.namespace,
2476 ).owner_type);
2477 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (loaded_struct.layout) {
2478 .auto, .@"extern" => if (loaded_struct.field_types.len > 0) .decl_struct else .decl_empty_struct,
2479 .@"packed" => if (loaded_struct.field_types.len > 0) .decl_packed_struct else .decl_empty_packed_struct,
2480 }));
2481 try dwarf.secOffset(di_nw, parent_ni, 0);
2482 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
2483 try diw.writeUleb128(decl.src_column + 1);
2484 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2485 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
2486 } else {
2487 const decl = zf.zir.?.getStructDecl(src_inst.?);
2488 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2489 ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?,
2490 ).owner_type);
2491 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (loaded_struct.layout) {
2492 .auto, .@"extern" => if (loaded_struct.field_types.len > 0) .type_decl_struct else .type_decl_empty_struct,
2493 .@"packed" => if (loaded_struct.field_types.len > 0) .type_decl_packed_struct else .type_decl_empty_packed_struct,
2494 }));
2495 try dwarf.secOffset(di_nw, parent_ni, 0);
2496 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
2497 try diw.writeUleb128(decl.src_column + 1);
2498 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));
2499 }
22302500 switch (loaded_struct.layout) {
22312501 .auto, .@"extern" => {
2232 const struct_is_file = loaded_struct.zir_index.resolve(ip) == .main_struct_inst;
2233 if (loaded_struct.name_nav.unwrap()) |name_ni| {
2234 assert(!struct_is_file);
2502 const ty: Type = .fromInterned(val);
2503 try diw.writeUleb128(ty.abiSize(zcu));
2504 try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
2505 try dwarf.genCaptures(pt, di_nw, loaded_struct.captures);
2506 for (0..loaded_struct.field_types.len) |field_index| {
2507 const is_comptime = loaded_struct.field_is_comptime_bits.get(ip, field_index);
2508 // TODO: we currently don't emit information about default values for
2509 // non-`comptime` fields, because these default values are resolved at a
2510 // separate time in the compiler frontend. To emit this information, the
2511 // frontend needs to tell us when the default values are available: like
2512 // how `Zcu.PerThread.ensureTypeLayoutUpToDate` enqueues a link task to
2513 // indicate completion of the type's layout, a task should be enqueued
2514 // by `Zcu.PerThread.ensureStructDefaultsUpToDate`, and upon receiving
2515 // it we should patch the correct default field values in.
2516 const field_default: InternPool.Index =
2517 if (is_comptime) loaded_struct.field_defaults.getOrNone(ip, field_index) else .none;
2518 assert(!(is_comptime and field_default == .none));
2519 const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2520 const field_default_class = switch (field_default) {
2521 .none => .no_possible_value,
2522 else => field_ty.classify(zcu),
2523 };
2524 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (field_default_class) {
2525 .no_possible_value, .one_possible_value => if (is_comptime) .field_comptime else .field,
2526 .runtime => if (is_comptime) .field_comptime_fully_runtime else .field_default_fully_runtime,
2527 .partially_comptime => if (is_comptime) .field_comptime_partially_comptime else .field_default_partially_comptime,
2528 .fully_comptime => if (is_comptime) .field_comptime_fully_comptime else .field_default_fully_comptime,
2529 }));
2530 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.field_names.get(ip)[field_index].toSlice(ip));
2531 try dwarf.refType(pt, di_nw, field_ty);
2532 if (!is_comptime) {
2533 try diw.writeUleb128(loaded_struct.field_offsets.get(ip)[field_index]);
2534 try diw.writeUleb128(loaded_struct.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse
2535 field_ty.abiAlignment(zcu).toByteUnits().?);
2536 }
2537 if (field_default_class.hasRuntimeBits())
2538 try dwarf.blockConst(pt, di_nw, .fromInterned(field_default));
2539 if (field_default_class.comptimeOnly())
2540 try dwarf.refConst(pt, di_nw, .fromInterned(field_default));
2541 }
2542 },
2543 .@"packed" => {
2544 try dwarf.refType(pt, di_nw, .fromInterned(loaded_struct.packed_backing_int_type));
2545 try dwarf.genCaptures(pt, di_nw, loaded_struct.captures);
2546 var field_bit_offset: u16 = 0;
2547 for (0..loaded_struct.field_types.len) |field_index| {
2548 try diw.writeUleb128(try dwarf.refAbbrevCode(.packed_field));
2549 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.field_names.get(ip)[field_index].toSlice(ip));
2550 const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2551 try dwarf.refType(pt, di_nw, field_ty);
2552 try diw.writeUleb128(field_bit_offset);
2553 field_bit_offset += @intCast(field_ty.bitSize(zcu));
2554 }
2555 },
2556 }
2557 if (loaded_struct.captures.len > 0 or loaded_struct.field_types.len > 0)
2558 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2559 },
2560 .union_type => {
2561 const loaded_union = ip.loadUnionType(val);
2562 const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type);
2563 const zfi = loaded_union.zir_index.resolveFile(ip);
2564 const zf = zcu.fileByIndex(zfi);
2565 if (loaded_union.captures.len > 0 or loaded_union.is_reified) {
2566 try diw.writeUleb128(try dwarf.refAbbrevCode(
2567 if (loaded_union.captures.len > 0 or loaded_union.field_types.len > 0) switch (loaded_union.layout) {
2568 .auto, .@"extern" => .decl_instance_union,
2569 .@"packed" => .decl_instance_packed_union,
2570 } else switch (loaded_union.layout) {
2571 .auto, .@"extern" => .decl_instance_empty_union,
2572 .@"packed" => .decl_instance_empty_packed_union,
2573 },
2574 ));
2575 try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0);
2576 } else if (loaded_union.name_nav.unwrap()) |name_ni| {
2577 const name_nav = ip.getNav(name_ni);
2578 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2579 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2580 name_nav.analysis.?.namespace,
2581 ).owner_type);
2582 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (loaded_union.layout) {
2583 .auto, .@"extern" => if (loaded_union.field_types.len > 0) .decl_union else .decl_empty_union,
2584 .@"packed" => if (loaded_union.field_types.len > 0) .decl_packed_union else .decl_empty_packed_union,
2585 }));
2586 try dwarf.secOffset(di_nw, parent_ni, 0);
2587 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
2588 try diw.writeUleb128(decl.src_column + 1);
2589 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2590 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
2591 } else {
2592 const decl = zf.zir.?.getUnionDecl(loaded_union.zir_index.resolve(ip).?);
2593 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2594 ip.namespacePtr(loaded_union.namespace).parent.unwrap().?,
2595 ).owner_type);
2596 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (loaded_union.layout) {
2597 .auto, .@"extern" => if (loaded_union.field_types.len > 0) .type_decl_union else .type_decl_empty_union,
2598 .@"packed" => if (loaded_union.field_types.len > 0) .type_decl_packed_union else .type_decl_empty_packed_union,
2599 }));
2600 try dwarf.secOffset(di_nw, parent_ni, 0);
2601 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
2602 try diw.writeUleb128(decl.src_column + 1);
2603 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_union.name.toSlice(ip));
2604 }
2605 switch (loaded_union.layout) {
2606 .auto, .@"extern" => {
2607 const union_layout = Type.getUnionLayout(loaded_union, zcu);
2608 try diw.writeUleb128(union_layout.abi_size);
2609 try diw.writeUleb128(union_layout.abi_align.toByteUnits().?);
2610 try dwarf.genCaptures(pt, di_nw, loaded_union.captures);
2611 if (loaded_union.has_runtime_tag) {
2612 try diw.writeUleb128(try dwarf.refAbbrevCode(.tagged_union));
2613 try dwarf.secOffset(di_nw, di_nw.ni, diw.end + dwarf.secOffsetSize());
2614 {
2615 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
2616 try dwarf.strp(&dwarf.debug_str, di_nw, "tag");
2617 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.enum_tag_type));
2618 try diw.writeUleb128(union_layout.tagOffset());
2619
2620 for (0..loaded_union.field_types.len) |field_index| {
2621 try diw.writeUleb128(try dwarf.refAbbrevCode(.tagged_union_field));
2622 try dwarf.enumConstValue(diw, loaded_tag, field_index);
2623 {
2624 try diw.writeUleb128(try dwarf.refAbbrevCode(.field));
2625 try dwarf.strp(
2626 &dwarf.debug_str,
2627 di_nw,
2628 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),
2629 );
2630 const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
2631 try dwarf.refType(pt, di_nw, field_ty);
2632 try diw.writeUleb128(union_layout.payloadOffset());
2633 try diw.writeUleb128(loaded_union.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse
2634 if (field_ty.isNoReturn(zcu)) 1 else field_ty.abiAlignment(zcu).toByteUnits().?);
2635 }
2636 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2637 }
2638 }
2639 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2640 } else for (0..loaded_union.field_types.len) |field_index| {
2641 try diw.writeUleb128(try dwarf.refAbbrevCode(.field));
2642 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_tag.field_names.get(ip)[field_index].toSlice(ip));
2643 const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
2644 try dwarf.refType(pt, di_nw, field_ty);
2645 try diw.writeUleb128(0);
2646 try diw.writeUleb128(loaded_union.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse
2647 if (field_ty.isNoReturn(zcu)) 1 else field_ty.abiAlignment(zcu).toByteUnits().?);
2648 }
2649 },
2650 .@"packed" => {
2651 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.packed_backing_int_type));
2652 for (0..loaded_union.field_types.len) |field_index| {
2653 try diw.writeUleb128(try dwarf.refAbbrevCode(.packed_field));
2654 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_tag.field_names.get(ip)[field_index].toSlice(ip));
2655 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.field_types.get(ip)[field_index]));
2656 try diw.writeUleb128(0);
2657 }
2658 },
2659 }
2660 if (loaded_union.captures.len > 0 or loaded_union.field_types.len > 0)
2661 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2662 },
2663 .enum_type => {
2664 const loaded_enum = ip.loadEnumType(val);
2665 switch (loaded_enum.owner_union) {
2666 .none => {
2667 const zfi = loaded_enum.zir_index.unwrap().?.resolveFile(ip);
2668 const zf = zcu.fileByIndex(zfi);
2669 if (loaded_enum.captures.len > 0 or loaded_enum.is_reified) {
2670 try diw.writeUleb128(try dwarf.refAbbrevCode(
2671 if (loaded_enum.captures.len > 0 or loaded_enum.field_names.len > 0)
2672 .decl_instance_enum
2673 else
2674 .decl_instance_empty_enum,
2675 ));
2676 try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0);
2677 } else if (loaded_enum.name_nav.unwrap()) |name_ni| {
22352678 const name_nav = ip.getNav(name_ni);
22362679 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
22372680 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
22382681 name_nav.analysis.?.namespace,
22392682 ).owner_type);
22402683 try diw.writeUleb128(try dwarf.refAbbrevCode(
2241 if (loaded_struct.field_types.len > 0) .decl_struct else .decl_namespace_struct,
2684 if (loaded_enum.field_names.len > 0) .decl_enum else .decl_empty_enum,
22422685 ));
22432686 try dwarf.secOffset(di_nw, parent_ni, 0);
22442687 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
......@@ -2246,107 +2689,173 @@ fn updateConstInner(
22462689 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
22472690 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
22482691 } else {
2249 const ui = dwarf.getUnit(zf.mod.?);
2250 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, zfi);
2251 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (loaded_struct.field_types.len) {
2252 0 => if (struct_is_file) .empty_file else .empty_struct_type,
2253 else => if (struct_is_file) .file else .struct_type,
2254 }));
2255 try diw.writeUleb128(@backingInt(fi));
2256 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.fqn.toSlice(ip));
2692 const decl = zf.zir.?.getEnumDecl(loaded_enum.zir_index.unwrap().?.resolve(ip).?);
2693 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2694 ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?,
2695 ).owner_type);
2696 try diw.writeUleb128(try dwarf.refAbbrevCode(
2697 if (loaded_enum.field_names.len > 0) .type_decl_enum else .type_decl_empty_enum,
2698 ));
2699 try dwarf.secOffset(di_nw, parent_ni, 0);
2700 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
2701 try diw.writeUleb128(decl.src_column + 1);
2702 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip));
22572703 }
2258 if (loaded_struct.field_types.len > 0) {
2259 const ty: Type = .fromInterned(val);
2260 try diw.writeUleb128(ty.abiSize(zcu));
2261 try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
2262 for (0..loaded_struct.field_types.len) |field_index| {
2263 const is_comptime = loaded_struct.field_is_comptime_bits.get(ip, field_index);
2264 // TODO: we currently don't emit information about default values for
2265 // non-`comptime` fields, because these default values are resolved at a
2266 // separate time in the compiler frontend. To emit this information, the
2267 // frontend needs to tell us when the default values are available: like
2268 // how `Zcu.PerThread.ensureTypeLayoutUpToDate` enqueues a link task to
2269 // indicate completion of the type's layout, a task should be enqueued
2270 // by `Zcu.PerThread.ensureStructDefaultsUpToDate`, and upon receiving
2271 // it we should patch the correct default field values in.
2272 const field_default: InternPool.Index =
2273 if (is_comptime) loaded_struct.field_defaults.getOrNone(ip, field_index) else .none;
2274 assert(!(is_comptime and field_default == .none));
2275 const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2276 const field_default_class = switch (field_default) {
2277 .none => .no_possible_value,
2278 else => field_ty.classify(zcu),
2279 };
2280 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (field_default_class) {
2281 .no_possible_value, .one_possible_value => if (is_comptime) .field_comptime else .field,
2282 .runtime => if (is_comptime) .field_comptime_fully_runtime else .field_default_fully_runtime,
2283 .partially_comptime => if (is_comptime) .field_comptime_partially_comptime else .field_default_partially_comptime,
2284 .fully_comptime => if (is_comptime) .field_comptime_fully_comptime else .field_default_fully_comptime,
2285 }));
2286 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.field_names.get(ip)[field_index].toSlice(ip));
2287 try dwarf.refConst(pt, di_nw, field_ty.toValue());
2288 if (!is_comptime) {
2289 try diw.writeUleb128(loaded_struct.field_offsets.get(ip)[field_index]);
2290 try diw.writeUleb128(loaded_struct.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse
2291 field_ty.abiAlignment(zcu).toByteUnits().?);
2292 }
2293 if (field_default_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, .fromInterned(field_default));
2294 if (field_default_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, .fromInterned(field_default));
2295 }
2296 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2297 } else try diw.writeByte(@intFromBool(false));
22982704 },
2299 .@"packed" => return,
2300 }
2301 },
2302 .enum_type => {
2303 const loaded_enum = ip.loadEnumType(val);
2304 if (loaded_enum.zir_index.unwrap()) |zir_index| {
2305 assert(loaded_enum.owner_union == .none);
2306 const zfi = zir_index.resolveFile(ip);
2307 const zf = zcu.fileByIndex(zfi);
2308 if (loaded_enum.name_nav.unwrap()) |name_ni| {
2309 const name_nav = ip.getNav(name_ni);
2310 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2311 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2312 name_nav.analysis.?.namespace,
2313 ).owner_type);
2314 try diw.writeUleb128(try dwarf.refAbbrevCode(
2315 if (loaded_enum.field_names.len > 0) .decl_enum else .decl_empty_enum,
2316 ));
2317 try dwarf.secOffset(di_nw, parent_ni, 0);
2318 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
2319 try diw.writeUleb128(decl.src_column + 1);
2320 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2321 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
2322 } else {
2323 const ui = dwarf.getUnit(zf.mod.?);
2324 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, zfi);
2705 else => {
23252706 try diw.writeUleb128(try dwarf.refAbbrevCode(
2326 if (loaded_enum.field_names.len > 0) .enum_type else .empty_enum_type,
2707 if (loaded_enum.field_names.len > 0) .generated_enum_type else .generated_empty_enum_type,
23272708 ));
2328 try diw.writeUleb128(@backingInt(fi));
23292709 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip));
2330 }
2331 } else {
2332 assert(loaded_enum.owner_union != .none);
2333 try diw.writeUleb128(try dwarf.refAbbrevCode(
2334 if (loaded_enum.field_names.len == 0) .generated_empty_enum_type else .generated_enum_type,
2335 ));
2336 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip));
2710 },
23372711 }
2338 try dwarf.refConst(pt, di_nw, .fromInterned(loaded_enum.int_tag_type));
2712 try dwarf.refType(pt, di_nw, .fromInterned(loaded_enum.int_tag_type));
23392713 for (0..loaded_enum.field_names.len) |field_index| {
23402714 try diw.writeUleb128(try dwarf.refAbbrevCode(.enum_field));
23412715 try dwarf.enumConstValue(diw, loaded_enum, field_index);
23422716 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.field_names.get(ip)[field_index].toSlice(ip));
23432717 }
2344 if (loaded_enum.field_names.len > 0) try diw.writeUleb128(@backingInt(AbbrevCode.null));
2718 if (loaded_enum.captures.len > 0 or loaded_enum.field_names.len > 0)
2719 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2720 },
2721 // no defined size, so lowered the same as incomplete struct types
2722 .opaque_type => return dwarf.updateConstIncompleteInner(pt, di_nw, val),
2723 .spirv_type => unreachable,
2724 .func_type => |func_type| {
2725 const is_nullary = func_type.param_types.len == 0 and !func_type.is_var_args;
2726 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
2727 defer zcu.gpa.free(name);
2728 try diw.writeUleb128(try dwarf.refAbbrevCode(
2729 if (is_nullary) .nullary_func_type else .func_type,
2730 ));
2731 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2732 const cc: DW.CC = cc: {
2733 if (zcu.getTarget().cCallingConvention()) |cc| {
2734 if (@as(std.lang.CallingConvention.Tag, cc) == func_type.cc) {
2735 break :cc .normal;
2736 }
2737 }
2738 // For better or worse, we try to match what Clang emits.
2739 break :cc switch (func_type.cc) {
2740 .@"inline" => .nocall,
2741 .async, .auto, .naked => .normal,
2742 .x86_64_sysv => .LLVM_X86_64SysV,
2743 .x86_64_win => .LLVM_Win64,
2744 .x86_64_regcall_v3_sysv => .LLVM_X86RegCall,
2745 .x86_64_regcall_v4_win => .LLVM_X86RegCall,
2746 .x86_64_vectorcall => .LLVM_vectorcall,
2747 .x86_sysv, .x86_win, .x86_mingw => .normal,
2748 .x86_64_preserve_none => .LLVM_PreserveNone,
2749 .x86_stdcall => .BORLAND_stdcall,
2750 .x86_fastcall => .BORLAND_msfastcall,
2751 .x86_thiscall => .BORLAND_thiscall,
2752 .x86_thiscall_mingw => .BORLAND_thiscall,
2753 .x86_regcall_v3 => .LLVM_X86RegCall,
2754 .x86_regcall_v4_win => .LLVM_X86RegCall,
2755 .x86_vectorcall => .LLVM_vectorcall,
2756
2757 .aarch64_aapcs => .normal,
2758 .aarch64_aapcs_darwin => .normal,
2759 .aarch64_aapcs_win => .normal,
2760 .aarch64_vfabi => .LLVM_AAPCS,
2761 .aarch64_vfabi_sve => .LLVM_AAPCS,
2762 .aarch64_preserve_none => .LLVM_PreserveNone,
2763
2764 .arm_aapcs => .LLVM_AAPCS,
2765 .arm_aapcs_vfp => .LLVM_AAPCS_VFP,
2766
2767 .riscv64_lp64_v,
2768 .riscv32_ilp32_v,
2769 => .LLVM_RISCVVectorCall,
2770
2771 .m68k_rtd => .LLVM_M68kRTD,
2772
2773 .sh_renesas => .GNU_renesas_sh,
2774
2775 .amdgcn_kernel => .LLVM_OpenCLKernel,
2776 .nvptx_kernel,
2777 .spirv_kernel,
2778 => .nocall,
2779
2780 .x86_64_interrupt,
2781 .x86_interrupt,
2782 .arm_interrupt,
2783 .mips64_interrupt,
2784 .mips_interrupt,
2785 .riscv64_interrupt,
2786 .riscv32_interrupt,
2787 .sh_interrupt,
2788 .arc_interrupt,
2789 .avr_builtin,
2790 .avr_signal,
2791 .avr_interrupt,
2792 .csky_interrupt,
2793 .m68k_interrupt,
2794 .microblaze_interrupt,
2795 .msp430_interrupt,
2796 => .normal,
2797
2798 else => .nocall,
2799 };
2800 };
2801 try diw.writeByte(@backingInt(cc));
2802 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
2803 if (!is_nullary) {
2804 for (0..func_type.param_types.len) |param_index| {
2805 try diw.writeUleb128(try dwarf.refAbbrevCode(.unnamed_param));
2806 try dwarf.refType(pt, di_nw, .fromInterned(func_type.param_types.get(ip)[param_index]));
2807 }
2808 if (func_type.is_var_args) try diw.writeUleb128(try dwarf.refAbbrevCode(.is_var_args));
2809 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2810 }
2811 },
2812 .error_set_type => |error_set_type| {
2813 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
2814 defer zcu.gpa.free(name);
2815 try diw.writeUleb128(try dwarf.refAbbrevCode(
2816 if (error_set_type.names.len > 0) .generated_enum_type else .generated_empty_enum_type,
2817 ));
2818 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2819 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
2820 for (0..error_set_type.names.len) |field_index| {
2821 const field_name = error_set_type.names.get(ip)[field_index];
2822 try diw.writeUleb128(try dwarf.refAbbrevCode(.enum_field));
2823 try diw.writeUleb128(DW.FORM.udata);
2824 try diw.writeUleb128(ip.getErrorValueIfExists(field_name).?);
2825 try dwarf.strp(&dwarf.debug_str, di_nw, field_name.toSlice(ip));
2826 }
2827 if (error_set_type.names.len > 0) try diw.writeUleb128(@backingInt(AbbrevCode.null));
2828 },
2829 .inferred_error_set_type => |func| {
2830 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
2831 defer zcu.gpa.free(name);
2832 try diw.writeUleb128(try dwarf.refAbbrevCode(.inferred_error_set_type));
2833 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2834 try dwarf.refType(pt, di_nw, switch (ip.funcIesResolvedUnordered(func)) {
2835 .none => .anyerror,
2836 else => |ies| .fromInterned(ies),
2837 });
23452838 },
2839
2840 else => return,
2841
2842 .memoized_call => unreachable, // not a value
23462843 }
23472844 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());
23482845}
23492846
2847fn optRepr(opt_child_type: Type, zcu: *const Zcu) enum { unpacked, opv_null, error_set, pointer } {
2848 if (opt_child_type.isNoReturn(zcu)) return .opv_null;
2849 return switch (opt_child_type.toIntern()) {
2850 .anyerror_type => .error_set,
2851 else => switch (zcu.intern_pool.indexToKey(opt_child_type.toIntern())) {
2852 else => .unpacked,
2853 .error_set_type, .inferred_error_set_type => .error_set,
2854 .ptr_type => |ptr_type| if (ptr_type.flags.is_allowzero) .unpacked else .pointer,
2855 },
2856 };
2857}
2858
23502859pub fn updateConstIncomplete(
23512860 dwarf: *Dwarf,
23522861 pt: Zcu.PerThread,
......@@ -2369,7 +2878,7 @@ fn updateConstIncompleteInner(
23692878 const ip = &zcu.intern_pool;
23702879 const diw = &di_nw.interface;
23712880 done: {
2372 const src_inst, const zf, const capture_names, const captures, const fqn, const maybe_name_nav, const namespace = container: switch (ip.indexToKey(val)) {
2881 const kind: enum { @"struct", @"union", @"enum" }, const zf, const src_line, const src_column, const is_reified, const captures, const name, const maybe_name_nav, const namespace = container: switch (ip.indexToKey(val)) {
23732882 .struct_type => {
23742883 const loaded_struct = ip.loadStructType(val);
23752884 const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse {
......@@ -2383,22 +2892,34 @@ fn updateConstIncompleteInner(
23832892 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);
23842893 try diw.writeUleb128(try dwarf.refAbbrevCode(.empty_file));
23852894 try diw.writeUleb128(@backingInt(fi));
2386 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.fqn.toSlice(ip));
2895 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));
23872896 try diw.writeByte(@intFromBool(true));
23882897 break :done;
23892898 },
2390 else => break :container .{
2391 src_inst,
2392 zf,
2393 switch (zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended.opcode) {
2899 else => {
2900 const data = zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended;
2901 const src_line, const src_column = src_loc: switch (data.opcode) {
23942902 else => unreachable,
2395 .struct_decl => zf.zir.?.getStructDecl(src_inst.inst).capture_names,
2396 .reify_struct => &.{},
2397 },
2398 loaded_struct.captures,
2399 loaded_struct.fqn,
2400 loaded_struct.name_nav,
2401 loaded_struct.namespace,
2903 .struct_decl => {
2904 const decl = zf.zir.?.getStructDecl(src_inst.inst);
2905 break :src_loc .{ decl.src_line, decl.src_column };
2906 },
2907 .reify_struct => {
2908 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.ReifyStruct, data.operand).data;
2909 break :src_loc .{ decl.src_line, decl.src_column };
2910 },
2911 };
2912 break :container .{
2913 .@"struct",
2914 zf,
2915 src_line,
2916 src_column,
2917 loaded_struct.is_reified,
2918 loaded_struct.captures,
2919 loaded_struct.name,
2920 loaded_struct.name_nav,
2921 loaded_struct.namespace,
2922 };
24022923 },
24032924 }
24042925 },
......@@ -2409,16 +2930,26 @@ fn updateConstIncompleteInner(
24092930 break :done;
24102931 };
24112932 const zf = zcu.fileByIndex(src_inst.file);
2933 const data = zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended;
2934 const src_line, const src_column = src_loc: switch (data.opcode) {
2935 else => unreachable,
2936 .union_decl => {
2937 const decl = zf.zir.?.getUnionDecl(src_inst.inst);
2938 break :src_loc .{ decl.src_line, decl.src_column };
2939 },
2940 .reify_union => {
2941 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.ReifyUnion, data.operand).data;
2942 break :src_loc .{ decl.src_line, decl.src_column };
2943 },
2944 };
24122945 break :container .{
2413 src_inst,
2946 .@"union",
24142947 zf,
2415 switch (zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended.opcode) {
2416 else => unreachable,
2417 .union_decl => zf.zir.?.getUnionDecl(src_inst.inst).capture_names,
2418 .reify_union => &.{},
2419 },
2948 src_line,
2949 src_column,
2950 loaded_union.is_reified,
24202951 loaded_union.captures,
2421 loaded_union.fqn,
2952 loaded_union.name,
24222953 loaded_union.name_nav,
24232954 loaded_union.namespace,
24242955 };
......@@ -2427,7 +2958,7 @@ fn updateConstIncompleteInner(
24272958 const loaded_enum = ip.loadEnumType(val);
24282959 const zir_index = loaded_enum.zir_index.unwrap() orelse {
24292960 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_empty_struct_type));
2430 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip));
2961 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip));
24312962 try diw.writeByte(@intFromBool(true));
24322963 break :done;
24332964 };
......@@ -2436,20 +2967,31 @@ fn updateConstIncompleteInner(
24362967 break :done;
24372968 };
24382969 const zf = zcu.fileByIndex(src_inst.file);
2970 const data = zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended;
2971 const src_line, const src_column = src_loc: switch (data.opcode) {
2972 else => unreachable,
2973 .enum_decl => {
2974 const decl = zf.zir.?.getEnumDecl(src_inst.inst);
2975 break :src_loc .{ decl.src_line, decl.src_column };
2976 },
2977 .reify_enum => {
2978 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.ReifyEnum, data.operand).data;
2979 break :src_loc .{ decl.src_line, decl.src_column };
2980 },
2981 };
24392982 break :container .{
2440 src_inst,
2983 .@"enum",
24412984 zf,
2442 switch (zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended.opcode) {
2443 else => unreachable,
2444 .enum_decl => zf.zir.?.getEnumDecl(src_inst.inst).capture_names,
2445 .reify_enum => &.{},
2446 },
2985 src_line,
2986 src_column,
2987 loaded_enum.is_reified,
24472988 loaded_enum.captures,
2448 loaded_enum.fqn,
2989 loaded_enum.name,
24492990 loaded_enum.name_nav,
24502991 loaded_enum.namespace,
24512992 };
24522993 },
2994 // always complete, but forwarded from `updateConstInner`
24532995 .opaque_type => {
24542996 const loaded_opaque = ip.loadOpaqueType(val);
24552997 const src_inst = loaded_opaque.zir_index.resolveFull(ip) orelse {
......@@ -2457,12 +2999,15 @@ fn updateConstIncompleteInner(
24572999 break :done;
24583000 };
24593001 const zf = zcu.fileByIndex(src_inst.file);
3002 const decl = zf.zir.?.getOpaqueDecl(src_inst.inst);
24603003 break :container .{
2461 src_inst,
3004 .@"struct",
24623005 zf,
2463 zf.zir.?.getOpaqueDecl(src_inst.inst).capture_names,
3006 decl.src_line,
3007 decl.src_column,
3008 false,
24643009 loaded_opaque.captures,
2465 loaded_opaque.fqn,
3010 loaded_opaque.name,
24663011 loaded_opaque.name_nav,
24673012 loaded_opaque.namespace,
24683013 };
......@@ -2477,92 +3022,117 @@ fn updateConstIncompleteInner(
24773022 },
24783023 else => |ty| {
24793024 try diw.writeUleb128(try dwarf.refAbbrevCode(.undefined_comptime_value));
2480 try dwarf.refConst(pt, di_nw, .fromInterned(ty));
3025 try dwarf.refType(pt, di_nw, .fromInterned(ty));
24813026 },
24823027 },
24833028 };
2484 const spec_di = if (false and captures.len > 0) try dwarf.getDecl(pt, val) else undefined;
2485 _ = spec_di;
2486 if (maybe_name_nav.unwrap()) |name_ni| {
3029 if (captures.len > 0 or is_reified) {
3030 try diw.writeUleb128(try dwarf.refAbbrevCode(if (captures.len > 0) switch (kind) {
3031 .@"struct" => .decl_instance_incomplete_struct,
3032 .@"union" => .decl_instance_incomplete_union,
3033 .@"enum" => .decl_instance_incomplete_enum,
3034 } else switch (kind) {
3035 .@"struct" => .decl_instance_empty_incomplete_struct,
3036 .@"union" => .decl_instance_empty_incomplete_union,
3037 .@"enum" => .decl_instance_empty_incomplete_enum,
3038 }));
3039 try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0);
3040 } else if (maybe_name_nav.unwrap()) |name_ni| {
24873041 const name_nav = ip.getNav(name_ni);
2488 const name_src_inst = name_nav.srcInst(ip).resolve(ip).?;
2489 const decl = zf.zir.?.getDeclaration(name_src_inst);
3042 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
24903043 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
24913044 name_nav.analysis.?.namespace,
24923045 ).owner_type);
2493 try diw.writeUleb128(try dwarf.refAbbrevCode(
2494 if (captures.len > 0) .decl_capturing_namespace_struct else .decl_namespace_struct,
2495 ));
3046 try diw.writeUleb128(try dwarf.refAbbrevCode(if (captures.len > 0) switch (kind) {
3047 .@"struct" => .decl_incomplete_struct,
3048 .@"union" => .decl_incomplete_union,
3049 .@"enum" => .decl_incomplete_enum,
3050 } else switch (kind) {
3051 .@"struct" => .decl_empty_incomplete_struct,
3052 .@"union" => .decl_empty_incomplete_union,
3053 .@"enum" => .decl_empty_incomplete_enum,
3054 }));
24963055 try dwarf.secOffset(di_nw, parent_ni, 0);
24973056 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
24983057 try diw.writeUleb128(decl.src_column + 1);
24993058 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
25003059 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
25013060 } else {
2502 const ui = dwarf.getUnit(zf.mod.?);
2503 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);
2504 const parent_ni = if (false) try dwarf.getDecl(pt, ip.namespacePtr(
3061 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
25053062 ip.namespacePtr(namespace).parent.unwrap().?,
25063063 ).owner_type);
2507 _ = parent_ni;
2508 try diw.writeUleb128(try dwarf.refAbbrevCode(
2509 if (captures.len > 0) .capturing_empty_struct_type else .empty_struct_type,
2510 ));
2511 try diw.writeUleb128(@backingInt(fi));
2512 try dwarf.strp(&dwarf.debug_str, di_nw, fqn.toSlice(ip));
3064 try diw.writeUleb128(try dwarf.refAbbrevCode(if (captures.len > 0) switch (kind) {
3065 .@"struct" => .type_decl_incomplete_struct,
3066 .@"union" => .type_decl_incomplete_union,
3067 .@"enum" => .type_decl_incomplete_enum,
3068 } else switch (kind) {
3069 .@"struct" => .type_decl_empty_incomplete_struct,
3070 .@"union" => .type_decl_empty_incomplete_union,
3071 .@"enum" => .type_decl_empty_incomplete_enum,
3072 }));
3073 try dwarf.secOffset(di_nw, parent_ni, 0);
3074 try diw.writeInt(u32, src_line + 1, dwarf.endian);
3075 try diw.writeUleb128(src_column + 1);
3076 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
25133077 }
2514 try diw.writeByte(@intFromBool(true));
2515 for (capture_names, captures.get(ip)) |capture_name, capture| switch (capture.unwrap()) {
2516 .@"comptime" => |capture_val| {
2517 const ty: Type = .fromInterned(ip.typeOf(capture_val));
2518 const ty_class = ty.classify(zcu);
2519 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (ty_class) {
2520 .no_possible_value => unreachable,
2521 .one_possible_value => .comptime_capture,
2522 .runtime => .comptime_capture_runtime,
2523 .partially_comptime => .comptime_capture_partially_comptime,
2524 .fully_comptime => .comptime_capture_fully_comptime,
2525 }));
2526 try dwarf.strp(&dwarf.debug_str, di_nw, zf.zir.?.nullTerminatedString(capture_name));
2527 try dwarf.refConst(pt, di_nw, ty.toValue());
2528 if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, .fromInterned(capture_val));
2529 if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, .fromInterned(capture_val));
2530 },
2531 .runtime => |capture_ty| {
2532 try diw.writeUleb128(try dwarf.refAbbrevCode(.runtime_capture));
2533 try dwarf.strp(&dwarf.debug_str, di_nw, zf.zir.?.nullTerminatedString(capture_name));
2534 try dwarf.refConst(pt, di_nw, .fromInterned(capture_ty));
2535 },
2536 .nav_val => |capture_nav| {
2537 const gi = try dwarf.getGlobal(capture_nav);
2538 try diw.writeUleb128(try dwarf.refAbbrevCode(.nav_capture));
2539 try dwarf.strp(&dwarf.debug_str, di_nw, zf.zir.?.nullTerminatedString(capture_name));
2540 try dwarf.exprLoc(di_nw, .{ .implicit_pointer = .{
2541 .node = gi.get(dwarf).debug_info_ni.unwrap().?,
2542 } });
2543 },
2544 .nav_ref => |capture_nav| {
2545 const gi = try dwarf.getGlobal(capture_nav);
2546 const capture_name_slice = try zcu.gpa.print("&{s}", .{zf.zir.?.nullTerminatedString(capture_name)});
2547 defer zcu.gpa.free(capture_name_slice);
2548 try diw.writeUleb128(try dwarf.refAbbrevCode(.nav_capture));
2549 try dwarf.strp(&dwarf.debug_str, di_nw, capture_name_slice);
2550 try dwarf.exprLoc(di_nw, .{ .stack_value = &.{ .implicit_pointer = .{
2551 .node = gi.get(dwarf).debug_info_ni.unwrap().?,
2552 } } });
2553 },
2554 };
3078 try dwarf.genCaptures(pt, di_nw, captures);
25553079 if (captures.len > 0) try diw.writeByte(@backingInt(AbbrevCode.null));
25563080 }
25573081 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());
25583082}
25593083
3084fn genCaptures(
3085 dwarf: *Dwarf,
3086 pt: Zcu.PerThread,
3087 di_nw: *MappedFile.Node.Writer,
3088 captures: anytype,
3089) link.EmitError!void {
3090 const zcu = pt.zcu;
3091 const ip = &zcu.intern_pool;
3092 const diw = &di_nw.interface;
3093 for (captures.get(ip)) |capture| switch (capture.unwrap()) {
3094 .@"comptime" => |capture_val| {
3095 const ty: Type = .fromInterned(ip.typeOf(capture_val));
3096 const ty_class = ty.classify(zcu);
3097 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (ty_class) {
3098 .no_possible_value => unreachable,
3099 .one_possible_value => .comptime_capture,
3100 .runtime => .comptime_capture_runtime,
3101 .partially_comptime => .comptime_capture_partially_comptime,
3102 .fully_comptime => .comptime_capture_fully_comptime,
3103 }));
3104 try dwarf.refType(pt, di_nw, ty);
3105 if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, .fromInterned(capture_val));
3106 if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, .fromInterned(capture_val));
3107 },
3108 .runtime => |capture_ty| {
3109 try diw.writeUleb128(try dwarf.refAbbrevCode(.runtime_capture));
3110 try dwarf.refType(pt, di_nw, .fromInterned(capture_ty));
3111 },
3112 .nav_val => |capture_nav| {
3113 const gi = try dwarf.getGlobal(capture_nav);
3114 try diw.writeUleb128(try dwarf.refAbbrevCode(.nav_capture));
3115 try dwarf.exprLoc(di_nw, .{ .implicit_pointer = .{
3116 .node = gi.get(dwarf).debug_info_ni.unwrap().?,
3117 } });
3118 },
3119 .nav_ref => |capture_nav| {
3120 const gi = try dwarf.getGlobal(capture_nav);
3121 try diw.writeUleb128(try dwarf.refAbbrevCode(.nav_capture));
3122 try dwarf.exprLoc(di_nw, .{ .stack_value = &.{ .implicit_pointer = .{
3123 .node = gi.get(dwarf).debug_info_ni.unwrap().?,
3124 } } });
3125 },
3126 };
3127}
3128
25603129pub fn genDecl(
25613130 dwarf: *Dwarf,
25623131 pt: Zcu.PerThread,
25633132 di_nw: *MappedFile.Node.Writer,
25643133 instance_val: InternPool.Index,
25653134) link.Error!void {
3135 log.debug("genDecl({f})", .{Value.fromInterned(instance_val).fmtValue(pt)});
25663136 dwarf.genDeclInner(pt, di_nw, instance_val) catch |err| switch (err) {
25673137 else => |e| return e,
25683138 error.WriteFailed => return dwarf.reportWriteError(di_nw),
......@@ -2574,68 +3144,221 @@ fn genDeclInner(
25743144 di_nw: *MappedFile.Node.Writer,
25753145 instance_val: InternPool.Index,
25763146) link.EmitError!void {
2577 const ip = &dwarf.lf.comp.zcu.?.intern_pool;
3147 const zcu = pt.zcu;
3148 const ip = &zcu.intern_pool;
25783149 const diw = &di_nw.interface;
2579 switch (ip.indexToKey(instance_val)) {
2580 else => unreachable,
2581 .struct_type => {
2582 const loaded_struct = ip.loadStructType(instance_val);
2583 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2584 ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?,
2585 ).owner_type);
2586 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_specification_struct));
2587 try dwarf.secOffset(di_nw, parent_ni, 0);
2588 try diw.writeInt(u32, 0, dwarf.endian);
2589 try diw.writeUleb128(0);
2590 try diw.writeByte(DW.ACCESS.public);
2591 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.fqn.toSlice(ip));
2592 },
2593 .enum_type => {
2594 const loaded_enum = ip.loadEnumType(instance_val);
2595 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2596 ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?,
2597 ).owner_type);
2598 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_specification_enum));
2599 try dwarf.secOffset(di_nw, parent_ni, 0);
2600 try diw.writeInt(u32, 0, dwarf.endian);
2601 try diw.writeUleb128(0);
2602 try diw.writeByte(DW.ACCESS.public);
2603 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip));
2604 },
2605 .union_type => {
2606 const loaded_union = ip.loadUnionType(instance_val);
2607 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2608 ip.namespacePtr(loaded_union.namespace).parent.unwrap().?,
2609 ).owner_type);
2610 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_specification_union));
2611 try dwarf.secOffset(di_nw, parent_ni, 0);
2612 try diw.writeInt(u32, 0, dwarf.endian);
2613 try diw.writeUleb128(0);
2614 try diw.writeByte(DW.ACCESS.public);
2615 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_union.fqn.toSlice(ip));
2616 },
2617 }
2618 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());
2619}
2620
2621pub fn updateLineNumber(
2622 dwarf: *Dwarf,
2623 mf: *MappedFile,
2624 inst: InternPool.TrackedInst.Index,
2625 line: u32,
2626) void {
2627 const di = dwarf.getDeclIfExists(inst) orelse return;
2628 const decl_ni = di.get(dwarf).debug_info_ni.unwrap().?;
2629 std.mem.writeInt(
2630 u32,
2631 decl_ni.slice(mf)[AbbrevCode.decl_size..][0..4],
2632 line + 1,
2633 dwarf.endian,
2634 );
2635}
2636
2637pub fn lostTracking(dwarf: *Dwarf, diw: *std.Io.Writer) link.EmitError!void {
2638 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
3150 done: {
3151 const kind: enum { @"struct", @"union", @"enum" }, const zf, const src_line, const src_column, const capture_names, const captures, const name, const maybe_name_nav, const namespace = container: switch (ip.indexToKey(instance_val)) {
3152 else => unreachable,
3153 .struct_type => {
3154 const loaded_struct = ip.loadStructType(instance_val);
3155 const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse {
3156 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
3157 break :done;
3158 };
3159 const zf = zcu.fileByIndex(src_inst.file);
3160 const inst = zf.zir.?.instructions.get(@backingInt(src_inst.inst));
3161 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {
3162 else => unreachable,
3163 .struct_init, .struct_init_ref => {
3164 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.StructInit, inst.data.pl_node.payload_index).data;
3165 break :decl .{ decl.src_line, decl.src_column, &.{} };
3166 },
3167 .struct_init_anon => {
3168 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.StructInitAnon, inst.data.pl_node.payload_index).data;
3169 break :decl .{ decl.src_line, decl.src_column, &.{} };
3170 },
3171 .extended => switch (inst.data.extended.opcode) {
3172 else => unreachable,
3173 .struct_decl => {
3174 const decl = zf.zir.?.getStructDecl(src_inst.inst);
3175 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };
3176 },
3177 .reify_struct => {
3178 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.ReifyStruct, inst.data.extended.operand).data;
3179 break :decl .{ decl.src_line, decl.src_column, &.{} };
3180 },
3181 },
3182 };
3183 break :container .{
3184 .@"struct",
3185 zf,
3186 src_line,
3187 src_column,
3188 capture_names,
3189 loaded_struct.captures,
3190 loaded_struct.name,
3191 loaded_struct.name_nav,
3192 loaded_struct.namespace,
3193 };
3194 },
3195 .union_type => {
3196 const loaded_union = ip.loadUnionType(instance_val);
3197 const src_inst = loaded_union.zir_index.resolveFull(ip) orelse {
3198 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
3199 break :done;
3200 };
3201 const zf = zcu.fileByIndex(src_inst.file);
3202 const inst = zf.zir.?.instructions.get(@backingInt(src_inst.inst));
3203 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {
3204 else => unreachable,
3205 .extended => switch (inst.data.extended.opcode) {
3206 else => unreachable,
3207 .union_decl => {
3208 const decl = zf.zir.?.getUnionDecl(src_inst.inst);
3209 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };
3210 },
3211 .reify_union => {
3212 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.ReifyUnion, inst.data.extended.operand).data;
3213 break :decl .{ decl.src_line, decl.src_column, &.{} };
3214 },
3215 },
3216 };
3217 break :container .{
3218 .@"union",
3219 zf,
3220 src_line,
3221 src_column,
3222 capture_names,
3223 loaded_union.captures,
3224 loaded_union.name,
3225 loaded_union.name_nav,
3226 loaded_union.namespace,
3227 };
3228 },
3229 .enum_type => {
3230 const loaded_enum = ip.loadEnumType(instance_val);
3231 const src_inst = loaded_enum.zir_index.unwrap().?.resolveFull(ip) orelse {
3232 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
3233 break :done;
3234 };
3235 const zf = zcu.fileByIndex(src_inst.file);
3236 const inst = zf.zir.?.instructions.get(@backingInt(src_inst.inst));
3237 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {
3238 else => unreachable,
3239 .extended => switch (inst.data.extended.opcode) {
3240 else => unreachable,
3241 .enum_decl => {
3242 const decl = zf.zir.?.getEnumDecl(src_inst.inst);
3243 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };
3244 },
3245 .reify_enum => {
3246 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.ReifyEnum, inst.data.extended.operand).data;
3247 break :decl .{ decl.src_line, decl.src_column, &.{} };
3248 },
3249 },
3250 };
3251 break :container .{
3252 .@"enum",
3253 zf,
3254 src_line,
3255 src_column,
3256 capture_names,
3257 loaded_enum.captures,
3258 loaded_enum.name,
3259 loaded_enum.name_nav,
3260 loaded_enum.namespace,
3261 };
3262 },
3263 .opaque_type => {
3264 const loaded_opaque = ip.loadOpaqueType(instance_val);
3265 const src_inst = loaded_opaque.zir_index.resolveFull(ip) orelse {
3266 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
3267 break :done;
3268 };
3269 const zf = zcu.fileByIndex(src_inst.file);
3270 const decl = zf.zir.?.getOpaqueDecl(src_inst.inst);
3271 break :container .{
3272 .@"struct",
3273 zf,
3274 decl.src_line,
3275 decl.src_column,
3276 decl.capture_names,
3277 loaded_opaque.captures,
3278 loaded_opaque.name,
3279 loaded_opaque.name_nav,
3280 loaded_opaque.namespace,
3281 };
3282 },
3283 };
3284 if (maybe_name_nav.unwrap()) |name_ni| {
3285 const name_nav = ip.getNav(name_ni);
3286 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
3287 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
3288 name_nav.analysis.?.namespace,
3289 ).owner_type);
3290 try diw.writeUleb128(try dwarf.refAbbrevCode(if (captures.len > 0) switch (kind) {
3291 .@"struct" => .decl_specification_struct,
3292 .@"union" => .decl_specification_union,
3293 .@"enum" => .decl_specification_enum,
3294 } else switch (kind) {
3295 .@"struct" => .decl_specification_empty_struct,
3296 .@"union" => .decl_specification_empty_union,
3297 .@"enum" => .decl_specification_empty_enum,
3298 }));
3299 try dwarf.secOffset(di_nw, parent_ni, 0);
3300 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
3301 try diw.writeUleb128(decl.src_column + 1);
3302 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
3303 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
3304 } else {
3305 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
3306 ip.namespacePtr(namespace).parent.unwrap().?,
3307 ).owner_type);
3308 try diw.writeUleb128(try dwarf.refAbbrevCode(if (captures.len > 0) switch (kind) {
3309 .@"struct" => .type_decl_specification_struct,
3310 .@"union" => .type_decl_specification_union,
3311 .@"enum" => .type_decl_specification_enum,
3312 } else switch (kind) {
3313 .@"struct" => .type_decl_specification_empty_struct,
3314 .@"union" => .type_decl_specification_empty_union,
3315 .@"enum" => .type_decl_specification_empty_enum,
3316 }));
3317 try dwarf.secOffset(di_nw, parent_ni, 0);
3318 try diw.writeInt(u32, src_line + 1, dwarf.endian);
3319 try diw.writeUleb128(src_column + 1);
3320 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
3321 }
3322 for (capture_names, captures.get(ip)) |capture_name, capture| {
3323 try diw.writeUleb128(try dwarf.refAbbrevCode(.capture_specification));
3324 switch (capture.unwrap()) {
3325 .@"comptime", .runtime, .nav_val => try dwarf.strp(
3326 &dwarf.debug_str,
3327 di_nw,
3328 zf.zir.?.nullTerminatedString(capture_name),
3329 ),
3330 .nav_ref => {
3331 const capture_name_slice = try zcu.gpa.print("&{s}", .{
3332 zf.zir.?.nullTerminatedString(capture_name),
3333 });
3334 defer zcu.gpa.free(capture_name_slice);
3335 try dwarf.strp(&dwarf.debug_str, di_nw, capture_name_slice);
3336 },
3337 }
3338 }
3339 if (captures.len > 0) try diw.writeUleb128(@backingInt(AbbrevCode.null));
3340 }
3341 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());
3342}
3343
3344pub fn updateLineNumber(
3345 dwarf: *Dwarf,
3346 mf: *MappedFile,
3347 inst: InternPool.TrackedInst.Index,
3348 line: u32,
3349) void {
3350 const di = dwarf.getDeclIfExists(inst) orelse return;
3351 const decl_ni = di.get(dwarf).debug_info_ni.unwrap().?;
3352 std.mem.writeInt(
3353 u32,
3354 decl_ni.slice(mf)[AbbrevCode.decl_size..][0..4],
3355 line + 1,
3356 dwarf.endian,
3357 );
3358}
3359
3360pub fn lostTracking(dwarf: *Dwarf, diw: *std.Io.Writer) link.EmitError!void {
3361 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
26393362}
26403363
26413364fn refAbbrevCodeIfExists(
......@@ -2746,6 +3469,14 @@ fn blockConst(
27463469 assert(start + size == nw.interface.end);
27473470}
27483471
3472fn refType(
3473 dwarf: *Dwarf,
3474 pt: Zcu.PerThread,
3475 nw: *MappedFile.Node.Writer,
3476 ty: Type,
3477) link.EmitError!void {
3478 return dwarf.refConst(pt, nw, ty.toValue());
3479}
27493480fn refConst(
27503481 dwarf: *Dwarf,
27513482 pt: Zcu.PerThread,
......@@ -2875,14 +3606,38 @@ pub const AbbrevCode = enum {
28753606 // decl, specification, and instance codes are assumed to all have the same uleb128 size
28763607 decl_lost,
28773608 decl_alias,
3609 decl_empty_incomplete_enum,
3610 decl_incomplete_enum,
28783611 decl_empty_enum,
28793612 decl_enum,
2880 decl_namespace_struct,
2881 decl_capturing_namespace_struct,
3613 type_decl_empty_incomplete_enum,
3614 type_decl_incomplete_enum,
3615 type_decl_empty_enum,
3616 type_decl_enum,
3617 decl_empty_incomplete_struct,
3618 decl_incomplete_struct,
3619 decl_empty_struct,
28823620 decl_struct,
3621 type_decl_empty_incomplete_struct,
3622 type_decl_incomplete_struct,
3623 type_decl_empty_struct,
3624 type_decl_struct,
3625 decl_empty_packed_struct,
28833626 decl_packed_struct,
3627 type_decl_empty_packed_struct,
3628 type_decl_packed_struct,
3629 decl_empty_incomplete_union,
3630 decl_incomplete_union,
3631 decl_empty_union,
28843632 decl_union,
3633 type_decl_empty_incomplete_union,
3634 type_decl_incomplete_union,
3635 type_decl_empty_union,
3636 type_decl_union,
3637 decl_empty_packed_union,
28853638 decl_packed_union,
3639 type_decl_empty_packed_union,
3640 type_decl_packed_union,
28863641 decl_var,
28873642 decl_const,
28883643 decl_const_runtime_bits,
......@@ -2894,17 +3649,35 @@ pub const AbbrevCode = enum {
28943649 decl_func_generic,
28953650 decl_extern_nullary_func,
28963651 decl_extern_func,
3652 decl_specification_empty_struct,
28973653 decl_specification_struct,
3654 type_decl_specification_empty_struct,
3655 type_decl_specification_struct,
3656 decl_specification_empty_enum,
28983657 decl_specification_enum,
3658 type_decl_specification_empty_enum,
3659 type_decl_specification_enum,
3660 decl_specification_empty_union,
28993661 decl_specification_union,
3662 type_decl_specification_empty_union,
3663 type_decl_specification_union,
29003664 decl_specification_func,
29013665 decl_instance_alias,
3666 decl_instance_empty_incomplete_enum,
3667 decl_instance_incomplete_enum,
29023668 decl_instance_empty_enum,
29033669 decl_instance_enum,
2904 decl_instance_namespace_struct,
3670 decl_instance_empty_incomplete_struct,
3671 decl_instance_incomplete_struct,
3672 decl_instance_empty_struct,
29053673 decl_instance_struct,
3674 decl_instance_empty_packed_struct,
29063675 decl_instance_packed_struct,
3676 decl_instance_empty_incomplete_union,
3677 decl_instance_incomplete_union,
3678 decl_instance_empty_union,
29073679 decl_instance_union,
3680 decl_instance_empty_packed_union,
29083681 decl_instance_packed_union,
29093682 decl_instance_var,
29103683 decl_instance_const,
......@@ -2963,17 +3736,7 @@ pub const AbbrevCode = enum {
29633736 generated_empty_struct_type,
29643737 generated_struct_type,
29653738 generated_union_type,
2966 empty_enum_type,
2967 enum_type,
2968 empty_struct_type,
2969 capturing_empty_struct_type,
2970 struct_type,
2971 empty_packed_struct_type,
2972 packed_struct_type,
2973 empty_union_type,
2974 union_type,
2975 empty_packed_union_type,
2976 packed_union_type,
3739 capture_specification,
29773740 comptime_capture,
29783741 comptime_capture_runtime,
29793742 comptime_capture_partially_comptime,
......@@ -3032,13 +3795,19 @@ pub const AbbrevCode = enum {
30323795 .{ .accessibility, .data1 },
30333796 .{ .name, .strp },
30343797 };
3035
3798 const type_decl_attrs = &[_]Attr{
3799 .{ .ZIG_parent, .ref_addr },
3800 .{ .decl_line, .data4 },
3801 .{ .decl_column, .udata },
3802 .{ .name, .strp },
3803 };
30363804 const decl_specification_attrs = decl_attrs ++ &[_]Attr{
30373805 .{ .declaration, .flag_present },
30383806 };
3039
3807 const type_decl_specification_attrs = type_decl_attrs ++ &[_]Attr{
3808 .{ .declaration, .flag_present },
3809 };
30403810 const decl_instance_attrs = &[_]Attr{
3041 .{ .ZIG_parent, .ref_addr },
30423811 .{ .specification, .ref_addr },
30433812 };
30443813
......@@ -3066,6 +3835,15 @@ pub const AbbrevCode = enum {
30663835 .{ .import, .ref_addr },
30673836 },
30683837 },
3838 .decl_empty_incomplete_enum = .{
3839 .tag = .enumeration_type,
3840 .attrs = decl_attrs,
3841 },
3842 .decl_incomplete_enum = .{
3843 .tag = .enumeration_type,
3844 .children = true,
3845 .attrs = decl_attrs,
3846 },
30693847 .decl_empty_enum = .{
30703848 .tag = .enumeration_type,
30713849 .attrs = decl_attrs ++ .{
......@@ -3079,17 +3857,42 @@ pub const AbbrevCode = enum {
30793857 .{ .type, .ref_addr },
30803858 },
30813859 },
3082 .decl_namespace_struct = .{
3083 .tag = .structure_type,
3084 .attrs = decl_attrs ++ .{
3085 .{ .declaration, .flag },
3860 .type_decl_empty_incomplete_enum = .{
3861 .tag = .enumeration_type,
3862 .attrs = type_decl_attrs,
3863 },
3864 .type_decl_incomplete_enum = .{
3865 .tag = .enumeration_type,
3866 .children = true,
3867 .attrs = type_decl_attrs,
3868 },
3869 .type_decl_empty_enum = .{
3870 .tag = .enumeration_type,
3871 .attrs = type_decl_attrs ++ .{
3872 .{ .type, .ref_addr },
3873 },
3874 },
3875 .type_decl_enum = .{
3876 .tag = .enumeration_type,
3877 .children = true,
3878 .attrs = type_decl_attrs ++ .{
3879 .{ .type, .ref_addr },
30863880 },
30873881 },
3088 .decl_capturing_namespace_struct = .{
3882 .decl_empty_incomplete_struct = .{
3883 .tag = .structure_type,
3884 .attrs = decl_attrs,
3885 },
3886 .decl_incomplete_struct = .{
30893887 .tag = .structure_type,
30903888 .children = true,
3889 .attrs = decl_attrs,
3890 },
3891 .decl_empty_struct = .{
3892 .tag = .structure_type,
30913893 .attrs = decl_attrs ++ .{
3092 .{ .declaration, .flag },
3894 .{ .byte_size, .udata },
3895 .{ .alignment, .udata },
30933896 },
30943897 },
30953898 .decl_struct = .{
......@@ -3100,6 +3903,36 @@ pub const AbbrevCode = enum {
31003903 .{ .alignment, .udata },
31013904 },
31023905 },
3906 .type_decl_empty_incomplete_struct = .{
3907 .tag = .structure_type,
3908 .attrs = type_decl_attrs,
3909 },
3910 .type_decl_incomplete_struct = .{
3911 .tag = .structure_type,
3912 .children = true,
3913 .attrs = type_decl_attrs,
3914 },
3915 .type_decl_empty_struct = .{
3916 .tag = .structure_type,
3917 .attrs = type_decl_attrs ++ .{
3918 .{ .byte_size, .udata },
3919 .{ .alignment, .udata },
3920 },
3921 },
3922 .type_decl_struct = .{
3923 .tag = .structure_type,
3924 .children = true,
3925 .attrs = type_decl_attrs ++ .{
3926 .{ .byte_size, .udata },
3927 .{ .alignment, .udata },
3928 },
3929 },
3930 .decl_empty_packed_struct = .{
3931 .tag = .structure_type,
3932 .attrs = decl_attrs ++ .{
3933 .{ .type, .ref_addr },
3934 },
3935 },
31033936 .decl_packed_struct = .{
31043937 .tag = .structure_type,
31053938 .children = true,
......@@ -3107,6 +3940,35 @@ pub const AbbrevCode = enum {
31073940 .{ .type, .ref_addr },
31083941 },
31093942 },
3943 .type_decl_empty_packed_struct = .{
3944 .tag = .structure_type,
3945 .attrs = type_decl_attrs ++ .{
3946 .{ .type, .ref_addr },
3947 },
3948 },
3949 .type_decl_packed_struct = .{
3950 .tag = .structure_type,
3951 .children = true,
3952 .attrs = type_decl_attrs ++ .{
3953 .{ .type, .ref_addr },
3954 },
3955 },
3956 .decl_empty_incomplete_union = .{
3957 .tag = .union_type,
3958 .attrs = decl_attrs,
3959 },
3960 .decl_incomplete_union = .{
3961 .tag = .union_type,
3962 .children = true,
3963 .attrs = decl_attrs,
3964 },
3965 .decl_empty_union = .{
3966 .tag = .union_type,
3967 .attrs = decl_attrs ++ .{
3968 .{ .byte_size, .udata },
3969 .{ .alignment, .udata },
3970 },
3971 },
31103972 .decl_union = .{
31113973 .tag = .union_type,
31123974 .children = true,
......@@ -3115,6 +3977,36 @@ pub const AbbrevCode = enum {
31153977 .{ .alignment, .udata },
31163978 },
31173979 },
3980 .type_decl_empty_incomplete_union = .{
3981 .tag = .union_type,
3982 .attrs = type_decl_attrs,
3983 },
3984 .type_decl_incomplete_union = .{
3985 .tag = .union_type,
3986 .children = true,
3987 .attrs = type_decl_attrs,
3988 },
3989 .type_decl_empty_union = .{
3990 .tag = .union_type,
3991 .attrs = type_decl_attrs ++ .{
3992 .{ .byte_size, .udata },
3993 .{ .alignment, .udata },
3994 },
3995 },
3996 .type_decl_union = .{
3997 .tag = .union_type,
3998 .children = true,
3999 .attrs = type_decl_attrs ++ .{
4000 .{ .byte_size, .udata },
4001 .{ .alignment, .udata },
4002 },
4003 },
4004 .decl_empty_packed_union = .{
4005 .tag = .union_type,
4006 .attrs = decl_attrs ++ .{
4007 .{ .type, .ref_addr },
4008 },
4009 },
31184010 .decl_packed_union = .{
31194011 .tag = .union_type,
31204012 .children = true,
......@@ -3122,6 +4014,19 @@ pub const AbbrevCode = enum {
31224014 .{ .type, .ref_addr },
31234015 },
31244016 },
4017 .type_decl_empty_packed_union = .{
4018 .tag = .union_type,
4019 .attrs = type_decl_attrs ++ .{
4020 .{ .type, .ref_addr },
4021 },
4022 },
4023 .type_decl_packed_union = .{
4024 .tag = .union_type,
4025 .children = true,
4026 .attrs = type_decl_attrs ++ .{
4027 .{ .type, .ref_addr },
4028 },
4029 },
31254030 .decl_var = .{
31264031 .tag = .variable,
31274032 .attrs = decl_attrs ++ .{
......@@ -3200,16 +4105,15 @@ pub const AbbrevCode = enum {
32004105 .decl_nullary_func_generic = .{
32014106 .tag = .subprogram,
32024107 .attrs = decl_attrs ++ .{
3203 //.{ .type, .ref_addr },
3204 //.{ .noreturn, .flag },
4108 .{ .type, .ref_addr },
4109 .{ .noreturn, .flag },
32054110 },
32064111 },
32074112 .decl_func_generic = .{
32084113 .tag = .subprogram,
32094114 .children = true,
32104115 .attrs = decl_attrs ++ .{
3211 //.{ .type, .ref_addr },
3212 //.{ .noreturn, .flag },
4116 .{ .type, .ref_addr },
32134117 },
32144118 },
32154119 .decl_extern_nullary_func = .{
......@@ -3233,18 +4137,60 @@ pub const AbbrevCode = enum {
32334137 .{ .noreturn, .flag },
32344138 },
32354139 },
4140 .decl_specification_empty_struct = .{
4141 .tag = .structure_type,
4142 .attrs = decl_specification_attrs,
4143 },
32364144 .decl_specification_struct = .{
32374145 .tag = .structure_type,
4146 .children = true,
4147 .attrs = decl_specification_attrs,
4148 },
4149 .type_decl_specification_empty_struct = .{
4150 .tag = .structure_type,
4151 .attrs = type_decl_specification_attrs,
4152 },
4153 .type_decl_specification_struct = .{
4154 .tag = .structure_type,
4155 .children = true,
4156 .attrs = type_decl_specification_attrs,
4157 },
4158 .decl_specification_empty_enum = .{
4159 .tag = .enumeration_type,
32384160 .attrs = decl_specification_attrs,
32394161 },
32404162 .decl_specification_enum = .{
32414163 .tag = .enumeration_type,
4164 .children = true,
4165 .attrs = decl_specification_attrs,
4166 },
4167 .type_decl_specification_empty_enum = .{
4168 .tag = .enumeration_type,
4169 .attrs = type_decl_specification_attrs,
4170 },
4171 .type_decl_specification_enum = .{
4172 .tag = .enumeration_type,
4173 .children = true,
4174 .attrs = type_decl_specification_attrs,
4175 },
4176 .decl_specification_empty_union = .{
4177 .tag = .union_type,
32424178 .attrs = decl_specification_attrs,
32434179 },
32444180 .decl_specification_union = .{
32454181 .tag = .union_type,
4182 .children = true,
32464183 .attrs = decl_specification_attrs,
32474184 },
4185 .type_decl_specification_empty_union = .{
4186 .tag = .union_type,
4187 .attrs = type_decl_specification_attrs,
4188 },
4189 .type_decl_specification_union = .{
4190 .tag = .union_type,
4191 .children = true,
4192 .attrs = type_decl_specification_attrs,
4193 },
32484194 .decl_specification_func = .{
32494195 .tag = .subprogram,
32504196 .attrs = decl_specification_attrs,
......@@ -3255,6 +4201,15 @@ pub const AbbrevCode = enum {
32554201 .{ .import, .ref_addr },
32564202 },
32574203 },
4204 .decl_instance_empty_incomplete_enum = .{
4205 .tag = .enumeration_type,
4206 .attrs = decl_instance_attrs,
4207 },
4208 .decl_instance_incomplete_enum = .{
4209 .tag = .enumeration_type,
4210 .children = true,
4211 .attrs = decl_instance_attrs,
4212 },
32584213 .decl_instance_empty_enum = .{
32594214 .tag = .enumeration_type,
32604215 .attrs = decl_instance_attrs ++ .{
......@@ -3268,11 +4223,20 @@ pub const AbbrevCode = enum {
32684223 .{ .type, .ref_addr },
32694224 },
32704225 },
3271 .decl_instance_namespace_struct = .{
4226 .decl_instance_empty_incomplete_struct = .{
4227 .tag = .structure_type,
4228 .attrs = decl_instance_attrs,
4229 },
4230 .decl_instance_incomplete_struct = .{
32724231 .tag = .structure_type,
32734232 .children = true,
4233 .attrs = decl_instance_attrs,
4234 },
4235 .decl_instance_empty_struct = .{
4236 .tag = .structure_type,
32744237 .attrs = decl_instance_attrs ++ .{
3275 .{ .declaration, .flag },
4238 .{ .byte_size, .udata },
4239 .{ .alignment, .udata },
32764240 },
32774241 },
32784242 .decl_instance_struct = .{
......@@ -3283,6 +4247,12 @@ pub const AbbrevCode = enum {
32834247 .{ .alignment, .udata },
32844248 },
32854249 },
4250 .decl_instance_empty_packed_struct = .{
4251 .tag = .structure_type,
4252 .attrs = decl_instance_attrs ++ .{
4253 .{ .type, .ref_addr },
4254 },
4255 },
32864256 .decl_instance_packed_struct = .{
32874257 .tag = .structure_type,
32884258 .children = true,
......@@ -3290,6 +4260,22 @@ pub const AbbrevCode = enum {
32904260 .{ .type, .ref_addr },
32914261 },
32924262 },
4263 .decl_instance_empty_incomplete_union = .{
4264 .tag = .union_type,
4265 .attrs = decl_instance_attrs,
4266 },
4267 .decl_instance_incomplete_union = .{
4268 .tag = .union_type,
4269 .children = true,
4270 .attrs = decl_instance_attrs,
4271 },
4272 .decl_instance_empty_union = .{
4273 .tag = .union_type,
4274 .attrs = decl_instance_attrs ++ .{
4275 .{ .byte_size, .udata },
4276 .{ .alignment, .udata },
4277 },
4278 },
32934279 .decl_instance_union = .{
32944280 .tag = .union_type,
32954281 .children = true,
......@@ -3298,6 +4284,12 @@ pub const AbbrevCode = enum {
32984284 .{ .alignment, .udata },
32994285 },
33004286 },
4287 .decl_instance_empty_packed_union = .{
4288 .tag = .union_type,
4289 .attrs = decl_instance_attrs ++ .{
4290 .{ .type, .ref_addr },
4291 },
4292 },
33014293 .decl_instance_packed_union = .{
33024294 .tag = .union_type,
33034295 .children = true,
......@@ -3769,114 +4761,21 @@ pub const AbbrevCode = enum {
37694761 .{ .alignment, .udata },
37704762 },
37714763 },
3772 .empty_enum_type = .{
3773 .tag = .enumeration_type,
3774 .attrs = &.{
3775 .{ .decl_file, .udata },
3776 .{ .name, .strp },
3777 .{ .type, .ref_addr },
3778 },
3779 },
3780 .enum_type = .{
3781 .tag = .enumeration_type,
3782 .children = true,
3783 .attrs = &.{
3784 .{ .decl_file, .udata },
3785 .{ .name, .strp },
3786 .{ .type, .ref_addr },
3787 },
3788 },
3789 .empty_struct_type = .{
3790 .tag = .structure_type,
3791 .attrs = &.{
3792 .{ .decl_file, .udata },
3793 .{ .name, .strp },
3794 .{ .declaration, .flag },
3795 },
3796 },
3797 .capturing_empty_struct_type = .{
3798 .tag = .structure_type,
3799 .children = true,
3800 .attrs = &.{
3801 .{ .decl_file, .udata },
3802 .{ .name, .strp },
3803 .{ .declaration, .flag },
3804 },
3805 },
3806 .struct_type = .{
3807 .tag = .structure_type,
3808 .children = true,
3809 .attrs = &.{
3810 .{ .decl_file, .udata },
3811 .{ .name, .strp },
3812 .{ .byte_size, .udata },
3813 .{ .alignment, .udata },
3814 },
3815 },
3816 .empty_packed_struct_type = .{
3817 .tag = .structure_type,
3818 .attrs = &.{
3819 .{ .decl_file, .udata },
3820 .{ .name, .strp },
3821 .{ .type, .ref_addr },
3822 },
3823 },
3824 .packed_struct_type = .{
3825 .tag = .structure_type,
3826 .children = true,
3827 .attrs = &.{
3828 .{ .decl_file, .udata },
3829 .{ .name, .strp },
3830 .{ .type, .ref_addr },
3831 },
3832 },
3833 .empty_union_type = .{
3834 .tag = .union_type,
3835 .attrs = &.{
3836 .{ .decl_file, .udata },
3837 .{ .name, .strp },
3838 .{ .byte_size, .udata },
3839 .{ .alignment, .udata },
3840 },
3841 },
3842 .union_type = .{
3843 .tag = .union_type,
3844 .children = true,
3845 .attrs = &.{
3846 .{ .decl_file, .udata },
3847 .{ .name, .strp },
3848 .{ .byte_size, .udata },
3849 .{ .alignment, .udata },
3850 },
3851 },
3852 .empty_packed_union_type = .{
3853 .tag = .union_type,
3854 .attrs = &.{
3855 .{ .decl_file, .udata },
3856 .{ .name, .strp },
3857 .{ .type, .ref_addr },
3858 },
3859 },
3860 .packed_union_type = .{
3861 .tag = .union_type,
3862 .children = true,
4764 .capture_specification = .{
4765 .tag = .template_value_parameter,
38634766 .attrs = &.{
3864 .{ .decl_file, .udata },
38654767 .{ .name, .strp },
3866 .{ .type, .ref_addr },
38674768 },
38684769 },
38694770 .comptime_capture = .{
38704771 .tag = .template_value_parameter,
38714772 .attrs = &.{
3872 .{ .name, .strp },
38734773 .{ .type, .ref_addr },
38744774 },
38754775 },
38764776 .comptime_capture_runtime = .{
38774777 .tag = .template_value_parameter,
38784778 .attrs = &.{
3879 .{ .name, .strp },
38804779 .{ .type, .ref_addr },
38814780 .{ .const_value, .block },
38824781 },
......@@ -3884,7 +4783,6 @@ pub const AbbrevCode = enum {
38844783 .comptime_capture_partially_comptime = .{
38854784 .tag = .template_value_parameter,
38864785 .attrs = &.{
3887 .{ .name, .strp },
38884786 .{ .type, .ref_addr },
38894787 .{ .const_value, .block },
38904788 .{ .ZIG_comptime_value, .ref_addr },
......@@ -3893,7 +4791,6 @@ pub const AbbrevCode = enum {
38934791 .comptime_capture_fully_comptime = .{
38944792 .tag = .template_value_parameter,
38954793 .attrs = &.{
3896 .{ .name, .strp },
38974794 .{ .type, .ref_addr },
38984795 .{ .ZIG_comptime_value, .ref_addr },
38994796 },
......@@ -3901,14 +4798,12 @@ pub const AbbrevCode = enum {
39014798 .runtime_capture = .{
39024799 .tag = .template_type_parameter,
39034800 .attrs = &.{
3904 .{ .name, .strp },
39054801 .{ .type, .ref_addr },
39064802 },
39074803 },
39084804 .nav_capture = .{
39094805 .tag = .template_value_parameter,
39104806 .attrs = &.{
3911 .{ .name, .strp },
39124807 .{ .location, .exprloc },
39134808 },
39144809 },
src/link/Elf2.zig+4-2
......@@ -9381,8 +9381,10 @@ fn genPending(elf: *Elf, pt: Zcu.PerThread) link.Error!void {
93819381 .strip => {},
93829382 .dwarf => {
93839383 const gpa = elf.base.comp.gpa;
9384 while (elf.dwarf.pending_decl) |pending| {
9385 elf.dwarf.pending_decl = null;
9384 while (true) {
9385 const pending = elf.dwarf.pending_decl;
9386 if (pending.instance_val == .none) break;
9387 elf.dwarf.pending_decl = .{ .di = undefined, .instance_val = .none };
93869388 const debug_info_ni = pending.di.get(&elf.dwarf).debug_info_ni.unwrap().?;
93879389 try debug_info_ni.moved(gpa, &elf.mf);
93889390 var di_nw: MappedFile.Node.Writer = undefined;
src/print_zir.zig+11-3
......@@ -1452,6 +1452,8 @@ const Writer = struct {
14521452 self.parent_decl_node = struct_decl.src_node;
14531453 defer self.parent_decl_node = prev_parent_decl_node;
14541454
1455 try stream.print(":{d}:{d} ", .{ struct_decl.src_line + 1, struct_decl.src_column + 1 });
1456
14551457 const fields_hash = self.code.getAssociatedSrcHash(inst).?;
14561458 try stream.print("hash({x}) ", .{&fields_hash});
14571459
......@@ -1514,6 +1516,8 @@ const Writer = struct {
15141516 self.parent_decl_node = union_decl.src_node;
15151517 defer self.parent_decl_node = prev_parent_decl_node;
15161518
1519 try stream.print(":{d}:{d} ", .{ union_decl.src_line + 1, union_decl.src_column + 1 });
1520
15171521 const fields_hash = self.code.getAssociatedSrcHash(inst).?;
15181522 try stream.print("hash({x}) ", .{&fields_hash});
15191523
......@@ -1590,6 +1594,8 @@ const Writer = struct {
15901594 self.parent_decl_node = enum_decl.src_node;
15911595 defer self.parent_decl_node = prev_parent_decl_node;
15921596
1597 try stream.print(":{d}:{d} ", .{ enum_decl.src_line + 1, enum_decl.src_column + 1 });
1598
15931599 const fields_hash = self.code.getAssociatedSrcHash(inst).?;
15941600 try stream.print("hash({x}) ", .{&fields_hash});
15951601
......@@ -1637,6 +1643,8 @@ const Writer = struct {
16371643 self.parent_decl_node = opaque_decl.src_node;
16381644 defer self.parent_decl_node = prev_parent_decl_node;
16391645
1646 try stream.print(":{d}:{d} ", .{ opaque_decl.src_line + 1, opaque_decl.src_column + 1 });
1647
16401648 try stream.print("{s}, ", .{@tagName(opaque_decl.name_strategy)});
16411649 try self.writeCaptures(stream, opaque_decl.captures, opaque_decl.capture_names);
16421650 try stream.writeAll(", ");
......@@ -2216,10 +2224,10 @@ const Writer = struct {
22162224 try stream.print("{s} '{s}'", .{ @tagName(decl.kind), self.code.nullTerminatedString(decl.name) });
22172225 },
22182226 }
2227 try stream.print(":{d}:{d}", .{ decl.src_line + 1, decl.src_column + 1 });
2228
22192229 const src_hash = self.code.getAssociatedSrcHash(inst).?;
2220 try stream.print(" line({d}) column({d}) hash({x})", .{
2221 decl.src_line, decl.src_column, &src_hash,
2222 });
2230 try stream.print(" hash({x})", .{&src_hash});
22232231
22242232 {
22252233 if (decl.type_body) |b| {
test/tests.zig+5-4
......@@ -3416,16 +3416,17 @@ pub fn addIncrementalTests(
34163416
34173417 if (options.skip_llvm and test_target.backend == .llvm) continue;
34183418
3419 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
3419 const target_str = b.fmt("{s}-{t}", .{
3420 resolved_target.query.zigTriple(b.allocator) catch @panic("OOM"),
3421 test_target.backend,
3422 });
34203423
34213424 if (options.test_target_filters.len > 0) {
34223425 for (options.test_target_filters) |filter| {
3423 if (std.mem.find(u8, triple_txt, filter) != null) break;
3426 if (std.mem.find(u8, target_str, filter) != null) break;
34243427 } else continue;
34253428 }
34263429
3427 const target_str = b.fmt("{s}-{t}", .{ triple_txt, test_target.backend });
3428
34293430 const run = b.addRunArtifact(incr_check);
34303431 run.setName(b.fmt("incr-check {s} '{s}'", .{ target_str, entry.basename }));
34313432