Skip to main content

Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

Main call graph structure containing nodes and edges

Implementations§

Source§

impl CallGraph

Source

pub fn entry_point_criticality_factor(is_entry_point: bool) -> f64

Pure function to calculate entry point criticality factor

Source

pub fn dependency_count_criticality_factor(dependency_count: usize) -> f64

Pure function to calculate dependency count criticality factor

Source

pub fn has_entry_point_caller<F>( callers: &[FunctionId], is_entry_point_fn: F, ) -> bool
where F: Fn(&FunctionId) -> bool,

Pure function to check if any caller is an entry point

Source

pub fn entry_point_caller_criticality_factor( has_entry_point_caller: bool, ) -> f64

Pure function to calculate entry point caller criticality factor

Source

pub fn calculate_criticality(&self, func_id: &FunctionId) -> f64

Source§

impl CallGraph

Source

pub fn resolve_cross_file_calls(&mut self)

Resolve cross-file function calls using parallel processing

This method processes unresolved calls in two phases:

  1. Parallel Resolution: Uses Rayon to resolve calls concurrently across multiple CPU cores, leveraging the pure functional nature of the resolution logic.
  2. Sequential Updates: Applies all resolutions to the graph sequentially to maintain data structure consistency.
§Performance

Expected speedup: 10-15% on multi-core systems (4-8 cores). Scales linearly with number of unresolved calls and available cores.

§Memory Usage

Memory overhead is minimal and predictable:

  • Stores resolved call pairs in a Vec<(FunctionCall, FunctionId)>
  • For typical codebases with 1000-2000 unresolved calls:
    • Each tuple: ~200-300 bytes (two FunctionId + one FunctionCall)
    • Total overhead: ~200KB-600KB for 1000-2000 resolutions
  • Peak memory during phase 1 (parallel resolution)
  • Memory freed after phase 2 (sequential updates)
  • Well under the 10MB budget specified in requirements
§Thread Safety

The resolution phase is thread-safe because:

  • Resolution logic is pure (no side effects)
  • All input data is immutable during resolution
  • No shared mutable state between threads
Source

pub fn resolve_cross_file_calls_sequential(&mut self)

Sequential resolution for testing and benchmarking

This method provides a non-parallel baseline for comparison with the parallel resolve_cross_file_calls() method. It’s primarily used for:

  • Verifying correctness of parallel implementation (determinism tests)
  • Performance benchmarking and comparison
  • Debugging and development

In production, prefer resolve_cross_file_calls() for better performance.

Source§

impl CallGraph

Source

pub fn merge(&mut self, other: CallGraph)

Source

pub fn add_function( &mut self, id: FunctionId, is_entry_point: bool, is_test: bool, complexity: u32, lines: usize, )

Source

pub fn add_call(&mut self, call: FunctionCall)

Source

pub fn add_call_parts( &mut self, caller: FunctionId, callee: FunctionId, call_type: CallType, )

Source

pub fn get_callees(&self, func_id: &FunctionId) -> Vec<FunctionId>

Source

pub fn get_callees_exact(&self, func_id: &FunctionId) -> Vec<FunctionId>

Source

pub fn node_count(&self) -> usize

Source

pub fn get_callers(&self, func_id: &FunctionId) -> Vec<FunctionId>

Source

pub fn get_callers_exact(&self, func_id: &FunctionId) -> Vec<FunctionId>

Source

pub fn get_dependency_count(&self, func_id: &FunctionId) -> usize

Source

pub fn get_all_functions(&self) -> impl Iterator<Item = &FunctionId>

Get all functions in the graph

Source

pub fn get_function_info( &self, func_id: &FunctionId, ) -> Option<(bool, bool, u32, usize)>

Get function info

Source

pub fn mark_as_trait_dispatch(&mut self, func_id: FunctionId)

Mark a function as being reachable through trait dispatch This helps reduce false positives in dead code detection

Source

pub fn is_entry_point(&self, func_id: &FunctionId) -> bool

Source

pub fn is_test_function(&self, func_id: &FunctionId) -> bool

Source

pub fn has_test_function_named(&self, name: &str) -> bool

Source

pub fn add_edge_by_name(&mut self, from: String, to: String, file: PathBuf)

Add an edge between two functions by name (used by critical path analyzer)

Source

pub fn get_callees_by_name(&self, function: &str) -> Vec<String>

Get callees by function name (returns function names)

Source

