Optimize `const` pattern guards for `StructuralEq` types
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
With inline_const_pat being removed in #138492, it might be nice to optimize codegen of pat if pat == const { .. }.
Right now
match a {
1 => 42,
b if b == 7 => 100,
_ => 99,
}
Produces a SwitchInt and then a separate equality check.
Changing the second pattern to 7 => 100 produces a single SwitchInt.
I assume that the optimizer can recover this (at least for simpler cases), but it might be nice for the compiler to generate the simplified MIR directly (especially with inline_const_pat gone).
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.
Research direction
Start from the issue's guarded-pattern example and inspect how the compiler lowers pat if pat == const into MIR, especially the separate equality check and SwitchInt. Compare that lowering with the direct 7 => 100 pattern and determine what would make the generated MIR equivalent; done means simpler cases produce a single SwitchInt without the extra equality check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100