| ... | ... | @@ -10414,7 +10414,41 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10414 | 10414 | } |
| 10415 | 10415 | }, |
| 10416 | 10416 | .Int => { |
| 10417 | | return sema.fail(block, special_prong_src, "TODO 'inline else' Int", .{}); |
| 10417 | var it = try RangeSetUnhandledIterator.init(sema, block, special_prong_src, operand_ty, range_set); |
| 10418 | var emit_bb = false; |
| 10419 | while (try it.next()) |cur| { |
| 10420 | cases_len += 1; |
| 10421 | |
| 10422 | const item_ref = try sema.addConstant(operand_ty, cur); |
| 10423 | case_block.inline_case_capture = item_ref; |
| 10424 | |
| 10425 | case_block.instructions.shrinkRetainingCapacity(0); |
| 10426 | case_block.wip_capture_scope = child_block.wip_capture_scope; |
| 10427 | |
| 10428 | if (emit_bb) try sema.emitBackwardBranch(block, special_prong_src); |
| 10429 | emit_bb = true; |
| 10430 | |
| 10431 | _ = sema.analyzeBodyInner(&case_block, special.body) catch |err| switch (err) { |
| 10432 | error.ComptimeBreak => { |
| 10433 | const zir_datas = sema.code.instructions.items(.data); |
| 10434 | const break_data = zir_datas[sema.comptime_break_inst].@"break"; |
| 10435 | try sema.addRuntimeBreak(&case_block, .{ |
| 10436 | .block_inst = break_data.block_inst, |
| 10437 | .operand = break_data.operand, |
| 10438 | .inst = sema.comptime_break_inst, |
| 10439 | }); |
| 10440 | }, |
| 10441 | else => |e| return e, |
| 10442 | }; |
| 10443 | |
| 10444 | // try wip_captures.finalize(); |
| 10445 | |
| 10446 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); |
| 10447 | cases_extra.appendAssumeCapacity(1); // items_len |
| 10448 | cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len)); |
| 10449 | cases_extra.appendAssumeCapacity(@enumToInt(item_ref)); |
| 10450 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); |
| 10451 | } |
| 10418 | 10452 | }, |
| 10419 | 10453 | .Bool => { |
| 10420 | 10454 | var emit_bb = false; |
| ... | ... | @@ -10561,6 +10595,55 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10561 | 10595 | return sema.analyzeBlockBody(block, src, &child_block, merges); |
| 10562 | 10596 | } |
| 10563 | 10597 | |
| 10598 | const RangeSetUnhandledIterator = struct { |
| 10599 | sema: *Sema, |
| 10600 | block: *Block, |
| 10601 | src: LazySrcLoc, |
| 10602 | ty: Type, |
| 10603 | cur: Value, |
| 10604 | max: Value, |
| 10605 | ranges: []const RangeSet.Range, |
| 10606 | range_i: usize = 0, |
| 10607 | first: bool = true, |
| 10608 | |
| 10609 | fn init(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, range_set: RangeSet) !RangeSetUnhandledIterator { |
| 10610 | const target = sema.mod.getTarget(); |
| 10611 | const min = try ty.minInt(sema.arena, target); |
| 10612 | const max = try ty.maxInt(sema.arena, target); |
| 10613 | |
| 10614 | return RangeSetUnhandledIterator{ |
| 10615 | .sema = sema, |
| 10616 | .block = block, |
| 10617 | .src = src, |
| 10618 | .ty = ty, |
| 10619 | .cur = min, |
| 10620 | .max = max, |
| 10621 | .ranges = range_set.ranges.items, |
| 10622 | }; |
| 10623 | } |
| 10624 | |
| 10625 | fn next(it: *RangeSetUnhandledIterator) !?Value { |
| 10626 | while (it.range_i < it.ranges.len) : (it.range_i += 1) { |
| 10627 | if (!it.first) { |
| 10628 | it.cur = try it.sema.intAdd(it.block, it.src, it.cur, Value.one, it.ty); |
| 10629 | } |
| 10630 | it.first = false; |
| 10631 | if (it.cur.compare(.lt, it.ranges[it.range_i].first, it.ty, it.sema.mod)) { |
| 10632 | return it.cur; |
| 10633 | } |
| 10634 | it.cur = it.ranges[it.range_i].last; |
| 10635 | } |
| 10636 | if (!it.first) { |
| 10637 | it.cur = try it.sema.intAdd(it.block, it.src, it.cur, Value.one, it.ty); |
| 10638 | } |
| 10639 | it.first = false; |
| 10640 | if (it.cur.compare(.lte, it.max, it.ty, it.sema.mod)) { |
| 10641 | return it.cur; |
| 10642 | } |
| 10643 | return null; |
| 10644 | } |
| 10645 | }; |
| 10646 | |
| 10564 | 10647 | fn resolveSwitchItemVal( |
| 10565 | 10648 | sema: *Sema, |
| 10566 | 10649 | block: *Block, |