pub struct InvalidationDetector { /* private fields */ }Expand description
Detects invalidation scope and computes reanalysis order.
Wraps DependencyGraph to provide:
- Propagation of invalidation through dependency edges
- Topological sorting for correct reanalysis order
- Comprehensive cycle detection using Tarjan’s algorithm
§Examples
use thread_flow::incremental::invalidation::InvalidationDetector;
use thread_flow::incremental::DependencyGraph;
use thread_flow::incremental::types::{DependencyEdge, DependencyType};
use std::path::PathBuf;
let mut graph = DependencyGraph::new();
graph.add_edge(DependencyEdge::new(
PathBuf::from("main.rs"),
PathBuf::from("lib.rs"),
DependencyType::Import,
));
let detector = InvalidationDetector::new(graph);
let result = detector.compute_invalidation_set(&[PathBuf::from("lib.rs")]);
assert!(result.invalidated_files.contains(&PathBuf::from("main.rs")));Implementations§
Source§impl InvalidationDetector
impl InvalidationDetector
Sourcepub fn new(graph: DependencyGraph) -> Self
pub fn new(graph: DependencyGraph) -> Self
Creates a new invalidation detector wrapping the given dependency graph.
§Arguments
graph- The dependency graph to use for invalidation detection.
§Examples
use thread_flow::incremental::invalidation::InvalidationDetector;
use thread_flow::incremental::DependencyGraph;
let graph = DependencyGraph::new();
let detector = InvalidationDetector::new(graph);Sourcepub fn compute_invalidation_set(
&self,
changed_files: &[PathBuf],
) -> InvalidationResult
pub fn compute_invalidation_set( &self, changed_files: &[PathBuf], ) -> InvalidationResult
Computes the complete invalidation set for the given changed files.
This is the primary high-level API for invalidation detection. It:
- Finds all files transitively affected by changes
- Attempts topological sort for reanalysis order
- Detects and reports any circular dependencies
Always returns a result (never fails). If cycles are detected,
they are reported in circular_dependencies and analysis_order
may be empty or partial.
§Arguments
changed_files- Files that have been modified or added.
§Returns
An InvalidationResult with:
- All affected files
- Topological order for reanalysis (if no cycles)
- Detected circular dependencies (if any)
§Examples
use thread_flow::incremental::invalidation::InvalidationDetector;
use thread_flow::incremental::DependencyGraph;
use std::path::PathBuf;
let graph = DependencyGraph::new();
let detector = InvalidationDetector::new(graph);
let result = detector.compute_invalidation_set(&[
PathBuf::from("src/utils.rs"),
]);
println!("Files to reanalyze: {}", result.invalidated_files.len());Sourcepub fn topological_sort(
&self,
files: &[PathBuf],
) -> Result<Vec<PathBuf>, InvalidationError>
pub fn topological_sort( &self, files: &[PathBuf], ) -> Result<Vec<PathBuf>, InvalidationError>
Performs topological sort on the given subset of files.
Returns files in dependency order: dependencies appear before their dependents. This is a lower-level API that directly exposes sort failures as errors.
§Arguments
files- The subset of files to sort.
§Errors
Returns InvalidationError::CircularDependency if a cycle is detected.
§Examples
use thread_flow::incremental::invalidation::InvalidationDetector;
use thread_flow::incremental::DependencyGraph;
use std::path::PathBuf;
let graph = DependencyGraph::new();
let detector = InvalidationDetector::new(graph);
let sorted = detector.topological_sort(&[
PathBuf::from("a.rs"),
PathBuf::from("b.rs"),
]);
match sorted {
Ok(order) => println!("Analysis order: {:?}", order),
Err(e) => eprintln!("Cycle detected: {}", e),
}Sourcepub fn propagate_invalidation(&self, root: &Path) -> Vec<PathBuf>
pub fn propagate_invalidation(&self, root: &Path) -> Vec<PathBuf>
Propagates invalidation from a single root file.
Finds all files transitively affected by changes to the given root. Uses BFS traversal following reverse dependency edges (dependents).
§Arguments
root- The changed file to propagate from.
§Returns
All files affected by the change, including the root itself.
§Examples
use thread_flow::incremental::invalidation::InvalidationDetector;
use thread_flow::incremental::DependencyGraph;
use std::path::PathBuf;
let graph = DependencyGraph::new();
let detector = InvalidationDetector::new(graph);
let affected = detector.propagate_invalidation(&PathBuf::from("core.rs"));
println!("Files affected: {}", affected.len());Trait Implementations§
Source§impl Clone for InvalidationDetector
impl Clone for InvalidationDetector
Source§fn clone(&self) -> InvalidationDetector
fn clone(&self) -> InvalidationDetector
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for InvalidationDetector
impl RefUnwindSafe for InvalidationDetector
impl Send for InvalidationDetector
impl Sync for InvalidationDetector
impl Unpin for InvalidationDetector
impl UnsafeUnpin for InvalidationDetector
impl UnwindSafe for InvalidationDetector
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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