Skip to main content

GraphSnapshot

Struct GraphSnapshot 

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

Immutable snapshot of a CodeGraph for long-running queries.

GraphSnapshot holds Arc references to the graph components, providing a consistent view that is isolated from concurrent mutations.

§Design

Snapshots are created via CodeGraph::snapshot() or ConcurrentCodeGraph::snapshot(). They are:

  • Immutable: No mutation methods available
  • Isolated: Independent of future graph mutations
  • Cheap: Only Arc clones, no data copying
  • Self-contained: Can outlive the original graph/lock

§Usage

use sqry_core::graph::unified::concurrent::{ConcurrentCodeGraph, GraphSnapshot};

let graph = ConcurrentCodeGraph::new();

// Create snapshot for a long query
let snapshot: GraphSnapshot = graph.snapshot();

// Snapshot can be used independently
let _epoch = snapshot.epoch();

Implementations§

Source§

impl GraphSnapshot

Source

pub fn nodes(&self) -> &NodeArena

Returns a reference to the node arena.

Source

pub fn edges(&self) -> &BidirectionalEdgeStore

Returns a reference to the bidirectional edge store.

Source

pub fn strings(&self) -> &StringInterner

Returns a reference to the string interner.

Source

pub fn files(&self) -> &FileRegistry

Returns a reference to the file registry.

Source

pub fn indices(&self) -> &AuxiliaryIndices

Returns a reference to the auxiliary indices.

Source

pub fn macro_metadata(&self) -> &NodeMetadataStore

Returns a reference to the macro boundary metadata store.

Source

pub fn fact_epoch(&self) -> u64

Returns the monotonic fact-layer epoch.

Source

pub fn node_provenance(&self, id: NodeId) -> Option<&NodeProvenance>

Looks up node provenance by NodeId.

Source

pub fn edge_provenance(&self, id: EdgeId) -> Option<&EdgeProvenance>

Looks up edge provenance by EdgeId.

Source

pub fn file_provenance(&self, id: FileId) -> Option<FileProvenanceView<'_>>

Returns a borrowed provenance view for a file.

Source

pub fn scope_arena(&self) -> &ScopeArena

Returns a reference to the scope arena at snapshot time.

Participates in MVCC: the snapshot holds an Arc clone of the arena as it existed when snapshot() was called. Subsequent calls to set_scope_arena on the source CodeGraph do not affect this view.

Source

pub fn alias_table(&self) -> &AliasTable

Returns a reference to the alias table at snapshot time.

Participates in MVCC: the snapshot holds an Arc clone of the table as it existed when snapshot() was called. Subsequent calls to set_alias_table on the source CodeGraph do not affect this view.

Source

pub fn shadow_table(&self) -> &ShadowTable

Returns a reference to the shadow table at snapshot time.

Participates in MVCC: the snapshot holds an Arc clone of the table as it existed when snapshot() was called. Subsequent calls to set_shadow_table on the source CodeGraph do not affect this view.

Source

pub fn scope_provenance_store(&self) -> &ScopeProvenanceStore

Returns a reference to the scope provenance store at snapshot time.

Participates in MVCC: the snapshot holds an Arc clone of the store as it existed when snapshot() was called. Subsequent calls to set_scope_provenance_store on the source CodeGraph do not affect this view.

Source

pub fn scope_provenance(&self, id: ScopeId) -> Option<&ScopeProvenance>

Looks up scope provenance by ScopeId at snapshot time.

Returns None if the slot is out of range, vacant, or the stored generation does not match (stale handle).

Source

pub fn scope_by_stable_id(&self, stable: ScopeStableId) -> Option<ScopeId>

Looks up the live ScopeId for a stable scope identity at snapshot time.

Returns None if no provenance record is registered for that stable id.

Source

pub fn file_segments(&self) -> &FileSegmentTable

Returns a reference to the file segment table at snapshot time.

Source

pub fn epoch(&self) -> u64

Returns the epoch at which this snapshot was taken.

This can be compared against the current graph epoch to detect if the graph has changed since the snapshot.

Source

pub fn epoch_matches(&self, other_epoch: u64) -> bool

Returns true if this snapshot’s epoch matches the given epoch.

Use this to validate cursors before continuing pagination.

Source

pub fn binding_plane(&self) -> BindingPlane<'_>

Returns a [BindingPlane] facade borrowing this snapshot’s lifetime.

The facade is the stable Phase 2 public API for scope/alias/shadow queries and witness-bearing resolution. It provides a single entry point (resolve) that returns both a BindingResult and an ordered step trace in a BindingResolution.

§MVCC note

