Skip to main content

SymbolTable

Struct SymbolTable 

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

A global symbol table for resolving cross-file references.

Implementations§

Source§

impl SymbolTable

Source

pub fn new() -> Self

Source

pub fn insert(&mut self, fqn: String, id: NodeId, file: PathBuf)

Registers a symbol definition.

Repeated FQNs accumulate instead of overwriting.

Source

pub fn resolve(&self, fqn: &str) -> Option<NodeId>

Resolves an exact FQN, but only when the definition is unambiguous.

Returns None for a colliding FQN so the caller can fall back to context-aware resolution rather than picking a definition at random.

Source

pub fn resolve_all(&self, fqn: &str) -> Vec<NodeId> ⓘ

All nodes defining this exact FQN, in deterministic order.

Source

pub fn get_file_exports(&self, file: &PathBuf) -> Option<&Vec<String>>

Returns all symbols exported by a file.

Source

pub fn clear(&mut self)

Source

pub fn resolve_ref(&self, name: &str, context_file: &Path) -> Resolution

Resolves a reference, preferring locality and reporting ambiguity.

Order:

  1. Exact FQN, unique → Exact
  2. Candidate gathering: exact-FQN entries plus every segment-aligned suffix match, deduplicated and sorted
  3. Single candidate → Exact / UniqueSuffix
  4. Exactly one candidate in the referencing file → SameFile
  5. Exactly one candidate in the referencing directory → SameDir
  6. Otherwise → Ambiguous
Source

pub fn resolve_ref_with_imports( &self, name: &str, context_file: &Path, imports: Option<&HashMap<String, String>>, ) -> Resolution

Resolve a reference, allowing the referencing file’s imports to break ties.

Without imports, a bare name matching definitions in several modules falls through to Ambiguous whenever no candidate shares a file or a directory with the caller — and the builder drops ambiguous edges. On a codebase that reuses a name across modules that is the common case, not the rare one: every call to it is discarded, and the module those calls belonged to reports no callers at all.

The disambiguating fact is usually written at the top of the file. from deep.l0.m14 import value_m14 says exactly which value_m14 is meant here. import_map already carries that, but only apply_import_validation consumed it, and that runs after a candidate has been chosen — so it never saw the references that were being thrown away. Consulting it during disambiguation instead of after it is the whole change.

imports maps a locally-visible name to the module it came from, so an aliased import (from x import y as z) is keyed on z.

Source

pub fn resolve_path(&self, path: &str, context_file: &Path) -> Resolution

Resolves a :: path reference: jobs::enqueue, Provider::new, crate::db::queries::get_user, my_app::app::create.

The path says where the definition lives, so it is matched on that rather than on the bare name:

  • a path some parser recorded verbatim (C++ ns::fn) matches directly;
  • a capitalised owner is a type, and Type::new is stored as Type.new;
  • anything else is a module, matched against the definition’s file (jobs.rs, app/mod.rs). Leading segments are dropped until one matches, so a crate-name prefix (my_app::app::…) works, and a definition re-exported from a submodule is found at lower confidence.

A path into an external crate (sqlx::query, std::fs::read) matches nothing here and stays unresolved, instead of binding to an unrelated local function that shares the last name.

Source

pub fn resolve_with_context( &self, name: &str, context_file: &Path, ) -> Option<NodeId>

Back-compatible wrapper returning only a confidently-resolved node.

Source

pub fn len(&self) -> usize

Number of distinct FQNs registered.

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl Clone for SymbolTable

Source§

fn clone(&self) -> Self

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 SymbolTable

Source§

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

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

impl Default for SymbolTable

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> 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> 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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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