Skip to main content

IncrementalAnalyzer

Struct IncrementalAnalyzer 

Source
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

Source

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

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

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
§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);
Source

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());
Source

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
§Examples
let affected = analyzer.invalidate_dependents(&changed_files).await?;
analyzer.reanalyze_invalidated(&affected).await?;
Source

pub fn graph(&self) -> &DependencyGraph

Returns a reference to the internal dependency graph.

§Examples
let graph = analyzer.graph();
println!("Graph has {} nodes and {} edges",
    graph.node_count(), graph.edge_count());
Source

pub fn graph_mut(&mut self) -> &mut DependencyGraph

Returns a mutable reference to the internal dependency graph.

§Examples
let graph = analyzer.graph_mut();
graph.add_edge(edge);
Source

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§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more