Skip to main content

Crate cjc_module

Crate cjc_module 

Source
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 / BTreeSet for deterministic iteration order, ensuring reproducible compilation regardless of filesystem enumeration order.
  • Symbol mangling uses a module_path::fn_name convention (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.cjc ─► build_module_graph() ─► ModuleGraph
                                        │
                     merge_programs() ◄─┘
                          │
                     MirProgram (ready for cjc-mir-exec)

Structs§

ImportInfo
A resolved import from one module to another.
ModuleGraph
A directed acyclic graph of module dependencies. Uses BTreeMap internally for deterministic iteration order.
ModuleId
A unique, deterministic identifier for a module derived from its path relative to the project root.
ModuleInfo
Metadata and parsed content for a single CJC source module.
VisibilityViolation
Errors produced by visibility checks.

Enums§

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