rust/compiler
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
..
rustc rustc: Use unix_sigpipe instead of rustc_driver::set_sigpipe_handler 2022-10-02 17:49:36 +02:00
rustc_apfloat
rustc_arena
rustc_ast Rollup merge of #104391 - nnethercote:deriving-cleanups, r=jackh726 2022-11-15 01:40:44 +01:00
rustc_ast_lowering Introduce ExprKind::IncludedBytes 2022-11-11 16:31:32 +00:00
rustc_ast_passes Rollup merge of #95710 - fee1-dead-contrib:stabilize_arbitrary_enum_discriminant, r=joshtriplett 2022-10-26 17:32:53 +05:30
rustc_ast_pretty Introduce ExprKind::IncludedBytes 2022-11-11 16:31:32 +00:00
rustc_attr Migrate all diagnostics 2022-10-23 10:09:44 +02:00
rustc_borrowck Rollup merge of #103960 - AndyJado:var_path_only_diag, r=davidtwco 2022-11-11 12:12:30 -05:00
rustc_builtin_macros Rollup merge of #104391 - nnethercote:deriving-cleanups, r=jackh726 2022-11-15 01:40:44 +01:00
rustc_codegen_cranelift add is_sized method on Abi and Layout, and use it 2022-11-13 12:23:53 +01:00
rustc_codegen_gcc add is_sized method on Abi and Layout, and use it 2022-11-13 12:23:53 +01:00
rustc_codegen_llvm Rollup merge of #104105 - davidtwco:split-dwarf-lto, r=michaelwoerister 2022-11-13 21:49:25 -05:00
rustc_codegen_ssa Auto merge of #104091 - BelovDV:issue-103044, r=petrochenkov 2022-11-15 00:38:08 +00:00
rustc_const_eval Rollup merge of #104356 - RalfJung:interpret-check-mplace, r=oli-obk 2022-11-14 19:26:18 +01:00
rustc_data_structures Use the interned stable hash as plain hash. 2022-11-11 13:02:37 +00:00
rustc_driver Rollup merge of #104184 - jyn514:rustdoc-version, r=davidtwco 2022-11-09 15:39:07 -05:00
rustc_error_codes Rollup merge of #103924 - PeteDevoy:patch-1, r=estebank 2022-11-11 20:51:39 +05:30
rustc_error_messages Auto merge of #104418 - matthiaskrgr:rollup-y4i6xjc, r=matthiaskrgr 2022-11-15 03:37:07 +00:00
rustc_errors Rollup merge of #104229 - compiler-errors:overlap-full-path, r=davidtwco 2022-11-14 19:26:16 +01:00
rustc_expand fix some typos in comments 2022-11-13 15:26:17 +08:00
rustc_feature Rollup merge of #104349 - rustaceanclub:master, r=oli-obk 2022-11-14 19:26:18 +01:00
rustc_fs_util
rustc_graphviz Add initial version of value analysis and dataflow constant propagation 2022-11-07 10:35:08 +01:00
rustc_hir Some tracing and comment cleanups 2022-11-04 17:10:07 +00:00
rustc_hir_analysis Auto merge of #104310 - Dylan-DPC:rollup-wgt1z4a, r=Dylan-DPC 2022-11-12 08:03:01 +00:00
rustc_hir_pretty pretty: fix to print some lifetimes on HIR pretty-print 2022-10-15 23:34:21 +09:00
rustc_hir_typeck Auto merge of #104428 - matthiaskrgr:rollup-jo3078i, r=matthiaskrgr 2022-11-15 06:43:28 +00:00
rustc_incremental Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_index Remove from compiler/ crates 2022-09-29 16:49:04 +09:00
rustc_infer Rollup merge of #104206 - compiler-errors:ocx-more-2, r=lcnr 2022-11-12 12:02:52 +05:30
rustc_interface Fix rustdoc --version when used with download-rustc 2022-11-09 02:54:51 -06:00
rustc_lexer Rollup merge of #103919 - nnethercote:unescaping-cleanups, r=matklad 2022-11-09 19:21:22 +05:30
rustc_lint Auto merge of #104428 - matthiaskrgr:rollup-jo3078i, r=matthiaskrgr 2022-11-15 06:43:28 +00:00
rustc_lint_defs Make PROC_MACRO_DERIVE_RESOLUTION_FALLBACK a hard error 2022-10-24 13:40:07 -05:00
rustc_llvm [llvm-wrapper] adapt for LLVM API change 2022-11-14 14:59:32 +00:00
rustc_log
rustc_macros Modify comment syntax error 2022-11-07 14:33:33 +08:00
rustc_metadata Wrap bundlen static libraries into object files 2022-11-14 12:01:49 +03:00
rustc_middle Auto merge of #101168 - jachris:dataflow-const-prop, r=oli-obk 2022-11-15 09:38:05 +00:00
rustc_mir_build Rollup merge of #104349 - rustaceanclub:master, r=oli-obk 2022-11-14 19:26:18 +01:00
rustc_mir_dataflow Remove log statement that was commented out 2022-11-12 20:32:09 +01:00
rustc_mir_transform Auto merge of #101168 - jachris:dataflow-const-prop, r=oli-obk 2022-11-15 09:38:05 +00:00
rustc_monomorphize Fix ICE when negative impl is collected during eager mono 2022-11-04 03:08:28 +00:00
rustc_parse Rollup merge of #104223 - fmease:recover-fn-ptr-with-generics, r=estebank 2022-11-14 19:26:16 +01:00
rustc_parse_format Fix rustc_parse_format spans following escaped utf-8 multibyte chars 2022-10-27 18:20:56 +00:00
rustc_passes Rollup merge of #104320 - fee1-dead-contrib:use-derive-const-in-std, r=oli-obk 2022-11-13 17:37:37 +01:00
rustc_plugin_impl Migrate all diagnostics 2022-10-23 10:09:44 +02:00
rustc_privacy privacy: Check effective visibility invariants 2022-11-05 16:25:41 +04:00
rustc_query_impl Make AbsoluteBytePos a u64. 2022-11-08 18:47:26 +00:00
rustc_query_system Hash spans when interning. 2022-11-11 13:02:37 +00:00
rustc_resolve Rollup merge of #104364 - petrochenkov:docice2, r=GuillaumeGomez 2022-11-14 19:26:19 +01:00
rustc_save_analysis Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_serialize rustdoc: use ThinVec for cleaned generics 2022-11-02 16:17:22 -07:00
rustc_session Add --print=split-debuginfo 2022-11-07 16:11:32 +01:00
rustc_smir Only keep one version of ImplicitSelfKind. 2022-09-13 19:18:23 +02:00
rustc_span Rollup merge of #104383 - WaffleLapkin:rustc_undiagnostic_item, r=compiler-errors 2022-11-15 01:40:44 +01:00
rustc_symbol_mangling 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
rustc_target Rollup merge of #104349 - rustaceanclub:master, r=oli-obk 2022-11-14 19:26:18 +01:00
rustc_trait_selection Auto merge of #104428 - matthiaskrgr:rollup-jo3078i, r=matthiaskrgr 2022-11-15 06:43:28 +00:00
rustc_traits Make rustc build with new chalk 2022-11-13 19:53:44 +00:00
rustc_transmute Auto merge of #103831 - chenyukang:yukang/fix-103751-ice, r=nagisa 2022-11-05 13:48:30 +00:00
rustc_ty_utils add is_sized method on Abi and Layout, and use it 2022-11-13 12:23:53 +01:00
rustc_type_ir deprecate DelaySpanBugEmitted and use ErrorGuaranteed directly 2022-11-02 23:15:49 +08:00