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] / [BTreeSet] for 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::MirProgram] with module-init statements prepended in topological order.
Typical workflow
entry.cjcl ─► build_module_graph() ─► ModuleGraph
│
merge_programs() ◄─┘
│
MirProgram (ready for cjc-mir-exec)