Folded constants, concrete generic requests, static trait evidence and explicit casts finish before HIR begins.
HIR and backends should not re-solve the same compile-time questions on every function body. Work that can finish early should finish early.
If a declaration is marked compile-time and its value fully folds, fold it. If a generic call needs a concrete function, request one. If a trait bound needs evidence, resolve it. If a conversion needs a cast, emit an explicit operation.
The marker does the deciding, not the value. # is what makes a declaration compile-time. A top-level runtime binding stays runtime even when its value never actually changes.
AST owns that static work.
greeting_prefix begins as source:
greeting_prefix #= "Hello"After checking and folding, it becomes a backend-neutral compile-time value. Exported folded facts copy into the immutable module interface. Consumers never re-parse or re-fold the provider's template or literal.
Constants are compile-time declarations and metadata, not runtime top-level statements. Const records may group fully folded struct or anonymous-record constants as field-access-only compile-time data. They are not runtime values to pass around.
$config build-input declarations enter as ordinary folded constants. They resolve into the backend-neutral constant lane; they create no runtime wrapper type and no special HIR node category.
Stage 4 owns the boundary:
fully checked authored AST
-> constant evaluation
-> known Bool branch selection
-> commit active generated requests and summaries
-> terminality validation over the active control flow
-> active executable AST
-> HIRStage 4 specialises ordinary executable work from resolved configuration values:
if remain frontend-validBool selects the active executable branch after source discoveryStage 4 adds no config-value branch node. HIR never redoes the decision, and Moth source has no platform-conditional source mechanism. Future compiler-owned $feature is a separate deferred structural-selection mechanism: it may select source structure before graph and declaration publication, but it is not another evaluator.
A generic template lives in the declaring module as an immutable validated template. At a call site, AST:
The build system aggregates requests across a compilation boundary and lends the published set as an immutable view. The compiler deduplicates each request against that set, then materialises each accepted request as a generated sidecar beside the base module.
Base artefacts stay immutable. Generated functions carry their own HIR, borrow facts and link facts. New concrete code grows beside the original template. The template itself does not mutate.
HIR and backends never infer generic arguments or consume unresolved template state. Concrete code appears before they look.
A generic signature can also connect an existing numeric origin through a declared parameter/result equality. Eligible exact uses in the same caller body resolve that origin before defaults. This bounded numeric rule adds neither callee-body inspection nor inference for a generic parameter without a numeric origin. Each concrete instance resolves its own body-local numeric state before HIR.
Traits and conformances are compile-time frontend metadata. AST validates requirements, explicit conformances, evidence lookup by concrete type and bound-provided receiver calls.
Static bound calls resolve to concrete executable targets before HIR. HIR carries no trait objects, erased dispatch or runtime trait evidence.
That choice rejects a familiar dynamic path. You cannot box "any Show" and discover methods later. You can write choices for closed heterogeneity and generics with evidence for static reuse.
Contextual coercion and explicit cast remain different paths.
Coercion happens when a receiving boundary accepts a value under documented rules. The boundary owner applies it.
Plain cast supplies the only conversion spelling. Its immediate concrete typed receiver supplies the target, not a constraint on the operand. AST resolves the source from independent eligible uses or the language default before classifying the complete source-target pair.
AST owns conversion policy and evidence. Foldable casts fold. Builtin runtime casts become explicit HIR operations and source-authored evidence becomes an ordinary direct function call before or during HIR lowering. Evidence metadata does not enter HIR. Char -> I32 produces the Unicode scalar code point, while I32 -> Char checks for a valid Unicode scalar.
Invalid conversions diagnose at the cast site. Runtime conversion failure follows ordinary implicit failure delivery through a compatible catch, builtin Error! slot or private same-module lane, not a separate cast channel.
Numbers look simple until every layer invents its own rules.
Accepted ownership splits cleanly:
moth-lexical owns shared spelling grammar and category, direct destination materialisation, exact fixed scalar identities and precision-aware formatting for the compiler and MON. It owns neither compiler type lookup nor a numeric runtime.An unconstrained whole-number origin defaults to I32 and a decimal/exponent origin defaults to F64. Exact receivers select a destination before direct materialisation, without an i32 or f64 intermediary. Constants finish that resolution at their declaration boundary, so later runtime uses cannot retype them. Completed AST and HIR retain no numeric unknowns or inference recipes.
Equal fixed types preserve their eligible arithmetic domain. I8 + I8 checks an I8 result, while F16 + F16 rounds and checks finiteness at F16 before another operation consumes the result. A wider scratch carrier cannot defer those boundaries. Dec applies its exact scale and rounding rule at each operation result.
The canonical numeric and cast references own language semantics. Target validation checks reachable operations against backend capabilities, including genuinely unsupported decimal, conversion or recovery paths. The Progress matrix owns implementation and backend coverage rather than this ownership contract.
A required const declaration (name #|args| -> Return:) prepares one bounded typed-AST executable for its body. Every call executes that prepared body with constant arguments; no runtime body is emitted. Preparation validates the signature, compiles the statement body, classifies every reachable expression and prepares catch handlers once. A refused declaration reports a source diagnostic instead of leaving a runtime path.
Release builds reuse the same executor for ordinary functions. Finalisation selects a conservative candidate graph: immutable shared parameters and one infallible result restricted to fixed scalars, Bool or Char; const-safe operations; body-local writes only; and a transitive closure with no missing dependency or cycle. Template operations are refused, and the provenance of every body expression must be carried by returned values, so an erased call cannot hide a project/config dependency. Only calls whose arguments fold to constants are rewritten. A refusal, failed proof, numeric failure, unrepresentable result shape or exhausted work/memory budget leaves the runtime call and its rewritten constant children in place. Replacement unites the call site's and evaluated value's synthetic-interface provenance so later link facts retain erased dependencies.
Work and retained-memory allocation use typed ConstExecutionLimits. Project configuration supplies bounded values; the compiler keeps hard safety maxima and an aggregate module allowance. Accounting is deterministic and never depends on elapsed wall-clock time. A budget refusal stays typed through template folding instead of becoming an ordinary diagnostic. Release budget advice is a deduplicated Note at the innermost refused call site and does not alter exit status. Required calls still report an error at the operation that spent the allowance.
Do not re-teach diagnostic transport here. The semantic rejection is the point.
Alternative: dynamic trait objects, broad implicit conversion and runtime generic interpretation.
Choice: static evidence, compiler-owned casts and concrete requests.
Benefit: HIR and backends receive fewer open-ended semantic questions. Parallel targets share one answered story.
Cost: less runtime dynamism and more compile-time rejection when evidence is missing.
$feature selection, trait objects and broad runtime reflection.You leave with folded constants, concrete requests, static evidence and finalised cast operations. Next: why the HTML template needs a temporary structural IR before HIR runtime work.