Expand description
CJC Module System
Deterministic module resolution, dependency graph construction, and program merging for multi-file CJC programs.
This crate provides the infrastructure for splitting CJC programs across
multiple source files. It handles file resolution, import parsing,
dependency-graph construction with cycle detection, symbol mangling,
visibility enforcement, and final merging of per-module MIR into a
single cjc_mir::MirProgram suitable for execution.
§Design principles
- All internal maps use
BTreeMap/BTreeSetfor deterministic iteration order, ensuring reproducible compilation regardless of filesystem enumeration order. - Symbol mangling uses a
module_path::fn_nameconvention (e.g.,math::linalg::solve). - Cycle detection is performed via DFS with a
BTreeSet-backed recursion stack and produces clear error messages. - The final output is a single merged
cjc_mir::MirProgramwith module-init statements prepended in topological order.
§Typical workflow
entry.cjc ─► build_module_graph() ─► ModuleGraph
│
merge_programs() ◄─┘
│
MirProgram (ready for cjc-mir-exec)Structs§
- Import
Info - A resolved import from one module to another.
- Module
Graph - A directed acyclic graph of module dependencies.
Uses
BTreeMapinternally for deterministic iteration order. - Module
Id - A unique, deterministic identifier for a module derived from its path relative to the project root.
- Module
Info - Metadata and parsed content for a single CJC source module.
- Visibility
Violation - Errors produced by visibility checks.
Enums§
- Module
Error - Errors that can occur during module resolution.
Functions§
- build_
import_ aliases - Build an alias map from a module’s imports for use during call resolution.
- build_
module_ graph - Build a module graph starting from the entry file.
- check_
visibility - Check visibility constraints after merging.
- merge_
programs - Merge multiple module ASTs into a single combined MIR program.
- resolve_
file - Resolve an import path to a source file, searching from the given root directory.