Expand description
Module loader for multi-file LOGOS projects.
Handles resolution and loading of module sources from various URI schemes, with caching to prevent duplicate loading.
§Supported URI Schemes
| Scheme | Example | Description |
|---|---|---|
file: | file:./geometry.md | Local filesystem (relative) |
logos: | logos:std | Built-in standard library |
| (none) | geometry.md | Defaults to file: scheme |
§Security
The loader prevents path traversal attacks by checking that resolved paths remain within the project root directory.
§Caching
Modules are cached by their normalized URI. The same module loaded from different base paths will be cached separately.
§Example
let mut loader = Loader::new(project_root);
let source = loader.resolve(Path::new("main.md"), "file:./lib/math.md")?;
println!("Loaded: {}", source.path.display());Structs§
- DepRoot
- A declared dependency’s resolved root: the alias an
Import <Name>.binds to (matched case-insensitively against the bare import name) and the canonicalized directory its modules live under. Populated from a project’sLargo.toml[dependencies]; empty for a single-project build. - Library
Provenance - Establishes, for the compilation or execution that runs while it lives, which functions of the program are the standard library’s definitions. Restores the enclosing provenance on drop, so nested and sequential compiles on one thread never see each other’s program.
- Loader
- Module loader that handles multiple URI schemes.
- Module
Source - A loaded module’s source content and metadata.
- Prelude
Segment - One run of
apply_prelude’s output tied back to where it came from:user_startis the byte offset of an untouched run of the caller’s own text,Nonemarks spliced stdlib text. Downstream span translation (deep check) inverts the prelude edit exactly through these runs.
Functions§
- apply_
prelude - Prepend the stdlib modules a program actually uses. Returns the source
unchanged when the program references no stdlib vocabulary or opts out with
## NoPrelude(in which case the opt-out marker is stripped so it never reaches the parser). This is the auto-import seam for both the interpreter and the compiler. - apply_
prelude_ mapped apply_preludeplus the exact edit it performed, as ordered output runs. A consumer that parses the expanded text and reports spans against the USER’s buffer must translate through these segments rather than assume the modules were prepended: they are spliced AFTER any leading title/comment prose, and## NoPreludeREMOVES its marker lines.- content_
type_ for - ★ THE MIME TABLE LIVES IN ONE PLACE, AND THAT PLACE IS
static.lg. ★ - defined_
names_ with_ visibility - Like
defined_names, but also reports whether each definition isprivate(declared## To private …/## A private …). Public-by-default: a name with noprivatemarker isfalse. Powers module encapsulation — a private name is usable by its owning module but not importable by any other file. Public so the language server can filter private names out of its cross-module surfaces (completion, auto-import, workspace symbols) from the one source of truth. - is_
library_ function - Is
namethe standard library’s own definition in the program being compiled? - keep_
reachable_ functions - Drop top-level
## To …function definitions that are UNREACHABLE from the program’s entry, keeping every non-function section (## Astructs,## Main, prose) and every function whose name is transitively called. This is the C backends’ tree-shake: a flat C namespace can’t tolerate emitting an unused stdlib function that either collides with a libc name or exercises a C-codegen gap the function is never actually reached through (the Rust backend tolerates both, so this is C-only). - library_
owned_ functions - The functions of an assembled program that ARE the standard library’s definitions: those whose
## Tosection is byte-identical to the section the library itself ships under that name. - prelude
- The full embedded prelude — every module’s CODE concatenated (what
apply_preludeprepends), documentation notes stripped. Identical bytes on every target (include_str!is compile-time). - prelude_
module_ sources - The RAW embedded stdlib module sources,
## Notedocumentation included — the seam the LSP reads literate docs from (teach::extract_literate_docs). - prelude_
vocabulary - Every identifier the prelude defines (across all modules) — derived from the modules.
- prune_
unreachable_ prelude - Drop ONLY the auto-imported stdlib PRELUDE functions that are never reachable, keeping EVERY
user-defined function untouched. This is the chip-encoder analog of
keep_reachable_functions, but safe for LOGOS’s non-name(call forms:apply_preludesplices a WHOLE module when the program mentions any of its names, so an UNCALLED prelude helper that reaches a host builtin (parseFloat,format, …) would make the flat chip image reject even though it never runs. This prunes those dead prelude helpers so the encoder lowers only what the program executes — with two safety differences from the C tree-shake: • it NEVER drops a user function (the prune set is exactly the prelude vocabulary), so a user procedure invoked by a LOGOS call form the call-only scan misses (Launch a task to worker, higher-orderapply(f, …)) is always kept; • reachability uses the PERMISSIVEreferences(any use position — the same predicateapply_preludesplices on), so a prelude function reached viato <fn>/of <fn>/ a value position is retained. The output is byte-identical to the input when nothing is pruned (no prelude, or all reachable), so the AOT/other hot paths are untouched. Over-pruning can only ever surface as a LOUD undefined reference. - prune_
unreachable_ prelude_ from prune_unreachable_preludetold which names the USER’s own (pre-prelude) source declares, so a name the stdlib also has is recognized as the user’s and kept. Callers that have the original source should prefer this; the bare form behaves as before.- prune_
unreachable_ prelude_ mapped prune_unreachable_preludeplus the KEPT byte ranges of the INPUT (merged and in order), so a consumer that parses the pruned text can remap an offset back to the original source. Deep check uses this to drop EXACTLY whatlargo builddrops (it prunes the same way before it parses) while keeping every rustc finding mapped to the user’s own line. The ranges partition the kept output: concatenatingsource[s..e]for each(s, e)reproduces the pruned string.- prune_
unreachable_ prelude_ mapped_ from prune_unreachable_prelude_fromwith the byte ranges ofsplicedit kept, asprune_unreachable_prelude_mappedreports them — for a caller that maps offsets in the pruned text back, and must still prune exactly as a build does.- prune_
unreachable_ prelude_ mapped_ with prune_unreachable_prelude_mappedwith the names the user’s own source declares, which are never eligible for pruning (see there).