1
Fork 0
rust/compiler/rustc_mir_dataflow/src
Dylan DPC c78e3c735a
Rollup merge of #107411 - cjgillot:dataflow-discriminant, r=oli-obk
Handle discriminant in DataflowConstProp

cc ``@jachris``
r? ``@JakobDegen``

This PR attempts to extend the DataflowConstProp pass to handle propagation of discriminants. We handle this by adding 2 new variants to `TrackElem`: `TrackElem::Variant` for enum variants and `TrackElem::Discriminant` for the enum discriminant pseudo-place.

The difficulty is that the enum discriminant and enum variants may alias each another. This is the issue of the `Option<NonZeroUsize>` test, which is the equivalent of https://github.com/rust-lang/unsafe-code-guidelines/issues/84 with a direct write.

To handle that, we generalize the flood process to flood all the potentially aliasing places. In particular:
- any write to `(PLACE as Variant)`, either direct or through a projection, floods `(PLACE as OtherVariant)` for all other variants and `discriminant(PLACE)`;
- `SetDiscriminant(PLACE)` floods `(PLACE as Variant)` for each variant.

This implies that flooding is not hierarchical any more, and that an assignment to a non-tracked place may need to flood a tracked place. This is handled by `for_each_aliasing_place` which generalizes `preorder_invoke`.

As we deaggregate enums by putting `SetDiscriminant` last, this allows to propagate the value of the discriminant.

This refactor will allow to make https://github.com/rust-lang/rust/pull/107009 able to handle discriminants too.
2023-02-15 12:24:55 +05:30
..
framework Fix uninlined_format_args for some compiler crates 2023-01-05 19:01:12 +01:00
impls Only exclude locals if the place is not indirect. 2023-02-06 21:51:45 +00:00
move_paths s/eval_usize/eval_target_usize/ for clarity 2023-02-14 08:51:19 +00:00
drop_flag_effects.rs Treat Drop as a rmw operation 2023-01-30 00:20:40 +01:00
elaborate_drops.rs s/eval_usize/eval_target_usize/ for clarity 2023-02-14 08:51:19 +00:00
errors.rs Migrate all diagnostics 2022-10-23 10:09:44 +02:00
lib.rs Handle discriminants in dataflow-const-prop. 2023-02-06 21:51:47 +00:00
rustc_peek.rs Rollup merge of #99027 - tmiasko:basic-blocks, r=oli-obk 2022-08-29 06:34:43 +02:00
storage.rs Replace Body::basic_blocks() with field access 2022-08-26 14:27:08 +02:00
un_derefer.rs Auto merge of #99667 - ouz-a:some_branch, r=oli-obk 2022-07-29 07:11:50 +00:00
value_analysis.rs Rollup merge of #107411 - cjgillot:dataflow-discriminant, r=oli-obk 2023-02-15 12:24:55 +05:30