]> git.lizzy.rs Git - rust.git/commit
UnreachableProp: Preserve unreachable branches for multiple targets
authorNilstrieb <48135649+Nilstrieb@users.noreply.github.com>
Tue, 26 Jul 2022 13:11:12 +0000 (15:11 +0200)
committerNilstrieb <48135649+Nilstrieb@users.noreply.github.com>
Sun, 21 Aug 2022 19:15:28 +0000 (21:15 +0200)
commiteafab660964bcd1e2c8b19cc2021cc5c7fee6c38
tree9a536e2b4f06a87280239be011c7325ff5b055c4
parent650bff80a623e17675ac72ae4d62ed200a4a3568
UnreachableProp: Preserve unreachable branches for multiple targets

Before, UnreachablePropagation removed all unreachable branches.
This was a pessimization, as it removed information about
reachability that was used later in the optimization pipeline.

For example, this code
```rust
pub enum Two { A, B }
pub fn identity(x: Two) -> Two {
    match x {
        Two::A => Two::A,
        Two::B => Two::B,
    }
}
```

basically has `switchInt() -> [0: 0, 1: 1, otherwise: unreachable]` for the match.
This allows it to be transformed into a simple `x`. If we remove the
unreachable branch, the transformation becomes illegal.
compiler/rustc_mir_transform/src/unreachable_prop.rs