Name resolution, type identity and receiving-boundary rules turn ordered shells into typed semantic structure.
Parsed text can look right and still mean nothing the machine should trust. greet(visitor) on the page is a shape. Until name resolution and type checking finish, it is not yet a call with a known callee, argument contract and return type.
The AST stage turns ordered shells and bound visibility into a typed semantic structure. That structure owns source meaning for the module.
A syntax tree records how tokens grouped: call expression, argument list, identifier nodes.
A semantic tree (still often stored as AST nodes in Moth) adds resolved facts:
greet namesvisitor namesTypeId valuesName resolution connects spellings to declarations. Type checking checks that operations and values agree under language rules. Semantic identity names the underlying declaration or type in a way that survives aliases and module boundaries.
Before checking, the page call is unresolved shape. After checking, it is a fact later stages may lower without reopening the dependency clauses.
AST consumes bound file visibility. It may validate semantic use of visible symbols. It does not rebuild dependency bindings or rediscover top-level visibility. If a top-level name cannot be found by walking sorted declarations and bound visibility, the missing fact belongs earlier in the pipeline.
Scopes nest inside bodies. The collision policy does not. All user-visible names share one rule: same-file declarations, source dependencies, binding-backed dependencies, aliases, prelude symbols and builtins cannot silently shadow one another.
Local declarations, dependency bindings and reserved interfaces remain distinct origins even when their spellings sit in one lookup table.
Each compiled module owns one local TypeEnvironment. Inside that module, TypeId equality is the only valid comparison for local semantic decisions.
Cross-module interfaces use canonical type identities, not donor-local indexes. A consumer may intern compact local handles for imported types. Equality across modules still compares canonical identity, never rendered names alone.
Why refuse donor-local indexes at the boundary? Because module-local numbering is an implementation accident. Stable meaning must survive recompilation order, re-exports and parallel workers.
Authored type syntax resolves straight to a TypeId. Declarations and signatures keep that syntax only where deferred resolution or an authored-name diagnostic needs it, and diagnostics render types from the TypeId.
Access classification stays separate from type identity. Mutability and exclusive access do not manufacture fake type shapes.
Numeric identities retain exact width, signedness, precision or decimal scale. The fixed types comprise I8, I16, I32, I64, U8, U16, U32, U64, F16, F32 and F64. Byte keeps a separate non-arithmetic octet identity, while Dec and Dec0 share scale zero and Dec1 through Dec256 retain distinct scales. Targets and build profiles never select these identities.
Expression evaluation finds an expression's natural type and stays strict. Contextual coercion applies only at explicit receiving boundaries owned by the frontend:
cast targetsthen arms with an explicit receiverNatural typing asks "what is this?" Contextual coercion asks "may this value enter that slot?" Explicit casts ask "please convert under compiler-owned rules." Those paths stay separate on purpose. Broad implicit conversion would hide bugs. Forbidding every conversion would drown source in noise.
On the page, visitor as a String meets greet's name parameter at a receiving boundary. The constant "Priya" met visitor's declaration boundary earlier.
AST gathers numeric constraints across one runtime body, including nested blocks, branches, loops and handlers. The dormant entry-root body follows the same rule, and each concrete generic instance gets its own state. Copies connect an existing numeric origin and mutable writes constrain one binding type, not a new type per write.
Exact receiving constraints outrank eligible local numeric peers, which outrank the I32 whole-number and F64 decimal/exponent defaults. All eligible uses participate before defaulting, regardless of source order. Conflicting exact receivers diagnose with both constraint locations. Literal size, trait evidence, failure effects and backend capabilities never choose a type.
A receiver reaches unresolved literal arithmetic and raw leaves beside named operands, but never retypes a named operand or completed result. A known generic signature can connect an existing numeric origin through its parameter/result equality. The compiler does not inspect the callee body or add general later-use inference. A plain cast takes its target from an immediate concrete receiver and resolves its source independently.
The compiler selects the destination before moth-lexical materialises retained spelling directly at the exact type, then selects operators and folds values. Equal fixed operand types preserve their eligible arithmetic domain: I8 + I8 -> I8 and F16 + F16 -> F16. Each integer result checks its selected width and each F16 operation rounds and checks finiteness before the next operation, even when a wider scratch carrier computes it.
Numeric unknowns belong only to construction state, never placeholder TypeIds or durable expression recipes. Constants resolve at their declaration boundary. Completed AST, HIR and published interfaces carry concrete canonical types and values, with no pending numeric state. The canonical Numbers references own the complete inference and operator rules.
Functions contain statements and expressions. Some constructs produce values: value-producing if, match and block-form catch act as closed receiving constructs rather than free-floating general expressions.
They are valid only where a receiver is explicit. Every producing path must satisfy the receiving arity. Non-unit success returns must be terminal before HIR lowering: control must not fall off the end without producing the promised values.
AST owns those diagnostics. If HIR later sees a non-unit function that can fall through, AST broke its contract, so HIR reports an internal transformation error instead of blaming the author.
HIR will make runtime control flow explicit. AST still owes a body that already makes sense.
Diagnostic transport and rendering wait for the diagnostics article. The semantic failures belong here.
Alternative: infer meaning from rendered type names, allow broad implicit conversion and permit shadowing as a convenience.
Choice: stable identities, strict names and narrow receiving-boundary rules.
Benefit: later stages consume facts rather than rediscovering source meaning from pretty strings.
Cost: source needs explicit disambiguation and casts in more cases.
You leave with a typed AST, semantic identities and checked executable bodies. Next: which static computations disappear before HIR, and which become explicit data.