authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-26 13:54:52+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-27 18:05:08+03:00
log07a7c2f7c86d72bd15e980d098aa2b46f236412f
treeabca05e07018c51db6cd84181327ad2b28d2cb8f
parentb4d81857f36a155daa884ba80bfd56c43a182663

stage2: remove redundant `is_ref` flag from `SwitchBlock.Bits`


4 files changed, 4 insertions(+), 12 deletions(-)

src/AstGen.zig-1
......@@ -6520,7 +6520,6 @@ fn switchExpr(
65206520 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.SwitchBlock{
65216521 .operand = cond,
65226522 .bits = Zir.Inst.SwitchBlock.Bits{
6523 .is_ref = any_payload_is_ref,
65246523 .has_multi_cases = multi_cases_len != 0,
65256524 .has_else = special_prong == .@"else",
65266525 .has_under = special_prong == .under,
src/Sema.zig+3-6
......@@ -8994,9 +8994,10 @@ fn zirSwitchCapture(
89948994 const switch_info = zir_datas[capture_info.switch_inst].pl_node;
89958995 const switch_extra = sema.code.extraData(Zir.Inst.SwitchBlock, switch_info.payload_index);
89968996 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_info.src_node };
8997 const operand_is_ref = switch_extra.data.bits.is_ref;
89988997 const cond_inst = Zir.refToIndex(switch_extra.data.operand).?;
8999 const cond_info = sema.code.instructions.items(.data)[cond_inst].un_node;
8998 const cond_info = zir_datas[cond_inst].un_node;
8999 const cond_tag = sema.code.instructions.items(.tag)[cond_inst];
9000 const operand_is_ref = cond_tag == .switch_cond_ref;
90009001 const operand_ptr = try sema.resolveInst(cond_info.operand);
90019002 const operand_ptr_ty = sema.typeOf(operand_ptr);
90029003 const operand_ty = if (operand_is_ref) operand_ptr_ty.childType() else operand_ptr_ty;
......@@ -9009,7 +9010,6 @@ fn zirSwitchCapture(
90099010 if (capture_info.prong_index == std.math.maxInt(@TypeOf(capture_info.prong_index))) {
90109011 // It is the else/`_` prong.
90119012 if (is_ref) {
9012 assert(operand_is_ref);
90139013 return operand_ptr;
90149014 }
90159015
......@@ -9069,8 +9069,6 @@ fn zirSwitchCapture(
90699069 }
90709070
90719071 if (is_ref) {
9072 assert(operand_is_ref);
9073
90749072 const field_ty_ptr = try Type.ptr(sema.arena, sema.mod, .{
90759073 .pointee_type = first_field.ty,
90769074 .@"addrspace" = .generic,
......@@ -9131,7 +9129,6 @@ fn zirSwitchCapture(
91319129 // In this case the capture value is just the passed-through value of the
91329130 // switch condition.
91339131 if (is_ref) {
9134 assert(operand_is_ref);
91359132 return operand_ptr;
91369133 } else {
91379134 return operand;
src/Zir.zig+1-4
......@@ -2952,12 +2952,9 @@ pub const Inst = struct {
29522952 has_else: bool,
29532953 /// If true, there is an underscore prong. This is mutually exclusive with `has_else`.
29542954 has_under: bool,
2955 /// If true, the `operand` is a pointer to the value being switched on.
2956 /// TODO this flag is redundant with the tag of operand and can be removed.
2957 is_ref: bool,
29582955 scalar_cases_len: ScalarCasesLen,
29592956
2960 pub const ScalarCasesLen = u28;
2957 pub const ScalarCasesLen = u29;
29612958
29622959 pub fn specialProng(bits: Bits) SpecialProng {
29632960 const has_else: u2 = @boolToInt(bits.has_else);
src/print_zir.zig-1
......@@ -1857,7 +1857,6 @@ const Writer = struct {
18571857 } else 0;
18581858
18591859 try self.writeInstRef(stream, extra.data.operand);
1860 try self.writeFlag(stream, ", ref", extra.data.bits.is_ref);
18611860
18621861 self.indent += 2;
18631862