BindingPlane<'_> borrows from this snapshot, which is already an MVCC-consistent view of the graph at snapshot time. Callers from CodeGraph or ConcurrentCodeGraph should follow the two-line pattern so the snapshot lifetime is explicit:

// CodeGraph caller:
let snapshot = graph.snapshot();
let plane = snapshot.binding_plane();

// ConcurrentCodeGraph caller:
let read_guard = concurrent.read();
let snapshot = read_guard.snapshot();
let plane = snapshot.binding_plane();
Source

pub fn find_by_pattern(&self, pattern: &str) -> Vec<NodeId>

Finds nodes matching a pattern.

Performs a simple substring match on node names and qualified names. Returns all matching node IDs.

Synthetic suppression (C_SUPPRESS): synthetic placeholder nodes — internal scaffolding the language plugins emit for binding-plane and scope analysis (e.g. the Go plugin’s <field:operand.field> field-access shadows and the <ident>@<offset> per-binding-site Variable nodes from the local-scope resolver) — are filtered out by default. Internal callers that need to reach these nodes (binding plane, scope / alias / shadow analysis) use Self::find_by_pattern_with_options with include_synthetic = true.

§Performance

Optimized to iterate over unique strings in the interner (smaller set) rather than all nodes in the arena.

§Arguments
  • pattern - The pattern to match (substring search)
§Returns

A vector of NodeIds for all matching nodes (synthetic placeholders excluded).

Source

pub fn find_by_pattern_with_options( &self, pattern: &str, include_synthetic: bool, ) -> Vec<NodeId>

Finds nodes matching a pattern with explicit control over synthetic placeholder visibility.

include_synthetic = false is the default surface used by every user-facing caller (CLI search, MCP semantic_search / pattern_search / relation_query, etc.). Synthetic placeholders are suppressed via two parallel checks that must agree:

  1. The authoritative NodeMetadata::Synthetic bit on the metadata store (crate::graph::unified::storage::metadata::NodeMetadataStore::is_synthetic).
  2. The structural name-shape fallback (crate::graph::unified::storage::arena::NodeEntry::is_synthetic_placeholder_name) for V10 snapshots written before the synthetic bit existed and for cross-file unification losers that retained their name but lost their metadata entry.

Either check matching is sufficient to suppress the node. The design lives in docs/development/public-issue-triage/ under the C_SUPPRESS unit; see also the rationale in crate::graph::unified::storage::metadata::NodeMetadata::Synthetic.

include_synthetic = true is internal-only. The binding plane, scope resolver, and rebuild’s coverage gate use this path to reach synthetic nodes for their structural integrity checks. No CLI / MCP surface should ever pass true.

Source

pub fn find_by_exact_name(&self, name: &str) -> Vec<NodeId>

Finds nodes whose interned simple or qualified name equals name byte-for-byte (case-sensitive).

This is the canonical surface for exact-name lookups — shared by the CLI --exact <pattern> shorthand (sqry-cli/src/commands/search.rs::run_regular_search) and the structural query planner’s name: predicate (sqry-db/src/planner/parse.rs, sqry-db/src/planner/execute.rs). Both surfaces are contract-bound (DAG B1_ALIGN) to return the same set against any fixture: the CLI calls this method directly, while the planner uses the same interner + by-name index pair internally when scanning, then applies the same synthetic filter.

Synthetic suppression. Synthetic placeholder nodes (Go-plugin <field:operand.field> shadows and <ident>@<offset> per-binding-site Variables; see Self::find_by_pattern_with_options for the full taxonomy) are excluded via Self::is_node_synthetic. There is no include_synthetic = true variant for the exact-match surface because the synthetic name shapes the structural fallback recognises (<…>, …@<offset>) cannot equal a user-typed name byte-for-byte; the metadata-bit channel is the only realistic leak vector and it is suppressed unconditionally.

§Performance

O(1) interner lookup + O(matches) filter. If name is not interned the result is empty without scanning any nodes.

§Arguments
  • name - The exact name to look up (no glob, no regex).
§Returns

Sorted, deduplicated NodeIds for every non-synthetic node whose entry.name or entry.qualified_name equals name. Returns an empty vector when name is not interned (i.e. no node could possibly carry that name).

Source

pub fn is_node_synthetic(&self, node_id: NodeId) -> bool

Returns true if the node should be treated as a synthetic placeholder for user-facing surfaces.

Combines the metadata-store flag and the structural name-shape fallback (see Self::find_by_pattern_with_options for the full rationale). Returns false for missing nodes (an unknown NodeId is not “synthetic” — it is “not present”).

Source

pub fn get_callees(&self, node: NodeId) -> Vec<NodeId>

Gets all callees of a node (functions called by this node).

Queries the forward edge store for all Calls edges from this node.

§Arguments
  • node - The node ID to query
