From 07a7c2f7c86d72bd15e980d098aa2b46f236412f Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Mon, 26 Sep 2022 13:54:52 +0300 Subject: [PATCH] stage2: remove redundant `is_ref` flag from `SwitchBlock.Bits` --- src/AstGen.zig | 1 - src/Sema.zig | 9 +++------ src/Zir.zig | 5 +---- src/print_zir.zig | 1 - 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index a516043bf2..fcf5835f1e 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -6520,7 +6520,6 @@ fn switchExpr( const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.SwitchBlock{ .operand = cond, .bits = Zir.Inst.SwitchBlock.Bits{ - .is_ref = any_payload_is_ref, .has_multi_cases = multi_cases_len != 0, .has_else = special_prong == .@"else", .has_under = special_prong == .under, diff --git a/src/Sema.zig b/src/Sema.zig index 72a5cb518f..f6a84341cc 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -8994,9 +8994,10 @@ fn zirSwitchCapture( const switch_info = zir_datas[capture_info.switch_inst].pl_node; const switch_extra = sema.code.extraData(Zir.Inst.SwitchBlock, switch_info.payload_index); const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_info.src_node }; - const operand_is_ref = switch_extra.data.bits.is_ref; const cond_inst = Zir.refToIndex(switch_extra.data.operand).?; - const cond_info = sema.code.instructions.items(.data)[cond_inst].un_node; + const cond_info = zir_datas[cond_inst].un_node; + const cond_tag = sema.code.instructions.items(.tag)[cond_inst]; + const operand_is_ref = cond_tag == .switch_cond_ref; const operand_ptr = try sema.resolveInst(cond_info.operand); const operand_ptr_ty = sema.typeOf(operand_ptr); const operand_ty = if (operand_is_ref) operand_ptr_ty.childType() else operand_ptr_ty; @@ -9009,7 +9010,6 @@ fn zirSwitchCapture( if (capture_info.prong_index == std.math.maxInt(@TypeOf(capture_info.prong_index))) { // It is the else/`_` prong. if (is_ref) { - assert(operand_is_ref); return operand_ptr; } @@ -9069,8 +9069,6 @@ fn zirSwitchCapture( } if (is_ref) { - assert(operand_is_ref); - const field_ty_ptr = try Type.ptr(sema.arena, sema.mod, .{ .pointee_type = first_field.ty, .@"addrspace" = .generic, @@ -9131,7 +9129,6 @@ fn zirSwitchCapture( // In this case the capture value is just the passed-through value of the // switch condition. if (is_ref) { - assert(operand_is_ref); return operand_ptr; } else { return operand; diff --git a/src/Zir.zig b/src/Zir.zig index 5b1aefea64..24248a6533 100644 --- a/src/Zir.zig +++ b/src/Zir.zig @@ -2952,12 +2952,9 @@ pub const Inst = struct { has_else: bool, /// If true, there is an underscore prong. This is mutually exclusive with `has_else`. has_under: bool, - /// If true, the `operand` is a pointer to the value being switched on. - /// TODO this flag is redundant with the tag of operand and can be removed. - is_ref: bool, scalar_cases_len: ScalarCasesLen, - pub const ScalarCasesLen = u28; + pub const ScalarCasesLen = u29; pub fn specialProng(bits: Bits) SpecialProng { const has_else: u2 = @boolToInt(bits.has_else); diff --git a/src/print_zir.zig b/src/print_zir.zig index b273365596..1d7083e8f1 100644 --- a/src/print_zir.zig +++ b/src/print_zir.zig @@ -1857,7 +1857,6 @@ const Writer = struct { } else 0; try self.writeInstRef(stream, extra.data.operand); - try self.writeFlag(stream, ", ref", extra.data.bits.is_ref); self.indent += 2;