Skip to main content

DepGraph

Struct DepGraph 

Source
pub struct DepGraph { /* private fields */ }

Implementations§

Source§

impl DepGraph

Source

pub fn new() -> Self

Create a new empty dependency graph.

Source

pub fn cached_normalize_key_path( &self, path: &Path, key_root: Option<&Path>, ) -> Arc<str>

Cached version of crate::depgraph::context::normalize_key_path.

Looks up (path, key_root) in path_key_cache. On hit, returns the cached Arc<str> without re-running the underlying normalization. On miss, computes via normalize_key_path and inserts (subject to the PATH_KEY_CACHE_MAX_ENTRIES cap — past the cap, the result is returned without caching so memory stays bounded).

Issue #550 — the compute_artifact_key hot loop’s per-header allocation hotspot.

Source

pub fn register(&self, ctx: CompileContext) -> ContextKey

Register a compilation context. Returns the context key. If the context already exists, returns the existing key.

Source

pub fn register_with_root_and_salt( &self, ctx: CompileContext, key_root: Option<NormalizedPath>, worktree_salt: Option<&Path>, ) -> ContextKey

Register a compilation context with an optional key root used to normalize project-local paths across workspace renames. Variant of Self::register_with_root that folds an optional worktree_salt into the context key (issue #474). Used by the multi-file compile path when keys::requires_worktree_in_key is true for the unit. Returns only the resulting ContextKey.

Source

pub fn register_with_root( &self, ctx: CompileContext, key_root: Option<NormalizedPath>, ) -> ContextKey

Source

pub fn register_with_root_result( &self, ctx: CompileContext, key_root: Option<NormalizedPath>, ) -> ContextRegistration

Source

pub fn register_with_root_and_salt_result( &self, ctx: CompileContext, key_root: Option<NormalizedPath>, worktree_salt: Option<&Path>, ) -> ContextRegistration

Issue #474: variant of Self::register_with_root_result that folds an optional worktree_salt into the context key. Used by the C/C++ compile pipeline when keys::requires_worktree_in_key returns true (PCH builds + MSVC), so the resulting cache entry is scoped to one worktree and can’t be served to a sibling clone whose embedded paths would diverge from the artifact’s.

Source

pub fn register_with_key( &self, key: ContextKey, ctx: CompileContext, ) -> ContextKey

Register a compilation context with a precomputed key.

Used for Rustc compilations where the context key is computed from RustcCompileContext (different domain tag) but the dep_graph stores a CompileContext with the source file path for freshness checks.

Source

pub fn register_with_key_and_root( &self, key: ContextKey, ctx: CompileContext, key_root: Option<NormalizedPath>, ) -> ContextKey

Source

pub fn register_with_key_and_root_result( &self, key: ContextKey, ctx: CompileContext, key_root: Option<NormalizedPath>, ) -> ContextRegistration

Source

pub fn register_rustc_with_key_and_root_result( &self, key: ContextKey, ctx: CompileContext, key_root: Option<NormalizedPath>, externs: Vec<(String, NormalizedPath)>, ) -> ContextRegistration

Register a rustc context with its current --extern file inputs.

Rustc context keys already reduce extern path prefixes to filename identity. The dependency graph keeps the actual extern paths here only for hashing/freshness; artifact keys incorporate them by crate name.

Source

pub fn is_cold(&self, key: &ContextKey) -> bool

Returns true if the context has never been updated (no artifact key). Used by the server to skip pre-compile hashing on cold contexts where check_diagnostic would return Cold without examining any hashes.

Source

pub fn check<F, G>( &self, key: &ContextKey, is_fresh: F, get_hash: G, ) -> CacheVerdict
where F: Fn(&Path) -> bool, G: Fn(&Path) -> Option<ContentHash>,

Check if a compilation can use cached output.

is_fresh is called for each file path. It should query Layer 1 (fscache) and return true if the file has not changed since last known state.

get_hash retrieves the content hash for a file from Layer 1.

Source

pub fn check_diagnostic<F, G>( &self, key: &ContextKey, is_fresh: F, get_hash: G, ) -> (CacheVerdict, String)
where F: Fn(&Path) -> bool, G: Fn(&Path) -> Option<ContentHash>,

Check if a compilation can use cached output, with diagnostic reason.

Same logic as check() but returns a reason string explaining why the verdict was reached (useful for session logs).

Source

pub fn try_fast_hit<G>( &self, key: &ContextKey, get_hash: G, ) -> Option<ArtifactKey>
where G: Fn(&Path) -> Option<ContentHash>,

Fast-path artifact key check: recompute the key from caller-provided hashes and compare against the stored key. Returns Some(key) when they match (common cache-hit case), None otherwise.

Compared to check_diagnostic, this method:

  • Uses a shared DashMap read (no write lock)
  • Skips redundant per-file journal freshness checks (caller already stat-verified every file during the hash phase)
  • Avoids NormalizedPath clones by working with references into the entry

Call this after hashing and before check_diagnostic. On None, fall back to the full check_diagnostic for miss-reason diagnostics.

Source

pub fn update<G>( &self, key: &ContextKey, scan_result: ScanResult, get_hash: G, ) -> Option<ArtifactKey>
where G: Fn(&Path) -> Option<ContentHash>,

After a compile (or on cold path), record the full include list.

get_hash retrieves the content hash for a file from Layer 1.

Source

pub fn invalidate_artifact_keys(&self, evicted_hex: &HashSet<String>) -> usize

Clear artifact_key on every context whose currently-recorded artifact key is in evicted_hex. Returns the number of contexts whose key was cleared.

Issue #680 — eviction-divergence fix. When the disk artifact GC (evict_disk_artifacts) removes an artifact, the depgraph contexts that point at the now-evicted key still report CacheVerdict::Hit { artifact_key } on their next check, which then surfaces in the daemon log as artifact_not_found and a wasted recompile (the user observed a 15.7% real hit rate on a soldr dogfood rebuild that should have been ~99%). Wiring the disk GC to call this method after each eviction batch keeps the two stores in agreement: the next check on an evicted context returns Cold (forcing a clean miss + re-store) instead of a stale Hit.

Key comparison uses the hex form (ArtifactKey::hash().to_hex()) so callers — which already have the evicted artifacts’ string keys from the disk eviction pass — do not have to round-trip through ArtifactKey construction.

last_accessed is intentionally NOT bumped — this is a passive invalidation, and resetting access time would extend the context’s trim() lifetime past its disk-evicted artifact.

Source

pub fn trim(&self, max_age: Duration) -> usize

Trim entries not accessed within the given duration. Returns the number of entries removed.

Source

pub fn clear(&self)

Clear all graph state: files, contexts, and stats counters.

Source

pub fn stats(&self) -> DepGraphStats

Get statistics about the graph.

Source

pub fn get_state(&self, key: &ContextKey) -> Option<ContextState>

Get the state of a context entry.

Source

pub fn state_breakdown(&self) -> (usize, usize, usize)

Count contexts by state. Returned as (cold, warm, stale).

Used by the daemon’s depgraph save / load logging to diagnose post-save / post-load state distribution — specifically to find out whether contexts are getting persisted as Warm (so is_cold returns false after restore, enabling the cache lookup path) or as Cold (so every warm-side compile takes the cold_skip branch and misses regardless of artifact-store state).

Source

pub fn contexts_with_artifact_key(&self) -> usize

Number of contexts whose artifact_key is set. Combined with state_breakdown() this distinguishes contexts that have a computed key (a successful prior compile) from contexts that were registered but never reached a Warm state.

Source

pub fn get_includes(&self, key: &ContextKey) -> Option<Vec<NormalizedPath>>

Get the resolved includes for a context.

Source

pub fn get_rustc_externs( &self, key: &ContextKey, ) -> Option<Vec<(String, NormalizedPath)>>

Get rustc extern input paths for a context.

Source

pub fn store_file_includes( &self, path: NormalizedPath, includes: Vec<IncludeDirective>, )

Store scanned includes for a file (shared file node).

Source

pub fn get_file_includes( &self, path: &NormalizedPath, ) -> Option<Vec<IncludeDirective>>

Get scanned includes for a file.

Source

pub fn mark_stale(&self, key: &ContextKey) -> bool

Mark a context as stale, requiring rescan on next check. Returns true if the context existed and was marked stale.

Source

pub fn ingest_compile_commands( &self, commands: &[CompileCommand], system_includes: &[NormalizedPath], ) -> Vec<ContextKey>

Bulk-populate contexts from parsed compile commands.

For each command, parses the arguments, builds a CompileContext (merging in the provided system include paths), and registers it. Returns the context keys for all successfully registered entries.

Source§

impl DepGraph

Source

pub fn to_snapshot(&self) -> DepGraphSnapshot

Create a serializable snapshot of the current graph state.

Source

pub fn from_snapshot(snap: DepGraphSnapshot) -> Self

Reconstruct a DepGraph from a deserialized snapshot.

Source§

impl DepGraph

Source

pub fn watch_set(&self) -> WatchSet

Compute the set of directories that should be watched.

Includes:

  • Parent directories of all resolved include paths (to detect modifications)
  • Parent directories of source files (to detect source changes)
  • All include search directories from all contexts (to detect new files)
Source

pub fn check_shadow(&self, new_file: &Path) -> Vec<ContextKey>

Check if a newly created file shadows any existing resolved include in any context. Returns context keys that should be marked stale.

A shadow occurs when new_file has the same filename as an existing resolved include, and new_file’s directory appears earlier (higher priority) in that context’s include search path.

Source

pub fn check_new_resolve(&self, new_file: &Path) -> Vec<ContextKey>

Check if a newly created file resolves any previously unresolved #include in any context. Returns affected context keys.

Trait Implementations§

Source§

impl Debug for DepGraph

The core dependency graph.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DepGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
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> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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<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