pub struct IncrementalAnalyzer { /* private fields */ }Expand description
Core incremental analysis coordinator.
Manages the dependency graph, storage backend, and coordinates change detection, invalidation, and reanalysis workflows.
§Examples
use thread_flow::incremental::analyzer::IncrementalAnalyzer;
use thread_flow::incremental::storage::InMemoryStorage;
let storage = Box::new(InMemoryStorage::new());
let mut analyzer = IncrementalAnalyzer::new(storage);Implementations§
Source§impl IncrementalAnalyzer
impl IncrementalAnalyzer
Sourcepub fn new(storage: Box<dyn StorageBackend>) -> Self
pub fn new(storage: Box<dyn StorageBackend>) -> Self
Creates a new incremental analyzer with the given storage backend.
Initializes with an empty dependency graph. To restore a previous
session, use IncrementalAnalyzer::from_storage instead.
§Arguments
storage- The storage backend to use for persistence.
§Examples
let storage = Box::new(InMemoryStorage::new());
let analyzer = IncrementalAnalyzer::new(storage);Sourcepub async fn from_storage(
storage: Box<dyn StorageBackend>,
) -> Result<Self, AnalyzerError>
pub async fn from_storage( storage: Box<dyn StorageBackend>, ) -> Result<Self, AnalyzerError>
Creates a new incremental analyzer and loads the dependency graph from storage.
This is the recommended way to initialize an analyzer for session continuity, as it restores the previous dependency graph state.
§Arguments
storage- The storage backend containing the previous session’s graph.
§Errors
Returns AnalyzerError::Storage if loading the graph fails.
§Examples
let storage = Box::new(PostgresStorage::new(config).await?);
let analyzer = IncrementalAnalyzer::from_storage(storage).await?;Sourcepub async fn analyze_changes(
&mut self,
paths: &[PathBuf],
) -> Result<AnalysisResult, AnalyzerError>
pub async fn analyze_changes( &mut self, paths: &[PathBuf], ) -> Result<AnalysisResult, AnalyzerError>
Analyzes a set of files to detect changes.
Compares current file fingerprints with stored fingerprints to identify which files have been added or modified. Uses Blake3-based content hashing for fast change detection.
Performance: Achieves <10ms overhead for 100 files with >90% cache hit rate.
§Arguments
paths- Slice of file paths to analyze for changes.
§Returns
An AnalysisResult containing changed files and performance metrics.
§Errors
AnalyzerError::Ioif file reading failsAnalyzerError::Storageif fingerprint loading fails
§Examples
let result = analyzer.analyze_changes(&[
PathBuf::from("src/main.rs"),
PathBuf::from("src/utils.rs"),
]).await?;
println!("Changed: {} files", result.changed_files.len());
println!("Cache hit rate: {:.1}%", result.cache_hit_rate * 100.0);Sourcepub async fn invalidate_dependents(
&self,
changed: &[PathBuf],
) -> Result<Vec<PathBuf>, AnalyzerError>
pub async fn invalidate_dependents( &self, changed: &[PathBuf], ) -> Result<Vec<PathBuf>, AnalyzerError>
Finds all files affected by changes to the given files.
Uses BFS traversal of the dependency graph to identify all files that transitively depend on the changed files. Only follows strong dependency edges (Import, Trait, Macro) for cascading invalidation.
Performance: O(V + E) where V = files, E = dependency edges. Achieves <5ms for 1000-node graphs.
§Arguments
changed- Slice of file paths that have changed.
§Returns
A vector of all affected file paths (including the changed files themselves).
§Errors
Returns AnalyzerError::Graph if graph traversal fails.
§Examples
let changed = vec![PathBuf::from("src/utils.rs")];
let affected = analyzer.invalidate_dependents(&changed).await?;
println!("Files requiring reanalysis: {}", affected.len());Sourcepub async fn reanalyze_invalidated(
&mut self,
files: &[PathBuf],
) -> Result<(), AnalyzerError>
pub async fn reanalyze_invalidated( &mut self, files: &[PathBuf], ) -> Result<(), AnalyzerError>
Reanalyzes invalidated files and updates the dependency graph.
Performs dependency extraction for all affected files, updates their fingerprints, and saves the new state to storage. Files are processed in topological order (dependencies before dependents) to ensure correctness.
Error Recovery: Skips files that fail extraction but continues processing other files. Extraction errors are logged but do not abort the entire batch.
§Arguments
files- Slice of file paths requiring reanalysis.
§Errors
AnalyzerError::Storageif persistence failsAnalyzerError::Graphif topological sort fails (cyclic dependency)
§Examples
let affected = analyzer.invalidate_dependents(&changed_files).await?;
analyzer.reanalyze_invalidated(&affected).await?;Sourcepub fn graph(&self) -> &DependencyGraph
pub fn graph(&self) -> &DependencyGraph
Sourcepub fn graph_mut(&mut self) -> &mut DependencyGraph
pub fn graph_mut(&mut self) -> &mut DependencyGraph
Sourcepub async fn persist(&self) -> Result<(), AnalyzerError>
pub async fn persist(&self) -> Result<(), AnalyzerError>
Persists the current dependency graph to storage.
§Errors
Returns AnalyzerError::Storage if persistence fails.
§Examples
analyzer.persist().await?;Auto Trait Implementations§
impl Freeze for IncrementalAnalyzer
impl !RefUnwindSafe for IncrementalAnalyzer
impl Send for IncrementalAnalyzer
impl Sync for IncrementalAnalyzer
impl Unpin for IncrementalAnalyzer
impl UnsafeUnpin for IncrementalAnalyzer
impl !UnwindSafe for IncrementalAnalyzer
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> 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