pub fn get_callers_by_name(&self, function: &str) -> Vec<String>

Get callers by function name (returns function names)

Source

pub fn get_transitive_callees( &self, func_id: &FunctionId, max_depth: usize, ) -> HashSet<FunctionId>

Source

pub fn get_transitive_callers( &self, func_id: &FunctionId, max_depth: usize, ) -> HashSet<FunctionId>

Source

pub fn find_entry_points(&self) -> Vec<FunctionId>

Source

pub fn find_all_functions(&self) -> Vec<FunctionId>

Source

pub fn get_functions_by_file(&self, file: &PathBuf) -> Vec<FunctionId>

Get all functions in a specific file

Source

pub fn get_functions_by_name(&self, name: &str) -> Vec<FunctionId>

Get all functions with a specific name

Source

pub fn get_functions_with_no_callers(&self) -> Vec<FunctionId>

Get all functions that have no callers

Source

pub fn get_function_calls(&self, func_id: &FunctionId) -> Vec<FunctionCall>

Source

pub fn get_all_calls(&self) -> Vec<FunctionCall>

Get all function calls in the graph (for testing and debugging)

Source

pub fn is_empty(&self) -> bool

Source

pub fn find_function(&self, query: &FunctionId) -> Option<FunctionId>

Find a function using fallback matching strategies Tries exact match first, then fuzzy match, then name-only match

Source

pub fn find_function_at_location( &self, file: &PathBuf, line: usize, ) -> Option<FunctionId>

Find a function at a specific file and line location Returns the function that contains the given line

Source

pub fn functions_in_file<'a>( nodes: &'a HashMap<FunctionId, FunctionNode>, file: &PathBuf, ) -> Vec<&'a FunctionId>

Pure function to filter functions by file

Source

pub fn find_best_line_match( functions: &[&FunctionId], target_line: usize, ) -> Option<FunctionId>

Pure function to find the best matching function by line proximity

Source

pub fn is_recursive(&self, func_id: &FunctionId) -> bool

Check if a function is recursive (calls itself directly or through a cycle)

Uses iterative DFS with explicit stack to avoid stack overflow on large graphs.

Source

pub fn topological_sort(&self) -> Result<Vec<FunctionId>, String>

Topological sort of functions for bottom-up analysis Returns functions in dependency order (leaves first, roots last)

Uses iterative DFS with explicit stack to avoid stack overflow on large graphs.

Source§

impl CallGraph

Source

pub fn meets_delegation_criteria( orchestrator_complexity: u32, callee_count: usize, ) -> bool

Pure function to check if delegation pattern criteria are met

Source

pub fn calculate_average_callee_complexity( callees: &[FunctionId], nodes: &HashMap<FunctionId, FunctionNode>, ) -> f64

Pure function to calculate average complexity of callees

Source

pub fn indicates_delegation( orchestrator_complexity: u32, avg_callee_complexity: f64, ) -> bool

Pure function to determine if complexity indicates delegation

Source

pub fn detect_delegation_pattern(&self, func_id: &FunctionId) -> bool

Source§

impl CallGraph

Source

pub fn find_test_functions(&self) -> Vec<FunctionId>

Source

pub fn is_test_helper(&self, func_id: &FunctionId) -> bool

Check if a function is only called by test functions (test helper) Returns true if:

  • The function has at least one caller
  • All callers are test functions
Source

pub fn is_production_entry_point( node: &FunctionNode, callers: &[FunctionId], ) -> bool

Pure function to check if a node is a production entry point

Source

pub fn find_test_only_functions(&self) -> HashSet<FunctionId>

Identify functions that are only reachable from test functions These are test infrastructure functions (mocks, helpers, fixtures, etc.)

Source§

impl CallGraph

Source

pub fn new() -> Self

Trait Implementations§

Source§

impl Clone for CallGraph

Source§

fn clone(&self) -> CallGraph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CallGraph

Source§

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

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

impl Default for CallGraph

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for CallGraph

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CallGraph

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> EnsureExt<T> for T

Source§

fn ensure<P, E>(self, predicate: P, error: E) -> Validation<T, NonEmptyVec<E>>
where P: Predicate<T>,

Validate that this value satisfies the given predicate. Read more
Source§

fn ensure_with<P, E, F>( self, predicate: P, error_fn: F, ) -> Validation<T, NonEmptyVec<E>>
where P: Predicate<T>, F: FnOnce(&T) -> E,

Validate with an error-generating function. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
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