Runtime values are value closures
A runtime value is a pair ⟨V, ρ⟩ of ir::Val syntax and the environment
closing it, and nothing else. ValClos(Val, Env) is that pair; its root V is
never a variable, and ρ binds every direct name of V: an occurrence outside a
thunk. A computation closure ⟨M, ρ⟩ belongs to the machine, not to the value
grammar. Val has one form per kind of value; the runtime adds none.
Decision
- Constants are syntax. Bytes, builtins and handles are
Valforms the elaborator never writes. Scalars and runtime constants are ⟨V, ∅⟩; a thunk is ⟨thunk M, ρ⟩; a list, record or map literal is ⟨[V…], ρ⟩. Hosts build a builtin value withValClos::builtin. - Restriction happens at formation.
ValClos::closerestricts ρ to the occurrences of V and pulls each missing direct name’s value from Σ into the capture.ValClos::thunkrestricts to the body’s occurrences; names in the body resolve ρ then Σ when it runs (a closure keeps only what it mentions). - A borrowed value is a pair of borrows.
VClosRef(&Val, &Env)has the same invariant.VClosRef::sub(V′, ρ)is the one way to read a component: a variable becomes its binding in one lookup (a bound value’s root is never a variable), anything else is ⟨V′, ρ⟩ sharing ρ. No read restricts or consults Σ. Every observation (view,shape,found,residual, the decoders, equality, order,Display, the first-order walk) is defined once onVClosRef;ValClosforwards.VClosRef::into_ownedkeeps a value past its borrow: ⟨V′, ρ⟩ sharing ρ, except that a V′ naming nothing gets ∅. view()reads the head constructor only.Viewhas one case per head; aVariant’s payload is aVClosRef, a bare tag’s is(), and a list or map is a one-caseListRef/MapRefwhosegetanditerresolve elements throughsub. Nothing below the head is formed or inspected until asked.- A tag spine is read iteratively (
VClosRef::peel_variants). A variant`l vshares v’s ρ; a builtin, handle or η-residual payload is bound to a fresh name, so those occur only at a closure’s root, never beneath a tag. - Builtins force to η-expansions. An arity-n entry forces to ⟨λa₀…λaₙ₋₁. δ(b; a⃗), {b ↦ c}⟩. β binds each argument; δ reads the entry and arguments from ρ. Partial application is an ordinary residual λ, boxed by a value-receiving frame. A call with exactly the entry’s arity runs it directly.
- Returns are fused. The machine state is a
CompClosure: ⟨M, ρ⟩ orErr(e).Stack::settlehands a produced value down the continuation at once, so there is no value register and noreturnnode at runtime.
Built data is ordinary syntax
A list or map built at run time is a value like any other: syntax over variables bound in ρ. A list is ⟨[x₀…xₙ], {xᵢ ↦ vᵢ}⟩, a map ⟨[:, k: xₖ…], {xₖ ↦ vₖ}⟩. There is no separate built representation.
- Placement. Putting v = ⟨W, σ⟩ into a node whose environment is ρ
(
Env::place): if W is an atom (unit, bool, int, float, string, bytes) it is inlined; anything else is bound in ρ under a fresh%itemKand the element is that variable. Why: syntax that names something never moves under an environment that could capture it, and a builtin, handle or η residual is never inline below a root. Inlining every name-free value would letacc = [$acc]in a loop build one deeply nestedVal; with atoms only, runtime nesting always goes through ρ, so marshalling (an explicit-stack walk over environments) and drop stay iterative. - Fresh names are local. A node built from scratch binds
%item0…%itemN; adding to an existing ρ binds the first%itemK, K ≥ |ρ|, that ρ does not bind. There is no global counter, and the elaborator never writes the tag. - Operations (
ListRef, called by the evaluator and builtins; none reimplements them):- cons, snoc place one element in the list’s own ρ: a persistent push and
at most one persistent
Envinsert, O(log n). - concat appends the nodes when both sides share ρ (pointer-equal); otherwise the larger side keeps its ρ and each element of the smaller is placed in it, O(smaller side). Syntax is never renamed.
- tail (
suffix, the[x, ...rest]pattern) splits the node and keeps ρ, O(log n).restkeeps the bindings of the elements it dropped until it dies. This is the one accepted exception to a closure keeps only what it mentions: restricting at every step would make a loop over a list O(n²). - maps are built fresh (
ValClos::map); the last pair wins.
- cons, snoc place one element in the list’s own ρ: a persistent push and
at most one persistent
- Nodes are persistent, occurrences lazy. A list node holds
imbl::Vector<Spanned<Val>>; a record or map node holdsimbl::OrdMap<Name, Spanned<Val>>, sorted and distinct by construction. ANode’s occurrence set is computed on first use (OnceLock): only source literals are restricted at formation, so a built node never pays for one. - Fields are an
IrDataassociated type, likeBytesandScheme: the persistent map at run time, a pair sequence on the wire. The structural decoder stays free of semantic checks;marshal/read/ir.rs(admit_sorted_fields) refuses a repeated or unordered key with a typedDuplicateField/UnorderedFieldat its path, for records, maps,withinandgrantalike. The elaborator refuses a key written twice in a literal (T0022), since a node holds one value per key.
Errors are not values
An error is the 0-ary operation error_r(); it is never held. In the
machine it is Err(e). Its handler (try, poll, audit, a guard release)
turns it into the record {frame, message, status, site} (ErrorFact::record)
and the error no longer exists. A caught failure is that record as plain data:
ValClos::from_datum, closed syntax with ρ = ∅. No value form carries an
ErrorFact.
raise r therefore always decodes the record and raises it as the program’s
own claim (ErrorRecord::claim): frame, message, status and site are kept; the
failure’s internal typed reason is not. The record programs see is unchanged.
A worker’s failure crosses as an ErrorFact, which await re-raises live; it
is never routed through a record value.
Why η, not argument counting
A residual function must cross a provenance frame as a λ. In
let m = { |f| map $f }; m g $xs, β binds f, then the body’s spanned
application puts CallSite above Arg xs. Counting adjacent Arg frames
lets force map see one argument; returning a thunk there makes it meet
Arg xs as a value: “not a function”. η leaves a λ, which crosses CallSite
like every λ.
δ’s entry comes from ρ, not Σ, so a host hook or override keeps its own
builtin identity. VClosRef::block hands the checker only a non-residual
thunk, which keeps δ out of inference. A residual has type name Lambda,
displays its builtin and supplied-argument count, and crosses as builtin
name, environment row and count; the receiver rebuilds its own η suffix.
Why withheld, not omitted
Omitting a handle binding is not unbinding it. Lookup falls through to Σ:
dropping lines ↦ h exposes Σ’s lines. Removing a list element renumbers
positions; removing a record field changes the shape. Handle::Withheld
keeps the binding, position, title and type Handle; observing it fails
withheld-handle, directing the caller to await the worker in its spawning
shell and pass the result.
Every child reads Marshalled bytes, which write each handle as its title
and read it back withheld, so no live handle is reachable in a child’s
inherited image (transport,
the engine protocol).
Representation boundaries
- ∅ is refcount-free.
Env::EMPTYallocates nothing; small environments areThinArc, large ones animblmap, so an insert is O(log n) at any size. Compiled bounds:Env ≤ 16,ValClos ≤ 48,Frame ≤ 128bytes. Fused return avoids a per-result syntax allocation; larger values and η’s binds remain real costs. - Dropping is trampolined. A dying value queues each environment and each uniquely owned list, record or map node it alone owns, and a tag spine is walked in a loop, so a value of any nesting drops in constant stack. Raw IR owners claim no such safety.
- The wire carries values as held. One row kind remains,
Row::Env. A value isValue::Closure { tags, val, env },Builtinby name,Residualby name, row and count, orHandleby title; a built list or map is a closure like any other.Val::Builtin,Val::HandleandCompKind::Builtinskip serde; the reader rebuilds residuals withBuiltinEntry::residual, never decoded δ syntax.
This decision fixes the value representation the evaluator steps over and that the checked IR is the calculus partitions.
Where
core/src/ir.rs:Val,Node,IrDataand itsFields,CompKind::Builtin, theExplicitphase; it namescrate::builtinandcrate::handle, nothing incrate::shell.core/src/ir/value.rs:ValClos,VClosRef,View, the drop trampoline;ir/value/list.rs:ListRefand the list operations;ir/value/map.rs:MapRef,ValClos::map;ir/value/first_order.rs:FOValueconversions;ir/env.rs:Env,Binding,Env::place.core/src/shell/runtime/close.rs:ValClos::close;shell/runtime/{compare,coerce}.rs: equality, order and decoders onVClosRef;core/src/builtin.rs:BuiltinEntry::eta,BuiltinEntry::residual.core/src/shell/evaluator/machine.rs:CompClosure,Next,Stack::settle,Stack::resume,Stack::unwind;shell/evaluator/assemble.rs: cons, snoc and concat for literals and argv;shell/runtime/error/record.rs:outcome_value;shell/builtins/misc.rs:raise.core/src/handle.rs:Handle::Withheld;core/src/marshal.rs,marshal/{wire,write,read}.rs,marshal/read/ir.rs:Marshalled;core/src/shell/runtime/state/construct.rs:Shell::marshal,Shell::child_of;exarch/src/shell_eval/builtins/harness.rs:`startmarshals the parent before enquiring.