Skip to main content

ModuleResolver

Struct ModuleResolver 

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

Project-wide module resolver backed by canonical DagId identities.

Implementations§

Source§

impl ModuleResolver

Source

pub fn from_modules<'a>( modules: impl IntoIterator<Item = (DagId, &'a File)>, ) -> Result<Self, ModuleResolveError>

Build a resolver from (DagId, File) pairs without registering any import scopes.

Call Self::register_import / Self::register_include for each loader-resolved edge after all modules have been added.

§Errors

Returns ModuleResolveError on duplicate modules or duplicate symbols.

Source

pub fn add_module( &mut self, owner: DagId, declarations: &[Declaration], ) -> Result<(), ModuleResolveError>

Add one module’s declaration symbols.

§Errors

Returns ModuleResolveError::DuplicateModule when owner already has a symbol table, or ModuleResolveError::DuplicateSymbol for duplicate namespace-local definitions inside the module.

Source

pub const fn modules(&self) -> &HashMap<DagId, ModuleSymbols>

Borrow all module symbol tables.

Source

pub const fn scopes(&self) -> &HashMap<DagId, ModuleScope>

Borrow all module import scopes.

Source

pub fn register_import( &mut self, owner: &DagId, path: &ModulePath, kind: &ImportKind, target: &DagId, ) -> Result<(), ModuleResolveError>

Register one loader-resolved import edge in owner’s scope.

path and kind come from the source AST. target is the canonical module identity chosen by the loader for that path. This function never re-resolves filesystem paths.

§Errors

Returns ModuleResolveError if either module is unknown, an imported item is missing/private, or the import introduces a duplicate local name.

Source

pub fn register_include( &mut self, owner: &DagId, path: &ModulePath, kind: &ImportKind, target: &DagId, ) -> Result<(), ModuleResolveError>

Register one loader-resolved include edge in owner’s scope.

Instantiated includes embed the dependency DAG body, but the source-level names introduced by the include are still a cross-module boundary and must preserve public visibility.

Source

pub fn inline_instantiated_include_indexes( &mut self, importer: &DagId, source: &DagId, bound: &HashSet<&str>, ) -> Result<(), ModuleResolveError>

Make an instantiated include’s own indexes resolvable in the importer.

An instantiated include inlines the dependency’s declaration bodies into the importer (see ir::lower::merge_dependency). Those bodies reference the dependency’s own indexes by their bare names (for s: Step, T[Step], Step.A), which are not bound to any importer symbol. The dependency’s declarations live in the synthetic include module source; copy each of its index symbols — re-homed onto the importer so they resolve against the flat merged registry that backs the importer’s declarations — into the importer’s own symbol table, variants included.

Indexes named in bound (the include’s index bindings/overrides) are skipped: a bound index is rewritten to the importer’s replacement before resolution, so the dependency’s original name must not shadow it. Indexes already declared in the importer are likewise left untouched.

§Errors

Returns ModuleResolveError::UnknownModule if either module is absent from the resolver.

Source

pub fn resolve_decl_path( &self, owner: &DagId, path: &NamePath, ) -> Result<ResolvedName<Decl>, ModuleResolveError>

Resolve a syntactic declaration/value path to a canonical owner + leaf.

Bare paths first search local declarations, then selective imports. Qualified paths resolve their qualifier through module aliases and then apply that alias boundary’s visibility rule.

Source

pub fn resolve_const_decl_path( &self, owner: &DagId, path: &NamePath, ) -> Result<ResolvedName<Decl>, ModuleResolveError>

Resolve a declaration path and require that it names a const declaration.

Source

pub fn decl_symbol_kind( &self, name: &ResolvedName<Decl>, ) -> Result<DeclSymbolKind, ModuleResolveError>

Return the semantic kind of a resolved declaration symbol.

Source

pub fn resolve_dimension_path( &self, owner: &DagId, path: &NamePath, ) -> Result<ResolvedName<Dim>, ModuleResolveError>

Resolve a syntactic dimension path to a canonical owner + leaf.

Source

pub fn resolve_unit_path( &self, owner: &DagId, path: &NamePath, ) -> Result<ResolvedName<Unit>, ModuleResolveError>

Resolve a syntactic unit path to a canonical owner + leaf.

Source

pub fn resolve_struct_type_path( &self, owner: &DagId, path: &NamePath, ) -> Result<ResolvedName<StructType>, ModuleResolveError>

Resolve a syntactic struct/tagged-union type path to a canonical owner + leaf.

Source

pub fn resolve_constructor_path( &self, owner: &DagId, path: &NamePath, ) -> Result<ResolvedName<Constructor>, ModuleResolveError>

Resolve a syntactic tagged-union constructor path to a canonical owner + leaf.

Source

pub fn resolve_constructor_ident_path( &self, owner: &DagId, path: &IdentPath, ) -> Result<ResolvedName<Constructor>, ModuleResolveError>

Resolve a span-aware constructor path without losing source path shape at the caller boundary.

Source

pub fn resolve_index_path( &self, owner: &DagId, path: &NamePath, ) -> Result<ResolvedName<Index>, ModuleResolveError>

Resolve a syntactic index path to a canonical owner + leaf.

Source

pub fn resolve_index_variant_path( &self, owner: &DagId, path: &NamePath, ) -> Result<ResolvedIndexVariant, ModuleResolveError>

Resolve a syntactic index-variant path such as Index.Variant or module.Index.Variant.

Source

pub fn resolve_index_variant_parts( &self, owner: &DagId, index_path: &NamePath, variant: &IndexVariantName, ) -> Result<ResolvedIndexVariant, ModuleResolveError>

Resolve an already-split index path plus variant leaf to a canonical index-variant identity.

This is the HIR-facing form for parser positions that preserve the index path and variant leaf separately (map keys, index arguments, and match labels). It avoids reconstructing a dotted string or re-parsing source text just to validate the variant against the canonical index.

Source

pub fn resolve_bare_index_variant( &self, owner: &DagId, variant: &IndexVariantName, ) -> Result<ResolvedIndexVariant, ModuleResolveError>

Resolve a bare variant leaf by searching local and selectively imported indexes in the current module scope.

Source

pub fn resolve_module_path( &self, owner: &DagId, path: &ModulePath, ) -> Result<DagId, ModuleResolveError>

Resolve a source inline-DAG/module path to its canonical DagId.

Single-segment paths first name inline DAG children of owner; when called from an inline DAG body and no nested child exists, they may also name sibling DAGs under the parent file. Qualified paths use the first segment as a module alias and append the remaining segments to the alias target. The returned identity is canonical; source qualifier text is not carried beyond this resolver boundary.

Source

pub fn scope(&self, owner: &DagId) -> Option<&ModuleScope>

Import scope registered for a module, if any.

IDE consumers use this to map canonical owners back to the module aliases a file spelled in its imports.

Trait Implementations§

Source§

impl Clone for ModuleResolver

Source§

fn clone(&self) -> ModuleResolver

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 ModuleResolver

Source§

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

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

impl Default for ModuleResolver

Source§

fn default() -> ModuleResolver

Returns the “default value” for a type. Read more
Source§

impl Eq for ModuleResolver

Source§

impl PartialEq for ModuleResolver

Source§

fn eq(&self, other: &ModuleResolver) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ModuleResolver

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.