summary refs log tree commit diff
path: root/compiler/rustc_mir_dataflow/src
AgeCommit message (Collapse)AuthorLines
2024-01-25Remove unused featuresclubby789-3/+1
2024-01-22Use a plain bitset for liveness analyses.Camille GILLOT-10/+17
2024-01-20Add a warning commentGeorgiy Komarov-0/+2
2024-01-20rustc_mir_dataflow: Add exports for external toolsGeorgiy Komarov-3/+3
Added back previously available exports: * Forward/Backward: used when implementing `AnalysisDomain` * Engine: used in user's code to solve the dataflow problem * SwitchIntEdgeEffects: used when implementing functions of the `Analysis` trait * graphviz: potentially useful for debugging purposes These exports are used when implementing external tools based on MIR dataflow framework. Closes #120130
2024-01-17Rollup merge of #115291 - cjgillot:dest-prop-save, r=JakobDegenMatthias Krüger-0/+157
Save liveness results for DestinationPropagation `DestinationPropagation` needs to verify that merge candidates do not conflict with each other. This is done by verifying that a local is not live when its counterpart is written to. To get the liveness information, the pass runs `MaybeLiveLocals` dataflow analysis repeatedly, once for each propagation round. This is quite costly, and the main driver for the perf impact on `ucd` and `diesel`. (See https://github.com/rust-lang/rust/pull/115105#issuecomment-1689205908) In order to mitigate this cost, this PR proposes to save the result of the analysis into a `SparseIntervalMatrix`, and mirror merges of locals into that matrix: `liveness(destination) := liveness(destination) union liveness(source)`. <details> <summary>Proof</summary> We denote by `'` all the quantities of the transformed program. Let $\varphi$ be a mapping of locals, which maps `source` to `destination`, and is identity otherwise. The exact liveness set after a statement is $out'(statement)$, and the proposed liveness set is $\varphi(out(statement))$. Consider a statement. Suppose that the output state verifies $out' \subset phi(out)$. We want to prove that $in' \subset \varphi(in)$ where $in = (out - kill) \cup gen$, and conclude by induction. We have 2 cases: either that statement is kept with locals renumbered by $\varphi$, or it is a tautological assignment and it removed. 1. If the statement is kept: the gen-set and the kill-set of $statement' = \varphi(statement)$ are $gen' = \varphi(gen)$ and $kill' = \varphi(kill)$ exactly. From soundness requirement 3, $\varphi(in)$ is disjoint from $\varphi(kill)$. This implies that $\varphi(out - kill)$ is disjoint from $\varphi(kill)$, and so $\varphi(out - kill) = \varphi(out) - \varphi(kill)$. Then $\varphi(in) = (\varphi(out) - \varphi(kill)) \cup \varphi(gen) = (\varphi(out) - kill') \cup gen'$. We can conclude that $out' \subset \varphi(out) \implies in' \subset \varphi(in)$. 2. If the statement is removed. As $\varphi(statement)$ is a tautological assignment, we know that $\varphi(gen) = \varphi(kill) = \\{ destination \\}$, while $gen' = kill' = \emptyset$. So $\varphi(in) = \varphi(out) \cup \\{ destination \\}$. Then $in' = out' \subset out \subset \varphi(in)$. By recursion, we can conclude by that $in' \subset \varphi(in)$ everywhere. </details> This approximate liveness results is only suboptimal if there are locals that fully disappear from the CFG due to an assignment cycle. These cases are quite unlikely, so we do not bother with them. This change allows to reduce the perf impact of DestinationPropagation by half on diesel and ucd (https://github.com/rust-lang/rust/pull/115105#issuecomment-1694701904). cc ````@JakobDegen````
2024-01-15compiler: Lower fn call arg spans down to MIRMartin Nordholts-3/+8
To enable improved accuracy of diagnostics in upcoming commits.
2024-01-07Use for_each instead of fold.Camille GILLOT-2/+2
2024-01-07Fix comment.Camille GILLOT-3/+1
2024-01-07Do not recompute liveness for DestinationPropagation.Camille GILLOT-1/+65
2024-01-07Move PointIndex to mir_dataflow.Camille GILLOT-0/+95
2023-12-28Remove movability from TyKind::CoroutineMichael Goulet-3/+3
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-12/+14
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-21Don't require owned data in `MaybeStorageDead`Tomasz Miąsko-6/+6
2023-12-15NFC don't convert types to identical typesMatthias Krüger-5/+1
2023-12-10remove redundant importssurechen-2/+0
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-08Tweak `GenKillAnalysis`.Nicholas Nethercote-19/+22
`GenKillAnalysis` has five methods that take a transfer function arg: - `statement_effect` - `before_statement_effect` - `terminator_effect` - `before_terminator_effect` - `call_return_effect` All the transfer function args have type `&mut impl GenKill<Self::Idx>`, except for `terminator_effect`, which takes the simpler `Self::Domain`. But only the first two need to be `impl GenKill`. The other three can all be `Self::Domain`, just like `Analysis`. So this commit changes the last two to take `Self::Domain`, making `GenKillAnalysis` and `Analysis` more similar. (Another idea would be to make all these methods `impl GenKill`. But that doesn't work: `MaybeInitializedPlaces::terminator_effect` requires the arg be `Self::Domain` so that `self_is_unwind_dead(place, state)` can be called on it.)
2023-12-08Remove `impl_visitable!`.Nicholas Nethercote-2/+2
It is used just once. With it removed, the relevant code is a little boilerplate-y but much easier to read, and is the same length. Overall I think it's an improvement.
2023-12-08Remove unused arguments from `ResultsVisitor::visit_block_{start,end}`.Nicholas Nethercote-34/+8
2023-11-27Deparameterize `Results` and `ResultsCursor`.Nicholas Nethercote-72/+27
They both now only ever contain a `Results<'tcx, A>`. This means `AnalysisResults` can be removed, as can many `borrow`/`borrow_mut` calls. Also `Results` no longer needs a `PhantomData` because `'tcx` is now named by `entry_sets`.
2023-11-27Remove `ResultsCloned` and `ResultsClonedCursor`.Nicholas Nethercote-26/+4
They're now unused.
2023-11-27Remove uses of `ResultsClonedCursor`.Nicholas Nethercote-14/+14
By just cloning the entire `Results` in the one place where `ResultsClonedCursor` was used. This is extra allocations but the performance effect is negligible.
2023-11-27Remove `ResultsRefCursor`.Nicholas Nethercote-29/+2
It's no longer used.
2023-11-27Remove another use of `as_results_cursor`.Nicholas Nethercote-40/+62
The new code is a little clunky, but I couldn't see how to make it better.
2023-11-27Remove `CloneAnalysis`.Nicholas Nethercote-29/+5
It's only implemented for analyses that implement `Copy`, which means it's basically a complicated synonym for `Copy`. So this commit removes it and uses `Copy` directly. (That direct use will be removed in a later commit.)
2023-11-27Remove some unused code relating to `ResultsCloned`.Nicholas Nethercote-39/+2
2023-11-27Use typedefs to clarify some impls.Nicholas Nethercote-2/+5
And insert some whitespace.
2023-11-25Rollup merge of #118288 - compiler-errors:is_some_and, r=lqd,dtolnayMichael Goulet-1/+1
Use `is_{some,ok}_and` more in the compiler slightly more fluent-reading code
2023-11-26Use `rustc_fluent_macro::fluent_messages!` directly.Nicholas Nethercote-2/+1
Currently we always do this: ``` use rustc_fluent_macro::fluent_messages; ... fluent_messages! { "./example.ftl" } ``` But there is no need, we can just do this everywhere: ``` rustc_fluent_macro::fluent_messages! { "./example.ftl" } ``` which is shorter.
2023-11-26Avoid need for `{D,Subd}iagnosticMessage` imports.Nicholas Nethercote-1/+0
The `fluent_messages!` macro produces uses of `crate::{D,Subd}iagnosticMessage`, which means that every crate using the macro must have this import: ``` use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; ``` This commit changes the macro to instead use `rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the imports.
2023-11-25is_{some,ok}_andMichael Goulet-1/+1
2023-11-25Auto merge of #118203 - nnethercote:rustc_mir_dataflow, r=cjgillotbors-164/+88
Minor `rustc_mir_dataflow` cleanups r? `@cjgillot`
2023-11-24Remove `ResultsCursor::get_with_analysis`.Nicholas Nethercote-6/+2
We can just call `ResultsCursor::state` and `ResultsCursor::analysis` separately.
2023-11-24Remove unnecessary `mut`.Nicholas Nethercote-1/+1
`mut_results` immediately below is the `&mut self` version, this one should be `&self`.
2023-11-24Remove unused arguments from `on_all_children_bits`.Nicholas Nethercote-56/+25
`on_all_children_bits` has two arguments that are unused: `tcx` and `body`. This was not detected by the compiler because it's a recursive function. This commit removes them, and removes lots of other arguments and fields that are no longer necessary.
2023-11-24Remove unused `EverInitializedPlaces::tcx` field.Nicholas Nethercote-4/+2
2023-11-24Remove unneeded derives from `MaybeLiveLocals`.Nicholas Nethercote-1/+0
2023-11-23Use `'mir` lifetime name more.Nicholas Nethercote-14/+14
Some types have a `body: &'mir Body<'tcx>` and some have `body: &'a Body<'tcx>`. The former is more readable, so this commit converts some fo the latter to the former.
2023-11-23Remove unnecessary things from `State` and `Map`.Nicholas Nethercote-25/+4
2023-11-23Remove unnecessary and misleading `..` in a pattern.Nicholas Nethercote-1/+0
All the fields are named.
2023-11-23Remove unnecessary `ValueAnalysisWrapper::Direction`.Nicholas Nethercote-5/+1
`Forward` is the default.
2023-11-23Reduce `pub` usage.Nicholas Nethercote-12/+10
2023-11-23Avoid unnecessary exports.Nicholas Nethercote-11/+11
2023-11-23Remove `indexes` module.Nicholas Nethercote-6/+1
It's not useful, and only obfuscates things.
2023-11-23Move `has_rustc_mir_with`.Nicholas Nethercote-19/+17
`lib.rs` is a strange place for it, and it's only used within `rustc_peek.rs`, so it doesn't need to be `pub`.
2023-11-23Reorder some `use` items.Nicholas Nethercote-8/+6
The current order is a mess.
2023-11-23Remove unused feature.Nicholas Nethercote-1/+0
2023-11-22Replace `no_ord_impl` with `orderable`.Nicholas Nethercote-0/+2
Similar to the previous commit, this replaces `newtype_index`'s opt-out `no_ord_impl` attribute with the opt-in `orderable` attribute.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-15/+11
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-08rename `BorrowKind::Shallow` to `Fake`lcnr-2/+2
also adds some comments
2023-11-08generator layout: ignore fake borrowslcnr-2/+7