A build chooses its command, builder and folded project values before any page source enters the compiler.
moth build does not open @entry.moth first. It asks a blunter question: which command, builder, profile and inputs should interpret this project at all?
Until those answers settle, the compiler has no honest graph to walk. Choose climate and soil first. Then grow the plant.
The Alpha compiler uses grouped project/html records and $config input declarations. HTML document metadata uses direct const root builder slots. Named project and html records are the accepted configuration design and current syntax. Entry eligibility comes from @entry.moth presence, not config or a source directive.
Bootstrap starts with the command, not with @config.moth.
The command selects:
checkThe selected builder exposes a capability surface before config compilation:
Directives are compiler-owned and join no builder surface. Unknown directives error and known-but-unavailable forms receive a deferred-feature diagnostic; there is no inactive-builder ignore policy. Multi-builder projects wait for future structural $feature selection.
The command chooses what kind of project this build is allowed to be. That choice decides which source kinds, packages and targets the project may use.
The three commands also differ in how far they run:
build compiles the entry, package and provider union, then lowers and writes outputs when it succeeds.dev compiles its complete graph on the first build. Rebuilds are currently fresh rather than incremental.check casts the widest net, taking in every discovered module plus check-only orphans and package surfaces. It plans and validates all the way through the ValidatedMemoryPlan, then stops before lowering or writing anything.With a project it can name, the build system finally goes looking for source.
@config.moth is build-system-owned compile-time Moth source. It is not a module. It produces no HIR, no entry, no runtime artefact and no package interface.
The file is a reserved compiler filename, not a fourth module root. It stays optional and build-only at the selected project root. A nested @config.moth is inert, and a case variant such as @Config.moth stays invalid. Unmarked config.moth is an ordinary helper, so an @config dependency resolves it when present and never the build-only file.
Config operates on exactly one authored file identity. It rejects source dependencies before path resolution. It never builds a config package graph.
The ordinary compiler owners still touch that one file:
tokenization
-> declaration-shell preparation with retained directive and input-contract facts
-> interface binding for the single config source
-> local declaration ordering
-> AST semantic checking and folding
-> folded project and builder record settings and bootstrap input resultsThen config stops. No borrow checker. No backend.
The accepted shape contains explicit $config declarations, at most one project record constant and an optional html record for an HTML project. It may also contain private helper constants, scalars and other foldable values allowed by the single-file compile-time surface. An empty or omitted html record supplies its defaults.
Rejected shape includes dependency clauses, runtime declarations, functions, traits, entry fragments, $export and nested config files. Config does not select the builder; the command already did.
The accepted starter shape is:
project #= (
name = "compiler_walkthrough",
)
html #= ()Version is optional, and there is no entry_root; the selected directory is the source root. The generated starter is queued with the implementation plan; moth new does not emit this form yet.
Config runs through one named compiler service, not a build-owned copy of the frontend. The build system hands over the single authored source and receives folded values, authored key locations and diagnostics. Config schema and how folded values apply to the project record stay build-owned. Source-module input defaults remain literal-only and resolve after graph discovery; that later resolution uses the canonical module service, not another evaluator.
@project$config marks exactly one explicitly typed top-level # binding. Its name names the input contract, its type fixes the receiving type and its initialiser supplies the fallback. Selected-source declarations use the same contract where an ordinary compile-time constant is legal.
Only explicit $config declarations create input contracts. Project fields and ordinary helper constants neither supply nor block same-named inputs. @project publishes project metadata, not private helpers or input declarations. A contract named version does not replace the separate project field identity.
Ordinary constants require initialisers. A non-optional $config declaration without an initialiser requires an input. An optional declaration resolves to none when no present fallback or external value exists. Input contracts accept String, Bool, Char, I8, I16, I32, I64, U8, U16, U32, U64, F16, F32, F64 and one optional layer around a supported primitive. They exclude Byte, Dec, aliases, inferred types, collections and records.
Project identity, source discovery and compiler-control fields remain fixed-only. $config dependence is rejected in the project record's name and template_const_loop_iteration_limit, including through helper constants. The project record has strict predefined fields; it does not become an open metadata record.
Bootstrap contracts resolve in this order:
Selected-source contracts resolve in this order:
$config contract, after compatibility validationBuild, check and dev share --input name=value. Classification recognises exact lowercase booleans, whole-number spelling, decimal/exponent spelling, quoted characters and quoted strings in that order. Other text falls back to String. Malformed quoted text produces a command-input diagnostic. Numeric inputs retain their original spelling and category until the exact contract resolves, then moth-lexical materialises them directly at that destination with range and finite checks, without an i32 or f64 intermediary. Whole spelling can initialise an F32 contract, while decimal spelling cannot initialise an integer contract merely because its value is whole.
Programmatic and builder inputs already carry exact primitive types and values. They permit only an exact type match or present wrapping into the matching optional type, not numeric width conversion or String coercion. Completed input values carry their exact canonical type and lossless value. Semantic fingerprints use that type and value, not raw spelling or source location.
The folded project record becomes a specialised immutable ProjectGlobalsInterface under the reserved @project dependency root. It carries stable field identities, folded backend-neutral values, source locations, field-level fingerprints and project-context provenance. It carries no AST, no HIR and no runtime body. @config.moth publishes no namespace of its own, so @project remains the only build-supplied project-global interface, with a fixed name and field contract.
Project modules and project-owned support packages may bind @project explicitly. The external project package surface cannot. Nothing injects it silently. Child modules, dependency aliases and packages cannot steal the @project root. Direct re-export of @project is forbidden.
For the greeting walkthrough, the bootstrap facts needed for Stage 0 are the project name, the selected directory root and builder settings. The separate input-contract results travel alongside them; neither set is reconstructed by scanning @project.
Resolved source $config values become ordinary folded constants. They can feed ordinary if for static Bool specialisation after source discovery. Both branches remain frontend-valid, and ordinary static if cannot remove declarations or dependencies. Future compiler-owned $feature is a separate deferred structural-selection mechanism before graph and declaration publication, not another evaluator.
Draw the line early and keep it sharp.
Owner | Responsibility |
|---|---|
Build system | discovers source, builds graphs, schedules modules, plans entries, writes outputs |
Compiler | prepares syntax, binds interfaces, checks semantics, lowers HIR, validates access and target contracts over explicit inputs |
Builder | assembles successful artefacts into project-shaped outputs after compilation succeeds and maps stable source semantics to platform-specific artefacts |
The compiler does not wander the filesystem inventing a project. The builder does not re-parse @entry.moth to rediscover greet. Each stage trusts the previous owner's facts.
The command and build system own target intent, target partition and physical-variant orchestration. Compiler-owned validation checks the assignment it is handed rather than choosing it. Builders expose stable capabilities and map them to target artefact forms. Source never observes physical target identity at all.
The compiler owns general directive syntax, $config contracts and project record validation. The build system applies folded project settings and runs bootstrap and graph orchestration; the HTML builder owns html record settings and its registered root slot destinations.
project field, invalid optional version or configuration-dependence violationThe command and config service report these as structured diagnostics. Entry eligibility is a later build-system fact validated from @entry.moth presence. It is not recovered by reopening @config.moth.
Alternative: an unrestricted host-language build script that can do anything the host process can do.
Choice: command-selected capabilities and typed compile-time config.
Benefit: the project contract stays visible and bounded before discovery. Tools can validate schema without executing arbitrary host code.
Cost: users lose general host-code build hooks and must fit builder schemas.
@config.moth service with explicit $config contracts, strict project and active-builder records, separate bootstrap input results and a specialised ProjectGlobalsInterface.@config.moth, $config input declarations, typed --input for build, check and dev, ordinary static-if integration and immutable explicit @project.@entry.moth presence.$feature selection, config dependencies and a general Moth build-script system.You leave with a validated command, a capability surface, folded project values and @project. Next: which files become semantic modules, and how a folder becomes a graph.