| ... | ... | @@ -11355,7 +11355,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11355 | 11355 | |
| 11356 | 11356 | const mod = sema.mod; |
| 11357 | 11357 | const gpa = sema.gpa; |
| 11358 | | const ip = &mod.intern_pool; |
| 11359 | 11358 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 11360 | 11359 | const src = inst_data.src(); |
| 11361 | 11360 | const src_node_offset = inst_data.src_node; |
| ... | ... | @@ -11944,6 +11943,71 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11944 | 11943 | unreachable; |
| 11945 | 11944 | } |
| 11946 | 11945 | |
| 11946 | _ = try sema.analyzeSwitchRuntimeBlock( |
| 11947 | spa, |
| 11948 | &child_block, |
| 11949 | src, |
| 11950 | operand, |
| 11951 | operand_ty, |
| 11952 | operand_src, |
| 11953 | case_vals, |
| 11954 | special, |
| 11955 | scalar_cases_len, |
| 11956 | multi_cases_len, |
| 11957 | union_originally, |
| 11958 | maybe_union_ty, |
| 11959 | err_set, |
| 11960 | src_node_offset, |
| 11961 | special_prong_src, |
| 11962 | seen_enum_fields, |
| 11963 | seen_errors, |
| 11964 | range_set, |
| 11965 | true_count, |
| 11966 | false_count, |
| 11967 | cond_dbg_node_index, |
| 11968 | ); |
| 11969 | |
| 11970 | return sema.analyzeBlockBody(block, src, &child_block, merges); |
| 11971 | } |
| 11972 | |
| 11973 | const SpecialProng = struct { |
| 11974 | body: []const Zir.Inst.Index, |
| 11975 | end: usize, |
| 11976 | capture: Zir.Inst.SwitchBlock.ProngInfo.Capture, |
| 11977 | is_inline: bool, |
| 11978 | has_tag_capture: bool, |
| 11979 | }; |
| 11980 | |
| 11981 | fn analyzeSwitchRuntimeBlock( |
| 11982 | sema: *Sema, |
| 11983 | spa: SwitchProngAnalysis, |
| 11984 | child_block: *Block, |
| 11985 | src: LazySrcLoc, |
| 11986 | operand: Air.Inst.Ref, |
| 11987 | operand_ty: Type, |
| 11988 | operand_src: LazySrcLoc, |
| 11989 | case_vals: std.ArrayListUnmanaged(Air.Inst.Ref), |
| 11990 | special: SpecialProng, |
| 11991 | scalar_cases_len: usize, |
| 11992 | multi_cases_len: usize, |
| 11993 | union_originally: bool, |
| 11994 | maybe_union_ty: Type, |
| 11995 | err_set: bool, |
| 11996 | src_node_offset: i32, |
| 11997 | special_prong_src: LazySrcLoc, |
| 11998 | seen_enum_fields: []?Module.SwitchProngSrc, |
| 11999 | seen_errors: SwitchErrorSet, |
| 12000 | range_set: RangeSet, |
| 12001 | true_count: u8, |
| 12002 | false_count: u8, |
| 12003 | cond_dbg_node_index: Zir.Inst.Index, |
| 12004 | ) CompileError!Air.Inst.Ref { |
| 12005 | const mod = sema.mod; |
| 12006 | const gpa = sema.gpa; |
| 12007 | const ip = &mod.intern_pool; |
| 12008 | |
| 12009 | const block = child_block.parent.?; |
| 12010 | |
| 11947 | 12011 | const estimated_cases_extra = (scalar_cases_len + multi_cases_len) * |
| 11948 | 12012 | @typeInfo(Air.SwitchBr.Case).Struct.fields.len + 2; |
| 11949 | 12013 | var cases_extra = try std.ArrayListUnmanaged(u32).initCapacity(gpa, estimated_cases_extra); |
| ... | ... | @@ -12534,27 +12598,23 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12534 | 12598 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr).Struct.fields.len + |
| 12535 | 12599 | cases_extra.items.len + final_else_body.len); |
| 12536 | 12600 | |
| 12537 | | _ = try child_block.addInst(.{ .tag = .switch_br, .data = .{ .pl_op = .{ |
| 12538 | | .operand = operand, |
| 12539 | | .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{ |
| 12540 | | .cases_len = @intCast(cases_len), |
| 12541 | | .else_body_len = @intCast(final_else_body.len), |
| 12542 | | }), |
| 12543 | | } } }); |
| 12601 | const payload_index = sema.addExtraAssumeCapacity(Air.SwitchBr{ |
| 12602 | .cases_len = @intCast(cases_len), |
| 12603 | .else_body_len = @intCast(final_else_body.len), |
| 12604 | }); |
| 12605 | |
| 12544 | 12606 | sema.air_extra.appendSliceAssumeCapacity(@ptrCast(cases_extra.items)); |
| 12545 | 12607 | sema.air_extra.appendSliceAssumeCapacity(@ptrCast(final_else_body)); |
| 12546 | 12608 | |
| 12547 | | return sema.analyzeBlockBody(block, src, &child_block, merges); |
| 12609 | return try child_block.addInst(.{ |
| 12610 | .tag = .switch_br, |
| 12611 | .data = .{ .pl_op = .{ |
| 12612 | .operand = operand, |
| 12613 | .payload = payload_index, |
| 12614 | } }, |
| 12615 | }); |
| 12548 | 12616 | } |
| 12549 | 12617 | |
| 12550 | | const SpecialProng = struct { |
| 12551 | | body: []const Zir.Inst.Index, |
| 12552 | | end: usize, |
| 12553 | | capture: Zir.Inst.SwitchBlock.ProngInfo.Capture, |
| 12554 | | is_inline: bool, |
| 12555 | | has_tag_capture: bool, |
| 12556 | | }; |
| 12557 | | |
| 12558 | 12618 | fn resolveSwitchComptime( |
| 12559 | 12619 | sema: *Sema, |
| 12560 | 12620 | spa: SwitchProngAnalysis, |