Change SwitchTarget (in TerminatorKind::SwitchInt) to use ScalarInt
@makai410 is already working on this.
Since Aug 13, 2026.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
The compiler has a type to represent integer values of arbitrary size and sign: ScalarInt. It comes with a bunch of useful helpers and is used throughout the interpreter, CTFE, and valtrees.
However, The SwitchInt terminator stores the variants as u128 rather than a ScalarInt. I think this is mostly for historical reasons, it is older than ScalarInt. However ScalarInt is also 1 byte bigger than u128 due to a size that is stored, largely as sanity check.
I think ideally we'd change SwitchTarget to use ScalarInt. If the extra byte per arm is too much (in fact it might be more, SmallVec is ptr-aligned so it will probably add padding), then alternatively we could add APIs to SwitchTarget that let one work with it as-if it was a ScalarInt, hiding the u128 from sight.
Cc @rust-lang/wg-mir-opt
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.