rustc_mir_dataflow/framework/
visitor.rsuse rustc_middle::mir::{self, BasicBlock, Location};
use super::{Analysis, Direction, Results};
pub fn visit_results<'mir, 'tcx, D, R>(
body: &'mir mir::Body<'tcx>,
blocks: impl IntoIterator<Item = BasicBlock>,
results: &mut R,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>,
) where
R: ResultsVisitable<'tcx, Domain = D>,
{
let mut state = results.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];
R::Direction::visit_results_in_block(&mut state, block, block_data, results, vis);
}
}
pub trait ResultsVisitor<'mir, 'tcx, R> {
type Domain;
fn visit_block_start(&mut self, _state: &Self::Domain) {}
fn visit_statement_before_primary_effect(
&mut self,
_results: &mut R,
_state: &Self::Domain,
_statement: &'mir mir::Statement<'tcx>,
_location: Location,
) {
}
fn visit_statement_after_primary_effect(
&mut self,
_results: &mut R,
_state: &Self::Domain,
_statement: &'mir mir::Statement<'tcx>,
_location: Location,
) {
}
fn visit_terminator_before_primary_effect(
&mut self,
_results: &mut R,
_state: &Self::Domain,
_terminator: &'mir mir::Terminator<'tcx>,
_location: Location,
) {
}
fn visit_terminator_after_primary_effect(
&mut self,
_results: &mut R,
_state: &Self::Domain,
_terminator: &'mir mir::Terminator<'tcx>,
_location: Location,
) {
}
fn visit_block_end(&mut self, _state: &Self::Domain) {}
}
pub trait ResultsVisitable<'tcx> {
type Direction: Direction;
type Domain;
fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain;
fn reset_to_block_entry(&self, state: &mut Self::Domain, block: BasicBlock);
fn reconstruct_before_statement_effect(
&mut self,
state: &mut Self::Domain,
statement: &mir::Statement<'tcx>,
location: Location,
);
fn reconstruct_statement_effect(
&mut self,
state: &mut Self::Domain,
statement: &mir::Statement<'tcx>,
location: Location,
);
fn reconstruct_before_terminator_effect(
&mut self,
state: &mut Self::Domain,
terminator: &mir::Terminator<'tcx>,
location: Location,
);
fn reconstruct_terminator_effect(
&mut self,
state: &mut Self::Domain,
terminator: &mir::Terminator<'tcx>,
location: Location,
);
}
impl<'tcx, A> ResultsVisitable<'tcx> for Results<'tcx, A>
where
A: Analysis<'tcx>,
{
type Domain = A::Domain;
type Direction = A::Direction;
fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain {
self.analysis.bottom_value(body)
}
fn reset_to_block_entry(&self, state: &mut Self::Domain, block: BasicBlock) {
state.clone_from(self.entry_set_for_block(block));
}
fn reconstruct_before_statement_effect(
&mut self,
state: &mut Self::Domain,
stmt: &mir::Statement<'tcx>,
loc: Location,
) {
self.analysis.apply_before_statement_effect(state, stmt, loc);
}
fn reconstruct_statement_effect(
&mut self,
state: &mut Self::Domain,
stmt: &mir::Statement<'tcx>,
loc: Location,
) {
self.analysis.apply_statement_effect(state, stmt, loc);
}
fn reconstruct_before_terminator_effect(
&mut self,
state: &mut Self::Domain,
term: &mir::Terminator<'tcx>,
loc: Location,
) {
self.analysis.apply_before_terminator_effect(state, term, loc);
}
fn reconstruct_terminator_effect(
&mut self,
state: &mut Self::Domain,
term: &mir::Terminator<'tcx>,
loc: Location,
) {
self.analysis.apply_terminator_effect(state, term, loc);
}
}