rust/compiler/rustc_middle/src/mir
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
..
interpret interpret: rename Pointer::from_addr → from_addr_invalid 2023-02-14 14:55:50 +01:00
basic_blocks.rs Rollup merge of #107151 - tmiasko:dominators-no-inline, r=compiler-errors 2023-01-23 19:30:01 +09:00
coverage.rs Replace enum ==s with matches where it makes sense 2023-01-30 12:26:26 +00:00
generic_graph.rs Replace Body::basic_blocks() with field access 2022-08-26 14:27:08 +02:00
generic_graphviz.rs Remove redundant graphviz escaping 2022-11-14 15:11:18 +01:00
graphviz.rs Use Mutability::{is_mut, is_not} 2023-01-30 12:26:26 +00:00
mod.rs Rollup merge of #107411 - cjgillot:dataflow-discriminant, r=oli-obk 2023-02-15 12:24:55 +05:30
mono.rs use a more descriptive name 2023-01-30 07:20:38 +02:00
patch.rs Replace Body::basic_blocks() with field access 2022-08-26 14:27:08 +02:00
pretty.rs Review changes 2023-01-31 07:54:01 +00:00
query.rs Use derive attributes for uninteresting traversals 2023-02-14 15:09:40 +00:00
spanview.rs Auto merge of #106227 - bryangarza:ctfe-limit, r=oli-obk 2023-01-29 04:11:27 +00:00
syntax.rs Put a DefId in AggregateKind. 2023-02-02 23:09:51 +00:00
tcx.rs s/eval_usize/eval_target_usize/ for clarity 2023-02-14 08:51:19 +00:00
terminator.rs Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
traversal.rs Refactor basic blocks control flow caches 2023-01-17 12:36:58 +01:00
type_foldable.rs Use derive attributes for uninteresting traversals 2023-02-14 15:09:40 +00:00
visit.rs Create stable metric to measure long computation in Const Eval 2023-01-23 23:56:22 +00:00