Lowerers translate validated HIR into target code without reopening source or rewriting language meaning.
One HIR operation may become a JavaScript expression in one partition and a Wasm instruction sequence in another. The meaning stays Moth. The spelling becomes target-native. Same source meaning, different host climates.
Lowerers translate validated inputs. They are not second language frontends.
A lowerer receives explicit records:
ValidatedMemoryPlan for this target/profile physical variant, including its already-settled planned affine-responsibility transitions, retained-edge obligation transitions and discharge operationsA lowerer does not:
If a lowerer needs a fact, an earlier owner should have recorded it.
The ValidatedMemoryPlan is the memory half of that rule. It arrives with every physical decision already settled:
The lowerer encodes those decisions and nothing more. It doesn't infer them from borrow facts, recompute a count delta or pick a cleanup site of its own. Borrow facts and validated lifetime topology stay in the room purely as validation context and assertion material.
Because the plan is built after target partition and target validation, it is scoped to one physical variant. The same source function can lower GC-native in a variant targeting a host collector, and collector-free with REC-capable handles in a variant targeting full memory control.
Those two variants share validated topology and source semantics. Their target, build profile, ABI identity, layout identity and runtime capability requirements can all differ, which is exactly why each one gets its own physical plan.
For the walkthrough, target-labelled entry, greet and template work arrive ready. The JavaScript path might own page orchestration. Neutral string work may sit in either partition depending on assignment.
The JS backend speaks host values and functions. It leans on the host GC for reachability. Runtime helpers implement language operations the surface syntax made look primitive: checked numerics, certain casts, template runtime pieces, error plumbing.
greet in JavaScript form preserves Moth contracts. A more permissive JS primitive cannot weaken checked arithmetic, finite F16/F32/F64 values or error propagation. Each float operation rounds and checks finiteness at its selected precision before a later operation consumes it.
NumericProofs lets JS replace a proven-safe checked integer operation with native carrier arithmetic and omit only impossible checks. For a proven narrowing it omits only the range predicate. Operands still lower once, in source order. Check elision stays independent of failure delivery. Recoverable operations retain their success branch and {tag, value} carrier. Narrowings retain their Number/BigInt conversion and success carrier. JavaScript's exact-integer Number carrier canonicalises zero to +0, while BigInt operations remain exact. Dec, binary floats, Byte and Power receive no integer-proof elision.
Emitted F16 values call native Math.f16round, so JavaScript hosts executing F16 code provide it built in. The Node integration harness requires Node 24 or newer and reports a missing prerequisite as an infrastructure failure that names the selected executable and its version.
The accepted final Wasm design uses a structured path:
Ownership-aware Wasm operations encode the plan's settled transitions at their planned semantic commit points. The lowerer emits planned discharge operations and retained-edge obligation transitions as provided. It does not derive ownership or obligation changes, recompute count deltas or choose cleanup sites.
In plain terms:
The structured path excludes dispatcher-loop LIR and the moth_start bootstrap. Moth-linked variants import page-local memory. Exact I64/U64 values use ordinary i64 carriers where appropriate, not a convenience-integer bridge that changes semantic type identity.
Lowerers distinguish canonical semantic type, scalar storage and computation carrier. Ordinary Wasm storage uses one byte for I8/U8/Byte, two for I16/U16 and four for I32/U32, all with i32 carriers. I64/U64 use eight bytes and i64 carriers. F16 uses two bytes with an f32 carrier, F32 four bytes with f32 and F64 eight bytes with f64.
Natural alignment and scalar-collection stride follow scalar byte size. Narrow loads preserve signedness and stores preserve the checked selected domain. An i32 carrier does not widen I8 + I8 -> I8. An f32 carrier does not delay F16 rounding or finite checks until storage.
Source-visible counts and positional indices use I32. Physical byte products, offsets, alignment and addresses use checked physical-size representations, not a requirement that every byte size fit I32. Scalar metadata creates no allocation family and moves no aggregate-layout or cleanup authority from ValidatedMemoryPlan. The Runtime and backend memory lowering reference owns the complete scalar storage contract.
Accepted HTML mixed-target design wants page-local shared Wasm runtime and memory rather than a scatter of isolated memories per module as the end state. Page-local shared Wasm runtime/memory applies to Moth-linked variants only. Imported WIT components use component-private memory and value conversion.
JavaScript companion facades and wrappers call Wasm exports through explicit handles and layout rules. The bridge is data, not guesswork.
Binding-backed calls lower through demand-driven glue. The binder's semantic interface already existed upstream. The lowerer maps stable external ids to imports, helpers or native operations.
At a binding-backed boundary, the closed external-boundary classification and the ValidatedMemoryPlan supply the ownership and obligation behaviour for this physical variant. The lowerer encodes that settled result rather than rereading borrow facts to work out whether a call transfers or discharges responsibility.
Borrow facts, last-use facts and validated lifetime topology stay upstream inputs and validation context. They never become a source for new physical decisions here.
What the lowerer emits follows the plan exactly. Where the plan chose a GC-native representation, planned ownership-specific operations may be absent from the target encoding. Where it chose affine, inferred-region, declared-region or REC handling, the lowerer emits what the plan says and nothing more.
Numeric proof elision is independent of failure delivery. Wasm marks a proven statement with explicit ProvenSafe; it does not infer safety from missing scratch. The emitter uses native integer opcodes and omits only the proven-impossible predicates while preserving the operation's required success and failure continuations. Power remains checked. A proven-safe 32-bit multiply needs no widened check-only product scratch, and a destination that aliases an input needs no temporary because the opcode reads its inputs before local.set.
Each target consumes only the proof classes its lowerer supports. Missing proof retains checks, and proof elision never grants a missing cast, decimal or recoverable-failure capability. The Progress matrix records backend coverage and genuine deferred lowering gaps.
Every backend answers to the same validation, and optimisation must preserve observable behaviour and the same accepted program set.
InfrastructureFailure laneTarget validation must diagnose user-facing target failures before lowering starts. Meeting one mid-emission means an earlier owner skipped a check.
Alternative: give each backend a source interpreter or separate frontend.
Choice: one validated semantic HIR plus target-owned lowering.
Benefit: source behaviour remains shared across JavaScript and Wasm.
Cost: each backend needs a faithful ABI and runtime implementation.
You leave with JavaScript, Wasm, wrappers, runtime modules and asset records as data. Next: how the HTML builder assembles and owns those outputs on disk, ending at <p>Hello, Priya!</p>.