pub struct PathExtractor<'tcx> {
cfg: CFG,
callsites: Vec<Callsite<'tcx>>,
loops: Vec<LoopInfo>,
block_to_loop: FxHashMap<BasicBlock, LoopId>,
paths: FxHashMap<CallsiteLocation, Vec<Path>>,
}Expand description
Extracts loop-aware paths for one function body.
Fields§
§cfg: CFG§callsites: Vec<Callsite<'tcx>>§loops: Vec<LoopInfo>§block_to_loop: FxHashMap<BasicBlock, LoopId>§paths: FxHashMap<CallsiteLocation, Vec<Path>>Implementations§
Source§impl<'tcx> PathExtractor<'tcx>
impl<'tcx> PathExtractor<'tcx>
Sourcepub fn new(
tcx: TyCtxt<'tcx>,
def_id: DefId,
callsites: Vec<Callsite<'tcx>>,
) -> Self
pub fn new( tcx: TyCtxt<'tcx>, def_id: DefId, callsites: Vec<Callsite<'tcx>>, ) -> Self
Create a path extractor for def_id and the callsites found in that body.
Sourcepub fn run(self) -> PathResult<'tcx>
pub fn run(self) -> PathResult<'tcx>
Run loop detection and path extraction, then return the collected result.
Sourcefn find_loops(&mut self)
fn find_loops(&mut self)
Detect loops in the function CFG and store their block-to-loop map.
Sourcefn find_paths(&mut self)
fn find_paths(&mut self)
Extract paths for every callsite owned by this extractor.
Sourcefn callsites_by_block(&self) -> FxHashMap<BasicBlock, CallsiteLocation>
fn callsites_by_block(&self) -> FxHashMap<BasicBlock, CallsiteLocation>
Build a map from callsite basic blocks to their stable locations.
Sourcefn find_paths_for_callsite(
&self,
callsite: &Callsite<'tcx>,
by_block: &FxHashMap<BasicBlock, CallsiteLocation>,
) -> Vec<Path>
fn find_paths_for_callsite( &self, callsite: &Callsite<'tcx>, by_block: &FxHashMap<BasicBlock, CallsiteLocation>, ) -> Vec<Path>
Extract paths for one callsite according to whether it is inside a loop.
Sourcefn find_entry_paths(
&self,
target: CallsiteLocation,
target_block: BasicBlock,
by_block: &FxHashMap<BasicBlock, CallsiteLocation>,
) -> Vec<Path>
fn find_entry_paths( &self, target: CallsiteLocation, target_block: BasicBlock, by_block: &FxHashMap<BasicBlock, CallsiteLocation>, ) -> Vec<Path>
Enumerate finite paths from function entry to a callsite outside loops.
The search does not expand loop bodies. When a successor enters a loop that does not contain the target callsite, the path records one loop-exit step and continues from the exit destination.
Sourcefn dfs_entry_paths(
&self,
current: BasicBlock,
target: CallsiteLocation,
target_block: BasicBlock,
by_block: &FxHashMap<BasicBlock, CallsiteLocation>,
visited: &mut FxHashSet<BasicBlock>,
stack: &mut Vec<PathStep>,
results: &mut Vec<Path>,
limit: usize,
)
fn dfs_entry_paths( &self, current: BasicBlock, target: CallsiteLocation, target_block: BasicBlock, by_block: &FxHashMap<BasicBlock, CallsiteLocation>, visited: &mut FxHashSet<BasicBlock>, stack: &mut Vec<PathStep>, results: &mut Vec<Path>, limit: usize, )
Search from the current block to an outside-loop target callsite.
Normal blocks are recorded directly. Entering a loop records a
PathStep::LoopExit for each loop exit rather than visiting the loop
body, which keeps the produced paths finite.
Sourcefn follow_loop_exits(
&self,
loop_id: LoopId,
target: CallsiteLocation,
target_block: BasicBlock,
by_block: &FxHashMap<BasicBlock, CallsiteLocation>,
visited: &mut FxHashSet<BasicBlock>,
stack: &mut Vec<PathStep>,
results: &mut Vec<Path>,
limit: usize,
)
fn follow_loop_exits( &self, loop_id: LoopId, target: CallsiteLocation, target_block: BasicBlock, by_block: &FxHashMap<BasicBlock, CallsiteLocation>, visited: &mut FxHashSet<BasicBlock>, stack: &mut Vec<PathStep>, results: &mut Vec<Path>, limit: usize, )
Continue an entry path through every exit of a loop.
This routine is used only when the target callsite is outside the loop. It records the selected exit and resumes the DFS at the exit destination.
Sourcefn find_loop_paths(
&self,
loop_id: LoopId,
target: CallsiteLocation,
target_block: BasicBlock,
) -> Vec<Path>
fn find_loop_paths( &self, loop_id: LoopId, target: CallsiteLocation, target_block: BasicBlock, ) -> Vec<Path>
Enumerate paths from a loop header to a callsite inside that loop.
These paths represent one possible iteration reaching the callsite. The number of earlier iterations is intentionally not encoded in the path; later verification stages should use loop facts to describe the header state.
Sourcefn dfs_loop_paths(
&self,
loop_id: LoopId,
current: BasicBlock,
target: CallsiteLocation,
target_block: BasicBlock,
loop_blocks: &FxHashSet<BasicBlock>,
visited: &mut FxHashSet<BasicBlock>,
stack: &mut Vec<PathStep>,
results: &mut Vec<Path>,
limit: usize,
)
fn dfs_loop_paths( &self, loop_id: LoopId, current: BasicBlock, target: CallsiteLocation, target_block: BasicBlock, loop_blocks: &FxHashSet<BasicBlock>, visited: &mut FxHashSet<BasicBlock>, stack: &mut Vec<PathStep>, results: &mut Vec<Path>, limit: usize, )
Search inside one loop from its header to an internal callsite.
Successors that leave the loop are ignored because outside-loop paths are represented by loop exits. This search only describes how an iteration reaches a callsite located in the loop body.
Auto Trait Implementations§
impl<'tcx> Freeze for PathExtractor<'tcx>
impl<'tcx> !RefUnwindSafe for PathExtractor<'tcx>
impl<'tcx> Send for PathExtractor<'tcx>
impl<'tcx> Sync for PathExtractor<'tcx>
impl<'tcx> Unpin for PathExtractor<'tcx>
impl<'tcx> !UnwindSafe for PathExtractor<'tcx>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more