zig/src
Justus Klausecker b79bd31356
Sema: rework switch_block[_ref/_err_union] logic
This commit aims to simplify and de-duplicate the logic required for
semantically analyzing `switch` expressions.

The core logic has been moved to `analyzeSwitchBlock`, `resolveSwitchBlock`
and `finishSwitchBlock` and has been rewritten around the new iterator-based
API exposed by `Zir.UnwrappedSwitchBlock`.

All validation logic and switch prong item resolution have been moved to
`validateSwitchBlock`, which produces a `ValidatedSwitchBlock` containing
all the necessary information for further analysis.

`Zir.UnwrappedSwitchBlock`, `ValidatedSwitchBlock` and `SwitchOperand`
replace `SwitchProngAnalysis` while adding more flexibility, mainly for
better integration with `switch_block_err_union`.

`analyzeSwitchBlock` has an explicit code path for OPV types which lowers
them to either a `block`-`br` or a `loop`-`repeat` construct instead of a
switch. Backends expect `switch` to actually have an operand that exists
at runtime, so this is a bug fix and avoids further special cases in the
rest of the switch logic.
`resolveSwitchBlock` and `finishSwitchBr` exclusively deal with operands
which can have more than one value, at comptime and at runtime respectively.

This commit also reworks `RangeSet` to be an unmanaged container and adds
`Air.SwitchBr.BranchHints` to offload some complexity from Sema to there
and save a few bytes of memory in the process.

Additionally, some new features have been implemented:
- decl literals and everything else requiring a result type (`@enumFromInt`!)
  may now be used as switch prong items
- union tag captures are now allowed for all prongs, not just `inline` ones
- switch prongs may contain errors which are not in the error set being
  switched on, if these prongs contain `=> comptime unreachable`

and some bugs have been fixed:
- lots of issues with switching on OPV types are now fixed
- the rules around unreachable `else` prongs when switching on errors now
  apply to *any* switch on an error, not just to `switch_block_err_union`,
  and are applied properly based on the AST
- switching on `void` no longer requires an `else` prong unconditionally
- lazy values are properly resolved before any comparisons with prong items
- evaluation order between all kinds of switch statements is now the same,
  with or without label
2026-01-11 11:37:17 +00:00
..
Air Liveness: improve logging 2026-01-11 11:37:16 +00:00
codegen llvm: fix jump table gen for labeled switch with single else prong 2026-01-11 11:37:16 +00:00
Compilation compiler: don't error on explicit link_libc=false on requiresLibC() targets 2026-01-05 16:50:46 +01:00
libs compiler_rt: fix sqrtf implementation; libc: remove sqrt implementations 2026-01-10 00:09:54 +01:00
link std: move memory locking and memory protection to process 2026-01-09 13:52:00 -08:00
Package std.Io.Dir: introduce renamePreserve and use it in File.Atomic.link 2026-01-07 11:03:37 -08:00
Sema compiler: replace thread pool with std.Io 2025-12-22 12:55:16 +00:00
Zcu Merge pull request '@extern: add support for SPIR-V locations and descriptors' (#30570) from ashpil/zig:extern-bindings-locations into master 2026-01-06 23:44:10 +01:00
Air.zig Sema: rework switch_block[_ref/_err_union] logic 2026-01-11 11:37:17 +00:00
Builtin.zig compiler: update to new createFileAtomic API 2026-01-05 20:28:58 -08:00
clang_options.zig zig cc: honor all -m and -mno- CPU feature flags 2021-11-26 19:59:33 -07:00
clang_options_data.zig zig cc: update options data to LLVM 21 2025-08-30 06:36:41 +02:00
codegen.zig codegen: fix tuple padding 2025-11-04 06:04:30 -05:00
Compilation.zig std: find a better home for the "preopens" concept 2026-01-08 05:06:31 +01:00
crash_report.zig fix more fallout from locking stderr 2025-12-23 22:15:10 -08:00
dev.zig remove all IBM AIX and z/OS support 2025-10-29 14:25:51 +01:00
fmt.zig compiler: update to new createFileAtomic API 2026-01-05 20:28:58 -08:00
IncrementalDebugServer.zig compiler: replace thread pool with std.Io 2025-12-22 12:55:16 +00:00
InternPool.zig Merge pull request '@extern: add support for SPIR-V locations and descriptors' (#30570) from ashpil/zig:extern-bindings-locations into master 2026-01-06 23:44:10 +01:00
introspect.zig rename env_map to environ_map 2026-01-04 00:27:09 -08:00
link.zig update API usage of std.crypto.random to io.random 2026-01-07 11:03:36 -08:00
main.zig std: find a better home for the "preopens" concept 2026-01-08 05:06:31 +01:00
mutable_value.zig compiler: replace thread pool with std.Io 2025-12-22 12:55:16 +00:00
Package.zig update API usage of std.crypto.random to io.random 2026-01-07 11:03:36 -08:00
print_env.zig std: find a better home for the "preopens" concept 2026-01-08 05:06:31 +01:00
print_targets.zig compiler: update various code to new fs API 2025-12-23 22:15:09 -08:00
print_value.zig frontend: introduce error.Canceled 2025-11-24 14:34:18 -08:00
print_zir.zig frontend: rework switch ZIR 2026-01-11 11:37:16 +00:00
print_zoir.zig std.Io: delete GenericReader 2025-08-29 17:14:26 -07:00
RangeSet.zig Sema: rework switch_block[_ref/_err_union] logic 2026-01-11 11:37:17 +00:00
register_manager.zig update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
Sema.zig Sema: rework switch_block[_ref/_err_union] logic 2026-01-11 11:37:17 +00:00
target.zig compiler: don't error on explicit link_libc=false on requiresLibC() targets 2026-01-05 16:50:46 +01:00
tracy.zig Update TracyAllocator to new allocator API 2025-07-05 00:24:40 +02:00
Type.zig src/Type: make doc comments prettier :) 2026-01-11 11:37:17 +00:00
Value.zig compiler: replace thread pool with std.Io 2025-12-22 12:55:16 +00:00
Zcu.zig Sema: rework switch_block[_ref/_err_union] logic 2026-01-11 11:37:17 +00:00
zig_clang_cc1_main.cpp zig cc: update driver files to LLVM 21 2025-08-30 06:36:40 +02:00
zig_clang_cc1as_main.cpp zig cc: update driver files to LLVM 21 2025-08-30 06:36:40 +02:00
zig_clang_driver.cpp zig cc: update driver files to LLVM 21 2025-08-30 06:36:40 +02:00
zig_llvm-ar.cpp zig cc: update driver files to LLVM 21 2025-08-30 06:36:40 +02:00
zig_llvm.cpp Support generating import libraries from mingw .def files without LLVM 2025-10-03 18:26:05 -07:00
zig_llvm.h Support generating import libraries from mingw .def files without LLVM 2025-10-03 18:26:05 -07:00