Skip to main content

ModuleResolver

Struct ModuleResolver 

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

Resolves and loads modules

Implementations§

Source§

impl ModuleResolver

Source

pub fn new(search_paths: Vec<PathBuf>) -> Self

Create a new resolver with given search paths

Source

pub fn mark_entry_module(&mut self, path_key: &str)

Record which loaded module is the compilation entry point.

The entry module’s pragmas are the ones the compiler honors; Self::ignored_import_pragmas skips it.

Source

pub fn ignored_import_pragmas(&self) -> Vec<IgnoredImportPragma>

List #pragma directives declared in imported (non-entry) modules.

Pragmas are entry-file-scoped, so anything an imported module declares is dropped at merge time. Callers surface these records as warnings so the scoping is never silent. The result is sorted by module path, then pragma name, for deterministic output.

Nested imports resolve relative to the importer’s directory, so one file can be loaded under several module-path spellings. Warnings are deduplicated on the canonical source file (one warning per file per pragma), keeping the alphabetically-first module label; the entry file itself never warns under any spelling.

Source

pub fn find_module_file( &self, base_dir: &Path, module_path: &[String], ) -> Option<PathBuf>

Find the file for a module path

Source

pub fn extract_exports(program: &Program) -> (HashSet<String>, HashSet<String>)

Extract exports from a parsed program Returns (predicate exports, function exports)

Source

pub fn load_module( &mut self, base_dir: &Path, module_path: &[String], ) -> Result<&LoadedModule, ModuleError>

Load a module from a logical path and make it the resolution root.

A successful call replaces any exact-file entry anchor used by Self::validate_imports and Self::merge_imports.

Source

pub fn load_entry_file( &mut self, entry_file: &Path, ) -> Result<&LoadedModule, ModuleError>

Load the compilation entry from its exact filesystem path.

Imported modules still use normal .xlog module lookup. The entry file itself may use any extension accepted by the caller. It is tracked separately from logical imports so a same-stem .xlog module remains addressable through use. Nested imports in an imported module resolve beside its canonical source target, making symbolic-link aliases independent of load order.

Source

pub fn check_import( &self, module_path: &[String], predicate: &str, ) -> Result<(), ModuleError>

Check if a predicate can be imported from a module

This compatibility inspection uses the first source registered for the logical path. Semantic validation follows importer-scoped resolved edges and does not use this alias lookup.

Source

pub fn validate_imports( &self, program: &Program, ) -> Result<(HashMap<String, Vec<String>>, HashMap<String, Vec<String>>), ModuleError>

Validate all imports in a program.

Import edges come from the most recently loaded entry file or root module when its declarations match program. A context-free request is accepted only when every logical path identifies one loaded source file.

Returns predicate and function names with the first resolved source module retained as a representative. Entry declarations and selected public import declarations participate in declaration compatibility checks. For signatures without a participating declaration, inferred head-column types from entry and selected public import clauses are validated before merging. Constants, head variables typed by ordinary body atoms or built-in arithmetic bindings, and aggregate result types supply evidence; unanchored variables do not.

Source

pub fn get_module(&self, module_path: &[String]) -> Option<&LoadedModule>

Get a loaded logical import by module path.

If several importer contexts registered the same logical path for different files, this compatibility view returns the first registered source. Semantic validation and merging use resolved import edges.

Source

pub fn entry(&self) -> Option<&LoadedModule>

Return the entry source loaded from its exact path, if present.

Source

pub fn is_loaded(&self, module_path: &str) -> bool

Check whether at least one source is registered for a logical import path.

Source

pub fn loaded_modules(&self) -> Vec<&str>

Get all registered logical import aliases (for testing).

Source

pub fn merge_imports(&self, program: Program) -> Result<Program, ModuleError>

Merge supported deterministic content from every resolved import.

Resolution follows the importer-scoped edges recorded by the matching entry file or root module. Without that anchor, every logical path must identify one loaded source. Imported entry-only content, incomplete exports, incompatible participating declarations, conflicting inferred head-column types for undeclared predicate signatures, and conflicting function definitions are rejected rather than silently omitted. Selected public predicate clauses from separate import branches are then merged into one relation.

§Arguments
  • program - The main program with imports to resolve
§Returns

The program with all imports merged in

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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