On this page

0064. One file per module with selective root-relative imports

Context

Programs need multiple files without fragmenting the grammar or disrupting whole-program type checking, specialization and coherence. Existing phases use bare string names, and method calls already use dot syntax.

Decision

Each file is a module. import a.b { x } loads a/b.hn relative to the root file's directory and binds selected public items as bare names. Imports precede declarations; import and pub are contextual. Items are private by default; pub applies to functions, structs, enums, newtypes and interfaces, not impls. Globs, qualified use sites and re-exports are unsupported in v1. The no-aliases rule alone is partially superseded by ADR-0073; all other decisions here remain accepted.

Load and bind the graph, rewrite module items to dotted internal names, and merge into one AST before existing resolution and type checking. Root names remain bare. C function names encode module path segments with lengths to avoid collisions. Sources, expression IDs and function file identities follow ADR-0068. This extends ADR-0006's single grammar.

Alternatives considered

Consequences

The existing name-keyed phases and single C translation unit remain usable; the binding rewrite must distinguish local references from module items. Aliases and packages are deferred to M9.2; M9.1 Step 4 handles further visibility rules.