Repository navigation
Design packages
Design issue: #36 — the ruling that binds.
STATUS: DESIGNED, NOT STARTED - rulings 1-18 are settled; stage 0 is in flight as #28 and #37; the marker's spelling and the questions under "Open" are ruled at the stage that needs them
A Maxon program is compiled as one unit: one declaration sweep, one merged module at each IR tier, one data table, and semantic passes that close over the whole call graph. Two costs follow from that.
- The compiler's own build is serial where it matters. A clean self-compile is about 68 s on a 6-core machine, and about 48 s of it is one thread: the passes that need the whole program. The three worker pools (parse, Std passes, backend) scale; the thread that feeds them does not.
- Every compile redoes the standard library. A small program whose library parse is served from the cache still spends about a third of its ~950 ms on work sized by the library: ~40 settle passes over the whole declaration index, a deep clone of it, a merge of every library file, checks over ~2,800 function headers of which a hello-world keeps 67. The library's share is the same in every program and is recomputed in each.
Both are the same missing thing: a unit smaller than the program that is compiled once, that later compiles read and never rewrite. The library is the first such unit, and a program's own packages are the rest.
What exists today, which the design builds on rather than replaces:
- A directory is a namespace; its qualifier is its path from the program root (
lib/fmt/islib.fmt). An unmarked declaration is visible to its directory's subtree;exportandpublicto every file. There is no import statement. -
stdlib.Xandscriptlib.<package>.Xalready qualify names of the library and of a scriptlib package, and a scriptlib package already shows only its marked declarations to a program. - The specification already says a library file never sees a declaration of the program, and that a program's declaration shadows the library's for the program's files only.
- A
.maxprojfile marks where a project begins and describes its builds. It says nothing about packages.
-
A package is a marked subtree (maintainer, 2026-11-15). A directory tree, marked as a package, whose files may refer to each other freely — cycles inside it included — as a crate's do. It is the unit of compilation. Packages are not one-per-directory, and a file does not import the other files of its own package.
-
One concept. The standard library (with the runtime tier beneath it), each scriptlib package, and each marked subtree of a program are packages. The files of a program that are in no marked subtree are its root package. A program that marks nothing is one root package over the library, and compiles as it does today.
-
The marker is a file in the subtree's root directory. It carries the package's dependencies and nothing a source file then has to repeat. The package's name is its directory path from the program root, which is already its namespace qualifier. The marker's file name and spelling are settled by the stage that adds it.
-
A package boundary cuts the directory rule. A marked subtree inside another package is its own package and no part of the enclosing one. Directory-subtree visibility stops at the boundary: the inner package sees the outer one only as a declared dependency.
-
Dependencies are declared, direct and acyclic. A package names declarations of the packages its marker lists, and of no other; a dependency's own dependencies are not nameable through it. The library is a dependency of every package without being listed. The root package needs no marker: it depends on every package of its tree, and nothing depends on it. Three errors, each naming its fix: a cycle between packages (the cycle is named); a name that belongs to a package the marker does not list (the dependency to add is named); a listed dependency nothing uses.
-
Inside a package nothing changes. Directories are namespaces, an unmarked declaration is visible to its directory's subtree, bare names resolve in today's order, and no file imports another.
-
publiccrosses a package boundary;exportdoes not.exportmakes a declaration visible to every file of its package.publicmakes it visible to every package that depends on that package. The unused-export audit asks its question inside the package; apublicdeclaration is the package's interface and is not audited there. -
There are no import lines. A bare name resolves inside its own package first, in today's order, and then to the single visible
publicdeclaration among the package's dependencies. Two candidates are an ambiguity error that lists the qualified spellings. A qualified name is<package>.<Name>;stdlib.Xandscriptlib.<package>.Xare that rule's existing instances. A package's own declaration outranks a dependency's of the same name, for the package's own files only. -
A package is sealed. Its meaning and its compiled form are a function of its own source, its dependencies, the target and the defines — never of a package that depends on it. This is the rule every stage is tested against. It has four consequences.
-
Lookup. No lookup made for a file returns a declaration from outside its package and its
dependencies'
publicdeclarations. - Names. A package's names, symbols and ids never move because of a dependent. Symbols are package-qualified. A dependent's declaration that shadows a dependency's takes its own identity and leaves the dependency's as written.
- Form. Where the compiler shapes a function by a fact about the whole program — a generic method's hidden parameters, whether a local is handed by reference, a called-once inline, a summary closed over the whole call graph — the package's own code takes the form its own closure decides. A form specialised to a dependent is the dependent's code, made from the dependency's template or body.
- Indirect calls. A call through an interface or a function value takes its convention from the declared requirement or function type, not from which functions exist.
-
Lookup. No lookup made for a file returns a declaration from outside its package and its
dependencies'
-
A package is compiled whole. Every body in it is parsed and checked when the package is compiled. What a program reaches is a selection made afterwards; it never decides what a dependency's parse holds. A body the target cannot support is reported only when it is reached.
-
What a package publishes. Its settled
publicdeclarations; a summary per function of what the semantic passes need from a callee (capabilities, parameter mutation, holds, throws, purity), computed over the package with its dependencies' summaries as input; the bodies that may be inlined into a dependent; its generic templates. A dependent reads these and writes none of them. No contract is declared on apublicsignature to stand in for a summary: a package waits for the packages it depends on. What is published is per target and per define set. -
An instance belongs to whoever asks for it. A generic instance, an extension default swept onto a conformer, and a witness table are the code and data of the package that requests them. Identical instances requested by two packages are made one at link.
-
Extensions and conformances. An extension's methods carry visibility as a type's members do: a
publicone is visible to the dependents of the extending package, and never to the package that declares the type. A conformance of a type to an interface is declared in the type's package or in the interface's package and nowhere else; the error names both places. An extension never replaces a member its type already has. A member the compiler supplies to a type is a member the type already has. The roster isequals,compareandhashwherever the type's verdict supplies them, plusclone. Only the type's own package may declare one in its place; an extension in any other package that declares it is refused (E3006). An interface extension's member is a default: it is not published onto a conformer that declares the member or to which the compiler supplies it, in any package, and that is not an error. An interface extension's default namedequals,compare,hashorcloneis never a type's member. -
The link selects and places; it changes no package's code. One serial step joins the packages' images: symbols across packages, instance deduplication, dead-function elimination, data layout, debug information, the live
defaultset, and the audits that need the whole program. -
Order is the package graph. A package is emitted after everything it depends on, ties broken by package name, and its files in source-path order. The image is byte-identical across runs, processor counts and the order sources are read in, and never depends on which package finished first. The library is therefore emitted before a program's own files.
-
Compiled once. What a package publishes is cached, keyed by its source, what its dependencies publish, the target and the defines. Cached machine code per package, joined by the link, is the end state; it is the last stage, and no earlier stage may make it impossible.
-
Packages compile side by side. Two packages with no path between them are compiled at the same time, each holding its own state for the whole pipeline. Nothing is cloned out of one module and spliced back per function across a package boundary.
-
What is not in this design. Fetching or versioning packages from outside a program's tree; a per-file import statement; memory owned by a package and dropped whole (a runtime question with its own issue when it is taken up).
- A library's or a scriptlib package's
exportdeclaration that a program uses must becomepublic(ruling 7). - A shadowed library type keeps its name and the program's takes a qualified symbol, where today the library's is renamed. Symbol names, backtraces and debug information change; what a program may write does not. The refusal of a library member spelled like a contested type name goes away.
- Emitted function order changes in every image (ruling 15).
- A conformance declared in a third package is refused (ruling 13).
- An extension in a higher layer that declares a compiler-supplied member of a lower layer's type
(
equals,compareorhashwhere the type's verdict supplies it,cloneon a struct or union) is refused; rename the method or wrap the type (ruling 13, stage 0).
Each lands with its RELEASE_NOTES.md entry when it makes source that compiled stop compiling.
Each stage lands green and is useful alone. Each is planned from a fresh survey when it starts; a question it raises is a question on #36.
| Stage | Change | What it buys |
|---|---|---|
| 0 | Sealing is enforced where layers exist today. A library file never sees a declaration from a layer above it (#28), and a layer above a type's own may not declare a member the compiler supplies to it (#28); a name the program and the library both declare does not decline the library baseline (#37). | Two silent wrong answers closed; the cold path for overlapping programs gone. |
| 1 | The library never renames. Package-qualified symbols; a program's shadowing declaration takes its own identity. | The library's parse stops depending on which names a program redeclares. |
| 2 |
The language. The marker, the dependency graph and its three errors, public across the boundary, bare and qualified names across packages, the conformance rule. A report of the package graph of a tree is its instrument. Packages are still compiled together. |
The boundary exists and is checked; the compiler's own source can start to be cut. |
| 3 | A fixed id space per package, and whole-package bodies. A package's ids are numbered before any dependent's; every body is built. | Library parses need no rebase, and their cache key loses the program's reach. |
| 4 | What a package publishes is settled once and frozen. A dependent reads it through a chained lookup; the library is emitted first. | The per-compile library work: up to ~330 ms of a ~950 ms small compile. |
| 5 | Per-package semantic passes and the link. Summaries flow along the graph; unrelated packages compile at the same time. | The serial thread of a large build is divided by the package graph. |
| 6 | The remaining whole-program forms become package-exact (ruling 9, "Form"). | What a package publishes is a function of the package alone. |
| 7 | Cached code per package. | The backend's share for unchanged packages. |
The compiler's own source is cut into packages once stage 2 exists, starting with what the rest reaches through a few names (the per-target backends, the language server, the MCP server, the debugger, the test runners) and tightening afterwards. Its 28 directories are one cycle today, which a marked subtree allows to remain one package while the cut proceeds.
- The marker's file name and spelling (stage 2).
- Generic code across a boundary (stage 6): the dependency's generic methods always take the general convention, or the specialised form is made per instance in the requesting package. Measure run time and code size of each on the benchmark examples first.
- The by-reference decision (stage 6): a local handed to a call the package cannot resolve is always by reference, or the decision is made after typing.
-
The cost of a whole-library compile (before stage 3): its cold time and resident size, from
check-stdliband a heap census. A staged library tier and a project rooted insidestdlib/are each their own library package, built once and used once. -
Auditing
public(stage 5): whether apublicdeclaration no package of the same tree uses is reported at link. -
Two dependencies that each add a
publicextension method of one name to one type (stage 2): an ambiguity at the use, or refused where the second dependency is listed. - A define that names a library constant (stage 4): part of the library package's key.
- How the compiler's source is cut (after stage 2), from the package-graph report.