about summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-31 02:12:50 +0000
committerbors <bors@rust-lang.org>2024-03-31 02:12:50 +0000
commit5baf1e13f568b61e121953bf6a3d09faee7dd446 (patch)
tree9119070a59e1f80681b9214068f4e36a9331ff29 /compiler/rustc_pattern_analysis/src
parent1aedc9640cd740976f49480c4efefe0c0311fbb9 (diff)
parent65efa5b3b9ec77be6a009a08ea07971d6438ec9b (diff)
downloadrust-5baf1e13f568b61e121953bf6a3d09faee7dd446.tar.gz
rust-5baf1e13f568b61e121953bf6a3d09faee7dd446.zip
Auto merge of #122459 - Nadrieril:sort-eq, r=oli-obk
match lowering: sort `Eq` candidates in the failure case too

This is a slight tweak to MIR gen of matches. Take a match like:
```rust
match (s, flag) {
    ("a", _) if foo() => 1,
    ("b", true) => 2,
    ("a", false) => 3,
    (_, true) => 4,
    _ => 5,
}
```
If we switch on `s == "a"`, the first candidate matches, and we learn almost nothing about the second candidate. So there's a choice:
1. (what we do today) stop sorting candidates, keep the "b" case grouped with everything below. This could allow us to be clever here and test on `flag == true` next.
2. (what this PR does) sort "b" into the failure case. The "b" will be alone (fewer opportunities for picking a good test), but that means the two "a" cases require a single test.

Today, we aren't clever in which tests we pick, so this is an unambiguous win. In a future where we pick tests better, idk. Grouping tests as much as possible feels like a generally good strategy.

This was proposed in https://github.com/rust-lang/rust/issues/29623 (9 years ago :D)
Diffstat (limited to 'compiler/rustc_pattern_analysis/src')
0 files changed, 0 insertions, 0 deletions