pub struct DataFlowGraphV2 { /* private fields */ }Expand description
Data flow graph with Data-Oriented Design.
§Design Principles
- SoA Layout: Variables and flows stored in separate arrays
- String-free: Variable names are SymbolIds
- Inverted Index: O(1) lookup from containing symbol to variables
- Cache-friendly: Dense arrays for iteration
- Integrated Trackers: BorrowTrackerV2 and LockTrackerV2 built-in
§Memory Layout
DataFlowGraphV2
├── vars: SecondaryMap<VarId, VarData> // Variable metadata
├── var_names: SecondaryMap<VarId, String>
├── flows: Vec<FlowData> // Flow metadata (with scope)
├── edges: Vec<FlowEdgeData> // Flow edges (parallel to flows)
├── scopes: Vec<ScopeData> // Scope tree
├── Adjacency Lists
│ ├── outgoing / incoming
├── Lookup Tables
│ ├── var_mapping: VarSymbolMapping
│ └── symbol_to_vars
└── Trackers
├── borrow_tracker
└── lock_trackerImplementations§
Source§impl DataFlowGraphV2
impl DataFlowGraphV2
Sourcepub fn with_capacity(var_capacity: usize, flow_capacity: usize) -> Self
pub fn with_capacity(var_capacity: usize, flow_capacity: usize) -> Self
Create with pre-allocated capacity.
Sourcepub fn add_var(
&mut self,
data: VarData,
name: String,
var_symbol_id: Option<SymbolId>,
) -> VarId
pub fn add_var( &mut self, data: VarData, name: String, var_symbol_id: Option<SymbolId>, ) -> VarId
Add a variable to the graph.
§Arguments
data: Variable metadata (parent, kind, line)name: Variable name (for display/debugging)var_symbol_id: The variable’s SymbolId if registered in SymbolRegistry, or None for local variables not in the registry.
§Returns
The VarId for referencing this variable in the dataflow graph.
Sourcepub fn var_mut(&mut self, id: VarId) -> Option<&mut VarData>
pub fn var_mut(&mut self, id: VarId) -> Option<&mut VarData>
Get mutable variable data by VarId.
Sourcepub fn vars_in_symbol(&self, symbol: SymbolId) -> &[VarId]
pub fn vars_in_symbol(&self, symbol: SymbolId) -> &[VarId]
Get all variables for a containing symbol.
Sourcepub fn add_flow(&mut self, from: VarId, to: VarId, data: FlowData) -> FlowId
pub fn add_flow(&mut self, from: VarId, to: VarId, data: FlowData) -> FlowId
Add a flow edge between two variables.
Returns the FlowId for the new flow.
Sourcepub fn edge(&self, id: FlowId) -> Option<&FlowEdgeData>
pub fn edge(&self, id: FlowId) -> Option<&FlowEdgeData>
Get flow edge by FlowId.
Sourcepub fn flow_count(&self) -> usize
pub fn flow_count(&self) -> usize
Get the number of flows.
Sourcepub fn successors(&self, var: VarId) -> impl Iterator<Item = VarId> + '_
pub fn successors(&self, var: VarId) -> impl Iterator<Item = VarId> + '_
Get target variables that receive values from this variable.
Sourcepub fn predecessors(&self, var: VarId) -> impl Iterator<Item = VarId> + '_
pub fn predecessors(&self, var: VarId) -> impl Iterator<Item = VarId> + '_
Get source variables that provide values to this variable.
Sourcepub fn impact(&self, start: VarId) -> Vec<VarId>
pub fn impact(&self, start: VarId) -> Vec<VarId>
Find all variables that this variable’s value flows to (transitive).
Impact analysis: “If I change this variable, what else is affected?”
Sourcepub fn provenance(&self, start: VarId) -> Vec<VarId>
pub fn provenance(&self, start: VarId) -> Vec<VarId>
Find all variables that contribute to this variable’s value (transitive).
Provenance analysis: “Where does this value come from?”
Sourcepub fn var_to_symbol(&self, var: VarId) -> Option<SymbolId>
pub fn var_to_symbol(&self, var: VarId) -> Option<SymbolId>
Convert VarId to SymbolId.
Sourcepub fn symbol_to_var(&self, symbol: SymbolId) -> Option<VarId>
pub fn symbol_to_var(&self, symbol: SymbolId) -> Option<VarId>
Convert SymbolId to VarId.
Sourcepub fn resolve_vars(
&self,
symbol_id: Option<SymbolId>,
name: Option<&str>,
registry: &SymbolRegistry,
) -> Option<(Vec<VarId>, String)>
pub fn resolve_vars( &self, symbol_id: Option<SymbolId>, name: Option<&str>, registry: &SymbolRegistry, ) -> Option<(Vec<VarId>, String)>
Resolve variables by SymbolId or name with tiered fallback.
Resolution order:
symbol_id→ O(1) lookup viavars_in_symbolname→ registry name lookup →vars_in_symbolfor each matchname→ fallback to dataflow variable name substring search
Returns (matching_vars, display_name) or None if neither input is provided.
Sourcepub fn iter_flows(
&self,
) -> impl Iterator<Item = (FlowId, &FlowData, &FlowEdgeData)>
pub fn iter_flows( &self, ) -> impl Iterator<Item = (FlowId, &FlowData, &FlowEdgeData)>
Iterate over all flows.
Sourcepub fn clear_for_symbols(&mut self, symbols: &[SymbolId])
pub fn clear_for_symbols(&mut self, symbols: &[SymbolId])
Clear variables and flows for the given parent symbols.
Used for incremental updates: clear data for modified functions, then rebuild from the updated AST.
Note: This doesn’t compact the flow arrays (they may contain stale edges referencing removed VarIds). The edges are effectively orphaned and ignored since the VarIds no longer exist in var_mapping.
Sourcepub fn add_scope(&mut self, data: ScopeData) -> ScopeId
pub fn add_scope(&mut self, data: ScopeData) -> ScopeId
Add a scope to the scope tree. Returns the ScopeId.
Sourcepub fn scope_count(&self) -> usize
pub fn scope_count(&self) -> usize
Get the number of scopes.
Sourcepub fn is_guarded(
&self,
var_name: &str,
scope: ScopeId,
kinds: &[GuardKind],
) -> bool
pub fn is_guarded( &self, var_name: &str, scope: ScopeId, kinds: &[GuardKind], ) -> bool
Check if a variable (by name) has a matching guard in the given scope or any ancestor.
Walks up the scope tree from scope looking for a guard whose
kind is in kinds and whose var_names contains var_name.
Sourcepub fn active_guards(&self, scope: ScopeId) -> Vec<&Guard>
pub fn active_guards(&self, scope: ScopeId) -> Vec<&Guard>
Collect all guards active in the scope chain (from scope up to root).
Sourcepub fn flows_of_kind_in_symbol(
&self,
symbol_id: SymbolId,
kind: FlowKind,
) -> Vec<(FlowId, &FlowData, &FlowEdgeData)>
pub fn flows_of_kind_in_symbol( &self, symbol_id: SymbolId, kind: FlowKind, ) -> Vec<(FlowId, &FlowData, &FlowEdgeData)>
Find all flows of a given kind within a symbol.
Sourcepub fn borrow_tracker(&self) -> &BorrowTrackerV2
pub fn borrow_tracker(&self) -> &BorrowTrackerV2
Get the borrow tracker.
Sourcepub fn borrow_tracker_mut(&mut self) -> &mut BorrowTrackerV2
pub fn borrow_tracker_mut(&mut self) -> &mut BorrowTrackerV2
Get mutable access to the borrow tracker.
Sourcepub fn lock_tracker(&self) -> &LockTrackerV2
pub fn lock_tracker(&self) -> &LockTrackerV2
Get the lock tracker.
Sourcepub fn lock_tracker_mut(&mut self) -> &mut LockTrackerV2
pub fn lock_tracker_mut(&mut self) -> &mut LockTrackerV2
Get mutable access to the lock tracker.
Sourcepub fn add_borrow(
&mut self,
source: VarId,
borrow: VarId,
kind: BorrowKind,
line: u32,
)
pub fn add_borrow( &mut self, source: VarId, borrow: VarId, kind: BorrowKind, line: u32, )
Add a borrow relationship.
Sourcepub fn end_borrow(&mut self, borrow: VarId, line: u32)
pub fn end_borrow(&mut self, borrow: VarId, line: u32)
End a borrow at a specific line.
Sourcepub fn borrow_conflicts(
&self,
source: VarId,
kind: BorrowKind,
at_line: u32,
) -> Vec<BorrowConflict>
pub fn borrow_conflicts( &self, source: VarId, kind: BorrowKind, at_line: u32, ) -> Vec<BorrowConflict>
Query borrow conflicts for a variable.
Sourcepub fn borrow_analysis(&self, symbol_id: SymbolId) -> BorrowAnalysis
pub fn borrow_analysis(&self, symbol_id: SymbolId) -> BorrowAnalysis
Analyze borrow conflicts and use-after-move errors for a symbol.
Scans all flows within the symbol to detect:
- Simultaneous mutable borrows
- Mutable + shared borrow conflicts
- Use after move
Trait Implementations§
Source§impl Clone for DataFlowGraphV2
impl Clone for DataFlowGraphV2
Source§fn clone(&self) -> DataFlowGraphV2
fn clone(&self) -> DataFlowGraphV2
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DataFlowGraphV2
impl Debug for DataFlowGraphV2
Source§impl Default for DataFlowGraphV2
impl Default for DataFlowGraphV2
Source§fn default() -> DataFlowGraphV2
fn default() -> DataFlowGraphV2
Auto Trait Implementations§
impl Freeze for DataFlowGraphV2
impl RefUnwindSafe for DataFlowGraphV2
impl Send for DataFlowGraphV2
impl Sync for DataFlowGraphV2
impl Unpin for DataFlowGraphV2
impl UnsafeUnpin for DataFlowGraphV2
impl UnwindSafe for DataFlowGraphV2
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