PathExtractor

Struct PathExtractor 

Source
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>

Source

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.

Source

pub fn run(self) -> PathResult<'tcx>

Run loop detection and path extraction, then return the collected result.

Source

fn find_loops(&mut self)

Detect loops in the function CFG and store their block-to-loop map.

Source

fn find_paths(&mut self)

Extract paths for every callsite owned by this extractor.

Source

fn callsites_by_block(&self) -> FxHashMap<BasicBlock, CallsiteLocation>

Build a map from callsite basic blocks to their stable locations.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V