rust/compiler/rustc_middle/src
bors 357f660729 Auto merge of #101168 - jachris:dataflow-const-prop, r=oli-obk
Add new MIR constant propagation based on dataflow analysis

The current constant propagation in `rustc_mir_transform/src/const_prop.rs` fails to handle many cases that would be expected from a constant propagation optimization. For example:
```rust
let x = if true { 0 } else { 0 };
```
This pull request adds a new constant propagation MIR optimization pass based on the existing dataflow analysis framework. Since most of the analysis is not unique to constant propagation, a generic framework has been extracted. It works on top of the existing framework and could be reused for other optimzations.

Closes #80038. Closes #81605.

## Todo
### Essential
- [x] [Writes to inactive enum variants](https://github.com/rust-lang/rust/pull/101168#pullrequestreview-1089493974). Resolved by rejecting the registration of places with downcast projections for now. Could be improved by flooding other variants if mutable access to a variant is observed.
- [X] Handle [`StatementKind::CopyNonOverlapping`](https://github.com/rust-lang/rust/pull/101168#discussion_r957774914). Resolved by flooding the destination.
- [x] Handle `UnsafeCell` / `!Freeze` correctly.
- [X] Overflow propagation of `CheckedBinaryOp`: Decided to not propagate if overflow flag is `true` (`false` will still be propagated)
- [x] More documentation in general.
- [x] Arguments for correctness, documentation of necessary assumptions.
- [x] Better performance, or alternatively, require `-Zmir-opt-level=3` for now.

### Extra
- [x]  Add explicit unreachability, i.e. upgrading the lattice from $\mathbb{P} \to \mathbb{V}$ to $\set{\bot} \cup (\mathbb{P} \to \mathbb{V})$.
- [x] Use storage statements to improve precision.
- [ ] Consider opening issue for duplicate diagnostics: https://github.com/rust-lang/rust/pull/101168#issuecomment-1276609950
- [ ] Flood moved-from places with $\bot$ (requires some changes for places with tracked projections).
- [ ] Add downcast projections back in.
- [ ] [Algebraic simplifications](https://github.com/rust-lang/rust/pull/101168#discussion_r957967878) (possibly with a shared API; done by old const prop).
- [ ] Propagation through slices / arrays.
- [ ] Find other optimizations that are done by old `const_prop.rs`, but not by this one.
2022-11-15 09:38:05 +00:00
..
dep_graph Allow query system to recover a HirId. 2022-10-01 15:58:42 +02:00
hir Tweak signatures in rustc_middle::hir::map. 2022-11-11 10:10:16 +00:00
infer Add an optional Span to BrAnon and use it to print better error for HRTB error from generator interior 2022-11-07 17:39:29 -05:00
middle resolve: Fill effective visibilities for import def ids in a separate pass 2022-11-05 17:55:20 +04:00
mir Auto merge of #101168 - jachris:dataflow-const-prop, r=oli-obk 2022-11-15 09:38:05 +00:00
query Resolve lifetimes independently for each item-like. 2022-11-11 10:11:50 +00:00
thir Use boxed slices in PatKind. 2022-09-02 07:26:22 +10:00
traits selection failure: recompute applicable impls 2022-11-08 14:48:07 +01:00
ty Rollup merge of #104357 - RalfJung:is-sized, r=cjgillot 2022-11-13 17:37:38 +01:00
util span: move MultiSpan 2022-04-05 07:01:00 +01:00
arena.rs Auto merge of #102698 - michaelwoerister:unord-collections, r=lncr 2022-10-29 06:20:48 +00:00
error.rs better error for rustc_strict_coherence misuse 2022-10-30 19:11:55 +00:00
lib.rs cfg-step code 2022-11-06 17:21:21 -05:00
lint.rs fix: typo 2022-11-06 11:22:29 -05:00
macros.rs add inline to TrivialTypeTraversalImpls 2022-10-17 10:54:03 +02:00
metadata.rs rustc: Parameterize ty::Visibility over used ID 2022-09-07 13:35:41 +04:00
tests.rs
thir.rs Use tidy-alphabetical in the compiler 2022-10-12 17:49:10 +05:30
values.rs Add domain size check to fix ICE 2022-11-09 10:19:23 -06:00