Files
zig/lib/std
Justus Klausecker e0108dec54 AstGen: allow labels to provide separate break and continue targets
Enhances `GenZir` to allow labels to provide separate `break` and `continue`
target blocks and adds some more information on continue targets to
communicate whether the target is a switch block or cannot be targeted by
`continue` at all.

The main motivation is enabling this:
```
const result: u32 = operand catch |err| label: switch (err) {
    else => continue :label error.MyError,
    error.MyError => break :label 1,
};
```
to be lowered to something like this:
```
%1 = block({
  %2 = is_non_err(%operand)
  %3 = condbr(%2, {
    %4 = err_union_payload_unsafe(%operand)
    %5 = break(%1, result) // targets enclosing `block`
  }, {
    %6 = err_union_code(%operand)
    %7 = switch_block(%6,
      else => {
        %8 = switch_continue(%7, "error.MyError") // targets `switch_block`
      },
      "error.MyError" => {
        %9 = break(%1, @one) // targets enclosing `block`
      },
    )
    %10 = break(%1, @void_value)
  })
})
```
which makes the non-error case and all breaks from switch prongs, but not
continues from switch prongs, peers.

This is required to avoid the problems described in gh#11957 for labeled
switches without having to introduce a fairly complex special case to the
`switch_block_err_union` logic. Since this construct is very rare in practice,
introducing this additional complexity just to save a few ZIR bytes is
likely not worth it, so the simplified lowering described above will be
used instead.

As a nice bonus, AstGen can now also detect a `continue` trying to target
a labeled block and emit an appropriate error message.
2026-01-11 11:37:16 +00:00
..
2025-11-22 22:42:38 +00:00
2026-01-04 00:27:08 -08:00
2026-01-10 17:43:33 +01:00
2025-12-23 22:15:10 -08:00
2025-11-22 22:42:38 +00:00
2025-09-30 13:44:54 +01:00
2025-12-27 20:40:19 +01:00
2026-01-04 17:23:45 -08:00
2025-09-20 14:34:18 -07:00
2025-12-22 10:00:35 -08:00
2025-11-22 22:42:38 +00:00
2026-01-08 12:36:07 -08:00
2025-08-29 17:14:26 -07:00
2025-08-29 17:14:26 -07:00
2025-11-22 22:42:38 +00:00
2026-01-07 11:03:36 -08:00
2025-08-28 18:30:57 -07:00
2025-07-16 10:27:39 -07:00
2026-01-04 00:27:08 -08:00