about summary refs log tree commit diff
path: root/compiler/rustc_mir_dataflow/src
AgeCommit message (Collapse)AuthorLines
2025-02-19Remove `rustc_middle::mir::tcx` module.Nicholas Nethercote-2/+0
This is a really weird module. For example, what does `tcx` in `rustc_middle::mir::tcx::PlaceTy` mean? The answer is "not much". The top-level module comment says: > Methods for the various MIR types. These are intended for use after > building is complete. Awfully broad for a module that has a handful of impl blocks for some MIR types, none of which really relates to `TyCtxt`. `git blame` indicates the comment is ancient, from 2015, and made sense then. This module is now vestigial. This commit removes it and moves all the code within into `rustc_middle::mir::statement`. Some specifics: - `Place`, `PlaceRef`, `Rvalue`, `Operand`, `BorrowKind`: they all have `impl` blocks in both the `tcx` and `statement` modules. The commit merges the former into the latter. - `BinOp`, `UnOp`: they only have `impl` blocks in `tcx`. The commit moves these into `statement`. - `PlaceTy`, `RvalueInitializationState`: they are defined in `tcx`. This commit moves them into `statement` *and* makes them available in `mir::*`, like many other MIR types.
2025-02-17Remove `SwitchIntTarget`.Nicholas Nethercote-18/+10
It's only passed to `Analysis::apply_switch_int_edge_effect`, and the existing impls of that method only use the `value` field. So pass that instead.
2025-02-17Add `SwitchTargetValue`.Nicholas Nethercote-8/+15
This is much clearer than `Option<u128>`.
2025-02-17Refactor `apply_effects_in_block`.Nicholas Nethercote-13/+7
Very minor changes that will make the next few commits easier to follow.
2025-02-14Move drop elaboration infrastructure.Nicholas Nethercote-1046/+22
`rustc_mir_dataflow/src/elaborate_drops.rs` contains some infrastructure used by a few MIR passes: the `elaborate_drop` function, the `DropElaborator` trait, etc. `rustc_mir_transform/src/elaborate_drops.rs` (same file name, different crate) contains the `ElaborateDrops` pass. It relies on a lot of the infrastructure from `rustc_mir_dataflow/src/elaborate_drops.rs`. It turns out that the drop infrastructure is only used in `rustc_mir_transform`, so this commit moves it there. (The only exception is the small `DropFlagState` type, which is moved to the existing `rustc_mir_dataflow/src/drop_flag_effects.rs`.) The file is renamed from `rustc_mir_dataflow/src/elaborate_drops.rs` to `rustc_mir_transform/src/elaborate_drop.rs` (with no trailing `s`) because (a) the `elaborate_drop` function is the most important export, and (b) `rustc_mir_transform/src/elaborate_drops.rs` already exists. All the infrastructure pieces that used to be `pub` are now `pub(crate)`, because they are now only used within `rustc_mir_transform`.
2025-02-08Rustfmtbjorn3-38/+51
2025-02-03Contracts core intrinsics.Felix S. Klock II-1/+5
These are hooks to: 1. control whether contract checks are run 2. allow 3rd party tools to intercept and reintepret the results of running contracts.
2025-01-31Implement MIR, CTFE, and codegen for unsafe bindersMichael Goulet-3/+7
2025-01-28Represent the raw pointer for a array length check as a new kind of fake borrowMichael Goulet-2/+2
2025-01-19Run `clippy --fix` for `unnecessary_map_or` lintYotam Ofek-1/+1
2025-01-18Revert "Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasper"Rémy Rakic-0/+2
This reverts commit e108481f74ff123ad98a63bd107a18d13035b275, reversing changes made to 303e8bd768526a5812bb1776e798e829ddb7d3ca.
2025-01-11rename `BitSet` to `DenseBitSet`Rémy Rakic-65/+65
This should make it clearer that this bitset is dense, with the advantages and disadvantages that it entails.
2024-12-24Auto merge of #134625 - compiler-errors:unsafe-binders-ty, r=oli-obkbors-0/+2
Begin to implement type system layer of unsafe binders Mostly TODOs, but there's a lot of match arms that are basically just noops so I wanted to split these out before I put up the MIR lowering/projection part of this logic. r? oli-obk Tracking: - https://github.com/rust-lang/rust/issues/130516
2024-12-22Begin to implement type system layer of unsafe bindersMichael Goulet-0/+2
2024-12-22Delete `Rvalue::Len`Scott McMurray-2/+0
Everything's moved to `PtrMetadata` instead.
2024-12-22Auto merge of #134326 - scottmcm:slice-drop-shim-ptrmetadata, r=saethlinbors-9/+66
Use `PtrMetadata` instead of `Len` in slice drop shims I tried to do a bigger change in #134297 which didn't work, so here's the part I really wanted: Removing another use of `Len`, in favour of `PtrMetadata`. Split into two commits where the first just adds a test, so you can look at the second commit to see how the drop shim for an array changes with this PR. Reusing the same reviewer from the last one: r? BoxyUwU
2024-12-18Auto merge of #133328 - nnethercote:simplify-SwitchInt-handling, r=tmiaskobors-235/+177
Simplify `SwitchInt` handling Dataflow handling of `SwitchInt` is currently complicated. This PR simplifies it. r? `@cjgillot`
2024-12-18Rollup merge of #134161 - nnethercote:overhaul-token-cursors, r=spastorino许杰友 Jieyou Xu (Joe)-1/+0
Overhaul token cursors Some nice cleanups here. r? `````@davidtwco`````
2024-12-18Remove a comment that shouldn't have been committed.Nicholas Nethercote-1/+0
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-3/+2
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-16Remove a `FIXME` comment.Nicholas Nethercote-2/+0
It is possible to avoid the clone as suggested in the comment. It would require introducing an enum with two variants `CloneBeforeModifying(&Domain)` and `Modifiable(&mut Domain)`. But it's not worth the effort, because this code path just isn't very hot. E.g. when compiling a large benchmark like `cargo-0.60.0` it's only hit a few thousand times.
2024-12-16Remove `opt_clone_from_or_clone`.Nicholas Nethercote-30/+13
Switches to the idiom used elsewhere of calling `Analysis::bottom_value` to initialize a `state` value outside a loop, and then using `clone_from` to update it within the loop. This is simpler and has no impact on performance.
2024-12-16Factor out some shared code from `Maybe{In,Unin}itializedPlaces`.Nicholas Nethercote-60/+53
2024-12-16Simplify dataflow `SwitchInt` handling.Nicholas Nethercote-172/+138
Current `SwitchInt` handling has complicated control flow. - The dataflow engine calls `Analysis::apply_switch_int_edge_effects`, passing in an "applier" that impls `SwitchIntEdgeEffects`. - `apply_switch_int_edge_effects` possibly calls `apply` on the applier, passing it a closure. - The `apply` method calls the closure on each `SwitchInt` edge. - The closure operates on the edge. I.e. control flow goes from the engine, to the analysis, to the applier (which came from the engine), to the closure (which came from the analysis). It took me a while to work this out. This commit changes to a simpler structure that maintains the important characteristics. - The dataflow engine calls `Analysis::get_switch_int_data`. - `get_switch_int_data` returns an `Option<Self::SwitchIntData>` value. - If that returned value was `Some`, the dataflow engine calls `Analysis::apply_switch_int_edge_effect` on each edge, passing the `Self::SwitchIntData` value. - `Analysis::apply_switch_int_edge_effect` operates on the edge. I.e. control flow goes from the engine, to the analysis, to the engine, to the analysis. Added: - The `Analysis::SwitchIntData` assoc type and the `Analysis::get_switch_int_data` method. Both only need to be defined by analyses that look at `SwitchInt` terminators. - The `MaybePlacesSwitchIntData` struct, which has three fields. Changes: - `Analysis::apply_switch_int_edge_effects` becomes `Analysis::apply_switch_int_edge_effect`, which is a little simpler because it's dealing with a single edge instead of all edges. Removed: - The `SwitchIntEdgeEffects` trait, and its two impls: `BackwardSwitchIntEdgeEffectsApplier` (which has six fields) and `ForwardSwitchIntEdgeEffectsApplier` structs (which has four fields). - The closure. The new structure is more concise and simpler.
2024-12-16Add a comment to `MaybeInitializedPlaces::apply_terminator_effect`.Nicholas Nethercote-0/+2
I tried reordering this method to more closely match `MaybeUninitializedPlaces::apply_terminator_effect`, but doing so breaks tests.
2024-12-14Use `PtrMetadata` instead of `Len` in slice drop shimsScott McMurray-9/+66
2024-12-13Rollup merge of #133938 - nnethercote:rustc_mir_dataflow-renamings, r=oli-obkMatthias Krüger-318/+260
`rustc_mir_dataflow` cleanups, including some renamings Some opinionated commits in this collection, let's see how we go. r? `@cjgillot`
2024-12-11Simplify `rustc_mir_dataflow::abs_domain`.Nicholas Nethercote-37/+11
`rustc_mir_dataflow` has a typedef `AbstractElem` that is equal to `ProjectionElem<AbstractOperand, AbstractType>`. `AbstractOperand` and `AbstractType` are both unit types. There is also has a trait `Lift` to convert a `PlaceElem` to an `AbstractElem`. But `rustc_mir_middle` already has a typedef `ProjectionKind` that is equal to `ProjectionElem<(), ()>`, which is equivalent to `AbstractElem`. So this commit reuses `ProjectionKind` in `rustc_mir_dataflow`, removes `AbstractElem`, and simplifies the `Lift` trait.
2024-12-10Rollup merge of #134065 - nnethercote:mv-write_graphviz_results, r=tmiaskoLeón Orell Valerian Liehr-191/+182
Move `write_graphviz_results` r? ``@tmiasko``
2024-12-10Reorder some `Analysis` methods.Nicholas Nethercote-33/+33
In most places, the `early` method is listed before the corresponding `primary` method, like you'd expect. This commit fixes two places where that isn't the case.
2024-12-10Rename some `Analysis` and `ResultsVisitor` methods.Nicholas Nethercote-117/+115
The words "before" and "after" have an obvious temporal meaning, e.g. `seek_before_primary_effect`, `visit_statement_{before,after}_primary_effect`. But "before" is also used to name the effect that occurs before the primary effect of a statement/terminator; this is `Effect::Before`. This leads to the confusing possibility of talking about things happening "before/after the before event". This commit removes this awkward overloading of "before" by renaming `Effect::Before` as `Effect::Early`. It also renames some of the `Analysis` and `ResultsVisitor` methods to be more consistent. Here are the before and after names: - `Effect::{Before,Primary}` -> `Effect::{Early,Primary}` - `apply_before_statement_effect` -> `apply_early_statement_effect` - `apply_statement_effect` -> `apply_primary_statement_effect` - `visit_statement_before_primary_effect` -> `visit_after_early_statement_effect` - `visit_statement_after_primary_effect` -> `visit_after_primary_statement_effect` (And s/statement/terminator/ for all the terminator events.)
2024-12-10Rename `EntrySets` as `EntryStates`.Nicholas Nethercote-15/+16
"Set" doesn't make much sense here, we refer to domain values as "state" everywhere else. (This name confused me for a while.)
2024-12-10Call all `Domain` values `state`.Nicholas Nethercote-90/+90
Currently they are called (most common) `state`, or `trans`, or (rare) `on_entry`. I think `trans` is short for "transfer function", which perhaps made more sense when `GenKillAnalysis` existed. Using `state` everywhere now is more consistent.
2024-12-10Refer to a couple of domains indirectly.Nicholas Nethercote-3/+2
Via the `Analysis::Domain` associated types, instead of the direct type name.
2024-12-10Remove lifetimes from `BorrowckDomain`.Nicholas Nethercote-7/+12
They are only present because it's currently defined in terms of the domains of `Borrows` and `MaybeUninitializedPlaces` and `EverInitializedPlaces` via associated types. This commit introduces typedefs for those domains, avoiding the lifetimes.
2024-12-10Remove unused dataflow trait impls and bounds.Nicholas Nethercote-64/+3
2024-12-10Fix an out-of-date comment.Nicholas Nethercote-1/+1
2024-12-09Remove an out-of-date comment.Nicholas Nethercote-4/+0
The part about zero-sized structures is totally wrong. The rest of it has almost no explanatory value; there are better explanations in comments elsewhere.
2024-12-09Move `write_graphviz_results` from `results.rs` to `graphviz.rs`.Nicholas Nethercote-187/+182
It's more graphviz-y than it is results-y. This lets us reduce visibility of several types in `graphviz.rs`.
2024-12-09Remove `ChunkedBitSet` impls that are no longer needed.Nicholas Nethercote-24/+2
`ChunkedBitSet` is no longer used directly by dataflow analyses, with `MixedBitSet` replacing it in those contexts.
2024-12-09Use `MixedBitSet` instead of `ChunkedBitSet` in `fmt.rs`.Nicholas Nethercote-6/+6
Just minimizing uses of `ChunkedBitSet`.
2024-12-05Change `ChunkedBitSet<MovePathIndex>`s to `MixedBitSet`.Nicholas Nethercote-11/+11
It's a performance win because `MixedBitSet` is faster and uses less memory than `ChunkedBitSet`. Also reflow some overlong comment lines in `lint_tail_expr_drop_order.rs`.
2024-12-05Introduce `MixedBitSet`.Nicholas Nethercote-3/+45
It just uses `BitSet` for small/medium sizes (<= 2048 bits) and `ChunkedBitSet` for larger sizes. This is good because `ChunkedBitSet` is slow and memory-hungry at smaller sizes.
2024-12-02Simplify `ResultsHandle`.Nicholas Nethercote-17/+3
The `Borrowed` variant is no longer used. This commit removes it, along with the `as_results_cursor` method that produces it, and renames `as_results_cursor_mut` as `as_results_cursor`.
2024-12-02Fix crash with `-Zdump-mir-dataflow`Nicholas Nethercote-5/+5
As of #133155 `Formatter:new` uses `as_results_cursor` to create a non-mutable results reference, and then later that is accessed via `deref_mut` which results in a runtime abort. Changing to `as_results_cursor_mut` fixes it. Fixes #133641.
2024-11-29Stop using `HybridBitSet` in dataflow diffs.Nicholas Nethercote-7/+7
As part of the larger goal of reducing `HybridBitSet` use in general. This code is for debugging only and isn't performance sensitive, so `ChunkedBitSet` should be fine.
2024-11-29Remove unused `HybridBitSet` methods from `BitSetExt`.Nicholas Nethercote-34/+2
2024-11-26Rollup merge of #133475 - nnethercote:MaybeStorage-improvements, r=lcnrMichael Goulet-28/+23
`MaybeStorage` improvements Minor dataflow improvements. r? `@tmiasko`
2024-11-26Rollup merge of #133326 - nnethercote:rm-DefinitelyInitializedPlaces, r=cjgillotMichael Goulet-278/+13
Remove the `DefinitelyInitializedPlaces` analysis. Its only use is in the `tests/ui/mir-dataflow/def_inits-1.rs` where it is tested via `rustc_peek_definite_init`. Also, it's probably buggy. It's supposed to be the inverse of `MaybeUninitializedPlaces`, and it mostly is, except that `apply_terminator_effect` is a little different, and `apply_switch_int_edge_effects` is missing. Unlike `MaybeUninitializedPlaces`, which is used extensively in borrow checking, any bugs in `DefinitelyInitializedPlaces` are easy to overlook because it is only used in one small test. This commit removes the analysis. It also removes `rustc_peek_definite_init`, `Dual` and `MeetSemiLattice`, all of which are no longer needed. r? ``@cjgillot``
2024-11-26Make some modules non-`pub`.Nicholas Nethercote-2/+2
- drop_flag_effects: `pub` items within are all re-exported in `lib.rs`. - un_derefer: doesn't contain any `pub` items.