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(...@@ -1884,7 +1884,8 @@ fn structInitExprAnon(
18841884
1885 const payload_index = try addExtra(astgen, Zir.Inst.StructInitAnon{1885 const payload_index = try addExtra(astgen, Zir.Inst.StructInitAnon{
1886 .abs_node = node,1886 .abs_node = node,
1887 .abs_line = astgen.source_line,1887 .src_line = astgen.source_line,
1888 .src_column = astgen.source_column,
1888 .fields_len = @intCast(struct_init.ast.fields.len),1889 .fields_len = @intCast(struct_init.ast.fields.len),
1889 });1890 });
1890 const field_size = @typeInfo(Zir.Inst.StructInitAnon.Item).@"struct".field_names.len;1891 const field_size = @typeInfo(Zir.Inst.StructInitAnon.Item).@"struct".field_names.len;
...@@ -1917,7 +1918,8 @@ fn structInitExprTyped(...@@ -1917,7 +1918,8 @@ fn structInitExprTyped(
19171918
1918 const payload_index = try addExtra(astgen, Zir.Inst.StructInit{1919 const payload_index = try addExtra(astgen, Zir.Inst.StructInit{
1919 .abs_node = node,1920 .abs_node = node,
1920 .abs_line = astgen.source_line,1921 .src_line = astgen.source_line,
1922 .src_column = astgen.source_column,
1921 .fields_len = @intCast(struct_init.ast.fields.len),1923 .fields_len = @intCast(struct_init.ast.fields.len),
1922 });1924 });
1923 const field_size = @typeInfo(Zir.Inst.StructInit.Item).@"struct".field_names.len;1925 const field_size = @typeInfo(Zir.Inst.StructInit.Item).@"struct".field_names.len;
...@@ -4846,9 +4848,13 @@ fn structDeclInner(...@@ -4846,9 +4848,13 @@ fn structDeclInner(
4846 astgen.advanceSourceCursorToNode(node);4848 astgen.advanceSourceCursorToNode(node);
48474849
4848 const decl_inst = try gz.reserveInstructionIndex();4850 const decl_inst = try gz.reserveInstructionIndex();
4851 const src_line = astgen.source_line;
4852 const src_column = astgen.source_column;
48494853
4850 if (container_decl.ast.members.len == 0 and maybe_backing_int_node == .none) {4854 if (container_decl.ast.members.len == 0 and maybe_backing_int_node == .none) {
4851 try gz.setStruct(decl_inst, .{4855 try gz.setStruct(decl_inst, .{
4856 .src_line = src_line,
4857 .src_column = src_column,
4852 .src_node = node,4858 .src_node = node,
4853 .name_strat = name_strat,4859 .name_strat = name_strat,
4854 .layout = layout,4860 .layout = layout,
...@@ -5003,6 +5009,8 @@ fn structDeclInner(...@@ -5003,6 +5009,8 @@ fn structDeclInner(
5003 astgen.src_hasher.final(&fields_hash);5009 astgen.src_hasher.final(&fields_hash);
50045010
5005 try gz.setStruct(decl_inst, .{5011 try gz.setStruct(decl_inst, .{
5012 .src_line = src_line,
5013 .src_column = src_column,
5006 .src_node = node,5014 .src_node = node,
5007 .name_strat = name_strat,5015 .name_strat = name_strat,
5008 .layout = layout,5016 .layout = layout,
...@@ -5151,6 +5159,8 @@ fn unionDeclInner(...@@ -5151,6 +5159,8 @@ fn unionDeclInner(
5151 astgen.advanceSourceCursorToNode(node);5159 astgen.advanceSourceCursorToNode(node);
51525160
5153 const decl_inst = try gz.reserveInstructionIndex();5161 const decl_inst = try gz.reserveInstructionIndex();
5162 const src_line = astgen.source_line;
5163 const src_column = astgen.source_column;
51545164
5155 var namespace: Scope.Namespace = .{5165 var namespace: Scope.Namespace = .{
5156 .parent = scope,5166 .parent = scope,
...@@ -5284,6 +5294,8 @@ fn unionDeclInner(...@@ -5284,6 +5294,8 @@ fn unionDeclInner(
5284 astgen.src_hasher.final(&fields_hash);5294 astgen.src_hasher.final(&fields_hash);
52855295
5286 try gz.setUnion(decl_inst, .{5296 try gz.setUnion(decl_inst, .{
5297 .src_line = src_line,
5298 .src_column = src_column,
5287 .src_node = node,5299 .src_node = node,
5288 .name_strat = name_strat,5300 .name_strat = name_strat,
5289 .kind = switch (layout) {5301 .kind = switch (layout) {
...@@ -5358,6 +5370,8 @@ fn containerDecl(...@@ -5358,6 +5370,8 @@ fn containerDecl(
5358 astgen.advanceSourceCursorToNode(node);5370 astgen.advanceSourceCursorToNode(node);
53595371
5360 const decl_inst = try gz.reserveInstructionIndex();5372 const decl_inst = try gz.reserveInstructionIndex();
5373 const src_line = astgen.source_line;
5374 const src_column = astgen.source_column;
53615375
5362 var namespace: Scope.Namespace = .{5376 var namespace: Scope.Namespace = .{
5363 .parent = scope,5377 .parent = scope,
...@@ -5482,6 +5496,8 @@ fn containerDecl(...@@ -5482,6 +5496,8 @@ fn containerDecl(
5482 astgen.src_hasher.final(&fields_hash);5496 astgen.src_hasher.final(&fields_hash);
54835497
5484 try gz.setEnum(decl_inst, .{5498 try gz.setEnum(decl_inst, .{
5499 .src_line = src_line,
5500 .src_column = src_column,
5485 .src_node = node,5501 .src_node = node,
5486 .name_strat = name_strat,5502 .name_strat = name_strat,
5487 .tag_type_body_len = tag_type_body_len,5503 .tag_type_body_len = tag_type_body_len,
...@@ -5504,6 +5520,8 @@ fn containerDecl(...@@ -5504,6 +5520,8 @@ fn containerDecl(
5504 astgen.advanceSourceCursorToNode(node);5520 astgen.advanceSourceCursorToNode(node);
55055521
5506 const decl_inst = try gz.reserveInstructionIndex();5522 const decl_inst = try gz.reserveInstructionIndex();
5523 const src_line = astgen.source_line;
5524 const src_column = astgen.source_column;
55075525
5508 var namespace: Scope.Namespace = .{5526 var namespace: Scope.Namespace = .{
5509 .parent = scope,5527 .parent = scope,
...@@ -5545,6 +5563,8 @@ fn containerDecl(...@@ -5545,6 +5563,8 @@ fn containerDecl(
5545 wip_decls.finish();5563 wip_decls.finish();
55465564
5547 try gz.setOpaque(decl_inst, .{5565 try gz.setOpaque(decl_inst, .{
5566 .src_line = src_line,
5567 .src_column = src_column,
5548 .src_node = node,5568 .src_node = node,
5549 .name_strat = name_strat,5569 .name_strat = name_strat,
5550 .decls_len = scan_result.decls_len,5570 .decls_len = scan_result.decls_len,
...@@ -9302,6 +9322,7 @@ fn builtinCall(...@@ -9302,6 +9322,7 @@ fn builtinCall(
9302 const field_attrs = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = field_attrs_ty } }, params[4], .struct_field_attrs);9322 const field_attrs = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = field_attrs_ty } }, params[4], .struct_field_attrs);
9303 const result = try gz.addExtendedPayloadSmall(.reify_struct, @backingInt(reify_name_strat), Zir.Inst.ReifyStruct{9323 const result = try gz.addExtendedPayloadSmall(.reify_struct, @backingInt(reify_name_strat), Zir.Inst.ReifyStruct{
9304 .src_line = gz.astgen.source_line,9324 .src_line = gz.astgen.source_line,
9325 .src_column = gz.astgen.source_column,
9305 .node = node,9326 .node = node,
9306 .layout = layout,9327 .layout = layout,
9307 .backing_ty = backing_ty,9328 .backing_ty = backing_ty,
...@@ -9330,6 +9351,7 @@ fn builtinCall(...@@ -9330,6 +9351,7 @@ fn builtinCall(
9330 const field_attrs = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = field_attrs_ty } }, params[4], .union_field_attrs);9351 const field_attrs = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = field_attrs_ty } }, params[4], .union_field_attrs);
9331 const result = try gz.addExtendedPayloadSmall(.reify_union, @backingInt(reify_name_strat), Zir.Inst.ReifyUnion{9352 const result = try gz.addExtendedPayloadSmall(.reify_union, @backingInt(reify_name_strat), Zir.Inst.ReifyUnion{
9332 .src_line = gz.astgen.source_line,9353 .src_line = gz.astgen.source_line,
9354 .src_column = gz.astgen.source_column,
9333 .node = node,9355 .node = node,
9334 .layout = layout,9356 .layout = layout,
9335 .arg_ty = arg_ty,9357 .arg_ty = arg_ty,
...@@ -9352,6 +9374,7 @@ fn builtinCall(...@@ -9352,6 +9374,7 @@ fn builtinCall(
9352 const field_values = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = field_values_ty } }, params[3], .enum_field_values);9374 const field_values = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = field_values_ty } }, params[3], .enum_field_values);
9353 const result = try gz.addExtendedPayloadSmall(.reify_enum, @backingInt(reify_name_strat), Zir.Inst.ReifyEnum{9375 const result = try gz.addExtendedPayloadSmall(.reify_enum, @backingInt(reify_name_strat), Zir.Inst.ReifyEnum{
9354 .src_line = gz.astgen.source_line,9376 .src_line = gz.astgen.source_line,
9377 .src_column = gz.astgen.source_column,
9355 .node = node,9378 .node = node,
9356 .tag_ty = tag_ty,9379 .tag_ty = tag_ty,
9357 .mode = mode,9380 .mode = mode,
...@@ -9365,6 +9388,7 @@ fn builtinCall(...@@ -9365,6 +9388,7 @@ fn builtinCall(
9365 const operand = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = spirv_type_options_ty } }, params[0], .type);9388 const operand = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = spirv_type_options_ty } }, params[0], .type);
9366 const result = try gz.addExtendedPayload(.reify_spirv_type, Zir.Inst.ReifySpirvType{9389 const result = try gz.addExtendedPayload(.reify_spirv_type, Zir.Inst.ReifySpirvType{
9367 .src_line = gz.astgen.source_line,9390 .src_line = gz.astgen.source_line,
9391 .src_column = gz.astgen.source_column,
9368 .node = node,9392 .node = node,
9369 .operand = operand,9393 .operand = operand,
9370 });9394 });
...@@ -12392,6 +12416,8 @@ const GenZir = struct {...@@ -12392,6 +12416,8 @@ const GenZir = struct {
12392 }12416 }
1239312417
12394 fn setStruct(gz: *GenZir, inst: Zir.Inst.Index, args: struct {12418 fn setStruct(gz: *GenZir, inst: Zir.Inst.Index, args: struct {
12419 src_line: u32,
12420 src_column: u32,
12395 src_node: Ast.Node.Index,12421 src_node: Ast.Node.Index,
12396 name_strat: Zir.Inst.NameStrategy,12422 name_strat: Zir.Inst.NameStrategy,
12397 layout: std.lang.Type.ContainerLayout,12423 layout: std.lang.Type.ContainerLayout,
...@@ -12428,7 +12454,8 @@ const GenZir = struct {...@@ -12428,7 +12454,8 @@ const GenZir = struct {
12428 .fields_hash_1 = fields_hash_arr[1],12454 .fields_hash_1 = fields_hash_arr[1],
12429 .fields_hash_2 = fields_hash_arr[2],12455 .fields_hash_2 = fields_hash_arr[2],
12430 .fields_hash_3 = fields_hash_arr[3],12456 .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,
12432 .src_node = args.src_node,12459 .src_node = args.src_node,
12433 });12460 });
1243412461
...@@ -12461,6 +12488,8 @@ const GenZir = struct {...@@ -12461,6 +12488,8 @@ const GenZir = struct {
12461 }12488 }
1246212489
12463 fn setUnion(gz: *GenZir, inst: Zir.Inst.Index, args: struct {12490 fn setUnion(gz: *GenZir, inst: Zir.Inst.Index, args: struct {
12491 src_line: u32,
12492 src_column: u32,
12464 src_node: Ast.Node.Index,12493 src_node: Ast.Node.Index,
12465 name_strat: Zir.Inst.NameStrategy,12494 name_strat: Zir.Inst.NameStrategy,
12466 kind: Zir.Inst.UnionDecl.Kind,12495 kind: Zir.Inst.UnionDecl.Kind,
...@@ -12495,7 +12524,8 @@ const GenZir = struct {...@@ -12495,7 +12524,8 @@ const GenZir = struct {
12495 .fields_hash_1 = fields_hash_arr[1],12524 .fields_hash_1 = fields_hash_arr[1],
12496 .fields_hash_2 = fields_hash_arr[2],12525 .fields_hash_2 = fields_hash_arr[2],
12497 .fields_hash_3 = fields_hash_arr[3],12526 .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,
12499 .src_node = args.src_node,12529 .src_node = args.src_node,
12500 });12530 });
1250112531
...@@ -12530,6 +12560,8 @@ const GenZir = struct {...@@ -12530,6 +12560,8 @@ const GenZir = struct {
12530 }12560 }
1253112561
12532 fn setEnum(gz: *GenZir, inst: Zir.Inst.Index, args: struct {12562 fn setEnum(gz: *GenZir, inst: Zir.Inst.Index, args: struct {
12563 src_line: u32,
12564 src_column: u32,
12533 src_node: Ast.Node.Index,12565 src_node: Ast.Node.Index,
12534 name_strat: Zir.Inst.NameStrategy,12566 name_strat: Zir.Inst.NameStrategy,
12535 tag_type_body_len: ?u32,12567 tag_type_body_len: ?u32,
...@@ -12563,7 +12595,8 @@ const GenZir = struct {...@@ -12563,7 +12595,8 @@ const GenZir = struct {
12563 .fields_hash_1 = fields_hash_arr[1],12595 .fields_hash_1 = fields_hash_arr[1],
12564 .fields_hash_2 = fields_hash_arr[2],12596 .fields_hash_2 = fields_hash_arr[2],
12565 .fields_hash_3 = fields_hash_arr[3],12597 .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,
12567 .src_node = args.src_node,12600 .src_node = args.src_node,
12568 });12601 });
1256912602
...@@ -12594,6 +12627,8 @@ const GenZir = struct {...@@ -12594,6 +12627,8 @@ const GenZir = struct {
12594 }12627 }
1259512628
12596 fn setOpaque(gz: *GenZir, inst: Zir.Inst.Index, args: struct {12629 fn setOpaque(gz: *GenZir, inst: Zir.Inst.Index, args: struct {
12630 src_line: u32,
12631 src_column: u32,
12597 src_node: Ast.Node.Index,12632 src_node: Ast.Node.Index,
12598 name_strat: Zir.Inst.NameStrategy,12633 name_strat: Zir.Inst.NameStrategy,
12599 decls_len: u32,12634 decls_len: u32,
...@@ -12615,7 +12650,8 @@ const GenZir = struct {...@@ -12615,7 +12650,8 @@ const GenZir = struct {
12615 args.decls.len);12650 args.decls.len);
1261612651
12617 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.OpaqueDecl{12652 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,
12619 .src_node = args.src_node,12655 .src_node = args.src_node,
12620 });12656 });
12621 if (captures_len != 0) astgen.extra.appendAssumeCapacity(captures_len);12657 if (captures_len != 0) astgen.extra.appendAssumeCapacity(captures_len);
lib/std/zig/Zir.zig+20-4
...@@ -3277,6 +3277,7 @@ pub const Inst = struct {...@@ -3277,6 +3277,7 @@ pub const Inst = struct {
32773277
3278 pub const ReifyStruct = struct {3278 pub const ReifyStruct = struct {
3279 src_line: u32,3279 src_line: u32,
3280 src_column: u32,
3280 /// This node is absolute, because `reify` instructions are tracked across updates, and3281 /// This node is absolute, because `reify` instructions are tracked across updates, and
3281 /// this simplifies the logic for getting source locations for types.3282 /// this simplifies the logic for getting source locations for types.
3282 node: Ast.Node.Index,3283 node: Ast.Node.Index,
...@@ -3289,6 +3290,7 @@ pub const Inst = struct {...@@ -3289,6 +3290,7 @@ pub const Inst = struct {
32893290
3290 pub const ReifyUnion = struct {3291 pub const ReifyUnion = struct {
3291 src_line: u32,3292 src_line: u32,
3293 src_column: u32,
3292 /// This node is absolute, because `reify` instructions are tracked across updates, and3294 /// This node is absolute, because `reify` instructions are tracked across updates, and
3293 /// this simplifies the logic for getting source locations for types.3295 /// this simplifies the logic for getting source locations for types.
3294 node: Ast.Node.Index,3296 node: Ast.Node.Index,
...@@ -3301,6 +3303,7 @@ pub const Inst = struct {...@@ -3301,6 +3303,7 @@ pub const Inst = struct {
33013303
3302 pub const ReifyEnum = struct {3304 pub const ReifyEnum = struct {
3303 src_line: u32,3305 src_line: u32,
3306 src_column: u32,
3304 /// This node is absolute, because `reify` instructions are tracked across updates, and3307 /// This node is absolute, because `reify` instructions are tracked across updates, and
3305 /// this simplifies the logic for getting source locations for types.3308 /// this simplifies the logic for getting source locations for types.
3306 node: Ast.Node.Index,3309 node: Ast.Node.Index,
...@@ -3312,6 +3315,7 @@ pub const Inst = struct {...@@ -3312,6 +3315,7 @@ pub const Inst = struct {
33123315
3313 pub const ReifySpirvType = struct {3316 pub const ReifySpirvType = struct {
3314 src_line: u32,3317 src_line: u32,
3318 src_column: u32,
3315 /// This node is absolute, because `reify` instructions are tracked across updates, and3319 /// This node is absolute, because `reify` instructions are tracked across updates, and
3316 /// this simplifies the logic for getting source locations for types.3320 /// this simplifies the logic for getting source locations for types.
3317 node: Ast.Node.Index,3321 node: Ast.Node.Index,
...@@ -3509,6 +3513,7 @@ pub const Inst = struct {...@@ -3509,6 +3513,7 @@ pub const Inst = struct {
3509 fields_hash_2: u32,3513 fields_hash_2: u32,
3510 fields_hash_3: u32,3514 fields_hash_3: u32,
3511 src_line: u32,3515 src_line: u32,
3516 src_column: u32,
3512 /// This node provides a new absolute baseline node for all instructions within this struct.3517 /// This node provides a new absolute baseline node for all instructions within this struct.
3513 src_node: Ast.Node.Index,3518 src_node: Ast.Node.Index,
35143519
...@@ -3664,6 +3669,7 @@ pub const Inst = struct {...@@ -3664,6 +3669,7 @@ pub const Inst = struct {
3664 fields_hash_2: u32,3669 fields_hash_2: u32,
3665 fields_hash_3: u32,3670 fields_hash_3: u32,
3666 src_line: u32,3671 src_line: u32,
3672 src_column: u32,
3667 /// This node provides a new absolute baseline node for all instructions within this struct.3673 /// This node provides a new absolute baseline node for all instructions within this struct.
3668 src_node: Ast.Node.Index,3674 src_node: Ast.Node.Index,
36693675
...@@ -3701,6 +3707,7 @@ pub const Inst = struct {...@@ -3701,6 +3707,7 @@ pub const Inst = struct {
3701 fields_hash_2: u32,3707 fields_hash_2: u32,
3702 fields_hash_3: u32,3708 fields_hash_3: u32,
3703 src_line: u32,3709 src_line: u32,
3710 src_column: u32,
3704 /// This node provides a new absolute baseline node for all instructions within this struct.3711 /// This node provides a new absolute baseline node for all instructions within this struct.
3705 src_node: Ast.Node.Index,3712 src_node: Ast.Node.Index,
37063713
...@@ -3756,6 +3763,7 @@ pub const Inst = struct {...@@ -3756,6 +3763,7 @@ pub const Inst = struct {
3756 /// 4. decl: Index, // for every decls_len; points to a `declaration` instruction3763 /// 4. decl: Index, // for every decls_len; points to a `declaration` instruction
3757 pub const OpaqueDecl = struct {3764 pub const OpaqueDecl = struct {
3758 src_line: u32,3765 src_line: u32,
3766 src_column: u32,
3759 /// This node provides a new absolute baseline node for all instructions within this struct.3767 /// This node provides a new absolute baseline node for all instructions within this struct.
3760 src_node: Ast.Node.Index,3768 src_node: Ast.Node.Index,
37613769
...@@ -3803,8 +3811,8 @@ pub const Inst = struct {...@@ -3803,8 +3811,8 @@ pub const Inst = struct {
3803 /// If this is an anonymous initialization (the operand is poison), this instruction becomes the owner of a type.3811 /// If this is an anonymous initialization (the operand is poison), this instruction becomes the owner of a type.
3804 /// To resolve source locations, we need an absolute source node.3812 /// To resolve source locations, we need an absolute source node.
3805 abs_node: Ast.Node.Index,3813 abs_node: Ast.Node.Index,
3806 /// Likewise, we need an absolute line number.3814 src_line: u32,
3807 abs_line: u32,3815 src_column: u32,
3808 fields_len: u32,3816 fields_len: u32,
38093817
3810 pub const Item = struct {3818 pub const Item = struct {
...@@ -3823,8 +3831,8 @@ pub const Inst = struct {...@@ -3823,8 +3831,8 @@ pub const Inst = struct {
3823 /// This is an anonymous initialization, meaning this instruction becomes the owner of a type.3831 /// This is an anonymous initialization, meaning this instruction becomes the owner of a type.
3824 /// To resolve source locations, we need an absolute source node.3832 /// To resolve source locations, we need an absolute source node.
3825 abs_node: Ast.Node.Index,3833 abs_node: Ast.Node.Index,
3826 /// Likewise, we need an absolute line number.3834 src_line: u32,
3827 abs_line: u32,3835 src_column: u32,
3828 fields_len: u32,3836 fields_len: u32,
38293837
3830 pub const Item = struct {3838 pub const Item = struct {
...@@ -5318,6 +5326,7 @@ pub fn getStructDecl(zir: *const Zir, struct_decl: Inst.Index) UnwrappedStructDe...@@ -5318,6 +5326,7 @@ pub fn getStructDecl(zir: *const Zir, struct_decl: Inst.Index) UnwrappedStructDe
5318 const field_bodies_overlong: []const Inst.Index = @ptrCast(zir.extra[extra_index..]);5326 const field_bodies_overlong: []const Inst.Index = @ptrCast(zir.extra[extra_index..]);
5319 return .{5327 return .{
5320 .src_line = extra.data.src_line,5328 .src_line = extra.data.src_line,
5329 .src_column = extra.data.src_column,
5321 .src_node = extra.data.src_node,5330 .src_node = extra.data.src_node,
5322 .name_strategy = small.name_strategy,5331 .name_strategy = small.name_strategy,
5323 .captures = captures,5332 .captures = captures,
...@@ -5335,6 +5344,7 @@ pub fn getStructDecl(zir: *const Zir, struct_decl: Inst.Index) UnwrappedStructDe...@@ -5335,6 +5344,7 @@ pub fn getStructDecl(zir: *const Zir, struct_decl: Inst.Index) UnwrappedStructDe
5335}5344}
5336pub const UnwrappedStructDecl = struct {5345pub const UnwrappedStructDecl = struct {
5337 src_line: u32,5346 src_line: u32,
5347 src_column: u32,
5338 src_node: Ast.Node.Index,5348 src_node: Ast.Node.Index,
5339 name_strategy: Inst.NameStrategy,5349 name_strategy: Inst.NameStrategy,
53405350
...@@ -5463,6 +5473,7 @@ pub fn getUnionDecl(zir: *const Zir, union_decl: Inst.Index) UnwrappedUnionDecl...@@ -5463,6 +5473,7 @@ pub fn getUnionDecl(zir: *const Zir, union_decl: Inst.Index) UnwrappedUnionDecl
5463 const field_bodies_overlong: []const Inst.Index = @ptrCast(zir.extra[extra_index..]);5473 const field_bodies_overlong: []const Inst.Index = @ptrCast(zir.extra[extra_index..]);
5464 return .{5474 return .{
5465 .src_line = extra.data.src_line,5475 .src_line = extra.data.src_line,
5476 .src_column = extra.data.src_column,
5466 .src_node = extra.data.src_node,5477 .src_node = extra.data.src_node,
5467 .name_strategy = small.name_strategy,5478 .name_strategy = small.name_strategy,
5468 .captures = captures,5479 .captures = captures,
...@@ -5479,6 +5490,7 @@ pub fn getUnionDecl(zir: *const Zir, union_decl: Inst.Index) UnwrappedUnionDecl...@@ -5479,6 +5490,7 @@ pub fn getUnionDecl(zir: *const Zir, union_decl: Inst.Index) UnwrappedUnionDecl
5479}5490}
5480pub const UnwrappedUnionDecl = struct {5491pub const UnwrappedUnionDecl = struct {
5481 src_line: u32,5492 src_line: u32,
5493 src_column: u32,
5482 src_node: Ast.Node.Index,5494 src_node: Ast.Node.Index,
5483 name_strategy: Inst.NameStrategy,5495 name_strategy: Inst.NameStrategy,
54845496
...@@ -5590,6 +5602,7 @@ pub fn getEnumDecl(zir: *const Zir, enum_decl: Inst.Index) UnwrappedEnumDecl {...@@ -5590,6 +5602,7 @@ pub fn getEnumDecl(zir: *const Zir, enum_decl: Inst.Index) UnwrappedEnumDecl {
5590 const field_bodies_overlong: []const Inst.Index = @ptrCast(zir.extra[extra_index..]);5602 const field_bodies_overlong: []const Inst.Index = @ptrCast(zir.extra[extra_index..]);
5591 return .{5603 return .{
5592 .src_line = extra.data.src_line,5604 .src_line = extra.data.src_line,
5605 .src_column = extra.data.src_column,
5593 .src_node = extra.data.src_node,5606 .src_node = extra.data.src_node,
5594 .name_strategy = small.name_strategy,5607 .name_strategy = small.name_strategy,
5595 .captures = captures,5608 .captures = captures,
...@@ -5604,6 +5617,7 @@ pub fn getEnumDecl(zir: *const Zir, enum_decl: Inst.Index) UnwrappedEnumDecl {...@@ -5604,6 +5617,7 @@ pub fn getEnumDecl(zir: *const Zir, enum_decl: Inst.Index) UnwrappedEnumDecl {
5604}5617}
5605pub const UnwrappedEnumDecl = struct {5618pub const UnwrappedEnumDecl = struct {
5606 src_line: u32,5619 src_line: u32,
5620 src_column: u32,
5607 src_node: Ast.Node.Index,5621 src_node: Ast.Node.Index,
5608 name_strategy: Inst.NameStrategy,5622 name_strategy: Inst.NameStrategy,
56095623
...@@ -5682,6 +5696,7 @@ pub fn getOpaqueDecl(zir: *const Zir, opaque_decl: Inst.Index) UnwrappedOpaqueDe...@@ -5682,6 +5696,7 @@ pub fn getOpaqueDecl(zir: *const Zir, opaque_decl: Inst.Index) UnwrappedOpaqueDe
5682 extra_index += decls_len;5696 extra_index += decls_len;
5683 return .{5697 return .{
5684 .src_line = extra.data.src_line,5698 .src_line = extra.data.src_line,
5699 .src_column = extra.data.src_column,
5685 .src_node = extra.data.src_node,5700 .src_node = extra.data.src_node,
5686 .name_strategy = small.name_strategy,5701 .name_strategy = small.name_strategy,
5687 .captures = captures,5702 .captures = captures,
...@@ -5691,6 +5706,7 @@ pub fn getOpaqueDecl(zir: *const Zir, opaque_decl: Inst.Index) UnwrappedOpaqueDe...@@ -5691,6 +5706,7 @@ pub fn getOpaqueDecl(zir: *const Zir, opaque_decl: Inst.Index) UnwrappedOpaqueDe
5691}5706}
5692pub const UnwrappedOpaqueDecl = struct {5707pub const UnwrappedOpaqueDecl = struct {
5693 src_line: u32,5708 src_line: u32,
5709 src_column: u32,
5694 src_node: Ast.Node.Index,5710 src_node: Ast.Node.Index,
5695 name_strategy: Inst.NameStrategy,5711 name_strategy: Inst.NameStrategy,
5696 captures: []const Inst.Capture,5712 captures: []const Inst.Capture,
src/Type.zig+2-2
...@@ -2693,8 +2693,8 @@ pub fn typeDeclSrcLine(ty: Type, zcu: *Zcu) ?u32 {...@@ -2693,8 +2693,8 @@ pub fn typeDeclSrcLine(ty: Type, zcu: *Zcu) ?u32 {
2693 };2693 };
2694 const inst = zir.instructions.get(@backingInt(info.inst));2694 const inst = zir.instructions.get(@backingInt(info.inst));
2695 return switch (inst.tag) {2695 return switch (inst.tag) {
2696 .struct_init, .struct_init_ref => zir.extraData(Zir.Inst.StructInit, 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.abs_line,2697 .struct_init_anon => zir.extraData(Zir.Inst.StructInitAnon, inst.data.pl_node.payload_index).data.src_line,
2698 .extended => switch (inst.data.extended.opcode) {2698 .extended => switch (inst.data.extended.opcode) {
2699 .struct_decl => zir.getStructDecl(info.inst).src_line,2699 .struct_decl => zir.getStructDecl(info.inst).src_line,
2700 .union_decl => zir.getUnionDecl(info.inst).src_line,2700 .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 {...@@ -864,26 +864,60 @@ fn updateZirRefs(pt: Zcu.PerThread) (Io.Cancelable || Allocator.Error)!void {
864 try comp.link_queue.enqueueZcu(comp, pt.tid, .{ .lost_tracking = tracked_inst_index });864 try comp.link_queue.enqueueZcu(comp, pt.tid, .{ .lost_tracking = tracked_inst_index });
865 continue;865 continue;
866 };866 };
867 tracked_inst.inst = InternPool.TrackedInst.MaybeLost.ZirIndex.wrap(new_inst);867 tracked_inst.inst = .wrap(new_inst);
868868
869 const old_zir = file.prev_zir.?.*;869 const old_zir = file.prev_zir.?.*;
870 const new_zir = file.zir.?;
871 const old_tag = old_zir.instructions.items(.tag)[@backingInt(old_inst)];870 const old_tag = old_zir.instructions.items(.tag)[@backingInt(old_inst)];
872 const old_data = old_zir.instructions.items(.data)[@backingInt(old_inst)];871 const old_data = old_zir.instructions.items(.data)[@backingInt(old_inst)];
873872
874 switch (old_tag) {873 const new_zir = file.zir.?;
875 .declaration => {874 const new_data = new_zir.instructions.items(.data)[@backingInt(new_inst)];
876 const old_line = old_zir.getDeclaration(old_inst).src_line;875
877 const new_line = new_zir.getDeclaration(new_inst).src_line;876 debug_update_line_number: {
878 if (old_line != new_line) {877 const old_line, const new_line = switch (old_tag) {
879 comp.link_prog_node.increaseEstimatedTotalItems(1);878 .declaration => .{
880 try comp.link_queue.enqueueZcu(comp, pt.tid, .{ .debug_update_line_number = .{879 old_zir.getDeclaration(old_inst).src_line,
881 .inst = tracked_inst_index,880 new_zir.getDeclaration(new_inst).src_line,
882 .line = new_line,881 },
883 } });882 .extended => switch (old_data.extended.opcode) {
884 }883 .struct_decl => .{
885 },884 old_zir.getStructDecl(old_inst).src_line,
886 else => {},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 } });
887 }921 }
888922
889 if (old_zir.getAssociatedSrcHash(old_inst)) |old_hash| hash_changed: {923 if (old_zir.getAssociatedSrcHash(old_inst)) |old_hash| hash_changed: {
src/link.zig+15-2
...@@ -875,10 +875,23 @@ pub const File = struct {...@@ -875,10 +875,23 @@ pub const File = struct {
875 assert(pt.zcu.llvm_object == null);875 assert(pt.zcu.llvm_object == null);
876 {876 {
877 const ti = ti_id.resolveFull(&pt.zcu.intern_pool).?;877 const ti = ti_id.resolveFull(&pt.zcu.intern_pool).?;
878 assert(ti.inst != .main_struct_inst);
879 const file = pt.zcu.fileByIndex(ti.file);878 const file = pt.zcu.fileByIndex(ti.file);
880 const inst = file.zir.?.instructions.get(@backingInt(ti.inst));879 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 }
882 }895 }
883 switch (base.tag) {896 switch (base.tag) {
884 .lld => unreachable,897 .lld => unreachable,
src/link/Dwarf.zig+2-1
...@@ -4627,6 +4627,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -4627,6 +4627,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
4627 }4627 }
4628 try diw.writeUleb128(@backingInt(AbbrevCode.null));4628 try diw.writeUleb128(@backingInt(AbbrevCode.null));
4629 },4629 },
4630
4630 .memoized_call => unreachable, // not a value4631 .memoized_call => unreachable, // not a value
4631 }4632 }
4632 try dwarf.debug_info.section.replaceEntry(unit, entry, dwarf, wip_nav.debug_info.written());4633 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...@@ -4651,7 +4652,7 @@ pub fn updateLineNumber(dwarf: *Dwarf, zcu: *Zcu, zir_index: InternPool.TrackedI
4651 const ip = &zcu.intern_pool;4652 const ip = &zcu.intern_pool;
46524653
4653 const inst_info = zir_index.resolveFull(ip).?;4654 const inst_info = zir_index.resolveFull(ip).?;
4654 assert(inst_info.inst != .main_struct_inst);4655 if (inst_info.inst == .main_struct_inst) return;
4655 const file = zcu.fileByIndex(inst_info.file);4656 const file = zcu.fileByIndex(inst_info.file);
46564657
4657 var line_buf: [4]u8 = undefined;4658 var line_buf: [4]u8 = undefined;
src/link/Dwarf2.zig+1316-421
...@@ -10,10 +10,7 @@ consts: std.ArrayList(Const),...@@ -10,10 +10,7 @@ consts: std.ArrayList(Const),
10globals: std.array_hash_map.Auto(InternPool.Nav.Index, Global),10globals: std.array_hash_map.Auto(InternPool.Nav.Index, Global),
11funcs: std.array_hash_map.Auto(InternPool.Nav.Index, Func),11funcs: std.array_hash_map.Auto(InternPool.Nav.Index, Func),
12decls: std.array_hash_map.Auto(InternPool.TrackedInst.Index, Decl),12decls: std.array_hash_map.Auto(InternPool.TrackedInst.Index, Decl),
13pending_decl: ?struct {13pending_decl: struct { di: Decl.Index, instance_val: InternPool.Index },
14 di: Decl.Index,
15 instance_val: InternPool.Index,
16},
1714
18debug_abbrev: Abbrev,15debug_abbrev: Abbrev,
19frame: Frame,16frame: Frame,
...@@ -680,7 +677,7 @@ pub const WipNav = struct {...@@ -680,7 +677,7 @@ pub const WipNav = struct {
680 const di_nw = &debug.info_writer;677 const di_nw = &debug.info_writer;
681 const diw = &di_nw.interface;678 const diw = &di_nw.interface;
682 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_func));679 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) {
684 .none => nav,681 .none => nav,
685 else => |generic_owner| ip.getNav(zcu.funcInfo(generic_owner).owner_nav),682 else => |generic_owner| ip.getNav(zcu.funcInfo(generic_owner).owner_nav),
686 }.analysis.?.namespace).owner_type));683 }.analysis.?.namespace).owner_type));
...@@ -692,7 +689,7 @@ pub const WipNav = struct {...@@ -692,7 +689,7 @@ pub const WipNav = struct {
692 .normal => nav.fqn,689 .normal => nav.fqn,
693 .@"extern", .@"export" => nav.name,690 .@"extern", .@"export" => nav.name,
694 }.toSlice(ip));691 }.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));
696 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, 0);693 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, 0);
697 debug.info_func_length_offset = diw.end;694 debug.info_func_length_offset = diw.end;
698 try diw.writeInt(u32, undefined, dwarf.endian);695 try diw.writeInt(u32, undefined, dwarf.endian);
...@@ -802,7 +799,7 @@ pub const WipNav = struct {...@@ -802,7 +799,7 @@ pub const WipNav = struct {
802 .local_var => if (opt_name) |_| .local_var else unreachable,799 .local_var => if (opt_name) |_| .local_var else unreachable,
803 }));800 }));
804 if (opt_name) |name| try dwarf.strp(&dwarf.debug_str, di_nw, name);801 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);
806 try dwarf.exprLoc(&debug.info_writer, loc);803 try dwarf.exprLoc(&debug.info_writer, loc);
807 debug.any_children = true;804 debug.any_children = true;
808 }805 }
...@@ -855,7 +852,7 @@ pub const WipNav = struct {...@@ -855,7 +852,7 @@ pub const WipNav = struct {
855 } else unreachable,852 } else unreachable,
856 }));853 }));
857 if (opt_name) |name| try dwarf.strp(&dwarf.debug_str, di_nw, name);854 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);
859 if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, val);856 if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, val);
860 if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, val);857 if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, val);
861 debug.any_children = true;858 debug.any_children = true;
...@@ -1251,7 +1248,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {...@@ -1251,7 +1248,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {
1251 .globals = .empty,1248 .globals = .empty,
1252 .funcs = .empty,1249 .funcs = .empty,
1253 .decls = .empty,1250 .decls = .empty,
1254 .pending_decl = null,1251 .pending_decl = .{ .di = undefined, .instance_val = .none },
12551252
1256 .debug_abbrev = .{1253 .debug_abbrev = .{
1257 .ni = .none,1254 .ni = .none,
...@@ -1457,33 +1454,42 @@ pub fn getFuncIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Func.Index {...@@ -1457,33 +1454,42 @@ pub fn getFuncIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Func.Index {
1457 return @fromBackingInt(@intCast(dwarf.funcs.getIndex(nav) orelse return null));1454 return @fromBackingInt(@intCast(dwarf.funcs.getIndex(nav) orelse return null));
1458}1455}
14591456
1460pub fn getDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedInst.Index {1457fn getDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedInst.Index {
1461 const ip = &dwarf.lf.comp.zcu.?.intern_pool;1458 const ip = &dwarf.lf.comp.zcu.?.intern_pool;
1462 switch (ip.indexToKey(val)) {1459 switch (ip.indexToKey(val)) {
1463 else => unreachable,1460 else => unreachable,
1464 .struct_type => {1461 .struct_type, .union_type, .enum_type, .opaque_type => |container, tag| switch (container) {
1465 const loaded_struct = ip.loadStructType(val);1462 .declared => |declared| switch (declared.captures.owned.len) {
1466 if (loaded_struct.captures.len == 0) return null;1463 0 => return null,
1467 return ip.getNav(loaded_struct.name_nav.unwrap() orelse1464 else => switch (tag) {
1468 return loaded_struct.zir_index).srcInst(ip);1465 else => unreachable,
1469 },1466 .struct_type => {
1470 .enum_type => {1467 const loaded_struct = ip.loadStructType(val);
1471 const loaded_enum = ip.loadEnumType(val);1468 return ip.getNav(loaded_struct.name_nav.unwrap() orelse
1472 if (loaded_enum.captures.len == 0) return null;1469 return loaded_struct.zir_index).srcInst(ip);
1473 return ip.getNav(loaded_enum.name_nav.unwrap() orelse1470 },
1474 return loaded_enum.zir_index.unwrap().?).srcInst(ip);1471 .union_type => {
1475 },1472 const loaded_union = ip.loadUnionType(val);
1476 .union_type => {1473 return ip.getNav(loaded_union.name_nav.unwrap() orelse
1477 const loaded_union = ip.loadUnionType(val);1474 return loaded_union.zir_index).srcInst(ip);
1478 if (loaded_union.captures.len == 0) return null;1475 },
1479 return ip.getNav(loaded_union.name_nav.unwrap() orelse1476 .enum_type => {
1480 return loaded_union.zir_index).srcInst(ip);1477 const loaded_enum = ip.loadEnumType(val);
1481 },1478 return ip.getNav(loaded_enum.name_nav.unwrap() orelse
1482 .opaque_type => {1479 return loaded_enum.zir_index.unwrap().?).srcInst(ip);
1483 const loaded_opaque = ip.loadOpaqueType(val);1480 },
1484 if (loaded_opaque.captures.len == 0) return null;1481 .opaque_type => {
1485 return ip.getNav(loaded_opaque.name_nav.unwrap() orelse1482 const loaded_opaque = ip.loadOpaqueType(val);
1486 return loaded_opaque.zir_index).srcInst(ip);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,
1487 },1493 },
1488 .func => |func| return ip.getNav(switch (func.generic_owner) {1494 .func => |func| return ip.getNav(switch (func.generic_owner) {
1489 .none => func.owner_nav,1495 .none => func.owner_nav,
...@@ -1496,7 +1502,7 @@ pub fn getDecl(...@@ -1496,7 +1502,7 @@ pub fn getDecl(
1496 pt: Zcu.PerThread,1502 pt: Zcu.PerThread,
1497 instance_val: InternPool.Index,1503 instance_val: InternPool.Index,
1498) link.Error!MappedFile.Node.Index {1504) link.Error!MappedFile.Node.Index {
1499 assert(dwarf.pending_decl == null);1505 assert(dwarf.pending_decl.instance_val == .none);
1500 const comp = dwarf.lf.comp;1506 const comp = dwarf.lf.comp;
1501 const gpa = comp.gpa;1507 const gpa = comp.gpa;
1502 const zcu = pt.zcu;1508 const zcu = pt.zcu;
...@@ -2003,13 +2009,15 @@ fn genDeclFuncGeneric(...@@ -2003,13 +2009,15 @@ fn genDeclFuncGeneric(
2003 name: []const u8,2009 name: []const u8,
2004 param_body: []const std.zig.Zir.Inst.Index,2010 param_body: []const std.zig.Zir.Inst.Index,
2005) link.EmitError!void {2011) link.EmitError!void {
2012 const zcu = pt.zcu;
2006 const diw = &di_nw.interface;2013 const diw = &di_nw.interface;
2007 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_func_generic));2014 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);
2009 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);2016 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
2010 try diw.writeUleb128(decl.src_column + 1);2017 try diw.writeUleb128(decl.src_column + 1);
2011 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);2018 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2012 try dwarf.strp(&dwarf.debug_str, di_nw, name);2019 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2020 try dwarf.refType(pt, di_nw, .fromInterned(fn_ty.return_type));
2013 var param_index: u32 = 0;2021 var param_index: u32 = 0;
2014 for (param_body) |param_inst| {2022 for (param_body) |param_inst| {
2015 switch (zir.getParamName(param_inst) orelse break) {2023 switch (zir.getParamName(param_inst) orelse break) {
...@@ -2019,7 +2027,7 @@ fn genDeclFuncGeneric(...@@ -2019,7 +2027,7 @@ fn genDeclFuncGeneric(
2019 try dwarf.strp(&dwarf.debug_str, di_nw, zir.nullTerminatedString(param_name));2027 try dwarf.strp(&dwarf.debug_str, di_nw, zir.nullTerminatedString(param_name));
2020 },2028 },
2021 }2029 }
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]));
2023 param_index += 1;2031 param_index += 1;
2024 }2032 }
2025 if (fn_ty.is_var_args) try diw.writeUleb128(try dwarf.refAbbrevCode(.is_var_args));2033 if (fn_ty.is_var_args) try diw.writeUleb128(try dwarf.refAbbrevCode(.is_var_args));
...@@ -2095,7 +2103,6 @@ fn updateConstInner(...@@ -2095,7 +2103,6 @@ fn updateConstInner(
2095 const ip = &zcu.intern_pool;2103 const ip = &zcu.intern_pool;
2096 const diw = &di_nw.interface;2104 const diw = &di_nw.interface;
2097 switch (ip.indexToKey(val)) {2105 switch (ip.indexToKey(val)) {
2098 else => return,
2099 .int_type => |int_type| {2106 .int_type => |int_type| {
2100 const ty: Type = .fromInterned(val);2107 const ty: Type = .fromInterned(val);
2101 try diw.writeUleb128(try dwarf.refAbbrevCode(.numeric_type));2108 try diw.writeUleb128(try dwarf.refAbbrevCode(.numeric_type));
...@@ -2111,17 +2118,13 @@ fn updateConstInner(...@@ -2111,17 +2118,13 @@ fn updateConstInner(
2111 },2118 },
2112 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {2119 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
2113 .one, .many, .c => {2120 .one, .many, .c => {
2114 const ty: Type = .fromInterned(val);2121 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
2115 const ptr_child_ty: Type = .fromInterned(ptr_type.child);2122 defer zcu.gpa.free(name);
2116 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (ptr_type.flags.alignment) {2123 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (ptr_type.flags.alignment) {
2117 .none => if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type,2124 .none => if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type,
2118 else => if (ptr_type.sentinel == .none) .ptr_aligned_type else .ptr_aligned_sentinel_type,2125 else => if (ptr_type.sentinel == .none) .ptr_aligned_type else .ptr_aligned_sentinel_type,
2119 }));2126 }));
2120 {2127 try dwarf.strp(&dwarf.debug_str, di_nw, name);
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 }
2125 if (ptr_type.sentinel != .none) try dwarf.blockConst(pt, di_nw, .fromInterned(ptr_type.sentinel));2128 if (ptr_type.sentinel != .none) try dwarf.blockConst(pt, di_nw, .fromInterned(ptr_type.sentinel));
2126 if (ptr_type.flags.alignment.toByteUnits()) |a| try diw.writeUleb128(a);2129 if (ptr_type.flags.alignment.toByteUnits()) |a| try diw.writeUleb128(a);
2127 try diw.writeByte(@backingInt(ptr_type.flags.address_space));2130 try diw.writeByte(@backingInt(ptr_type.flags.address_space));
...@@ -2139,31 +2142,181 @@ fn updateConstInner(...@@ -2139,31 +2142,181 @@ fn updateConstInner(
2139 );2142 );
2140 }2143 }
2141 if (ptr_type.flags.is_volatile) try diw.writeUleb128(try dwarf.refAbbrevCode(.is_volatile));2144 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));
2143 },2146 },
2144 .slice => {2147 .slice => {
2145 const ty: Type = .fromInterned(val);2148 const ty: Type = .fromInterned(val);
2149 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
2150 defer zcu.gpa.free(name);
2146 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_struct_type));2151 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_struct_type));
2147 {2152 try dwarf.strp(&dwarf.debug_str, di_nw, name);
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 diw.writeUleb128(ty.abiSize(zcu));2153 try diw.writeUleb128(ty.abiSize(zcu));
2153 try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);2154 try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
2154 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));2155 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
2155 try dwarf.strp(&dwarf.debug_str, di_nw, "ptr");2156 try dwarf.strp(&dwarf.debug_str, di_nw, "ptr");
2156 const ptr_field_ty = ty.slicePtrFieldType(zcu);2157 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);
2158 try diw.writeUleb128(0);2159 try diw.writeUleb128(0);
2159 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));2160 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
2160 try dwarf.strp(&dwarf.debug_str, di_nw, "len");2161 try dwarf.strp(&dwarf.debug_str, di_nw, "len");
2161 const len_field_ty: Type = .usize;2162 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);
2163 try diw.writeUleb128(len_field_ty.abiAlignment(zcu).forward(ptr_field_ty.abiSize(zcu)));2164 try diw.writeUleb128(len_field_ty.abiAlignment(zcu).forward(ptr_field_ty.abiSize(zcu)));
2164 try diw.writeUleb128(@backingInt(AbbrevCode.null));2165 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2165 },2166 },
2166 },2167 },
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 },
2167 .simple_type => |simple_type| switch (simple_type) {2320 .simple_type => |simple_type| switch (simple_type) {
2168 .f16,2321 .f16,
2169 .f32,2322 .f32,
...@@ -2220,25 +2373,315 @@ fn updateConstInner(...@@ -2220,25 +2373,315 @@ fn updateConstInner(
2220 var name_buf: ["@TypeOf(undefined)".len]u8 = undefined;2373 var name_buf: ["@TypeOf(undefined)".len]u8 = undefined;
2221 try dwarf.strp(&dwarf.debug_str, di_nw, std.mem.print(&name_buf, "{f}", .{ty.fmt(pt)}) catch unreachable);2374 try dwarf.strp(&dwarf.debug_str, di_nw, std.mem.print(&name_buf, "{f}", .{ty.fmt(pt)}) catch unreachable);
2222 },2375 },
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 },
2224 .adhoc_inferred_error_set => unreachable,2391 .adhoc_inferred_error_set => unreachable,
2225 },2392 },
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 },
2226 .struct_type => {2445 .struct_type => {
2227 const loaded_struct = ip.loadStructType(val);2446 const loaded_struct = ip.loadStructType(val);
2228 const zfi = loaded_struct.zir_index.resolveFile(ip);2447 const zfi = loaded_struct.zir_index.resolveFile(ip);
2229 const zf = zcu.fileByIndex(zfi);2448 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 }
2230 switch (loaded_struct.layout) {2500 switch (loaded_struct.layout) {
2231 .auto, .@"extern" => {2501 .auto, .@"extern" => {
2232 const struct_is_file = loaded_struct.zir_index.resolve(ip) == .main_struct_inst;2502 const ty: Type = .fromInterned(val);
2233 if (loaded_struct.name_nav.unwrap()) |name_ni| {2503 try diw.writeUleb128(ty.abiSize(zcu));
2234 assert(!struct_is_file);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| {
2235 const name_nav = ip.getNav(name_ni);2678 const name_nav = ip.getNav(name_ni);
2236 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);2679 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2237 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(2680 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2238 name_nav.analysis.?.namespace,2681 name_nav.analysis.?.namespace,
2239 ).owner_type);2682 ).owner_type);
2240 try diw.writeUleb128(try dwarf.refAbbrevCode(2683 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,
2242 ));2685 ));
2243 try dwarf.secOffset(di_nw, parent_ni, 0);2686 try dwarf.secOffset(di_nw, parent_ni, 0);
2244 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);2687 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
...@@ -2246,107 +2689,173 @@ fn updateConstInner(...@@ -2246,107 +2689,173 @@ fn updateConstInner(
2246 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);2689 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2247 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));2690 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
2248 } else {2691 } else {
2249 const ui = dwarf.getUnit(zf.mod.?);2692 const decl = zf.zir.?.getEnumDecl(loaded_enum.zir_index.unwrap().?.resolve(ip).?);
2250 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, zfi);2693 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2251 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (loaded_struct.field_types.len) {2694 ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?,
2252 0 => if (struct_is_file) .empty_file else .empty_struct_type,2695 ).owner_type);
2253 else => if (struct_is_file) .file else .struct_type,2696 try diw.writeUleb128(try dwarf.refAbbrevCode(
2254 }));2697 if (loaded_enum.field_names.len > 0) .type_decl_enum else .type_decl_empty_enum,
2255 try diw.writeUleb128(@backingInt(fi));2698 ));
2256 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.fqn.toSlice(ip));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));
2257 }2703 }
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));
2298 },2704 },
2299 .@"packed" => return,2705 else => {
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);
2325 try diw.writeUleb128(try dwarf.refAbbrevCode(2706 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,
2327 ));2708 ));
2328 try diw.writeUleb128(@backingInt(fi));
2329 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip));2709 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip));
2330 }2710 },
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));
2337 }2711 }
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));
2339 for (0..loaded_enum.field_names.len) |field_index| {2713 for (0..loaded_enum.field_names.len) |field_index| {
2340 try diw.writeUleb128(try dwarf.refAbbrevCode(.enum_field));2714 try diw.writeUleb128(try dwarf.refAbbrevCode(.enum_field));
2341 try dwarf.enumConstValue(diw, loaded_enum, field_index);2715 try dwarf.enumConstValue(diw, loaded_enum, field_index);
2342 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.field_names.get(ip)[field_index].toSlice(ip));2716 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.field_names.get(ip)[field_index].toSlice(ip));
2343 }2717 }
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 });
2345 },2838 },
2839
2840 else => return,
2841
2842 .memoized_call => unreachable, // not a value
2346 }2843 }
2347 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());2844 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());
2348}2845}
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
2350pub fn updateConstIncomplete(2859pub fn updateConstIncomplete(
2351 dwarf: *Dwarf,2860 dwarf: *Dwarf,
2352 pt: Zcu.PerThread,2861 pt: Zcu.PerThread,
...@@ -2369,7 +2878,7 @@ fn updateConstIncompleteInner(...@@ -2369,7 +2878,7 @@ fn updateConstIncompleteInner(
2369 const ip = &zcu.intern_pool;2878 const ip = &zcu.intern_pool;
2370 const diw = &di_nw.interface;2879 const diw = &di_nw.interface;
2371 done: {2880 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)) {
2373 .struct_type => {2882 .struct_type => {
2374 const loaded_struct = ip.loadStructType(val);2883 const loaded_struct = ip.loadStructType(val);
2375 const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse {2884 const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse {
...@@ -2383,22 +2892,34 @@ fn updateConstIncompleteInner(...@@ -2383,22 +2892,34 @@ fn updateConstIncompleteInner(
2383 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);2892 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);
2384 try diw.writeUleb128(try dwarf.refAbbrevCode(.empty_file));2893 try diw.writeUleb128(try dwarf.refAbbrevCode(.empty_file));
2385 try diw.writeUleb128(@backingInt(fi));2894 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));
2387 try diw.writeByte(@intFromBool(true));2896 try diw.writeByte(@intFromBool(true));
2388 break :done;2897 break :done;
2389 },2898 },
2390 else => break :container .{2899 else => {
2391 src_inst,2900 const data = zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended;
2392 zf,2901 const src_line, const src_column = src_loc: switch (data.opcode) {
2393 switch (zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended.opcode) {
2394 else => unreachable,2902 else => unreachable,
2395 .struct_decl => zf.zir.?.getStructDecl(src_inst.inst).capture_names,2903 .struct_decl => {
2396 .reify_struct => &.{},2904 const decl = zf.zir.?.getStructDecl(src_inst.inst);
2397 },2905 break :src_loc .{ decl.src_line, decl.src_column };
2398 loaded_struct.captures,2906 },
2399 loaded_struct.fqn,2907 .reify_struct => {
2400 loaded_struct.name_nav,2908 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.ReifyStruct, data.operand).data;
2401 loaded_struct.namespace,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 };
2402 },2923 },
2403 }2924 }
2404 },2925 },
...@@ -2409,16 +2930,26 @@ fn updateConstIncompleteInner(...@@ -2409,16 +2930,26 @@ fn updateConstIncompleteInner(
2409 break :done;2930 break :done;
2410 };2931 };
2411 const zf = zcu.fileByIndex(src_inst.file);2932 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 };
2412 break :container .{2945 break :container .{
2413 src_inst,2946 .@"union",
2414 zf,2947 zf,
2415 switch (zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended.opcode) {2948 src_line,
2416 else => unreachable,2949 src_column,
2417 .union_decl => zf.zir.?.getUnionDecl(src_inst.inst).capture_names,2950 loaded_union.is_reified,
2418 .reify_union => &.{},
2419 },
2420 loaded_union.captures,2951 loaded_union.captures,
2421 loaded_union.fqn,2952 loaded_union.name,
2422 loaded_union.name_nav,2953 loaded_union.name_nav,
2423 loaded_union.namespace,2954 loaded_union.namespace,
2424 };2955 };
...@@ -2427,7 +2958,7 @@ fn updateConstIncompleteInner(...@@ -2427,7 +2958,7 @@ fn updateConstIncompleteInner(
2427 const loaded_enum = ip.loadEnumType(val);2958 const loaded_enum = ip.loadEnumType(val);
2428 const zir_index = loaded_enum.zir_index.unwrap() orelse {2959 const zir_index = loaded_enum.zir_index.unwrap() orelse {
2429 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_empty_struct_type));2960 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));
2431 try diw.writeByte(@intFromBool(true));2962 try diw.writeByte(@intFromBool(true));
2432 break :done;2963 break :done;
2433 };2964 };
...@@ -2436,20 +2967,31 @@ fn updateConstIncompleteInner(...@@ -2436,20 +2967,31 @@ fn updateConstIncompleteInner(
2436 break :done;2967 break :done;
2437 };2968 };
2438 const zf = zcu.fileByIndex(src_inst.file);2969 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 };
2439 break :container .{2982 break :container .{
2440 src_inst,2983 .@"enum",
2441 zf,2984 zf,
2442 switch (zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended.opcode) {2985 src_line,
2443 else => unreachable,2986 src_column,
2444 .enum_decl => zf.zir.?.getEnumDecl(src_inst.inst).capture_names,2987 loaded_enum.is_reified,
2445 .reify_enum => &.{},
2446 },
2447 loaded_enum.captures,2988 loaded_enum.captures,
2448 loaded_enum.fqn,2989 loaded_enum.name,
2449 loaded_enum.name_nav,2990 loaded_enum.name_nav,
2450 loaded_enum.namespace,2991 loaded_enum.namespace,
2451 };2992 };
2452 },2993 },
2994 // always complete, but forwarded from `updateConstInner`
2453 .opaque_type => {2995 .opaque_type => {
2454 const loaded_opaque = ip.loadOpaqueType(val);2996 const loaded_opaque = ip.loadOpaqueType(val);
2455 const src_inst = loaded_opaque.zir_index.resolveFull(ip) orelse {2997 const src_inst = loaded_opaque.zir_index.resolveFull(ip) orelse {
...@@ -2457,12 +2999,15 @@ fn updateConstIncompleteInner(...@@ -2457,12 +2999,15 @@ fn updateConstIncompleteInner(
2457 break :done;2999 break :done;
2458 };3000 };
2459 const zf = zcu.fileByIndex(src_inst.file);3001 const zf = zcu.fileByIndex(src_inst.file);
3002 const decl = zf.zir.?.getOpaqueDecl(src_inst.inst);
2460 break :container .{3003 break :container .{
2461 src_inst,3004 .@"struct",
2462 zf,3005 zf,
2463 zf.zir.?.getOpaqueDecl(src_inst.inst).capture_names,3006 decl.src_line,
3007 decl.src_column,
3008 false,
2464 loaded_opaque.captures,3009 loaded_opaque.captures,
2465 loaded_opaque.fqn,3010 loaded_opaque.name,
2466 loaded_opaque.name_nav,3011 loaded_opaque.name_nav,
2467 loaded_opaque.namespace,3012 loaded_opaque.namespace,
2468 };3013 };
...@@ -2477,92 +3022,117 @@ fn updateConstIncompleteInner(...@@ -2477,92 +3022,117 @@ fn updateConstIncompleteInner(
2477 },3022 },
2478 else => |ty| {3023 else => |ty| {
2479 try diw.writeUleb128(try dwarf.refAbbrevCode(.undefined_comptime_value));3024 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));
2481 },3026 },
2482 },3027 },
2483 };3028 };
2484 const spec_di = if (false and captures.len > 0) try dwarf.getDecl(pt, val) else undefined;3029 if (captures.len > 0 or is_reified) {
2485 _ = spec_di;3030 try diw.writeUleb128(try dwarf.refAbbrevCode(if (captures.len > 0) switch (kind) {
2486 if (maybe_name_nav.unwrap()) |name_ni| {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| {
2487 const name_nav = ip.getNav(name_ni);3041 const name_nav = ip.getNav(name_ni);
2488 const name_src_inst = name_nav.srcInst(ip).resolve(ip).?;3042 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2489 const decl = zf.zir.?.getDeclaration(name_src_inst);
2490 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(3043 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2491 name_nav.analysis.?.namespace,3044 name_nav.analysis.?.namespace,
2492 ).owner_type);3045 ).owner_type);
2493 try diw.writeUleb128(try dwarf.refAbbrevCode(3046 try diw.writeUleb128(try dwarf.refAbbrevCode(if (captures.len > 0) switch (kind) {
2494 if (captures.len > 0) .decl_capturing_namespace_struct else .decl_namespace_struct,3047 .@"struct" => .decl_incomplete_struct,
2495 ));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 }));
2496 try dwarf.secOffset(di_nw, parent_ni, 0);3055 try dwarf.secOffset(di_nw, parent_ni, 0);
2497 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);3056 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
2498 try diw.writeUleb128(decl.src_column + 1);3057 try diw.writeUleb128(decl.src_column + 1);
2499 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);3058 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2500 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));3059 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
2501 } else {3060 } else {
2502 const ui = dwarf.getUnit(zf.mod.?);3061 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
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(
2505 ip.namespacePtr(namespace).parent.unwrap().?,3062 ip.namespacePtr(namespace).parent.unwrap().?,
2506 ).owner_type);3063 ).owner_type);
2507 _ = parent_ni;3064 try diw.writeUleb128(try dwarf.refAbbrevCode(if (captures.len > 0) switch (kind) {
2508 try diw.writeUleb128(try dwarf.refAbbrevCode(3065 .@"struct" => .type_decl_incomplete_struct,
2509 if (captures.len > 0) .capturing_empty_struct_type else .empty_struct_type,3066 .@"union" => .type_decl_incomplete_union,
2510 ));3067 .@"enum" => .type_decl_incomplete_enum,
2511 try diw.writeUleb128(@backingInt(fi));3068 } else switch (kind) {
2512 try dwarf.strp(&dwarf.debug_str, di_nw, fqn.toSlice(ip));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));
2513 }3077 }
2514 try diw.writeByte(@intFromBool(true));3078 try dwarf.genCaptures(pt, di_nw, captures);
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 };
2555 if (captures.len > 0) try diw.writeByte(@backingInt(AbbrevCode.null));3079 if (captures.len > 0) try diw.writeByte(@backingInt(AbbrevCode.null));
2556 }3080 }
2557 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());3081 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());
2558}3082}
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
2560pub fn genDecl(3129pub fn genDecl(
2561 dwarf: *Dwarf,3130 dwarf: *Dwarf,
2562 pt: Zcu.PerThread,3131 pt: Zcu.PerThread,
2563 di_nw: *MappedFile.Node.Writer,3132 di_nw: *MappedFile.Node.Writer,
2564 instance_val: InternPool.Index,3133 instance_val: InternPool.Index,
2565) link.Error!void {3134) link.Error!void {
3135 log.debug("genDecl({f})", .{Value.fromInterned(instance_val).fmtValue(pt)});
2566 dwarf.genDeclInner(pt, di_nw, instance_val) catch |err| switch (err) {3136 dwarf.genDeclInner(pt, di_nw, instance_val) catch |err| switch (err) {
2567 else => |e| return e,3137 else => |e| return e,
2568 error.WriteFailed => return dwarf.reportWriteError(di_nw),3138 error.WriteFailed => return dwarf.reportWriteError(di_nw),
...@@ -2574,68 +3144,221 @@ fn genDeclInner(...@@ -2574,68 +3144,221 @@ fn genDeclInner(
2574 di_nw: *MappedFile.Node.Writer,3144 di_nw: *MappedFile.Node.Writer,
2575 instance_val: InternPool.Index,3145 instance_val: InternPool.Index,
2576) link.EmitError!void {3146) link.EmitError!void {
2577 const ip = &dwarf.lf.comp.zcu.?.intern_pool;3147 const zcu = pt.zcu;
3148 const ip = &zcu.intern_pool;
2578 const diw = &di_nw.interface;3149 const diw = &di_nw.interface;
2579 switch (ip.indexToKey(instance_val)) {3150 done: {
2580 else => unreachable,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)) {
2581 .struct_type => {3152 else => unreachable,
2582 const loaded_struct = ip.loadStructType(instance_val);3153 .struct_type => {
2583 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(3154 const loaded_struct = ip.loadStructType(instance_val);
2584 ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?,3155 const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse {
2585 ).owner_type);3156 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
2586 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_specification_struct));3157 break :done;
2587 try dwarf.secOffset(di_nw, parent_ni, 0);3158 };
2588 try diw.writeInt(u32, 0, dwarf.endian);3159 const zf = zcu.fileByIndex(src_inst.file);
2589 try diw.writeUleb128(0);3160 const inst = zf.zir.?.instructions.get(@backingInt(src_inst.inst));
2590 try diw.writeByte(DW.ACCESS.public);3161 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {
2591 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.fqn.toSlice(ip));3162 else => unreachable,
2592 },3163 .struct_init, .struct_init_ref => {
2593 .enum_type => {3164 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.StructInit, inst.data.pl_node.payload_index).data;
2594 const loaded_enum = ip.loadEnumType(instance_val);3165 break :decl .{ decl.src_line, decl.src_column, &.{} };
2595 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(3166 },
2596 ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?,3167 .struct_init_anon => {
2597 ).owner_type);3168 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.StructInitAnon, inst.data.pl_node.payload_index).data;
2598 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_specification_enum));3169 break :decl .{ decl.src_line, decl.src_column, &.{} };
2599 try dwarf.secOffset(di_nw, parent_ni, 0);3170 },
2600 try diw.writeInt(u32, 0, dwarf.endian);3171 .extended => switch (inst.data.extended.opcode) {
2601 try diw.writeUleb128(0);3172 else => unreachable,
2602 try diw.writeByte(DW.ACCESS.public);3173 .struct_decl => {
2603 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip));3174 const decl = zf.zir.?.getStructDecl(src_inst.inst);
2604 },3175 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };
2605 .union_type => {3176 },
2606 const loaded_union = ip.loadUnionType(instance_val);3177 .reify_struct => {
2607 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(3178 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.ReifyStruct, inst.data.extended.operand).data;
2608 ip.namespacePtr(loaded_union.namespace).parent.unwrap().?,3179 break :decl .{ decl.src_line, decl.src_column, &.{} };
2609 ).owner_type);3180 },
2610 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_specification_union));3181 },
2611 try dwarf.secOffset(di_nw, parent_ni, 0);3182 };
2612 try diw.writeInt(u32, 0, dwarf.endian);3183 break :container .{
2613 try diw.writeUleb128(0);3184 .@"struct",
2614 try diw.writeByte(DW.ACCESS.public);3185 zf,
2615 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_union.fqn.toSlice(ip));3186 src_line,
2616 },3187 src_column,
2617 }3188 capture_names,
2618 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());3189 loaded_struct.captures,
2619}3190 loaded_struct.name,
26203191 loaded_struct.name_nav,
2621pub fn updateLineNumber(3192 loaded_struct.namespace,
2622 dwarf: *Dwarf,3193 };
2623 mf: *MappedFile,3194 },
2624 inst: InternPool.TrackedInst.Index,3195 .union_type => {
2625 line: u32,3196 const loaded_union = ip.loadUnionType(instance_val);
2626) void {3197 const src_inst = loaded_union.zir_index.resolveFull(ip) orelse {
2627 const di = dwarf.getDeclIfExists(inst) orelse return;3198 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
2628 const decl_ni = di.get(dwarf).debug_info_ni.unwrap().?;3199 break :done;
2629 std.mem.writeInt(3200 };
2630 u32,3201 const zf = zcu.fileByIndex(src_inst.file);
2631 decl_ni.slice(mf)[AbbrevCode.decl_size..][0..4],3202 const inst = zf.zir.?.instructions.get(@backingInt(src_inst.inst));
2632 line + 1,3203 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {
2633 dwarf.endian,3204 else => unreachable,
2634 );3205 .extended => switch (inst.data.extended.opcode) {
2635}3206 else => unreachable,
26363207 .union_decl => {
2637pub fn lostTracking(dwarf: *Dwarf, diw: *std.Io.Writer) link.EmitError!void {3208 const decl = zf.zir.?.getUnionDecl(src_inst.inst);
2638 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));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));
2639}3362}
26403363
2641fn refAbbrevCodeIfExists(3364fn refAbbrevCodeIfExists(
...@@ -2746,6 +3469,14 @@ fn blockConst(...@@ -2746,6 +3469,14 @@ fn blockConst(
2746 assert(start + size == nw.interface.end);3469 assert(start + size == nw.interface.end);
2747}3470}
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}
2749fn refConst(3480fn refConst(
2750 dwarf: *Dwarf,3481 dwarf: *Dwarf,
2751 pt: Zcu.PerThread,3482 pt: Zcu.PerThread,
...@@ -2875,14 +3606,38 @@ pub const AbbrevCode = enum {...@@ -2875,14 +3606,38 @@ pub const AbbrevCode = enum {
2875 // decl, specification, and instance codes are assumed to all have the same uleb128 size3606 // decl, specification, and instance codes are assumed to all have the same uleb128 size
2876 decl_lost,3607 decl_lost,
2877 decl_alias,3608 decl_alias,
3609 decl_empty_incomplete_enum,
3610 decl_incomplete_enum,
2878 decl_empty_enum,3611 decl_empty_enum,
2879 decl_enum,3612 decl_enum,
2880 decl_namespace_struct,3613 type_decl_empty_incomplete_enum,
2881 decl_capturing_namespace_struct,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,
2882 decl_struct,3620 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,
2883 decl_packed_struct,3626 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,
2884 decl_union,3632 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,
2885 decl_packed_union,3638 decl_packed_union,
3639 type_decl_empty_packed_union,
3640 type_decl_packed_union,
2886 decl_var,3641 decl_var,
2887 decl_const,3642 decl_const,
2888 decl_const_runtime_bits,3643 decl_const_runtime_bits,
...@@ -2894,17 +3649,35 @@ pub const AbbrevCode = enum {...@@ -2894,17 +3649,35 @@ pub const AbbrevCode = enum {
2894 decl_func_generic,3649 decl_func_generic,
2895 decl_extern_nullary_func,3650 decl_extern_nullary_func,
2896 decl_extern_func,3651 decl_extern_func,
3652 decl_specification_empty_struct,
2897 decl_specification_struct,3653 decl_specification_struct,
3654 type_decl_specification_empty_struct,
3655 type_decl_specification_struct,
3656 decl_specification_empty_enum,
2898 decl_specification_enum,3657 decl_specification_enum,
3658 type_decl_specification_empty_enum,
3659 type_decl_specification_enum,
3660 decl_specification_empty_union,
2899 decl_specification_union,3661 decl_specification_union,
3662 type_decl_specification_empty_union,
3663 type_decl_specification_union,
2900 decl_specification_func,3664 decl_specification_func,
2901 decl_instance_alias,3665 decl_instance_alias,
3666 decl_instance_empty_incomplete_enum,
3667 decl_instance_incomplete_enum,
2902 decl_instance_empty_enum,3668 decl_instance_empty_enum,
2903 decl_instance_enum,3669 decl_instance_enum,
2904 decl_instance_namespace_struct,3670 decl_instance_empty_incomplete_struct,
3671 decl_instance_incomplete_struct,
3672 decl_instance_empty_struct,
2905 decl_instance_struct,3673 decl_instance_struct,
3674 decl_instance_empty_packed_struct,
2906 decl_instance_packed_struct,3675 decl_instance_packed_struct,
3676 decl_instance_empty_incomplete_union,
3677 decl_instance_incomplete_union,
3678 decl_instance_empty_union,
2907 decl_instance_union,3679 decl_instance_union,
3680 decl_instance_empty_packed_union,
2908 decl_instance_packed_union,3681 decl_instance_packed_union,
2909 decl_instance_var,3682 decl_instance_var,
2910 decl_instance_const,3683 decl_instance_const,
...@@ -2963,17 +3736,7 @@ pub const AbbrevCode = enum {...@@ -2963,17 +3736,7 @@ pub const AbbrevCode = enum {
2963 generated_empty_struct_type,3736 generated_empty_struct_type,
2964 generated_struct_type,3737 generated_struct_type,
2965 generated_union_type,3738 generated_union_type,
2966 empty_enum_type,3739 capture_specification,
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,
2977 comptime_capture,3740 comptime_capture,
2978 comptime_capture_runtime,3741 comptime_capture_runtime,
2979 comptime_capture_partially_comptime,3742 comptime_capture_partially_comptime,
...@@ -3032,13 +3795,19 @@ pub const AbbrevCode = enum {...@@ -3032,13 +3795,19 @@ pub const AbbrevCode = enum {
3032 .{ .accessibility, .data1 },3795 .{ .accessibility, .data1 },
3033 .{ .name, .strp },3796 .{ .name, .strp },
3034 };3797 };
30353798 const type_decl_attrs = &[_]Attr{
3799 .{ .ZIG_parent, .ref_addr },
3800 .{ .decl_line, .data4 },
3801 .{ .decl_column, .udata },
3802 .{ .name, .strp },
3803 };
3036 const decl_specification_attrs = decl_attrs ++ &[_]Attr{3804 const decl_specification_attrs = decl_attrs ++ &[_]Attr{
3037 .{ .declaration, .flag_present },3805 .{ .declaration, .flag_present },
3038 };3806 };
30393807 const type_decl_specification_attrs = type_decl_attrs ++ &[_]Attr{
3808 .{ .declaration, .flag_present },
3809 };
3040 const decl_instance_attrs = &[_]Attr{3810 const decl_instance_attrs = &[_]Attr{
3041 .{ .ZIG_parent, .ref_addr },
3042 .{ .specification, .ref_addr },3811 .{ .specification, .ref_addr },
3043 };3812 };
30443813
...@@ -3066,6 +3835,15 @@ pub const AbbrevCode = enum {...@@ -3066,6 +3835,15 @@ pub const AbbrevCode = enum {
3066 .{ .import, .ref_addr },3835 .{ .import, .ref_addr },
3067 },3836 },
3068 },3837 },
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 },
3069 .decl_empty_enum = .{3847 .decl_empty_enum = .{
3070 .tag = .enumeration_type,3848 .tag = .enumeration_type,
3071 .attrs = decl_attrs ++ .{3849 .attrs = decl_attrs ++ .{
...@@ -3079,17 +3857,42 @@ pub const AbbrevCode = enum {...@@ -3079,17 +3857,42 @@ pub const AbbrevCode = enum {
3079 .{ .type, .ref_addr },3857 .{ .type, .ref_addr },
3080 },3858 },
3081 },3859 },
3082 .decl_namespace_struct = .{3860 .type_decl_empty_incomplete_enum = .{
3083 .tag = .structure_type,3861 .tag = .enumeration_type,
3084 .attrs = decl_attrs ++ .{3862 .attrs = type_decl_attrs,
3085 .{ .declaration, .flag },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 },
3086 },3880 },
3087 },3881 },
3088 .decl_capturing_namespace_struct = .{3882 .decl_empty_incomplete_struct = .{
3883 .tag = .structure_type,
3884 .attrs = decl_attrs,
3885 },
3886 .decl_incomplete_struct = .{
3089 .tag = .structure_type,3887 .tag = .structure_type,
3090 .children = true,3888 .children = true,
3889 .attrs = decl_attrs,
3890 },
3891 .decl_empty_struct = .{
3892 .tag = .structure_type,
3091 .attrs = decl_attrs ++ .{3893 .attrs = decl_attrs ++ .{
3092 .{ .declaration, .flag },3894 .{ .byte_size, .udata },
3895 .{ .alignment, .udata },
3093 },3896 },
3094 },3897 },
3095 .decl_struct = .{3898 .decl_struct = .{
...@@ -3100,6 +3903,36 @@ pub const AbbrevCode = enum {...@@ -3100,6 +3903,36 @@ pub const AbbrevCode = enum {
3100 .{ .alignment, .udata },3903 .{ .alignment, .udata },
3101 },3904 },
3102 },3905 },
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 },
3103 .decl_packed_struct = .{3936 .decl_packed_struct = .{
3104 .tag = .structure_type,3937 .tag = .structure_type,
3105 .children = true,3938 .children = true,
...@@ -3107,6 +3940,35 @@ pub const AbbrevCode = enum {...@@ -3107,6 +3940,35 @@ pub const AbbrevCode = enum {
3107 .{ .type, .ref_addr },3940 .{ .type, .ref_addr },
3108 },3941 },
3109 },3942 },
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 },
3110 .decl_union = .{3972 .decl_union = .{
3111 .tag = .union_type,3973 .tag = .union_type,
3112 .children = true,3974 .children = true,
...@@ -3115,6 +3977,36 @@ pub const AbbrevCode = enum {...@@ -3115,6 +3977,36 @@ pub const AbbrevCode = enum {
3115 .{ .alignment, .udata },3977 .{ .alignment, .udata },
3116 },3978 },
3117 },3979 },
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 },
3118 .decl_packed_union = .{4010 .decl_packed_union = .{
3119 .tag = .union_type,4011 .tag = .union_type,
3120 .children = true,4012 .children = true,
...@@ -3122,6 +4014,19 @@ pub const AbbrevCode = enum {...@@ -3122,6 +4014,19 @@ pub const AbbrevCode = enum {
3122 .{ .type, .ref_addr },4014 .{ .type, .ref_addr },
3123 },4015 },
3124 },4016 },
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 },
3125 .decl_var = .{4030 .decl_var = .{
3126 .tag = .variable,4031 .tag = .variable,
3127 .attrs = decl_attrs ++ .{4032 .attrs = decl_attrs ++ .{
...@@ -3200,16 +4105,15 @@ pub const AbbrevCode = enum {...@@ -3200,16 +4105,15 @@ pub const AbbrevCode = enum {
3200 .decl_nullary_func_generic = .{4105 .decl_nullary_func_generic = .{
3201 .tag = .subprogram,4106 .tag = .subprogram,
3202 .attrs = decl_attrs ++ .{4107 .attrs = decl_attrs ++ .{
3203 //.{ .type, .ref_addr },4108 .{ .type, .ref_addr },
3204 //.{ .noreturn, .flag },4109 .{ .noreturn, .flag },
3205 },4110 },
3206 },4111 },
3207 .decl_func_generic = .{4112 .decl_func_generic = .{
3208 .tag = .subprogram,4113 .tag = .subprogram,
3209 .children = true,4114 .children = true,
3210 .attrs = decl_attrs ++ .{4115 .attrs = decl_attrs ++ .{
3211 //.{ .type, .ref_addr },4116 .{ .type, .ref_addr },
3212 //.{ .noreturn, .flag },
3213 },4117 },
3214 },4118 },
3215 .decl_extern_nullary_func = .{4119 .decl_extern_nullary_func = .{
...@@ -3233,18 +4137,60 @@ pub const AbbrevCode = enum {...@@ -3233,18 +4137,60 @@ pub const AbbrevCode = enum {
3233 .{ .noreturn, .flag },4137 .{ .noreturn, .flag },
3234 },4138 },
3235 },4139 },
4140 .decl_specification_empty_struct = .{
4141 .tag = .structure_type,
4142 .attrs = decl_specification_attrs,
4143 },
3236 .decl_specification_struct = .{4144 .decl_specification_struct = .{
3237 .tag = .structure_type,4145 .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,
3238 .attrs = decl_specification_attrs,4160 .attrs = decl_specification_attrs,
3239 },4161 },
3240 .decl_specification_enum = .{4162 .decl_specification_enum = .{
3241 .tag = .enumeration_type,4163 .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,
3242 .attrs = decl_specification_attrs,4178 .attrs = decl_specification_attrs,
3243 },4179 },
3244 .decl_specification_union = .{4180 .decl_specification_union = .{
3245 .tag = .union_type,4181 .tag = .union_type,
4182 .children = true,
3246 .attrs = decl_specification_attrs,4183 .attrs = decl_specification_attrs,
3247 },4184 },
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 },
3248 .decl_specification_func = .{4194 .decl_specification_func = .{
3249 .tag = .subprogram,4195 .tag = .subprogram,
3250 .attrs = decl_specification_attrs,4196 .attrs = decl_specification_attrs,
...@@ -3255,6 +4201,15 @@ pub const AbbrevCode = enum {...@@ -3255,6 +4201,15 @@ pub const AbbrevCode = enum {
3255 .{ .import, .ref_addr },4201 .{ .import, .ref_addr },
3256 },4202 },
3257 },4203 },
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 },
3258 .decl_instance_empty_enum = .{4213 .decl_instance_empty_enum = .{
3259 .tag = .enumeration_type,4214 .tag = .enumeration_type,
3260 .attrs = decl_instance_attrs ++ .{4215 .attrs = decl_instance_attrs ++ .{
...@@ -3268,11 +4223,20 @@ pub const AbbrevCode = enum {...@@ -3268,11 +4223,20 @@ pub const AbbrevCode = enum {
3268 .{ .type, .ref_addr },4223 .{ .type, .ref_addr },
3269 },4224 },
3270 },4225 },
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 = .{
3272 .tag = .structure_type,4231 .tag = .structure_type,
3273 .children = true,4232 .children = true,
4233 .attrs = decl_instance_attrs,
4234 },
4235 .decl_instance_empty_struct = .{
4236 .tag = .structure_type,
3274 .attrs = decl_instance_attrs ++ .{4237 .attrs = decl_instance_attrs ++ .{
3275 .{ .declaration, .flag },4238 .{ .byte_size, .udata },
4239 .{ .alignment, .udata },
3276 },4240 },
3277 },4241 },
3278 .decl_instance_struct = .{4242 .decl_instance_struct = .{
...@@ -3283,6 +4247,12 @@ pub const AbbrevCode = enum {...@@ -3283,6 +4247,12 @@ pub const AbbrevCode = enum {
3283 .{ .alignment, .udata },4247 .{ .alignment, .udata },
3284 },4248 },
3285 },4249 },
4250 .decl_instance_empty_packed_struct = .{
4251 .tag = .structure_type,
4252 .attrs = decl_instance_attrs ++ .{
4253 .{ .type, .ref_addr },
4254 },
4255 },
3286 .decl_instance_packed_struct = .{4256 .decl_instance_packed_struct = .{
3287 .tag = .structure_type,4257 .tag = .structure_type,
3288 .children = true,4258 .children = true,
...@@ -3290,6 +4260,22 @@ pub const AbbrevCode = enum {...@@ -3290,6 +4260,22 @@ pub const AbbrevCode = enum {
3290 .{ .type, .ref_addr },4260 .{ .type, .ref_addr },
3291 },4261 },
3292 },4262 },
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 },
3293 .decl_instance_union = .{4279 .decl_instance_union = .{
3294 .tag = .union_type,4280 .tag = .union_type,
3295 .children = true,4281 .children = true,
...@@ -3298,6 +4284,12 @@ pub const AbbrevCode = enum {...@@ -3298,6 +4284,12 @@ pub const AbbrevCode = enum {
3298 .{ .alignment, .udata },4284 .{ .alignment, .udata },
3299 },4285 },
3300 },4286 },
4287 .decl_instance_empty_packed_union = .{
4288 .tag = .union_type,
4289 .attrs = decl_instance_attrs ++ .{
4290 .{ .type, .ref_addr },
4291 },
4292 },
3301 .decl_instance_packed_union = .{4293 .decl_instance_packed_union = .{
3302 .tag = .union_type,4294 .tag = .union_type,
3303 .children = true,4295 .children = true,
...@@ -3769,114 +4761,21 @@ pub const AbbrevCode = enum {...@@ -3769,114 +4761,21 @@ pub const AbbrevCode = enum {
3769 .{ .alignment, .udata },4761 .{ .alignment, .udata },
3770 },4762 },
3771 },4763 },
3772 .empty_enum_type = .{4764 .capture_specification = .{
3773 .tag = .enumeration_type,4765 .tag = .template_value_parameter,
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,
3863 .attrs = &.{4766 .attrs = &.{
3864 .{ .decl_file, .udata },
3865 .{ .name, .strp },4767 .{ .name, .strp },
3866 .{ .type, .ref_addr },
3867 },4768 },
3868 },4769 },
3869 .comptime_capture = .{4770 .comptime_capture = .{
3870 .tag = .template_value_parameter,4771 .tag = .template_value_parameter,
3871 .attrs = &.{4772 .attrs = &.{
3872 .{ .name, .strp },
3873 .{ .type, .ref_addr },4773 .{ .type, .ref_addr },
3874 },4774 },
3875 },4775 },
3876 .comptime_capture_runtime = .{4776 .comptime_capture_runtime = .{
3877 .tag = .template_value_parameter,4777 .tag = .template_value_parameter,
3878 .attrs = &.{4778 .attrs = &.{
3879 .{ .name, .strp },
3880 .{ .type, .ref_addr },4779 .{ .type, .ref_addr },
3881 .{ .const_value, .block },4780 .{ .const_value, .block },
3882 },4781 },
...@@ -3884,7 +4783,6 @@ pub const AbbrevCode = enum {...@@ -3884,7 +4783,6 @@ pub const AbbrevCode = enum {
3884 .comptime_capture_partially_comptime = .{4783 .comptime_capture_partially_comptime = .{
3885 .tag = .template_value_parameter,4784 .tag = .template_value_parameter,
3886 .attrs = &.{4785 .attrs = &.{
3887 .{ .name, .strp },
3888 .{ .type, .ref_addr },4786 .{ .type, .ref_addr },
3889 .{ .const_value, .block },4787 .{ .const_value, .block },
3890 .{ .ZIG_comptime_value, .ref_addr },4788 .{ .ZIG_comptime_value, .ref_addr },
...@@ -3893,7 +4791,6 @@ pub const AbbrevCode = enum {...@@ -3893,7 +4791,6 @@ pub const AbbrevCode = enum {
3893 .comptime_capture_fully_comptime = .{4791 .comptime_capture_fully_comptime = .{
3894 .tag = .template_value_parameter,4792 .tag = .template_value_parameter,
3895 .attrs = &.{4793 .attrs = &.{
3896 .{ .name, .strp },
3897 .{ .type, .ref_addr },4794 .{ .type, .ref_addr },
3898 .{ .ZIG_comptime_value, .ref_addr },4795 .{ .ZIG_comptime_value, .ref_addr },
3899 },4796 },
...@@ -3901,14 +4798,12 @@ pub const AbbrevCode = enum {...@@ -3901,14 +4798,12 @@ pub const AbbrevCode = enum {
3901 .runtime_capture = .{4798 .runtime_capture = .{
3902 .tag = .template_type_parameter,4799 .tag = .template_type_parameter,
3903 .attrs = &.{4800 .attrs = &.{
3904 .{ .name, .strp },
3905 .{ .type, .ref_addr },4801 .{ .type, .ref_addr },
3906 },4802 },
3907 },4803 },
3908 .nav_capture = .{4804 .nav_capture = .{
3909 .tag = .template_value_parameter,4805 .tag = .template_value_parameter,
3910 .attrs = &.{4806 .attrs = &.{
3911 .{ .name, .strp },
3912 .{ .location, .exprloc },4807 .{ .location, .exprloc },
3913 },4808 },
3914 },4809 },
src/link/Elf2.zig+4-2
...@@ -9381,8 +9381,10 @@ fn genPending(elf: *Elf, pt: Zcu.PerThread) link.Error!void {...@@ -9381,8 +9381,10 @@ fn genPending(elf: *Elf, pt: Zcu.PerThread) link.Error!void {
9381 .strip => {},9381 .strip => {},
9382 .dwarf => {9382 .dwarf => {
9383 const gpa = elf.base.comp.gpa;9383 const gpa = elf.base.comp.gpa;
9384 while (elf.dwarf.pending_decl) |pending| {9384 while (true) {
9385 elf.dwarf.pending_decl = null;9385 const pending = elf.dwarf.pending_decl;
9386 if (pending.instance_val == .none) break;
9387 elf.dwarf.pending_decl = .{ .di = undefined, .instance_val = .none };
9386 const debug_info_ni = pending.di.get(&elf.dwarf).debug_info_ni.unwrap().?;9388 const debug_info_ni = pending.di.get(&elf.dwarf).debug_info_ni.unwrap().?;
9387 try debug_info_ni.moved(gpa, &elf.mf);9389 try debug_info_ni.moved(gpa, &elf.mf);
9388 var di_nw: MappedFile.Node.Writer = undefined;9390 var di_nw: MappedFile.Node.Writer = undefined;
src/print_zir.zig+11-3
...@@ -1452,6 +1452,8 @@ const Writer = struct {...@@ -1452,6 +1452,8 @@ const Writer = struct {
1452 self.parent_decl_node = struct_decl.src_node;1452 self.parent_decl_node = struct_decl.src_node;
1453 defer self.parent_decl_node = prev_parent_decl_node;1453 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
1455 const fields_hash = self.code.getAssociatedSrcHash(inst).?;1457 const fields_hash = self.code.getAssociatedSrcHash(inst).?;
1456 try stream.print("hash({x}) ", .{&fields_hash});1458 try stream.print("hash({x}) ", .{&fields_hash});
14571459
...@@ -1514,6 +1516,8 @@ const Writer = struct {...@@ -1514,6 +1516,8 @@ const Writer = struct {
1514 self.parent_decl_node = union_decl.src_node;1516 self.parent_decl_node = union_decl.src_node;
1515 defer self.parent_decl_node = prev_parent_decl_node;1517 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
1517 const fields_hash = self.code.getAssociatedSrcHash(inst).?;1521 const fields_hash = self.code.getAssociatedSrcHash(inst).?;
1518 try stream.print("hash({x}) ", .{&fields_hash});1522 try stream.print("hash({x}) ", .{&fields_hash});
15191523
...@@ -1590,6 +1594,8 @@ const Writer = struct {...@@ -1590,6 +1594,8 @@ const Writer = struct {
1590 self.parent_decl_node = enum_decl.src_node;1594 self.parent_decl_node = enum_decl.src_node;
1591 defer self.parent_decl_node = prev_parent_decl_node;1595 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
1593 const fields_hash = self.code.getAssociatedSrcHash(inst).?;1599 const fields_hash = self.code.getAssociatedSrcHash(inst).?;
1594 try stream.print("hash({x}) ", .{&fields_hash});1600 try stream.print("hash({x}) ", .{&fields_hash});
15951601
...@@ -1637,6 +1643,8 @@ const Writer = struct {...@@ -1637,6 +1643,8 @@ const Writer = struct {
1637 self.parent_decl_node = opaque_decl.src_node;1643 self.parent_decl_node = opaque_decl.src_node;
1638 defer self.parent_decl_node = prev_parent_decl_node;1644 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
1640 try stream.print("{s}, ", .{@tagName(opaque_decl.name_strategy)});1648 try stream.print("{s}, ", .{@tagName(opaque_decl.name_strategy)});
1641 try self.writeCaptures(stream, opaque_decl.captures, opaque_decl.capture_names);1649 try self.writeCaptures(stream, opaque_decl.captures, opaque_decl.capture_names);
1642 try stream.writeAll(", ");1650 try stream.writeAll(", ");
...@@ -2216,10 +2224,10 @@ const Writer = struct {...@@ -2216,10 +2224,10 @@ const Writer = struct {
2216 try stream.print("{s} '{s}'", .{ @tagName(decl.kind), self.code.nullTerminatedString(decl.name) });2224 try stream.print("{s} '{s}'", .{ @tagName(decl.kind), self.code.nullTerminatedString(decl.name) });
2217 },2225 },
2218 }2226 }
2227 try stream.print(":{d}:{d}", .{ decl.src_line + 1, decl.src_column + 1 });
2228
2219 const src_hash = self.code.getAssociatedSrcHash(inst).?;2229 const src_hash = self.code.getAssociatedSrcHash(inst).?;
2220 try stream.print(" line({d}) column({d}) hash({x})", .{2230 try stream.print(" hash({x})", .{&src_hash});
2221 decl.src_line, decl.src_column, &src_hash,
2222 });
22232231
2224 {2232 {
2225 if (decl.type_body) |b| {2233 if (decl.type_body) |b| {
test/tests.zig+5-4
...@@ -3416,16 +3416,17 @@ pub fn addIncrementalTests(...@@ -3416,16 +3416,17 @@ pub fn addIncrementalTests(
34163416
3417 if (options.skip_llvm and test_target.backend == .llvm) continue;3417 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
3421 if (options.test_target_filters.len > 0) {3424 if (options.test_target_filters.len > 0) {
3422 for (options.test_target_filters) |filter| {3425 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;
3424 } else continue;3427 } else continue;
3425 }3428 }
34263429
3427 const target_str = b.fmt("{s}-{t}", .{ triple_txt, test_target.backend });
3428
3429 const run = b.addRunArtifact(incr_check);3430 const run = b.addRunArtifact(incr_check);
3430 run.setName(b.fmt("incr-check {s} '{s}'", .{ target_str, entry.basename }));3431 run.setName(b.fmt("incr-check {s} '{s}'", .{ target_str, entry.basename }));
34313432