pub struct SymbolTable { /* private fields */ }Expand description
A global symbol table for resolving cross-file references.
Implementations§
Source§impl SymbolTable
impl SymbolTable
pub fn new() -> Self
Sourcepub fn insert(&mut self, fqn: String, id: NodeId, file: PathBuf)
pub fn insert(&mut self, fqn: String, id: NodeId, file: PathBuf)
Registers a symbol definition.
Repeated FQNs accumulate instead of overwriting.
Sourcepub fn resolve(&self, fqn: &str) -> Option<NodeId>
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.
Sourcepub fn resolve_all(&self, fqn: &str) -> Vec<NodeId> ⓘ
pub fn resolve_all(&self, fqn: &str) -> Vec<NodeId> ⓘ
All nodes defining this exact FQN, in deterministic order.
Sourcepub fn get_file_exports(&self, file: &PathBuf) -> Option<&Vec<String>>
pub fn get_file_exports(&self, file: &PathBuf) -> Option<&Vec<String>>
Returns all symbols exported by a file.
pub fn clear(&mut self)
Sourcepub fn resolve_ref(&self, name: &str, context_file: &Path) -> Resolution
pub fn resolve_ref(&self, name: &str, context_file: &Path) -> Resolution
Resolves a reference, preferring locality and reporting ambiguity.
Order:
- Exact FQN, unique →
Exact - Candidate gathering: exact-FQN entries plus every segment-aligned suffix match, deduplicated and sorted
- Single candidate →
Exact/UniqueSuffix - Exactly one candidate in the referencing file →
SameFile - Exactly one candidate in the referencing directory →
SameDir - Otherwise →
Ambiguous
Sourcepub fn resolve_ref_with_imports(
&self,
name: &str,
context_file: &Path,
imports: Option<&HashMap<String, String>>,
) -> Resolution
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.
Sourcepub fn resolve_path(&self, path: &str, context_file: &Path) -> Resolution
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::newis stored asType.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.
Sourcepub fn resolve_with_context(
&self,
name: &str,
context_file: &Path,
) -> Option<NodeId>
pub fn resolve_with_context( &self, name: &str, context_file: &Path, ) -> Option<NodeId>
Back-compatible wrapper returning only a confidently-resolved node.