The checked IR is the calculus
The checked Rust IR has the CBPV partition: control is syntax, operations on values are primitives, and shell interpretation is a separate layer. Every new IR form is classified into one of the three.
Decision
- Control:
Return,Force,Lam,App,Bind,Seq,Rec,If,Case,Try,Guard,Capture. Failure is the machine’sErr(Break)state, not a computation.Apppushes one argument frame per argument and forces; a λ consumes arguments, and a residual function is boxed when none remain. Everyletruns its RHS. - Primitives:
Binary,Negate,Not,Render,Concat,Decode,Index,Update,List,Map. Operands are values; no primitive runs a computation, resolves a name or consults shell state. It may fail. - Shell:
Exec,Pipeline,Redirect,Within,Grant,Spawn,Gather,Audit,Tilde,Use.Use(Arc<Module>)is a checked module linked by elaboration from one written path; the checker instantiates its decided public schemes, the evaluator runs it under Σ alone and returns its public bindings as a record. Source reads, cycle and depth checks belong to linking. - Runtime-only δ:
CompKind::Builtinis a host-operation form, distinct from the value-onlyPrim. The elaborator writes none; a builtin forces to a λ-chain ending in δ, which reads its entry and arguments from ρ, andValClos::blockkeeps residuals out of rechecking (runtime values are value closures). Boundary builtins stay inference-expanded overExec, keeping their per-use checked site.
The machine state is ⟨M, ρ⟩ or Err(e); Stack::settle passes values down
without a register (evaluator,
the machine narrative).
Consequences
Elaboration and the checker write what would otherwise be evaluator
mechanism: the IR invariant states the resulting
rules. Hoisting makes collection assembly pure: a repeated computed map key
fails only after all operands have run. Interpolation is render binds then one
concatenation. The checker writes returned-thunk forces and binding captures
(Capture(M) to d. Prim::Decode(d)) explicitly
(a coercion is syntax).
- A bare tag carries
():`tand`t ()are one value, in grant decoding too. - Only a written sequence or
letadds the abandoned-steps hint; synthetic binds add none. - Destructuring parameters bind after the whole lambda chain; a later plain name also gets a body bind when an earlier destructuring parameter binds it.
- A spread into a written value head or a lexically bound head is an elaboration refusal; builtin and session-binding heads refuse in the checker (T0056).
- A runtime destructuring-parameter mismatch points at the parameter, not the call site.
- Host-file and nested-table options are checked key by written key during
generation (SPEC §15.3). Readback freezes sites and settles schemes after
Solver::closesucceeds (SPEC §17.5).
Runtime boundaries
- Higher-order builtins (
map,each, …) run their function arguments in a nested machine throughmachine::apply, a host function, not a machine rule. - Execution outside the machine:
Pipelinestages use nestedevaluate,Spawnbodies usemachine::applyon a worker, session hooks useevaluator::apply, andGatherjoins its children. - Errors and numbers: errors are data records; numbers are checked
i64and finitef64. guardacquires a resource and passes it to the body and the release; the release also observes the body’s ending (a guard acquires).
Where
core/src/ir.rs:CompKind,CompKind::Builtin,CompKind::Use,Prim,Val;core/src/typecheck/env.rs:Inferringexcludes δ.core/src/typecheck/solve.rs:Solver::bindingandSolver::argumentsuspend the matches that decide binding modes and returned-thunk splits.core/src/typecheck/readback.rs:Readback::toplevelapplies those decisions and settles schemes after successful unit closure;captured_stringbuilds capture/decode (type inference).core/src/shell/evaluator/machine.rs:Stack::settle,Frame,CompClosure,Next;core/src/ir/value.rs:ValClos;core/src/builtin.rs:BuiltinEntry::eta.