about summary refs log tree commit diff
path: root/compiler/rustc_mir_dataflow
AgeCommit message (Collapse)AuthorLines
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.
2024-11-26Move `always_storage_live_locals`.Nicholas Nethercote-22/+20
It's very closely related to `MaybeStorageLive` and `MaybeStorageDead`. It's weird that it's currently in a different module.
2024-11-26Improve `MaybeStorageLive::initialize_start_block`.Nicholas Nethercote-4/+1
We can union the two sets the easy way. This removes the need for the domain size check, because `union` does that same check itself.
2024-11-26Make it possible for `ResultsCursor` to borrow a `Results`.Nicholas Nethercote-25/+76
`ResultsCursor` currently owns its `Results`. But sometimes the `Results` is needed again afterwards. So there is `ResultsCursor::into_results` for extracting the `Results`, which leads to some awkwardness. This commit adds `ResultsHandle`, a `Cow`-like type that can either borrow or own a a `Results`. `ResultsCursor` now uses it. This is good because some `ResultsCursor`s really want to own their `Results`, while others just want to borrow it. We end with with a few more lines of code, but get some nice cleanups. - `ResultsCursor::into_results` and `Formatter::into_results` are removed. - `write_graphviz_results` now just borrows a `Results`, instead of the awkward "take ownership of a `Results` and then return it unchanged" pattern. This reinstates the cursor flexibility that was lost in #118230 -- which removed the old `ResultsRefCursor` and `ResultsCloneCursor` types -- but in a much simpler way. Hooray!
2024-11-26Tweak `MaybeBorrowedLocals::transfer_function` usage.Nicholas Nethercote-1/+1
In `MaybeRequiresStorage::apply_before_statement_effect`, call `transfer_function` directly, as is already done in `MaybeRequiresStorage::apply_before_terminator_effect`. This makes it clear that the operation doesn't rely on the `MaybeBorrowedLocals` results.
2024-11-26Remove `self` param for `MaybeBorrowedLocals::transfer_function`.Nicholas Nethercote-7/+4
It is unnecessary.
2024-11-26Add some useful comments.Nicholas Nethercote-12/+24
Describing some things that took me a long time to understand.
2024-11-26Merge `apply_effects_in_block` and `join_state_into_successors_of`.Nicholas Nethercote-162/+132
They are always called in succession, so it's simpler if they are merged into a single function.
2024-11-23`ElaborateDrops`: use typing_env directlylcnr-2/+2
2024-11-22Remove the `DefinitelyInitializedPlaces` analysis.Nicholas Nethercote-278/+13
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.
2024-11-20reduce false positives of tail-expr-drop-order from consumed valuesDing Xiang Fei-0/+3
take 2 open up coroutines tweak the wordings the lint works up until 2021 We were missing one case, for ADTs, which was causing `Result` to yield incorrect results. only include field spans with significant types deduplicate and eliminate field spans switch to emit spans to impl Drops Co-authored-by: Niko Matsakis <nikomat@amazon.com> collect drops instead of taking liveness diff apply some suggestions and add explantory notes small fix on the cache let the query recurse through coroutine new suggestion format with extracted variable name fine-tune the drop span and messages bugfix on runtime borrows tweak message wording filter out ecosystem types earlier apply suggestions clippy check lint level at session level further restrict applicability of the lint translate bid into nop for stable mir detect cycle in type structure
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-15/+14
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-05Remove `ResultsVisitable`.Nicholas Nethercote-173/+73
Now that `Results` is the only impl of `ResultsVisitable`, the trait can be removed. This simplifies things by removining unnecessary layers of indirection and abstraction. - `ResultsVisitor` is simpler. - Its type parameter changes from `R` (an analysis result) to the simpler `A` (an analysis). - It no longer needs the `Domain` associated type, because it can use `A::Domain`. - Occurrences of `R` become `Results<'tcx, A>`, because there is now only one kind of analysis results. - `save_as_intervals` also changes type parameter from `R` to `A`. - The `results.reconstruct_*` method calls are replaced with `results.analysis.apply_*` method calls, which are equivalent. - `Direction::visit_results_in_block` is simpler, with a single generic param (`A`) instead of two (`D` and `R`/`F`, with a bound connecting them). Likewise for `visit_results`. - The `ResultsVisitor` impls for `MirBorrowCtxt` and `StorageConflictVisitor` are now specific about the type of the analysis results they work with. They both used to have a type param `R` but they weren't genuinely generic. In both cases there was only a single results type that made sense to instantiate them with.
2024-11-05Replace `BorrowckResults` with `Borrowck`.Nicholas Nethercote-6/+6
The results of most analyses end up in a `Results<'tcx, A>`, where `A` is the analysis. It's then possible to traverse the results via a `ResultsVisitor`, which relies on the `ResultsVisitable` trait. (That trait ends up using the same `apply_*` methods that were used when computing the analysis, albeit indirectly.) This pattern of "compute analysis results, then visit them" is common. But there is one exception. For borrow checking we compute three separate analyses (`Borrows`, `MaybeUninitializedPlaces`, and `EverInitializedPlaces`), combine them into a single `BorrowckResults`, and then do a single visit of that `BorrowckResults` with `MirBorrowckResults`. `BorrowckResults` is just different enough from `Results` that it requires the existence of `ResultsVisitable`, which abstracts over the traversal differences between `Results` and `BorrowckResults`. This commit changes things by introducing `Borrowck` and bundling the three borrowck analysis results into a standard `Results<Borrowck>` instead of the exceptional `BorrowckResults`. Once that's done, the results can be visited like any other analysis results. `BorrowckResults` is removed, as is `impl ResultsVisitable for BorrowckResults`. (It's instructive to see how similar the added `impl Analysis for Borrowck` is to the removed `impl ResultsVisitable for BorrowckResults`. They're both doing exactly the same things.) Overall this increases the number of lines of code and might not seem like a win. But it enables the removal of `ResultsVisitable` in the next commit, which results in many simplifications.
2024-11-03compiler: Remove unused rustc_target from Cargo.tomlsJubilee Young-1/+0
2024-10-31Remove `ValueAnalysis` and `ValueAnalysisWrapper`.Nicholas Nethercote-412/+4
They represent a lot of abstraction and indirection, but they're only used for `ConstAnalysis`, and apparently won't be used for any other analyses in the future. This commit inlines and removes them, which makes `ConstAnalysis` easier to read and understand.
2024-10-30Rollup merge of #132246 - workingjubilee:campaign-on-irform, r=compiler-errorsJubilee-1/+1
Rename `rustc_abi::Abi` to `BackendRepr` Remove the confabulation of `rustc_abi::Abi` with what "ABI" actually means by renaming it to `BackendRepr`, and rename `Abi::Aggregate` to `BackendRepr::Memory`. The type never actually represented how things are passed, as that has to have `PassMode` considered, at minimum, but rather it just is how we represented some things to the backend. This conflation arose because LLVM, the primary backend at the time, would lower certain IR forms using certain ABIs. Even that only somewhat was true, as it broke down when one ventured significantly afield of what is described by the System V AMD64 ABI either by using different architectures, ABI-modifying IR annotations, the same architecture **with different ISA extensions enabled**, or other... unexpected delights. Unfortunately both names are still somewhat of a misnomer right now, as people have written code for years based on this misunderstanding. Still, their original names are even moreso, and for better or worse, this backend code hasn't received as much maintenance as the rest of the compiler, lately. Actually arriving at a correct end-state will simply require us to disentangle a lot of code in order to fix, much of it pointlessly repeated in several places. Thus this is not an "actual fix", just a way to deflect further misunderstandings.
2024-10-30Rollup merge of #132346 - nnethercote:some-graphviz-tweaks, r=cjgillot许杰友 Jieyou Xu (Joe)-53/+58
Some graphviz tweaks r? `@cjgillot`
2024-10-30Rollup merge of #132338 - nnethercote:rm-Engine, r=nnethercoteMatthias Krüger-147/+104
Remove `Engine` It's just unnecessary plumbing. Removing it results in less code, and simpler code. r? ``@cjgillot``
2024-10-30Return label from `write_node_label`.Nicholas Nethercote-4/+10
Instead of appending an empty label. Because it's conceptually simpler.