| author | |
| committer | |
| log | 260c84535546c81028cf42f1eb6ec9f17275db0f |
| tree | 566fd6156bbbbed22741b0d94b996542ee334ae6 |
| parent | 10784c7fc8d419fff943994f1aa5a454d4e43391 |
| signature |
Previously, the `src_node` field of `struct_decl`, `union_decl`,
`enum_decl`, and `opaque_decl` was optional, included in trailing data
only if a flag in `Small` was set. However, this was unnecessary logic:
AstGen always provided the source node. We can simplify a few bits of
logic by making this field non-optional, moving it into non-trailing
data.
There was one place where the field was actually omitted before: the
root struct of a file was at source node 0, so the node was
coincidentally elided. Therefore, this commit has a fixed cost of 4
bytes of ZIR per file.5 files changed, 111 insertions(+), 178 deletions(-)
src/AstGen.zig+19-25| ... | @@ -12918,20 +12918,20 @@ const GenZir = struct { | ... | @@ -12918,20 +12918,20 @@ const GenZir = struct { |
| 12918 | const astgen = gz.astgen; | 12918 | const astgen = gz.astgen; |
| 12919 | const gpa = astgen.gpa; | 12919 | const gpa = astgen.gpa; |
| 12920 | 12920 | ||
| 12921 | // Node 0 is valid for the root `struct_decl` of a file! | ||
| 12922 | assert(args.src_node != 0 or gz.parent.tag == .top); | ||
| 12923 | |||
| 12921 | const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash); | 12924 | const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash); |
| 12922 | 12925 | ||
| 12923 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.StructDecl).Struct.fields.len + 6); | 12926 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.StructDecl).Struct.fields.len + 4); |
| 12924 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.StructDecl{ | 12927 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.StructDecl{ |
| 12925 | .fields_hash_0 = fields_hash_arr[0], | 12928 | .fields_hash_0 = fields_hash_arr[0], |
| 12926 | .fields_hash_1 = fields_hash_arr[1], | 12929 | .fields_hash_1 = fields_hash_arr[1], |
| 12927 | .fields_hash_2 = fields_hash_arr[2], | 12930 | .fields_hash_2 = fields_hash_arr[2], |
| 12928 | .fields_hash_3 = fields_hash_arr[3], | 12931 | .fields_hash_3 = fields_hash_arr[3], |
| 12932 | .src_node = gz.nodeIndexToRelative(args.src_node), | ||
| 12929 | }); | 12933 | }); |
| 12930 | 12934 | ||
| 12931 | if (args.src_node != 0) { | ||
| 12932 | const node_offset = gz.nodeIndexToRelative(args.src_node); | ||
| 12933 | astgen.extra.appendAssumeCapacity(@bitCast(node_offset)); | ||
| 12934 | } | ||
| 12935 | if (args.fields_len != 0) { | 12935 | if (args.fields_len != 0) { |
| 12936 | astgen.extra.appendAssumeCapacity(args.fields_len); | 12936 | astgen.extra.appendAssumeCapacity(args.fields_len); |
| 12937 | } | 12937 | } |
| ... | @@ -12949,7 +12949,6 @@ const GenZir = struct { | ... | @@ -12949,7 +12949,6 @@ const GenZir = struct { |
| 12949 | .data = .{ .extended = .{ | 12949 | .data = .{ .extended = .{ |
| 12950 | .opcode = .struct_decl, | 12950 | .opcode = .struct_decl, |
| 12951 | .small = @bitCast(Zir.Inst.StructDecl.Small{ | 12951 | .small = @bitCast(Zir.Inst.StructDecl.Small{ |
| 12952 | .has_src_node = args.src_node != 0, | ||
| 12953 | .has_fields_len = args.fields_len != 0, | 12952 | .has_fields_len = args.fields_len != 0, |
| 12954 | .has_decls_len = args.decls_len != 0, | 12953 | .has_decls_len = args.decls_len != 0, |
| 12955 | .has_backing_int = args.backing_int_ref != .none, | 12954 | .has_backing_int = args.backing_int_ref != .none, |
| ... | @@ -12981,20 +12980,19 @@ const GenZir = struct { | ... | @@ -12981,20 +12980,19 @@ const GenZir = struct { |
| 12981 | const astgen = gz.astgen; | 12980 | const astgen = gz.astgen; |
| 12982 | const gpa = astgen.gpa; | 12981 | const gpa = astgen.gpa; |
| 12983 | 12982 | ||
| 12983 | assert(args.src_node != 0); | ||
| 12984 | |||
| 12984 | const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash); | 12985 | const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash); |
| 12985 | 12986 | ||
| 12986 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len + 5); | 12987 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len + 4); |
| 12987 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.UnionDecl{ | 12988 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.UnionDecl{ |
| 12988 | .fields_hash_0 = fields_hash_arr[0], | 12989 | .fields_hash_0 = fields_hash_arr[0], |
| 12989 | .fields_hash_1 = fields_hash_arr[1], | 12990 | .fields_hash_1 = fields_hash_arr[1], |
| 12990 | .fields_hash_2 = fields_hash_arr[2], | 12991 | .fields_hash_2 = fields_hash_arr[2], |
| 12991 | .fields_hash_3 = fields_hash_arr[3], | 12992 | .fields_hash_3 = fields_hash_arr[3], |
| 12993 | .src_node = gz.nodeIndexToRelative(args.src_node), | ||
| 12992 | }); | 12994 | }); |
| 12993 | 12995 | ||
| 12994 | if (args.src_node != 0) { | ||
| 12995 | const node_offset = gz.nodeIndexToRelative(args.src_node); | ||
| 12996 | astgen.extra.appendAssumeCapacity(@bitCast(node_offset)); | ||
| 12997 | } | ||
| 12998 | if (args.tag_type != .none) { | 12996 | if (args.tag_type != .none) { |
| 12999 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type)); | 12997 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type)); |
| 13000 | } | 12998 | } |
| ... | @@ -13012,7 +13010,6 @@ const GenZir = struct { | ... | @@ -13012,7 +13010,6 @@ const GenZir = struct { |
| 13012 | .data = .{ .extended = .{ | 13010 | .data = .{ .extended = .{ |
| 13013 | .opcode = .union_decl, | 13011 | .opcode = .union_decl, |
| 13014 | .small = @bitCast(Zir.Inst.UnionDecl.Small{ | 13012 | .small = @bitCast(Zir.Inst.UnionDecl.Small{ |
| 13015 | .has_src_node = args.src_node != 0, | ||
| 13016 | .has_tag_type = args.tag_type != .none, | 13013 | .has_tag_type = args.tag_type != .none, |
| 13017 | .has_body_len = args.body_len != 0, | 13014 | .has_body_len = args.body_len != 0, |
| 13018 | .has_fields_len = args.fields_len != 0, | 13015 | .has_fields_len = args.fields_len != 0, |
| ... | @@ -13039,20 +13036,19 @@ const GenZir = struct { | ... | @@ -13039,20 +13036,19 @@ const GenZir = struct { |
| 13039 | const astgen = gz.astgen; | 13036 | const astgen = gz.astgen; |
| 13040 | const gpa = astgen.gpa; | 13037 | const gpa = astgen.gpa; |
| 13041 | 13038 | ||
| 13039 | assert(args.src_node != 0); | ||
| 13040 | |||
| 13042 | const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash); | 13041 | const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash); |
| 13043 | 13042 | ||
| 13044 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.EnumDecl).Struct.fields.len + 5); | 13043 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.EnumDecl).Struct.fields.len + 4); |
| 13045 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.EnumDecl{ | 13044 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.EnumDecl{ |
| 13046 | .fields_hash_0 = fields_hash_arr[0], | 13045 | .fields_hash_0 = fields_hash_arr[0], |
| 13047 | .fields_hash_1 = fields_hash_arr[1], | 13046 | .fields_hash_1 = fields_hash_arr[1], |
| 13048 | .fields_hash_2 = fields_hash_arr[2], | 13047 | .fields_hash_2 = fields_hash_arr[2], |
| 13049 | .fields_hash_3 = fields_hash_arr[3], | 13048 | .fields_hash_3 = fields_hash_arr[3], |
| 13049 | .src_node = gz.nodeIndexToRelative(args.src_node), | ||
| 13050 | }); | 13050 | }); |
| 13051 | 13051 | ||
| 13052 | if (args.src_node != 0) { | ||
| 13053 | const node_offset = gz.nodeIndexToRelative(args.src_node); | ||
| 13054 | astgen.extra.appendAssumeCapacity(@bitCast(node_offset)); | ||
| 13055 | } | ||
| 13056 | if (args.tag_type != .none) { | 13052 | if (args.tag_type != .none) { |
| 13057 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type)); | 13053 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type)); |
| 13058 | } | 13054 | } |
| ... | @@ -13070,7 +13066,6 @@ const GenZir = struct { | ... | @@ -13070,7 +13066,6 @@ const GenZir = struct { |
| 13070 | .data = .{ .extended = .{ | 13066 | .data = .{ .extended = .{ |
| 13071 | .opcode = .enum_decl, | 13067 | .opcode = .enum_decl, |
| 13072 | .small = @bitCast(Zir.Inst.EnumDecl.Small{ | 13068 | .small = @bitCast(Zir.Inst.EnumDecl.Small{ |
| 13073 | .has_src_node = args.src_node != 0, | ||
| 13074 | .has_tag_type = args.tag_type != .none, | 13069 | .has_tag_type = args.tag_type != .none, |
| 13075 | .has_body_len = args.body_len != 0, | 13070 | .has_body_len = args.body_len != 0, |
| 13076 | .has_fields_len = args.fields_len != 0, | 13071 | .has_fields_len = args.fields_len != 0, |
| ... | @@ -13090,13 +13085,13 @@ const GenZir = struct { | ... | @@ -13090,13 +13085,13 @@ const GenZir = struct { |
| 13090 | const astgen = gz.astgen; | 13085 | const astgen = gz.astgen; |
| 13091 | const gpa = astgen.gpa; | 13086 | const gpa = astgen.gpa; |
| 13092 | 13087 | ||
| 13093 | try astgen.extra.ensureUnusedCapacity(gpa, 2); | 13088 | assert(args.src_node != 0); |
| 13094 | const payload_index: u32 = @intCast(astgen.extra.items.len); | 13089 | |
| 13090 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.OpaqueDecl).Struct.fields.len + 1); | ||
| 13091 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.OpaqueDecl{ | ||
| 13092 | .src_node = gz.nodeIndexToRelative(args.src_node), | ||
| 13093 | }); | ||
| 13095 | 13094 | ||
| 13096 | if (args.src_node != 0) { | ||
| 13097 | const node_offset = gz.nodeIndexToRelative(args.src_node); | ||
| 13098 | astgen.extra.appendAssumeCapacity(@bitCast(node_offset)); | ||
| 13099 | } | ||
| 13100 | if (args.decls_len != 0) { | 13095 | if (args.decls_len != 0) { |
| 13101 | astgen.extra.appendAssumeCapacity(args.decls_len); | 13096 | astgen.extra.appendAssumeCapacity(args.decls_len); |
| 13102 | } | 13097 | } |
| ... | @@ -13105,7 +13100,6 @@ const GenZir = struct { | ... | @@ -13105,7 +13100,6 @@ const GenZir = struct { |
| 13105 | .data = .{ .extended = .{ | 13100 | .data = .{ .extended = .{ |
| 13106 | .opcode = .opaque_decl, | 13101 | .opcode = .opaque_decl, |
| 13107 | .small = @bitCast(Zir.Inst.OpaqueDecl.Small{ | 13102 | .small = @bitCast(Zir.Inst.OpaqueDecl.Small{ |
| 13108 | .has_src_node = args.src_node != 0, | ||
| 13109 | .has_decls_len = args.decls_len != 0, | 13103 | .has_decls_len = args.decls_len != 0, |
| 13110 | .name_strategy = gz.anon_name_strategy, | 13104 | .name_strategy = gz.anon_name_strategy, |
| 13111 | }), | 13105 | }), |
src/Autodoc.zig+12-45| ... | @@ -3395,19 +3395,10 @@ fn walkInstruction( | ... | @@ -3395,19 +3395,10 @@ fn walkInstruction( |
| 3395 | .enclosing_type = type_slot_index, | 3395 | .enclosing_type = type_slot_index, |
| 3396 | }; | 3396 | }; |
| 3397 | 3397 | ||
| 3398 | const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small)); | 3398 | const extra = file.zir.extraData(Zir.Inst.OpaqueDecl, extended.operand); |
| 3399 | var extra_index: usize = extended.operand; | 3399 | var extra_index: usize = extra.end; |
| 3400 | |||
| 3401 | const src_node: ?i32 = if (small.has_src_node) blk: { | ||
| 3402 | const src_node = @as(i32, @bitCast(file.zir.extra[extra_index])); | ||
| 3403 | extra_index += 1; | ||
| 3404 | break :blk src_node; | ||
| 3405 | } else null; | ||
| 3406 | 3400 | ||
| 3407 | const src_info = if (src_node) |sn| | 3401 | const src_info = try self.srcLocInfo(file, extra.data.src_node, parent_src); |
| 3408 | try self.srcLocInfo(file, sn, parent_src) | ||
| 3409 | else | ||
| 3410 | parent_src; | ||
| 3411 | 3402 | ||
| 3412 | var decl_indexes: std.ArrayListUnmanaged(usize) = .{}; | 3403 | var decl_indexes: std.ArrayListUnmanaged(usize) = .{}; |
| 3413 | var priv_decl_indexes: std.ArrayListUnmanaged(usize) = .{}; | 3404 | var priv_decl_indexes: std.ArrayListUnmanaged(usize) = .{}; |
| ... | @@ -3498,18 +3489,10 @@ fn walkInstruction( | ... | @@ -3498,18 +3489,10 @@ fn walkInstruction( |
| 3498 | }; | 3489 | }; |
| 3499 | 3490 | ||
| 3500 | const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small)); | 3491 | const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small)); |
| 3501 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len; | 3492 | const extra = file.zir.extraData(Zir.Inst.UnionDecl, extended.operand); |
| 3502 | 3493 | var extra_index: usize = extra.end; | |
| 3503 | const src_node: ?i32 = if (small.has_src_node) blk: { | ||
| 3504 | const src_node = @as(i32, @bitCast(file.zir.extra[extra_index])); | ||
| 3505 | extra_index += 1; | ||
| 3506 | break :blk src_node; | ||
| 3507 | } else null; | ||
| 3508 | 3494 | ||
| 3509 | const src_info = if (src_node) |sn| | 3495 | const src_info = try self.srcLocInfo(file, extra.data.src_node, parent_src); |
| 3510 | try self.srcLocInfo(file, sn, parent_src) | ||
| 3511 | else | ||
| 3512 | parent_src; | ||
| 3513 | 3496 | ||
| 3514 | // We delay analysis because union tags can refer to | 3497 | // We delay analysis because union tags can refer to |
| 3515 | // decls defined inside the union itself. | 3498 | // decls defined inside the union itself. |
| ... | @@ -3628,18 +3611,10 @@ fn walkInstruction( | ... | @@ -3628,18 +3611,10 @@ fn walkInstruction( |
| 3628 | }; | 3611 | }; |
| 3629 | 3612 | ||
| 3630 | const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small)); | 3613 | const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small)); |
| 3631 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.EnumDecl).Struct.fields.len; | 3614 | const extra = file.zir.extraData(Zir.Inst.EnumDecl, extended.operand); |
| 3632 | 3615 | var extra_index: usize = extra.end; | |
| 3633 | const src_node: ?i32 = if (small.has_src_node) blk: { | ||
| 3634 | const src_node = @as(i32, @bitCast(file.zir.extra[extra_index])); | ||
| 3635 | extra_index += 1; | ||
| 3636 | break :blk src_node; | ||
| 3637 | } else null; | ||
| 3638 | 3616 | ||
| 3639 | const src_info = if (src_node) |sn| | 3617 | const src_info = try self.srcLocInfo(file, extra.data.src_node, parent_src); |
| 3640 | try self.srcLocInfo(file, sn, parent_src) | ||
| 3641 | else | ||
| 3642 | parent_src; | ||
| 3643 | 3618 | ||
| 3644 | const tag_type: ?DocData.Expr = if (small.has_tag_type) blk: { | 3619 | const tag_type: ?DocData.Expr = if (small.has_tag_type) blk: { |
| 3645 | const tag_type = file.zir.extra[extra_index]; | 3620 | const tag_type = file.zir.extra[extra_index]; |
| ... | @@ -3779,18 +3754,10 @@ fn walkInstruction( | ... | @@ -3779,18 +3754,10 @@ fn walkInstruction( |
| 3779 | }; | 3754 | }; |
| 3780 | 3755 | ||
| 3781 | const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small)); | 3756 | const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small)); |
| 3782 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len; | 3757 | const extra = file.zir.extraData(Zir.Inst.StructDecl, extended.operand); |
| 3783 | 3758 | var extra_index: usize = extra.end; | |
| 3784 | const src_node: ?i32 = if (small.has_src_node) blk: { | ||
| 3785 | const src_node = @as(i32, @bitCast(file.zir.extra[extra_index])); | ||
| 3786 | extra_index += 1; | ||
| 3787 | break :blk src_node; | ||
| 3788 | } else null; | ||
| 3789 | 3759 | ||
| 3790 | const src_info = if (src_node) |sn| | 3760 | const src_info = try self.srcLocInfo(file, extra.data.src_node, parent_src); |
| 3791 | try self.srcLocInfo(file, sn, parent_src) | ||
| 3792 | else | ||
| 3793 | parent_src; | ||
| 3794 | 3761 | ||
| 3795 | const fields_len = if (small.has_fields_len) blk: { | 3762 | const fields_len = if (small.has_fields_len) blk: { |
| 3796 | const fields_len = file.zir.extra[extra_index]; | 3763 | const fields_len = file.zir.extra[extra_index]; |
src/Sema.zig+10-27| ... | @@ -2725,7 +2725,6 @@ pub fn getStructType( | ... | @@ -2725,7 +2725,6 @@ pub fn getStructType( |
| 2725 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 2725 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 2726 | 2726 | ||
| 2727 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len; | 2727 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len; |
| 2728 | extra_index += @intFromBool(small.has_src_node); | ||
| 2729 | const fields_len = if (small.has_fields_len) blk: { | 2728 | const fields_len = if (small.has_fields_len) blk: { |
| 2730 | const fields_len = sema.code.extra[extra_index]; | 2729 | const fields_len = sema.code.extra[extra_index]; |
| 2731 | extra_index += 1; | 2730 | extra_index += 1; |
| ... | @@ -2778,10 +2777,7 @@ fn zirStructDecl( | ... | @@ -2778,10 +2777,7 @@ fn zirStructDecl( |
| 2778 | const mod = sema.mod; | 2777 | const mod = sema.mod; |
| 2779 | const ip = &mod.intern_pool; | 2778 | const ip = &mod.intern_pool; |
| 2780 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 2779 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 2781 | const src: LazySrcLoc = if (small.has_src_node) blk: { | 2780 | const src = sema.code.extraData(Zir.Inst.StructDecl, extended.operand).data.src(); |
| 2782 | const node_offset: i32 = @bitCast(sema.code.extra[extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len]); | ||
| 2783 | break :blk LazySrcLoc.nodeOffset(node_offset); | ||
| 2784 | } else unreachable; // MLUGG TODO | ||
| 2785 | 2781 | ||
| 2786 | // Because these three things each reference each other, `undefined` | 2782 | // Because these three things each reference each other, `undefined` |
| 2787 | // placeholders are used before being set after the struct type gains an | 2783 | // placeholders are used before being set after the struct type gains an |
| ... | @@ -2941,13 +2937,10 @@ fn zirEnumDecl( | ... | @@ -2941,13 +2937,10 @@ fn zirEnumDecl( |
| 2941 | const mod = sema.mod; | 2937 | const mod = sema.mod; |
| 2942 | const gpa = sema.gpa; | 2938 | const gpa = sema.gpa; |
| 2943 | const small: Zir.Inst.EnumDecl.Small = @bitCast(extended.small); | 2939 | const small: Zir.Inst.EnumDecl.Small = @bitCast(extended.small); |
| 2944 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.EnumDecl).Struct.fields.len; | 2940 | const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand); |
| 2941 | var extra_index: usize = extra.end; | ||
| 2945 | 2942 | ||
| 2946 | const src: LazySrcLoc = if (small.has_src_node) blk: { | 2943 | const src = extra.data.src(); |
| 2947 | const node_offset: i32 = @bitCast(sema.code.extra[extra_index]); | ||
| 2948 | extra_index += 1; | ||
| 2949 | break :blk LazySrcLoc.nodeOffset(node_offset); | ||
| 2950 | } else unreachable; // MLUGG TODO | ||
| 2951 | const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x }; | 2944 | const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x }; |
| 2952 | 2945 | ||
| 2953 | const tag_type_ref = if (small.has_tag_type) blk: { | 2946 | const tag_type_ref = if (small.has_tag_type) blk: { |
| ... | @@ -3214,13 +3207,10 @@ fn zirUnionDecl( | ... | @@ -3214,13 +3207,10 @@ fn zirUnionDecl( |
| 3214 | const mod = sema.mod; | 3207 | const mod = sema.mod; |
| 3215 | const gpa = sema.gpa; | 3208 | const gpa = sema.gpa; |
| 3216 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); | 3209 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); |
| 3217 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len; | 3210 | const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand); |
| 3211 | var extra_index: usize = extra.end; | ||
| 3218 | 3212 | ||
| 3219 | const src: LazySrcLoc = if (small.has_src_node) blk: { | 3213 | const src = extra.data.src(); |
| 3220 | const node_offset: i32 = @bitCast(sema.code.extra[extra_index]); | ||
| 3221 | extra_index += 1; | ||
| 3222 | break :blk LazySrcLoc.nodeOffset(node_offset); | ||
| 3223 | } else unreachable; // MLUGG TODO | ||
| 3224 | 3214 | ||
| 3225 | extra_index += @intFromBool(small.has_tag_type); | 3215 | extra_index += @intFromBool(small.has_tag_type); |
| 3226 | extra_index += @intFromBool(small.has_body_len); | 3216 | extra_index += @intFromBool(small.has_body_len); |
| ... | @@ -3323,13 +3313,10 @@ fn zirOpaqueDecl( | ... | @@ -3323,13 +3313,10 @@ fn zirOpaqueDecl( |
| 3323 | 3313 | ||
| 3324 | const mod = sema.mod; | 3314 | const mod = sema.mod; |
| 3325 | const small: Zir.Inst.OpaqueDecl.Small = @bitCast(extended.small); | 3315 | const small: Zir.Inst.OpaqueDecl.Small = @bitCast(extended.small); |
| 3326 | var extra_index: usize = extended.operand; | 3316 | const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand); |
| 3317 | var extra_index: usize = extra.end; | ||
| 3327 | 3318 | ||
| 3328 | const src: LazySrcLoc = if (small.has_src_node) blk: { | 3319 | const src = extra.data.src(); |
| 3329 | const node_offset: i32 = @bitCast(sema.code.extra[extra_index]); | ||
| 3330 | extra_index += 1; | ||
| 3331 | break :blk LazySrcLoc.nodeOffset(node_offset); | ||
| 3332 | } else unreachable; // MLUGG TODO | ||
| 3333 | 3320 | ||
| 3334 | const decls_len = if (small.has_decls_len) blk: { | 3321 | const decls_len = if (small.has_decls_len) blk: { |
| 3335 | const decls_len = sema.code.extra[extra_index]; | 3322 | const decls_len = sema.code.extra[extra_index]; |
| ... | @@ -35662,7 +35649,6 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp | ... | @@ -35662,7 +35649,6 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp |
| 35662 | 35649 | ||
| 35663 | if (small.has_backing_int) { | 35650 | if (small.has_backing_int) { |
| 35664 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len; | 35651 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len; |
| 35665 | extra_index += @intFromBool(small.has_src_node); | ||
| 35666 | extra_index += @intFromBool(small.has_fields_len); | 35652 | extra_index += @intFromBool(small.has_fields_len); |
| 35667 | extra_index += @intFromBool(small.has_decls_len); | 35653 | extra_index += @intFromBool(small.has_decls_len); |
| 35668 | 35654 | ||
| ... | @@ -36374,8 +36360,6 @@ fn structZirInfo(zir: Zir, zir_index: Zir.Inst.Index) struct { | ... | @@ -36374,8 +36360,6 @@ fn structZirInfo(zir: Zir, zir_index: Zir.Inst.Index) struct { |
| 36374 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 36360 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 36375 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len; | 36361 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len; |
| 36376 | 36362 | ||
| 36377 | extra_index += @intFromBool(small.has_src_node); | ||
| 36378 | |||
| 36379 | const fields_len = if (small.has_fields_len) blk: { | 36363 | const fields_len = if (small.has_fields_len) blk: { |
| 36380 | const fields_len = zir.extra[extra_index]; | 36364 | const fields_len = zir.extra[extra_index]; |
| 36381 | extra_index += 1; | 36365 | extra_index += 1; |
| ... | @@ -36843,7 +36827,6 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -36843,7 +36827,6 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 36843 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len; | 36827 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len; |
| 36844 | 36828 | ||
| 36845 | const src = LazySrcLoc.nodeOffset(0); | 36829 | const src = LazySrcLoc.nodeOffset(0); |
| 36846 | extra_index += @intFromBool(small.has_src_node); | ||
| 36847 | 36830 | ||
| 36848 | const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: { | 36831 | const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: { |
| 36849 | const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); | 36832 | const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); |
src/Zir.zig+56-44| ... | @@ -3022,20 +3022,19 @@ pub const Inst = struct { | ... | @@ -3022,20 +3022,19 @@ pub const Inst = struct { |
| 3022 | }; | 3022 | }; |
| 3023 | 3023 | ||
| 3024 | /// Trailing: | 3024 | /// Trailing: |
| 3025 | /// 0. src_node: i32, // if has_src_node | 3025 | /// 0. fields_len: u32, // if has_fields_len |
| 3026 | /// 1. fields_len: u32, // if has_fields_len | 3026 | /// 1. decls_len: u32, // if has_decls_len |
| 3027 | /// 2. decls_len: u32, // if has_decls_len | 3027 | /// 2. backing_int_body_len: u32, // if has_backing_int |
| 3028 | /// 3. backing_int_body_len: u32, // if has_backing_int | 3028 | /// 3. backing_int_ref: Ref, // if has_backing_int and backing_int_body_len is 0 |
| 3029 | /// 4. backing_int_ref: Ref, // if has_backing_int and backing_int_body_len is 0 | 3029 | /// 4. backing_int_body_inst: Inst, // if has_backing_int and backing_int_body_len is > 0 |
| 3030 | /// 5. backing_int_body_inst: Inst, // if has_backing_int and backing_int_body_len is > 0 | 3030 | /// 5. decl: Index, // for every decls_len; points to a `declaration` instruction |
| 3031 | /// 6. decl: Index, // for every decls_len; points to a `declaration` instruction | 3031 | /// 6. flags: u32 // for every 8 fields |
| 3032 | /// 7. flags: u32 // for every 8 fields | ||
| 3033 | /// - sets of 4 bits: | 3032 | /// - sets of 4 bits: |
| 3034 | /// 0b000X: whether corresponding field has an align expression | 3033 | /// 0b000X: whether corresponding field has an align expression |
| 3035 | /// 0b00X0: whether corresponding field has a default expression | 3034 | /// 0b00X0: whether corresponding field has a default expression |
| 3036 | /// 0b0X00: whether corresponding field is comptime | 3035 | /// 0b0X00: whether corresponding field is comptime |
| 3037 | /// 0bX000: whether corresponding field has a type expression | 3036 | /// 0bX000: whether corresponding field has a type expression |
| 3038 | /// 8. fields: { // for every fields_len | 3037 | /// 7. fields: { // for every fields_len |
| 3039 | /// field_name: u32, // if !is_tuple | 3038 | /// field_name: u32, // if !is_tuple |
| 3040 | /// doc_comment: NullTerminatedString, // .empty if no doc comment | 3039 | /// doc_comment: NullTerminatedString, // .empty if no doc comment |
| 3041 | /// field_type: Ref, // if corresponding bit is not set. none means anytype. | 3040 | /// field_type: Ref, // if corresponding bit is not set. none means anytype. |
| ... | @@ -3043,7 +3042,7 @@ pub const Inst = struct { | ... | @@ -3043,7 +3042,7 @@ pub const Inst = struct { |
| 3043 | /// align_body_len: u32, // if corresponding bit is set | 3042 | /// align_body_len: u32, // if corresponding bit is set |
| 3044 | /// init_body_len: u32, // if corresponding bit is set | 3043 | /// init_body_len: u32, // if corresponding bit is set |
| 3045 | /// } | 3044 | /// } |
| 3046 | /// 10. bodies: { // for every fields_len | 3045 | /// 8. bodies: { // for every fields_len |
| 3047 | /// field_type_body_inst: Inst, // for each field_type_body_len | 3046 | /// field_type_body_inst: Inst, // for each field_type_body_len |
| 3048 | /// align_body_inst: Inst, // for each align_body_len | 3047 | /// align_body_inst: Inst, // for each align_body_len |
| 3049 | /// init_body_inst: Inst, // for each init_body_len | 3048 | /// init_body_inst: Inst, // for each init_body_len |
| ... | @@ -3055,8 +3054,13 @@ pub const Inst = struct { | ... | @@ -3055,8 +3054,13 @@ pub const Inst = struct { |
| 3055 | fields_hash_1: u32, | 3054 | fields_hash_1: u32, |
| 3056 | fields_hash_2: u32, | 3055 | fields_hash_2: u32, |
| 3057 | fields_hash_3: u32, | 3056 | fields_hash_3: u32, |
| 3057 | src_node: i32, | ||
| 3058 | |||
| 3059 | pub fn src(self: StructDecl) LazySrcLoc { | ||
| 3060 | return LazySrcLoc.nodeOffset(self.src_node); | ||
| 3061 | } | ||
| 3062 | |||
| 3058 | pub const Small = packed struct { | 3063 | pub const Small = packed struct { |
| 3059 | has_src_node: bool, | ||
| 3060 | has_fields_len: bool, | 3064 | has_fields_len: bool, |
| 3061 | has_decls_len: bool, | 3065 | has_decls_len: bool, |
| 3062 | has_backing_int: bool, | 3066 | has_backing_int: bool, |
| ... | @@ -3068,7 +3072,7 @@ pub const Inst = struct { | ... | @@ -3068,7 +3072,7 @@ pub const Inst = struct { |
| 3068 | any_default_inits: bool, | 3072 | any_default_inits: bool, |
| 3069 | any_comptime_fields: bool, | 3073 | any_comptime_fields: bool, |
| 3070 | any_aligned_fields: bool, | 3074 | any_aligned_fields: bool, |
| 3071 | _: u2 = undefined, | 3075 | _: u3 = undefined, |
| 3072 | }; | 3076 | }; |
| 3073 | }; | 3077 | }; |
| 3074 | 3078 | ||
| ... | @@ -3102,16 +3106,15 @@ pub const Inst = struct { | ... | @@ -3102,16 +3106,15 @@ pub const Inst = struct { |
| 3102 | }; | 3106 | }; |
| 3103 | 3107 | ||
| 3104 | /// Trailing: | 3108 | /// Trailing: |
| 3105 | /// 0. src_node: i32, // if has_src_node | 3109 | /// 0. tag_type: Ref, // if has_tag_type |
| 3106 | /// 1. tag_type: Ref, // if has_tag_type | 3110 | /// 1. body_len: u32, // if has_body_len |
| 3107 | /// 2. body_len: u32, // if has_body_len | 3111 | /// 2. fields_len: u32, // if has_fields_len |
| 3108 | /// 3. fields_len: u32, // if has_fields_len | 3112 | /// 3. decls_len: u32, // if has_decls_len |
| 3109 | /// 4. decls_len: u32, // if has_decls_len | 3113 | /// 4. decl: Index, // for every decls_len; points to a `declaration` instruction |
| 3110 | /// 5. decl: Index, // for every decls_len; points to a `declaration` instruction | 3114 | /// 5. inst: Index // for every body_len |
| 3111 | /// 6. inst: Index // for every body_len | 3115 | /// 6. has_bits: u32 // for every 32 fields |
| 3112 | /// 7. has_bits: u32 // for every 32 fields | ||
| 3113 | /// - the bit is whether corresponding field has an value expression | 3116 | /// - the bit is whether corresponding field has an value expression |
| 3114 | /// 8. fields: { // for every fields_len | 3117 | /// 7. fields: { // for every fields_len |
| 3115 | /// field_name: u32, | 3118 | /// field_name: u32, |
| 3116 | /// doc_comment: u32, // .empty if no doc_comment | 3119 | /// doc_comment: u32, // .empty if no doc_comment |
| 3117 | /// value: Ref, // if corresponding bit is set | 3120 | /// value: Ref, // if corresponding bit is set |
| ... | @@ -3123,33 +3126,37 @@ pub const Inst = struct { | ... | @@ -3123,33 +3126,37 @@ pub const Inst = struct { |
| 3123 | fields_hash_1: u32, | 3126 | fields_hash_1: u32, |
| 3124 | fields_hash_2: u32, | 3127 | fields_hash_2: u32, |
| 3125 | fields_hash_3: u32, | 3128 | fields_hash_3: u32, |
| 3129 | src_node: i32, | ||
| 3130 | |||
| 3131 | pub fn src(self: EnumDecl) LazySrcLoc { | ||
| 3132 | return LazySrcLoc.nodeOffset(self.src_node); | ||
| 3133 | } | ||
| 3134 | |||
| 3126 | pub const Small = packed struct { | 3135 | pub const Small = packed struct { |
| 3127 | has_src_node: bool, | ||
| 3128 | has_tag_type: bool, | 3136 | has_tag_type: bool, |
| 3129 | has_body_len: bool, | 3137 | has_body_len: bool, |
| 3130 | has_fields_len: bool, | 3138 | has_fields_len: bool, |
| 3131 | has_decls_len: bool, | 3139 | has_decls_len: bool, |
| 3132 | name_strategy: NameStrategy, | 3140 | name_strategy: NameStrategy, |
| 3133 | nonexhaustive: bool, | 3141 | nonexhaustive: bool, |
| 3134 | _: u8 = undefined, | 3142 | _: u9 = undefined, |
| 3135 | }; | 3143 | }; |
| 3136 | }; | 3144 | }; |
| 3137 | 3145 | ||
| 3138 | /// Trailing: | 3146 | /// Trailing: |
| 3139 | /// 0. src_node: i32, // if has_src_node | 3147 | /// 0. tag_type: Ref, // if has_tag_type |
| 3140 | /// 1. tag_type: Ref, // if has_tag_type | 3148 | /// 1. body_len: u32, // if has_body_len |
| 3141 | /// 2. body_len: u32, // if has_body_len | 3149 | /// 2. fields_len: u32, // if has_fields_len |
| 3142 | /// 3. fields_len: u32, // if has_fields_len | 3150 | /// 3. decls_len: u32, // if has_decls_len |
| 3143 | /// 4. decls_len: u32, // if has_decls_len | 3151 | /// 4. decl: Index, // for every decls_len; points to a `declaration` instruction |
| 3144 | /// 5. decl: Index, // for every decls_len; points to a `declaration` instruction | 3152 | /// 5. inst: Index // for every body_len |
| 3145 | /// 6. inst: Index // for every body_len | 3153 | /// 6. has_bits: u32 // for every 8 fields |
| 3146 | /// 7. has_bits: u32 // for every 8 fields | ||
| 3147 | /// - sets of 4 bits: | 3154 | /// - sets of 4 bits: |
| 3148 | /// 0b000X: whether corresponding field has a type expression | 3155 | /// 0b000X: whether corresponding field has a type expression |
| 3149 | /// 0b00X0: whether corresponding field has a align expression | 3156 | /// 0b00X0: whether corresponding field has a align expression |
| 3150 | /// 0b0X00: whether corresponding field has a tag value expression | 3157 | /// 0b0X00: whether corresponding field has a tag value expression |
| 3151 | /// 0bX000: unused | 3158 | /// 0bX000: unused |
| 3152 | /// 8. fields: { // for every fields_len | 3159 | /// 7. fields: { // for every fields_len |
| 3153 | /// field_name: NullTerminatedString, // null terminated string index | 3160 | /// field_name: NullTerminatedString, // null terminated string index |
| 3154 | /// doc_comment: NullTerminatedString, // .empty if no doc comment | 3161 | /// doc_comment: NullTerminatedString, // .empty if no doc comment |
| 3155 | /// field_type: Ref, // if corresponding bit is set | 3162 | /// field_type: Ref, // if corresponding bit is set |
| ... | @@ -3164,8 +3171,13 @@ pub const Inst = struct { | ... | @@ -3164,8 +3171,13 @@ pub const Inst = struct { |
| 3164 | fields_hash_1: u32, | 3171 | fields_hash_1: u32, |
| 3165 | fields_hash_2: u32, | 3172 | fields_hash_2: u32, |
| 3166 | fields_hash_3: u32, | 3173 | fields_hash_3: u32, |
| 3174 | src_node: i32, | ||
| 3175 | |||
| 3176 | pub fn src(self: UnionDecl) LazySrcLoc { | ||
| 3177 | return LazySrcLoc.nodeOffset(self.src_node); | ||
| 3178 | } | ||
| 3179 | |||
| 3167 | pub const Small = packed struct { | 3180 | pub const Small = packed struct { |
| 3168 | has_src_node: bool, | ||
| 3169 | has_tag_type: bool, | 3181 | has_tag_type: bool, |
| 3170 | has_body_len: bool, | 3182 | has_body_len: bool, |
| 3171 | has_fields_len: bool, | 3183 | has_fields_len: bool, |
| ... | @@ -3180,20 +3192,24 @@ pub const Inst = struct { | ... | @@ -3180,20 +3192,24 @@ pub const Inst = struct { |
| 3180 | /// true | false | union(T) { } | 3192 | /// true | false | union(T) { } |
| 3181 | auto_enum_tag: bool, | 3193 | auto_enum_tag: bool, |
| 3182 | any_aligned_fields: bool, | 3194 | any_aligned_fields: bool, |
| 3183 | _: u5 = undefined, | 3195 | _: u6 = undefined, |
| 3184 | }; | 3196 | }; |
| 3185 | }; | 3197 | }; |
| 3186 | 3198 | ||
| 3187 | /// Trailing: | 3199 | /// Trailing: |
| 3188 | /// 0. src_node: i32, // if has_src_node | 3200 | /// 0. decls_len: u32, // if has_decls_len |
| 3189 | /// 1. decls_len: u32, // if has_decls_len | 3201 | /// 1. decl: Index, // for every decls_len; points to a `declaration` instruction |
| 3190 | /// 2. decl: Index, // for every decls_len; points to a `declaration` instruction | ||
| 3191 | pub const OpaqueDecl = struct { | 3202 | pub const OpaqueDecl = struct { |
| 3203 | src_node: i32, | ||
| 3204 | |||
| 3205 | pub fn src(self: OpaqueDecl) LazySrcLoc { | ||
| 3206 | return LazySrcLoc.nodeOffset(self.src_node); | ||
| 3207 | } | ||
| 3208 | |||
| 3192 | pub const Small = packed struct { | 3209 | pub const Small = packed struct { |
| 3193 | has_src_node: bool, | ||
| 3194 | has_decls_len: bool, | 3210 | has_decls_len: bool, |
| 3195 | name_strategy: NameStrategy, | 3211 | name_strategy: NameStrategy, |
| 3196 | _: u12 = undefined, | 3212 | _: u13 = undefined, |
| 3197 | }; | 3213 | }; |
| 3198 | }; | 3214 | }; |
| 3199 | 3215 | ||
| ... | @@ -3495,7 +3511,6 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { | ... | @@ -3495,7 +3511,6 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { |
| 3495 | .struct_decl => { | 3511 | .struct_decl => { |
| 3496 | const small: Inst.StructDecl.Small = @bitCast(extended.small); | 3512 | const small: Inst.StructDecl.Small = @bitCast(extended.small); |
| 3497 | var extra_index: u32 = @intCast(extended.operand + @typeInfo(Inst.StructDecl).Struct.fields.len); | 3513 | var extra_index: u32 = @intCast(extended.operand + @typeInfo(Inst.StructDecl).Struct.fields.len); |
| 3498 | extra_index += @intFromBool(small.has_src_node); | ||
| 3499 | extra_index += @intFromBool(small.has_fields_len); | 3514 | extra_index += @intFromBool(small.has_fields_len); |
| 3500 | const decls_len = if (small.has_decls_len) decls_len: { | 3515 | const decls_len = if (small.has_decls_len) decls_len: { |
| 3501 | const decls_len = zir.extra[extra_index]; | 3516 | const decls_len = zir.extra[extra_index]; |
| ... | @@ -3522,7 +3537,6 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { | ... | @@ -3522,7 +3537,6 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { |
| 3522 | .enum_decl => { | 3537 | .enum_decl => { |
| 3523 | const small: Inst.EnumDecl.Small = @bitCast(extended.small); | 3538 | const small: Inst.EnumDecl.Small = @bitCast(extended.small); |
| 3524 | var extra_index: u32 = @intCast(extended.operand + @typeInfo(Inst.EnumDecl).Struct.fields.len); | 3539 | var extra_index: u32 = @intCast(extended.operand + @typeInfo(Inst.EnumDecl).Struct.fields.len); |
| 3525 | extra_index += @intFromBool(small.has_src_node); | ||
| 3526 | extra_index += @intFromBool(small.has_tag_type); | 3540 | extra_index += @intFromBool(small.has_tag_type); |
| 3527 | extra_index += @intFromBool(small.has_body_len); | 3541 | extra_index += @intFromBool(small.has_body_len); |
| 3528 | extra_index += @intFromBool(small.has_fields_len); | 3542 | extra_index += @intFromBool(small.has_fields_len); |
| ... | @@ -3541,7 +3555,6 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { | ... | @@ -3541,7 +3555,6 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { |
| 3541 | .union_decl => { | 3555 | .union_decl => { |
| 3542 | const small: Inst.UnionDecl.Small = @bitCast(extended.small); | 3556 | const small: Inst.UnionDecl.Small = @bitCast(extended.small); |
| 3543 | var extra_index: u32 = @intCast(extended.operand + @typeInfo(Inst.UnionDecl).Struct.fields.len); | 3557 | var extra_index: u32 = @intCast(extended.operand + @typeInfo(Inst.UnionDecl).Struct.fields.len); |
| 3544 | extra_index += @intFromBool(small.has_src_node); | ||
| 3545 | extra_index += @intFromBool(small.has_tag_type); | 3558 | extra_index += @intFromBool(small.has_tag_type); |
| 3546 | extra_index += @intFromBool(small.has_body_len); | 3559 | extra_index += @intFromBool(small.has_body_len); |
| 3547 | extra_index += @intFromBool(small.has_fields_len); | 3560 | extra_index += @intFromBool(small.has_fields_len); |
| ... | @@ -3559,8 +3572,7 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { | ... | @@ -3559,8 +3572,7 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { |
| 3559 | }, | 3572 | }, |
| 3560 | .opaque_decl => { | 3573 | .opaque_decl => { |
| 3561 | const small: Inst.OpaqueDecl.Small = @bitCast(extended.small); | 3574 | const small: Inst.OpaqueDecl.Small = @bitCast(extended.small); |
| 3562 | var extra_index: u32 = extended.operand; | 3575 | var extra_index: u32 = @intCast(extended.operand + @typeInfo(Inst.OpaqueDecl).Struct.fields.len); |
| 3563 | extra_index += @intFromBool(small.has_src_node); | ||
| 3564 | const decls_len = if (small.has_decls_len) decls_len: { | 3576 | const decls_len = if (small.has_decls_len) decls_len: { |
| 3565 | const decls_len = zir.extra[extra_index]; | 3577 | const decls_len = zir.extra[extra_index]; |
| 3566 | extra_index += 1; | 3578 | extra_index += 1; |
src/print_zir.zig+14-37| ... | @@ -1405,12 +1405,6 @@ const Writer = struct { | ... | @@ -1405,12 +1405,6 @@ const Writer = struct { |
| 1405 | 1405 | ||
| 1406 | var extra_index: usize = extra.end; | 1406 | var extra_index: usize = extra.end; |
| 1407 | 1407 | ||
| 1408 | const src_node: ?i32 = if (small.has_src_node) blk: { | ||
| 1409 | const src_node = @as(i32, @bitCast(self.code.extra[extra_index])); | ||
| 1410 | extra_index += 1; | ||
| 1411 | break :blk src_node; | ||
| 1412 | } else null; | ||
| 1413 | |||
| 1414 | const fields_len = if (small.has_fields_len) blk: { | 1408 | const fields_len = if (small.has_fields_len) blk: { |
| 1415 | const fields_len = self.code.extra[extra_index]; | 1409 | const fields_len = self.code.extra[extra_index]; |
| 1416 | extra_index += 1; | 1410 | extra_index += 1; |
| ... | @@ -1453,7 +1447,7 @@ const Writer = struct { | ... | @@ -1453,7 +1447,7 @@ const Writer = struct { |
| 1453 | try stream.writeAll("{}, "); | 1447 | try stream.writeAll("{}, "); |
| 1454 | } else { | 1448 | } else { |
| 1455 | const prev_parent_decl_node = self.parent_decl_node; | 1449 | const prev_parent_decl_node = self.parent_decl_node; |
| 1456 | if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off); | 1450 | self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node); |
| 1457 | defer self.parent_decl_node = prev_parent_decl_node; | 1451 | defer self.parent_decl_node = prev_parent_decl_node; |
| 1458 | 1452 | ||
| 1459 | try stream.writeAll("{\n"); | 1453 | try stream.writeAll("{\n"); |
| ... | @@ -1534,7 +1528,7 @@ const Writer = struct { | ... | @@ -1534,7 +1528,7 @@ const Writer = struct { |
| 1534 | } | 1528 | } |
| 1535 | 1529 | ||
| 1536 | const prev_parent_decl_node = self.parent_decl_node; | 1530 | const prev_parent_decl_node = self.parent_decl_node; |
| 1537 | if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off); | 1531 | self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node); |
| 1538 | try stream.writeAll("{\n"); | 1532 | try stream.writeAll("{\n"); |
| 1539 | self.indent += 2; | 1533 | self.indent += 2; |
| 1540 | 1534 | ||
| ... | @@ -1587,7 +1581,7 @@ const Writer = struct { | ... | @@ -1587,7 +1581,7 @@ const Writer = struct { |
| 1587 | try stream.writeByteNTimes(' ', self.indent); | 1581 | try stream.writeByteNTimes(' ', self.indent); |
| 1588 | try stream.writeAll("})"); | 1582 | try stream.writeAll("})"); |
| 1589 | } | 1583 | } |
| 1590 | try self.writeSrcNode(stream, src_node); | 1584 | try self.writeSrcNode(stream, extra.data.src_node); |
| 1591 | } | 1585 | } |
| 1592 | 1586 | ||
| 1593 | fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { | 1587 | fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { |
| ... | @@ -1605,12 +1599,6 @@ const Writer = struct { | ... | @@ -1605,12 +1599,6 @@ const Writer = struct { |
| 1605 | 1599 | ||
| 1606 | var extra_index: usize = extra.end; | 1600 | var extra_index: usize = extra.end; |
| 1607 | 1601 | ||
| 1608 | const src_node: ?i32 = if (small.has_src_node) blk: { | ||
| 1609 | const src_node = @as(i32, @bitCast(self.code.extra[extra_index])); | ||
| 1610 | extra_index += 1; | ||
| 1611 | break :blk src_node; | ||
| 1612 | } else null; | ||
| 1613 | |||
| 1614 | const tag_type_ref = if (small.has_tag_type) blk: { | 1602 | const tag_type_ref = if (small.has_tag_type) blk: { |
| 1615 | const tag_type_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); | 1603 | const tag_type_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); |
| 1616 | extra_index += 1; | 1604 | extra_index += 1; |
| ... | @@ -1644,7 +1632,7 @@ const Writer = struct { | ... | @@ -1644,7 +1632,7 @@ const Writer = struct { |
| 1644 | try stream.writeAll("{}"); | 1632 | try stream.writeAll("{}"); |
| 1645 | } else { | 1633 | } else { |
| 1646 | const prev_parent_decl_node = self.parent_decl_node; | 1634 | const prev_parent_decl_node = self.parent_decl_node; |
| 1647 | if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off); | 1635 | self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node); |
| 1648 | defer self.parent_decl_node = prev_parent_decl_node; | 1636 | defer self.parent_decl_node = prev_parent_decl_node; |
| 1649 | 1637 | ||
| 1650 | try stream.writeAll("{\n"); | 1638 | try stream.writeAll("{\n"); |
| ... | @@ -1663,7 +1651,7 @@ const Writer = struct { | ... | @@ -1663,7 +1651,7 @@ const Writer = struct { |
| 1663 | 1651 | ||
| 1664 | if (fields_len == 0) { | 1652 | if (fields_len == 0) { |
| 1665 | try stream.writeAll("})"); | 1653 | try stream.writeAll("})"); |
| 1666 | try self.writeSrcNode(stream, src_node); | 1654 | try self.writeSrcNode(stream, extra.data.src_node); |
| 1667 | return; | 1655 | return; |
| 1668 | } | 1656 | } |
| 1669 | try stream.writeAll(", "); | 1657 | try stream.writeAll(", "); |
| ... | @@ -1672,7 +1660,7 @@ const Writer = struct { | ... | @@ -1672,7 +1660,7 @@ const Writer = struct { |
| 1672 | extra_index += body.len; | 1660 | extra_index += body.len; |
| 1673 | 1661 | ||
| 1674 | const prev_parent_decl_node = self.parent_decl_node; | 1662 | const prev_parent_decl_node = self.parent_decl_node; |
| 1675 | if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off); | 1663 | self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node); |
| 1676 | try self.writeBracedDecl(stream, body); | 1664 | try self.writeBracedDecl(stream, body); |
| 1677 | try stream.writeAll(", {\n"); | 1665 | try stream.writeAll(", {\n"); |
| 1678 | 1666 | ||
| ... | @@ -1740,7 +1728,7 @@ const Writer = struct { | ... | @@ -1740,7 +1728,7 @@ const Writer = struct { |
| 1740 | self.indent -= 2; | 1728 | self.indent -= 2; |
| 1741 | try stream.writeByteNTimes(' ', self.indent); | 1729 | try stream.writeByteNTimes(' ', self.indent); |
| 1742 | try stream.writeAll("})"); | 1730 | try stream.writeAll("})"); |
| 1743 | try self.writeSrcNode(stream, src_node); | 1731 | try self.writeSrcNode(stream, extra.data.src_node); |
| 1744 | } | 1732 | } |
| 1745 | 1733 | ||
| 1746 | fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { | 1734 | fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { |
| ... | @@ -1758,12 +1746,6 @@ const Writer = struct { | ... | @@ -1758,12 +1746,6 @@ const Writer = struct { |
| 1758 | 1746 | ||
| 1759 | var extra_index: usize = extra.end; | 1747 | var extra_index: usize = extra.end; |
| 1760 | 1748 | ||
| 1761 | const src_node: ?i32 = if (small.has_src_node) blk: { | ||
| 1762 | const src_node = @as(i32, @bitCast(self.code.extra[extra_index])); | ||
| 1763 | extra_index += 1; | ||
| 1764 | break :blk src_node; | ||
| 1765 | } else null; | ||
| 1766 | |||
| 1767 | const tag_type_ref = if (small.has_tag_type) blk: { | 1749 | const tag_type_ref = if (small.has_tag_type) blk: { |
| 1768 | const tag_type_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); | 1750 | const tag_type_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); |
| 1769 | extra_index += 1; | 1751 | extra_index += 1; |
| ... | @@ -1795,7 +1777,7 @@ const Writer = struct { | ... | @@ -1795,7 +1777,7 @@ const Writer = struct { |
| 1795 | try stream.writeAll("{}, "); | 1777 | try stream.writeAll("{}, "); |
| 1796 | } else { | 1778 | } else { |
| 1797 | const prev_parent_decl_node = self.parent_decl_node; | 1779 | const prev_parent_decl_node = self.parent_decl_node; |
| 1798 | if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off); | 1780 | self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node); |
| 1799 | defer self.parent_decl_node = prev_parent_decl_node; | 1781 | defer self.parent_decl_node = prev_parent_decl_node; |
| 1800 | 1782 | ||
| 1801 | try stream.writeAll("{\n"); | 1783 | try stream.writeAll("{\n"); |
| ... | @@ -1816,7 +1798,7 @@ const Writer = struct { | ... | @@ -1816,7 +1798,7 @@ const Writer = struct { |
| 1816 | extra_index += body.len; | 1798 | extra_index += body.len; |
| 1817 | 1799 | ||
| 1818 | const prev_parent_decl_node = self.parent_decl_node; | 1800 | const prev_parent_decl_node = self.parent_decl_node; |
| 1819 | if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off); | 1801 | self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node); |
| 1820 | try self.writeBracedDecl(stream, body); | 1802 | try self.writeBracedDecl(stream, body); |
| 1821 | if (fields_len == 0) { | 1803 | if (fields_len == 0) { |
| 1822 | try stream.writeAll(", {})"); | 1804 | try stream.writeAll(", {})"); |
| ... | @@ -1864,7 +1846,7 @@ const Writer = struct { | ... | @@ -1864,7 +1846,7 @@ const Writer = struct { |
| 1864 | try stream.writeByteNTimes(' ', self.indent); | 1846 | try stream.writeByteNTimes(' ', self.indent); |
| 1865 | try stream.writeAll("})"); | 1847 | try stream.writeAll("})"); |
| 1866 | } | 1848 | } |
| 1867 | try self.writeSrcNode(stream, src_node); | 1849 | try self.writeSrcNode(stream, extra.data.src_node); |
| 1868 | } | 1850 | } |
| 1869 | 1851 | ||
| 1870 | fn writeOpaqueDecl( | 1852 | fn writeOpaqueDecl( |
| ... | @@ -1873,13 +1855,8 @@ const Writer = struct { | ... | @@ -1873,13 +1855,8 @@ const Writer = struct { |
| 1873 | extended: Zir.Inst.Extended.InstData, | 1855 | extended: Zir.Inst.Extended.InstData, |
| 1874 | ) !void { | 1856 | ) !void { |
| 1875 | const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small)); | 1857 | const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small)); |
| 1876 | var extra_index: usize = extended.operand; | 1858 | const extra = self.code.extraData(Zir.Inst.OpaqueDecl, extended.operand); |
| 1877 | 1859 | var extra_index: usize = extra.end; | |
| 1878 | const src_node: ?i32 = if (small.has_src_node) blk: { | ||
| 1879 | const src_node = @as(i32, @bitCast(self.code.extra[extra_index])); | ||
| 1880 | extra_index += 1; | ||
| 1881 | break :blk src_node; | ||
| 1882 | } else null; | ||
| 1883 | 1860 | ||
| 1884 | const decls_len = if (small.has_decls_len) blk: { | 1861 | const decls_len = if (small.has_decls_len) blk: { |
| 1885 | const decls_len = self.code.extra[extra_index]; | 1862 | const decls_len = self.code.extra[extra_index]; |
| ... | @@ -1893,7 +1870,7 @@ const Writer = struct { | ... | @@ -1893,7 +1870,7 @@ const Writer = struct { |
| 1893 | try stream.writeAll("{})"); | 1870 | try stream.writeAll("{})"); |
| 1894 | } else { | 1871 | } else { |
| 1895 | const prev_parent_decl_node = self.parent_decl_node; | 1872 | const prev_parent_decl_node = self.parent_decl_node; |
| 1896 | if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off); | 1873 | self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node); |
| 1897 | defer self.parent_decl_node = prev_parent_decl_node; | 1874 | defer self.parent_decl_node = prev_parent_decl_node; |
| 1898 | 1875 | ||
| 1899 | try stream.writeAll("{\n"); | 1876 | try stream.writeAll("{\n"); |
| ... | @@ -1903,7 +1880,7 @@ const Writer = struct { | ... | @@ -1903,7 +1880,7 @@ const Writer = struct { |
| 1903 | try stream.writeByteNTimes(' ', self.indent); | 1880 | try stream.writeByteNTimes(' ', self.indent); |
| 1904 | try stream.writeAll("})"); | 1881 | try stream.writeAll("})"); |
| 1905 | } | 1882 | } |
| 1906 | try self.writeSrcNode(stream, src_node); | 1883 | try self.writeSrcNode(stream, extra.data.src_node); |
| 1907 | } | 1884 | } |
| 1908 | 1885 | ||
| 1909 | fn writeErrorSetDecl( | 1886 | fn writeErrorSetDecl( |