Files
rust/compiler/rustc_mir_dataflow/src/framework/visitor.rs
Nicholas Nethercote c904c6aaff Remove ResultsVisitable.
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-05 10:18:03 +11:00

84 lines
2.6 KiB
Rust

use rustc_middle::mir::{self, BasicBlock, Location};
use super::{Analysis, Direction, Results};
/// Calls the corresponding method in `ResultsVisitor` for every location in a `mir::Body` with the
/// dataflow state at that location.
pub fn visit_results<'mir, 'tcx, A>(
body: &'mir mir::Body<'tcx>,
blocks: impl IntoIterator<Item = BasicBlock>,
results: &mut Results<'tcx, A>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
) where
A: Analysis<'tcx>,
{
let mut state = results.analysis.bottom_value(body);
#[cfg(debug_assertions)]
let reachable_blocks = mir::traversal::reachable_as_bitset(body);
for block in blocks {
#[cfg(debug_assertions)]
assert!(reachable_blocks.contains(block));
let block_data = &body[block];
A::Direction::visit_results_in_block(&mut state, block, block_data, results, vis);
}
}
/// A visitor over the results of an `Analysis`.
pub trait ResultsVisitor<'mir, 'tcx, A>
where
A: Analysis<'tcx>,
{
fn visit_block_start(&mut self, _state: &A::Domain) {}
/// Called with the `before_statement_effect` of the given statement applied to `state` but not
/// its `statement_effect`.
fn visit_statement_before_primary_effect(
&mut self,
_results: &mut Results<'tcx, A>,
_state: &A::Domain,
_statement: &'mir mir::Statement<'tcx>,
_location: Location,
) {
}
/// Called with both the `before_statement_effect` and the `statement_effect` of the given
/// statement applied to `state`.
fn visit_statement_after_primary_effect(
&mut self,
_results: &mut Results<'tcx, A>,
_state: &A::Domain,
_statement: &'mir mir::Statement<'tcx>,
_location: Location,
) {
}
/// Called with the `before_terminator_effect` of the given terminator applied to `state` but
/// not its `terminator_effect`.
fn visit_terminator_before_primary_effect(
&mut self,
_results: &mut Results<'tcx, A>,
_state: &A::Domain,
_terminator: &'mir mir::Terminator<'tcx>,
_location: Location,
) {
}
/// Called with both the `before_terminator_effect` and the `terminator_effect` of the given
/// terminator applied to `state`.
///
/// The `call_return_effect` (if one exists) will *not* be applied to `state`.
fn visit_terminator_after_primary_effect(
&mut self,
_results: &mut Results<'tcx, A>,
_state: &A::Domain,
_terminator: &'mir mir::Terminator<'tcx>,
_location: Location,
) {
}
fn visit_block_end(&mut self, _state: &A::Domain) {}
}