§Returns

A vector of NodeIds representing functions called by this node.

Source

pub fn get_callers(&self, node: NodeId) -> Vec<NodeId>

Gets all callers of a node (functions that call this node).

Queries the reverse edge store for all Calls edges to this node.

§Arguments
  • node - The node ID to query
§Returns

A vector of NodeIds representing functions that call this node.

Source

pub fn iter_nodes(&self) -> impl Iterator<Item = (NodeId, &NodeEntry)>

Iterates over all nodes in the graph.

Returns an iterator yielding (NodeId, &NodeEntry) pairs for all occupied slots in the arena.

§Returns

An iterator over (NodeId, &NodeEntry) pairs.

Source

pub fn iter_edges( &self, ) -> impl Iterator<Item = (NodeId, NodeId, EdgeKind)> + '_

Iterates over all edges in the graph.

Returns an iterator yielding (source, target, EdgeKind) tuples for all edges in the forward edge store.

§Returns

An iterator over edge tuples.

Source

pub fn get_node(&self, id: NodeId) -> Option<&NodeEntry>

Gets a node entry by ID.

Returns a reference to the NodeEntry if the ID is valid, or None if the ID is invalid or stale.

§Arguments
  • id - The node ID to look up
§Returns

A reference to the NodeEntry, or None if not found.

Source§

impl GraphSnapshot

Source

pub fn resolve_symbol(&self, query: &SymbolQuery<'_>) -> SymbolResolutionOutcome

Resolves one symbol with explicit file-aware outcome classification.

Source

pub fn find_symbol_candidates( &self, query: &SymbolQuery<'_>, ) -> SymbolCandidateOutcome

Finds ordered candidates from the first eligible non-empty bucket.

Source

pub fn find_symbol_candidates_with_witness( &self, query: &SymbolQuery<'_>, ) -> SymbolCandidateSearchWitness

Finds ordered candidates from the first eligible non-empty bucket, preserving the bucket that produced them.

Source

pub fn resolve_symbol_with_witness( &self, query: &SymbolQuery<'_>, ) -> SymbolResolutionWitness

Resolve one symbol while preserving witness metadata about the winning candidate bucket and ordered candidates.

Source

pub fn resolve_file_scope( &self, file_scope: &FileScope<'_>, ) -> Result<ResolvedFileScope, FileScopeError>

Resolves an external file scope into an indexed file scope.

§Errors

Returns FileScopeError::FileNotIndexed when the requested file scope is not present in the loaded graph indices.

Source

pub fn normalize_symbol_query( &self, query: &SymbolQuery<'_>, file_scope: &ResolvedFileScope, ) -> NormalizedSymbolQuery

Normalizes a raw symbol query into canonical graph form.

Source

pub fn resolve_global_symbol_ambiguity_aware( &self, symbol: &str, file_scope: FileScope<'_>, ) -> Result<NodeId, SymbolResolveError>

Resolve a symbol to one NodeId with a typed ambiguity error.

This is the single, shared resolver used by every CLI, LSP, and MCP surface that must collapse a user-supplied symbol name to one canonical node. It accepts both bare names (NeedTags) and fully-qualified names (main.SelectorSource.NeedTags or main::SelectorSource::NeedTags):

  • For a fully-qualified name, the resolver normalizes native delimiters (.) to graph-canonical :: form and looks up the exact-qualified bucket. A unique match is the only acceptable resolution — there is no fuzzy fallback to simple-name candidates even if the qualified form has zero hits, because qualified names are a user contract.
  • For a bare name, the resolver tries the exact-simple bucket and resolves the unique match. If two or more nodes share the simple name (e.g. a struct field and a local variable), it returns SymbolResolveError::Ambiguous with the candidate list.

The candidate list is sorted lexicographically by (qualified_name, file_path, start_line, start_column) and capped at AMBIGUOUS_SYMBOL_CANDIDATE_CAP.

§Errors
§File scope

file_scope follows the same semantics as SymbolQuery::file_scope:

Trait Implementations§

Source§

impl Clone for GraphSnapshot

Source§

fn clone(&self) -> GraphSnapshot

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for GraphSnapshot

Source§

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

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

impl GraphAccess for GraphSnapshot

Source§

fn nodes(&self) -> &NodeArena

Returns the node arena (read-only).
Source§

fn edges(&self) -> &BidirectionalEdgeStore

Returns the bidirectional edge store (read-only).
Source§

fn strings(&self) -> &StringInterner

Returns the string interner (read-only).
Source§

fn files(&self) -> &FileRegistry

Returns the file registry (read-only).
Source§

fn indices(&self) -> &AuxiliaryIndices

Returns the auxiliary indices (read-only).

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> 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<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
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