Skip to content

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

Open

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions