1use rustc_middle::mir::{self, BasicBlock, Location};
23use super::{Analysis, Direction, Results};
45/// Calls the visitor methods in `vis` for every location in every block in `blocks`. Note that
6/// every block in `blocks` must be reachable, and a `debug_assert` checks this.
7pub fn visit_results<'mir, 'tcx, A>(
8 body: &'mir mir::Body<'tcx>,
9 blocks: impl IntoIterator<Item = BasicBlock>,
10 results: &Results<'tcx, A>,
11 vis: &mut impl ResultsVisitor<'tcx, A>,
12) where
13A: Analysis<'tcx>,
14{
15let mut state = results.analysis.bottom_value(body);
1617#[cfg(debug_assertions)]
18let reachable_blocks = mir::traversal::reachable_as_bitset(body);
1920for block in blocks {
21#[cfg(debug_assertions)]
22if !reachable_blocks.contains(block) {
::core::panicking::panic("assertion failed: reachable_blocks.contains(block)")
};assert!(reachable_blocks.contains(block));
2324let block_data = &body[block];
25 state.clone_from(&results.entry_states[block]);
26 A::Direction::visit_results_in_block(&results.analysis, &mut state, block, block_data, vis);
27 }
28}
2930/// A visitor over the results of an `Analysis`. Use this when you want to inspect domain values in
31/// many or all locations; use `ResultsCursor` if you want to inspect domain values only in certain
32/// locations.
33pub trait ResultsVisitor<'tcx, A>
34where
35A: Analysis<'tcx>,
36{
37/// Called after the "early" effect of the given statement is applied to `state`.
38fn visit_after_early_statement_effect(
39&mut self,
40 _state: &A::Domain,
41 _statement: &mir::Statement<'tcx>,
42 _location: Location,
43 ) {
44 }
4546/// Called after the "primary" effect of the given statement is applied to `state`.
47fn visit_after_primary_statement_effect(
48&mut self,
49 _state: &A::Domain,
50 _statement: &mir::Statement<'tcx>,
51 _location: Location,
52 ) {
53 }
5455/// Called after the "early" effect of the given terminator is applied to `state`.
56fn visit_after_early_terminator_effect(
57&mut self,
58 _state: &A::Domain,
59 _terminator: &mir::Terminator<'tcx>,
60 _location: Location,
61 ) {
62 }
6364/// Called after the "primary" effect of the given terminator is applied to `state`.
65 ///
66 /// The `call_return_effect` (if one exists) will *not* be applied to `state`.
67fn visit_after_primary_terminator_effect(
68&mut self,
69 _state: &A::Domain,
70 _terminator: &mir::Terminator<'tcx>,
71 _location: Location,
72 ) {
73 }
74}