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(...@@ -6520,7 +6520,6 @@ fn switchExpr(
6520 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.SwitchBlock{6520 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.SwitchBlock{
6521 .operand = cond,6521 .operand = cond,
6522 .bits = Zir.Inst.SwitchBlock.Bits{6522 .bits = Zir.Inst.SwitchBlock.Bits{
6523 .is_ref = any_payload_is_ref,
6524 .has_multi_cases = multi_cases_len != 0,6523 .has_multi_cases = multi_cases_len != 0,
6525 .has_else = special_prong == .@"else",6524 .has_else = special_prong == .@"else",
6526 .has_under = special_prong == .under,6525 .has_under = special_prong == .under,
src/Sema.zig+3-6
...@@ -8994,9 +8994,10 @@ fn zirSwitchCapture(...@@ -8994,9 +8994,10 @@ fn zirSwitchCapture(
8994 const switch_info = zir_datas[capture_info.switch_inst].pl_node;8994 const switch_info = zir_datas[capture_info.switch_inst].pl_node;
8995 const switch_extra = sema.code.extraData(Zir.Inst.SwitchBlock, switch_info.payload_index);8995 const switch_extra = sema.code.extraData(Zir.Inst.SwitchBlock, switch_info.payload_index);
8996 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_info.src_node };8996 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_info.src_node };
8997 const operand_is_ref = switch_extra.data.bits.is_ref;
8998 const cond_inst = Zir.refToIndex(switch_extra.data.operand).?;8997 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;
9000 const operand_ptr = try sema.resolveInst(cond_info.operand);9001 const operand_ptr = try sema.resolveInst(cond_info.operand);
9001 const operand_ptr_ty = sema.typeOf(operand_ptr);9002 const operand_ptr_ty = sema.typeOf(operand_ptr);
9002 const operand_ty = if (operand_is_ref) operand_ptr_ty.childType() else operand_ptr_ty;9003 const operand_ty = if (operand_is_ref) operand_ptr_ty.childType() else operand_ptr_ty;
...@@ -9009,7 +9010,6 @@ fn zirSwitchCapture(...@@ -9009,7 +9010,6 @@ fn zirSwitchCapture(
9009 if (capture_info.prong_index == std.math.maxInt(@TypeOf(capture_info.prong_index))) {9010 if (capture_info.prong_index == std.math.maxInt(@TypeOf(capture_info.prong_index))) {
9010 // It is the else/`_` prong.9011 // It is the else/`_` prong.
9011 if (is_ref) {9012 if (is_ref) {
9012 assert(operand_is_ref);
9013 return operand_ptr;9013 return operand_ptr;
9014 }9014 }
90159015
...@@ -9069,8 +9069,6 @@ fn zirSwitchCapture(...@@ -9069,8 +9069,6 @@ fn zirSwitchCapture(
9069 }9069 }
90709070
9071 if (is_ref) {9071 if (is_ref) {
9072 assert(operand_is_ref);
9073
9074 const field_ty_ptr = try Type.ptr(sema.arena, sema.mod, .{9072 const field_ty_ptr = try Type.ptr(sema.arena, sema.mod, .{
9075 .pointee_type = first_field.ty,9073 .pointee_type = first_field.ty,
9076 .@"addrspace" = .generic,9074 .@"addrspace" = .generic,
...@@ -9131,7 +9129,6 @@ fn zirSwitchCapture(...@@ -9131,7 +9129,6 @@ fn zirSwitchCapture(
9131 // In this case the capture value is just the passed-through value of the9129 // In this case the capture value is just the passed-through value of the
9132 // switch condition.9130 // switch condition.
9133 if (is_ref) {9131 if (is_ref) {
9134 assert(operand_is_ref);
9135 return operand_ptr;9132 return operand_ptr;
9136 } else {9133 } else {
9137 return operand;9134 return operand;
src/Zir.zig+1-4
...@@ -2952,12 +2952,9 @@ pub const Inst = struct {...@@ -2952,12 +2952,9 @@ pub const Inst = struct {
2952 has_else: bool,2952 has_else: bool,
2953 /// If true, there is an underscore prong. This is mutually exclusive with `has_else`.2953 /// If true, there is an underscore prong. This is mutually exclusive with `has_else`.
2954 has_under: bool,2954 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,
2958 scalar_cases_len: ScalarCasesLen,2955 scalar_cases_len: ScalarCasesLen,
29592956
2960 pub const ScalarCasesLen = u28;2957 pub const ScalarCasesLen = u29;
29612958
2962 pub fn specialProng(bits: Bits) SpecialProng {2959 pub fn specialProng(bits: Bits) SpecialProng {
2963 const has_else: u2 = @boolToInt(bits.has_else);2960 const has_else: u2 = @boolToInt(bits.has_else);
src/print_zir.zig-1
...@@ -1857,7 +1857,6 @@ const Writer = struct {...@@ -1857,7 +1857,6 @@ const Writer = struct {
1857 } else 0;1857 } else 0;
18581858
1859 try self.writeInstRef(stream, extra.data.operand);1859 try self.writeInstRef(stream, extra.data.operand);
1860 try self.writeFlag(stream, ", ref", extra.data.bits.is_ref);
18611860
1862 self.indent += 2;1861 self.indent += 2;
18631862