Skip to main content

Module module_resolver

Module module_resolver 

Source
Expand description

v2.76.0 — Phase 0 of the Epistemic Module System: dependency discovery.

Builds the module dependency DAG for a multi-file AXON project and topologically sorts it (Kahn), refusing cycles (axon-T955).

§Design

  • In-memory-first. The resolver operates over a ModuleSet — a deterministic map from ModulePath to source text. The filesystem walk (ModuleSet::from_entry_file) is one constructor on top; the enterprise bundle path and the LSP feed sources directly (ModuleSet::from_memory) and never touch a disk.
  • Lexer-true scanning. scan_imports tokenizes with the real AXON lexer and walks tokens — no AST, and crucially no regex: discovery can never recognize a different import grammar than the parser does (the drift class the retired Python EMS’s regex scanner invited).
  • Lenient scan, authoritative parse. A malformed import statement is skipped by the scanner — the parser owns the canonical diagnostic. The scanner’s only job is to know which files to load.
  • Deterministic everywhere. BTreeMap/BTreeSet ordering, and the Kahn ready-queue pops the smallest module path first, so the topological order is a pure function of the module set (section 4.4 of the EMS paper — the property the enterprise ir_sha256 dedupe anchor relies on).

§Refusal posture

Two import forms parse but are refused downstream (axon-T953, in the type-checker’s module mode): the non-selective import a.b (name pollution — #include wearing a module system’s clothes) and the @scope-prefixed form (reserved for a future package registry). The resolver records them (so the diagnostics can fire with real locations) but neither loads files nor contributes DAG edges for them.

Structs§

LoadedModule
One loaded module: its display origin (path or bundle key) + source.
ModuleError
A Phase-0 resolution failure. Rendered by the CLI in the house error [line N]: shape against the importing file.
ModuleGraph
The resolved dependency graph: every module’s scanned imports plus the deterministic topological order (dependencies first, entry last).
ModulePath
A dotted module path: axon.security["axon", "security"]<modules-root>/axon/security.axon.
ModuleSet
The complete, deterministic set of modules for one compilation: the entry plus every transitively imported module.
ScannedImport
One import statement as seen by the Phase-0 token scan.

Constants§

MAX_MODULES
Hard ceiling on the number of modules a single project may load. Fail-closed guard against runaway transitive graphs; generous by an order of magnitude over any real deployment seen to date.

Functions§

scan_imports
Extract every import statement from source via the real lexer.