pub struct CodeGraphV2 { /* private fields */ }Expand description
Symbol relationship graph with Data-Oriented Design.
§Design Principles
- petgraph-free: No NodeIndex, direct SymbolId operations
- SoA Layout: Edges stored in separate arrays for cache efficiency
- String-free: All references use SymbolId/FileId
- SmallVec: Stack allocation for typical adjacency sizes
§Memory Layout
CodeGraphV2
├── Edge Storage (SoA)
│ └── edges: Vec<EdgeData>
├── Adjacency Lists (SymbolId → EdgeIds)
│ ├── outgoing: SecondaryMap<SymbolId, SmallVec<[EdgeId; 4]>>
│ └── incoming: SecondaryMap<SymbolId, SmallVec<[EdgeId; 4]>>
├── Indices
│ ├── by_kind: HashMap<SymbolKind, SmallVec<[SymbolId; 16]>>
│ └── crate_roots: SmallVec<[SymbolId; 4]>
└── Match Expressions
├── match_expr_index: SecondaryMap<SymbolId, SmallVec<[MatchExprId; 2]>>
└── match_exprs: Vec<MatchExprDataV2>NOTE: Deserialize is NOT derived because CodeGraphV2 contains SecondaryMap<SymbolId, …> and SymbolId is process-specific. Serialize is kept for debugging/inspection.
Implementations§
Source§impl CodeGraphV2
impl CodeGraphV2
Sourcepub fn with_capacity(_nodes: usize, edges: usize) -> Self
pub fn with_capacity(_nodes: usize, edges: usize) -> Self
Create a graph with pre-allocated capacity.
Sourcepub fn add_node(&mut self, id: SymbolId) -> bool
pub fn add_node(&mut self, id: SymbolId) -> bool
Add a symbol to the graph.
Returns true if the symbol was newly added, false if it already existed.
Sourcepub fn remove_node(&mut self, id: SymbolId) -> bool
pub fn remove_node(&mut self, id: SymbolId) -> bool
Remove a symbol and all its edges from the graph.
Returns true if the symbol was removed.
Sourcepub fn clear_outgoing_edges(&mut self, id: SymbolId)
pub fn clear_outgoing_edges(&mut self, id: SymbolId)
Clear all outgoing edges from a symbol.
Used for incremental updates: clear old edges before rebuilding. Does not remove the node itself or its incoming edges.
Sourcepub fn add_edge(
&mut self,
from: SymbolId,
to: SymbolId,
kind: CodeEdgeV2,
) -> EdgeId
pub fn add_edge( &mut self, from: SymbolId, to: SymbolId, kind: CodeEdgeV2, ) -> EdgeId
Add an edge between two symbols.
Both symbols are automatically added to the graph if not present.
Sourcepub fn has_edge(&self, from: SymbolId, to: SymbolId, kind: CodeEdgeV2) -> bool
pub fn has_edge(&self, from: SymbolId, to: SymbolId, kind: CodeEdgeV2) -> bool
Check if an edge exists between two symbols.
Sourcepub fn add_crate_root(&mut self, id: SymbolId)
pub fn add_crate_root(&mut self, id: SymbolId)
Add a crate root symbol.
Sourcepub fn crate_roots(&self) -> &[SymbolId]
pub fn crate_roots(&self) -> &[SymbolId]
Get crate root symbols.
Sourcepub fn add_to_kind_index(&mut self, id: SymbolId, kind: SymbolKind)
pub fn add_to_kind_index(&mut self, id: SymbolId, kind: SymbolKind)
Add a symbol to the kind index.
Sourcepub fn iter_by_kind(
&self,
kind: SymbolKind,
) -> impl Iterator<Item = SymbolId> + '_
pub fn iter_by_kind( &self, kind: SymbolKind, ) -> impl Iterator<Item = SymbolId> + '_
Iterate over symbols of a specific kind.
Sourcepub fn outgoing_edges(
&self,
id: SymbolId,
) -> impl Iterator<Item = &EdgeData> + '_
pub fn outgoing_edges( &self, id: SymbolId, ) -> impl Iterator<Item = &EdgeData> + '_
Get outgoing edges from a symbol.
Sourcepub fn incoming_edges(
&self,
id: SymbolId,
) -> impl Iterator<Item = &EdgeData> + '_
pub fn incoming_edges( &self, id: SymbolId, ) -> impl Iterator<Item = &EdgeData> + '_
Get incoming edges to a symbol.
Sourcepub fn callers_of(&self, id: SymbolId) -> impl Iterator<Item = SymbolId> + '_
pub fn callers_of(&self, id: SymbolId) -> impl Iterator<Item = SymbolId> + '_
Find callers of a symbol (deduplicated).
Sourcepub fn callees_of(&self, id: SymbolId) -> impl Iterator<Item = SymbolId> + '_
pub fn callees_of(&self, id: SymbolId) -> impl Iterator<Item = SymbolId> + '_
Find callees of a symbol (deduplicated).
Sourcepub fn implementors_of(
&self,
trait_id: SymbolId,
) -> impl Iterator<Item = SymbolId> + '_
pub fn implementors_of( &self, trait_id: SymbolId, ) -> impl Iterator<Item = SymbolId> + '_
Find implementors of a trait.
Sourcepub fn children_of(
&self,
parent_id: SymbolId,
) -> impl Iterator<Item = SymbolId> + '_
pub fn children_of( &self, parent_id: SymbolId, ) -> impl Iterator<Item = SymbolId> + '_
Find children (contained symbols) of a parent.
Sourcepub fn parent_of(&self, id: SymbolId) -> Option<SymbolId>
pub fn parent_of(&self, id: SymbolId) -> Option<SymbolId>
Find the parent (container) of a symbol.
Sourcepub fn reference_count(&self, id: SymbolId) -> usize
pub fn reference_count(&self, id: SymbolId) -> usize
Get the reference count for a symbol (call references only).
Sourcepub fn impl_count(&self, id: SymbolId) -> usize
pub fn impl_count(&self, id: SymbolId) -> usize
Get the impl count for a symbol.
Sourcepub fn add_match_expr(
&mut self,
function_id: SymbolId,
data: MatchExprDataV2,
) -> MatchExprId
pub fn add_match_expr( &mut self, function_id: SymbolId, data: MatchExprDataV2, ) -> MatchExprId
Add a match expression to a function.
Sourcepub fn match_exprs_in(
&self,
function_id: SymbolId,
) -> impl Iterator<Item = &MatchExprDataV2> + '_
pub fn match_exprs_in( &self, function_id: SymbolId, ) -> impl Iterator<Item = &MatchExprDataV2> + '_
Get match expressions in a function.
Sourcepub fn match_exprs_for_enum(
&self,
enum_id: SymbolId,
) -> impl Iterator<Item = (SymbolId, &MatchExprDataV2)> + '_
pub fn match_exprs_for_enum( &self, enum_id: SymbolId, ) -> impl Iterator<Item = (SymbolId, &MatchExprDataV2)> + '_
Find all match expressions that match on a given enum.
Sourcepub fn match_expr_count(&self) -> usize
pub fn match_expr_count(&self) -> usize
Get total number of match expressions.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get the number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Get the number of edges.
Sourcepub fn callers_chain(&self, start: SymbolId, max_depth: usize) -> Vec<ChainNode>
pub fn callers_chain(&self, start: SymbolId, max_depth: usize) -> Vec<ChainNode>
Find all callers transitively up to max_depth.
Returns a list of (SymbolId, depth) pairs where depth indicates how many hops from the starting symbol.
§Example
A calls B, B calls C, C calls D
callers_chain(D, 3) returns: [(C, 1), (B, 2), (A, 3)]Sourcepub fn callees_chain(&self, start: SymbolId, max_depth: usize) -> Vec<ChainNode>
pub fn callees_chain(&self, start: SymbolId, max_depth: usize) -> Vec<ChainNode>
Find all callees transitively up to max_depth.
Returns a list of (SymbolId, depth) pairs where depth indicates how many hops from the starting symbol.
§Example
A calls B, B calls C, C calls D
callees_chain(A, 3) returns: [(B, 1), (C, 2), (D, 3)]Sourcepub fn analyze_chain(
&self,
start: SymbolId,
max_depth: usize,
direction: ChainDirection,
) -> ChainResult
pub fn analyze_chain( &self, start: SymbolId, max_depth: usize, direction: ChainDirection, ) -> ChainResult
Get full chain result with statistics.
Trait Implementations§
Source§impl Clone for CodeGraphV2
impl Clone for CodeGraphV2
Source§fn clone(&self) -> CodeGraphV2
fn clone(&self) -> CodeGraphV2
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for CodeGraphV2
impl Default for CodeGraphV2
Source§fn default() -> CodeGraphV2
fn default() -> CodeGraphV2
Auto Trait Implementations§
impl Freeze for CodeGraphV2
impl RefUnwindSafe for CodeGraphV2
impl Send for CodeGraphV2
impl Sync for CodeGraphV2
impl Unpin for CodeGraphV2
impl UnsafeUnpin for CodeGraphV2
impl UnwindSafe for CodeGraphV2
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> 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