rust-lang / rust-lang/rust

Change SwitchTarget (in TerminatorKind::SwitchInt) to use ScalarInt

Open
#124,127 0 comments 2 reactions 1 assignee View on GitHub

@makai410 is already working on this.

Since Aug 13, 2026.

A-MIR C-enhancement T-compiler
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.