pub struct ModuleResolver { /* private fields */ }Expand description
Resolves and loads modules
Implementations§
Source§impl ModuleResolver
impl ModuleResolver
Sourcepub fn mark_entry_module(&mut self, path_key: &str)
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.
Sourcepub fn ignored_import_pragmas(&self) -> Vec<IgnoredImportPragma>
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.
Sourcepub fn find_module_file(
&self,
base_dir: &Path,
module_path: &[String],
) -> Option<PathBuf>
pub fn find_module_file( &self, base_dir: &Path, module_path: &[String], ) -> Option<PathBuf>
Find the file for a module path
Sourcepub fn extract_exports(program: &Program) -> (HashSet<String>, HashSet<String>)
pub fn extract_exports(program: &Program) -> (HashSet<String>, HashSet<String>)
Extract exports from a parsed program Returns (predicate exports, function exports)
Sourcepub fn load_module(
&mut self,
base_dir: &Path,
module_path: &[String],
) -> Result<&LoadedModule, ModuleError>
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.
Sourcepub fn load_entry_file(
&mut self,
entry_file: &Path,
) -> Result<&LoadedModule, ModuleError>
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.
Sourcepub fn check_import(
&self,
module_path: &[String],
predicate: &str,
) -> Result<(), ModuleError>
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.
Sourcepub fn validate_imports(
&self,
program: &Program,
) -> Result<(HashMap<String, Vec<String>>, HashMap<String, Vec<String>>), ModuleError>
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.
Sourcepub fn get_module(&self, module_path: &[String]) -> Option<&LoadedModule>
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.
Sourcepub fn entry(&self) -> Option<&LoadedModule>
pub fn entry(&self) -> Option<&LoadedModule>
Return the entry source loaded from its exact path, if present.
Sourcepub fn is_loaded(&self, module_path: &str) -> bool
pub fn is_loaded(&self, module_path: &str) -> bool
Check whether at least one source is registered for a logical import path.
Sourcepub fn loaded_modules(&self) -> Vec<&str>
pub fn loaded_modules(&self) -> Vec<&str>
Get all registered logical import aliases (for testing).
Sourcepub fn merge_imports(&self, program: Program) -> Result<Program, ModuleError>
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