Skip to main content

Module vm

Module vm 

Source
Expand description

Register bytecode VM.

A fast, portable interpreter that runs the same RuntimeValue semantics as the tree-walker. It is the browser/WASM execution engine and the substrate the native copy-and-patch JIT tiers up from. Built incrementally, RED-first, differential-tested against the tree-walker.

Re-exports§

pub use compiler::Compiler;
pub use disasm::disassemble;
pub use disasm::format_constant;
pub use disasm::op_io;
pub use disasm::DisasmLine;
pub use disasm::OpIo;
pub use journal::HistoryTape;
pub use journal::JournalEntry;
pub use reverse::reversibility;
pub use reverse::EffectKind;
pub use reverse::InverseSpec;
pub use reverse::JournalKind;
pub use reverse::RevClass;

Modules§

aot_tier
AOT-native tier loader (HOTSWAP §Axis-3 / P15): dlopen a rustc-built cdylib (produced by crate::compile::build_native_cdylib) and wrap an exported logos_native_<fn> symbol as a NativeFn the VM dispatches through the existing NativeSlot::Ready path — no new dispatch, the hot-swap seam already exists.
bg_aot
Background AOT-native compilation (HOTSWAP §Axis-3 / P18).
binisa
The binary Silicon ISA — the register bytecode as a stable, self-contained, chip-decodable byte stream. The text sibling is crate::vm::isa (emit_isa, the human-readable assembly listing); this is the machine form of the SAME opcode set.
compiler
AST → bytecode compiler.
disasm
Bytecode disassembler — readable text for the Studio debug drawer and any future largo --disasm. Pure, headless, no VM state. Bytecode disassembler — renders a CompiledProgram’s Op stream as readable text for the debugger (status line, bytecode tape) and any future largo --disasm. Common ops get a clean infix form (constants resolved, registers as R{n}, jump targets inline); the long tail falls back to the Op Debug form, so a newly added op is never a panic — just a plainer line.
fn_bytecode
A relocatable, self-contained per-function bytecode unit (HOTSWAP §7).
isa
R6 — the Tier-5 Silicon ISA emitter. The register-VM opcode set becomes the native ISA; each stencil family maps to a functional unit. This lowers a CompiledProgram to LOGOS Silicon ISA assembly — the SAME opcodes the interpreter/VM/JIT/AOT run, now as the chip’s instruction set.
journal
The history tape — the Bennett/Landauer “garbage” of reverse execution.
pebble
Pebbling — the reverse-liveness pass that decides which journal entries a recording run actually NEEDS, driving the Bennett history tape toward the Landauer floor.
peephole
★ THE IR PEEPHOLE ★ — a semantics-preserving CompiledProgram → CompiledProgram transform: block-local forward copy-propagation followed by dead-move elimination. It exists for the backends that lower the bytecode straight to a final target with no downstream optimizing assembler — RISC-V asm, WASM, the spatial fabric. gcc already performs exactly this coalescing for the C tier (register-to-register moves fold away, dead copies vanish), so C does not need it; the flat backends ship the VM compiler’s move cascades verbatim without it.
perf_map
LOGOS_PERF_MAP — name the JIT’s machine code for perf.
reach
Which compiled functions — and which ops — can run.
reverse
Reversibility classification of the ISA — the static substrate for running the whole language backward (forward ; reverse ≡ identity), the software prerequisite for the adiabatic / sub-Landauer chip. Locked by tests/reverse_op_lock.rs. Reversibility classification of the bytecode ISA — the static substrate for running the whole language BACKWARD (forward ; reverse ≡ identity).
session
A program the VM has run, held open so a host can call back into it.
tier_cache
Tier cache (HOTSWAP §P12): persist a compiled FnBytecode keyed by (source, optimization-config, tier) so a re-run skips re-optimization.
tier_trace
LOGOS_TIER_TRACE — one line per execution-tier hot-swap (HOTSWAP §P13).
wasm
WebAssembly code generation from VM bytecode — one shared codegen, two consumers.
wasm_jit
Back-compat facade: the WS6 browser WASM-JIT tier moved into the shared wasm codegen submodule — wasm::func for the byte emitter, wasm::region_jit for the tier + host. machine.rs (super::wasm_jit::WasmTier) and the wasm_jit_* differential/browser test suites still reach it here, unchanged.

Structs§

ArrayPin
CalleeSig
A natively-compiled LOOP REGION (OSR-lite): no arguments, no return — every effect flows through the enclosing frame’s registers. What a REGION needs to know about a function it might call: the declared signature (all-scalar = replay-pure = inlinable) and the function index for its table slot.
CompiledFunction
A compiled user function (or closure body). All bodies share the program’s single code vector; entry_pc is where this one begins. A closure body’s frame layout is [params… , capture values… , capture-present flags…].
CompiledProgram
A compiled program: the constant pool, the linear bytecode (Main first, then every function body), the size of Main’s register frame, and the function table (indexed by FuncIdx, with a name → index map for call resolution).
EnumTypeDef
An enum type’s resolved per-variant payload layout, carried in the bytecode so a consumer can type a When V (binds) payload extraction on a value whose construction isn’t visible (an enum PARAMETER) — the sum-type analog of StructTypeDef.
EnumVariantDef
One variant of an enum: its constructor name and the resolved types of its payload fields, in position order (empty for a nullary variant). A BindArm extracts payload position index.
FnTable
The per-program native ENTRY TABLE (EXODIA 4.7’s hot-swap seam): two atomic slots per function — [entry pointer, register count] — written when a function’s chain compiles, read by native call stencils through a patched slot address, and the place Tier-2 swaps optimized code in. The backing Vec never reallocates (fixed at construction), so slot addresses are stable for the program’s lifetime.
HoistGuard
A hoisted region-entry bounds check (V8 loop bound-check elimination): the loop’s covered accesses run unchecked iff, at entry, the pinned array is long enough for the whole loop and the induction floor is in range. The VM declines the region (replays on bytecode) if it fails.
NativeCtx
Per-program cells the native tier shares with every chain it compiles: the deopt status (any side-exit anywhere unwinds the whole native stack), and the LIVE LOGOS DEPTH the call stencils count against MAX_CALL_DEPTH. Clone is an Arc bump on each cell — a background-compile request carries a clone so the worker patches the same per-program table/status/depth the interpreter does.
NativeFrame
One materialized native frame for a PRECISE deopt (outermost first). offset/return_pc/return_reg describe the link from the PREVIOUS frame (they are meaningless for index 0, whose link belongs to the interpreted call site).
ObsSiteDesc
One compiled observation site (indexed by Op::Obs { site }).
RegionReturn
A Return statement INSIDE the region (the siftDown early-exit shape): the value slot, its re-boxing kind, and the flag slot the return path sets — after write-back the VM performs the actual function return.
StructTypeDef
A struct type’s resolved field layout (fields in declaration / slot order), carried in the bytecode so any consumer can address a struct’s fields without re-deriving them from the AST.
Value
A VM value (fat 16-byte representation).
Vm

Enums§

BoundaryType
A parameter’s (or struct field’s) declared type, RESOLVED at compile time into a self-contained form a STATICALLY-typed consumer can use without the AST or the interner. The dynamically-typed tree-walker/VM and the scalar-only native JIT never needed static types, so they were not put in the bytecode before; they are now a first-class part of the compiled program (a struct is referenced by name, its layout living in CompiledProgram::struct_types).
ChanElem
A bytecode instruction. Every field is a small Copy scalar (registers, constant-pool indices, interned symbols), so the dispatch loop reads each op by value instead of clone()-ing through the Clone machinery. The declared element type of a Pipe of T, carried on Op::ChanNew so a consumer that models a channel as a typed FIFO queue (the direct-WASM AOT) can type a Receive/select arm’s bound variable even when the pipe is never sent to (an empty Pipe of Text in a timeout-only select). A Copy tag — the scalar element types cover every pipe the corpus declares; a struct/enum element resolves to ChanElem::Unknown (falls back to the untyped queue, exactly as before).
Constant
A constant-pool entry.
NativeOutcome
What one native function call produced.
NativeRet
How a native function’s return value re-boxes.
NativeWriteback
A final mutable argument: raw scalar bits or a borrowed list handle, or an owned value detached from the native allocation registry before it is drained.
ObsSiteKind
What an Op::Obs emits, resolved at COMPILE time (Wave 13). A Message carries the speech-act category, the that-clause text, and the payload NAMES (values live in the op’s register range); SpanEnter/SpanExit carry the span label. Kept off the hot loop — the machine only reads it.
ObservedKind
What the VM OBSERVED in each register at the hot back-edge that triggered region compilation — the kinds the adapter SPECULATES on (sound because every later entry re-checks them via the guard set).
Op
ParamKind
A DECLARED parameter’s native representation.
PinElem
One pinned array for a region run: the register holding the list, the frame slots that receive its buffer pointer and length at entry, and the element kind the region speculated on. The VM borrows each DISTINCT Rc<RefCell<…>> exactly once for the whole native run (aliased registers resolve to the same buffer, so native writes through one name are visible through every other — and there is zero refcount or borrow traffic inside the loop). Arrays mutate IN PLACE: no write-back, and the deopt replay is sound by prefix-idempotence (the replay recomputes exactly the values the native prefix already wrote). Element kind of a pinned buffer (decides the stencil’s access width: 8-byte for Int/Float bits, 1-byte for Bool).
RegBox
How one raw register slot re-boxes during frame materialization.
RegionOutcome
What one native region run produced.
RegionReturnKind
How a region-return value travels.
SlotKind
The runtime kind a native frame slot carries: entry guards check the VM register’s discriminant against it and copy the raw representation in (f64 travels as bits); write-back re-boxes by it.

Constants§

MAX_EXPR_DEPTH
Maximum expression nesting depth the compiler will descend before erroring (guards the compiler’s own recursion against adversarial inputs). Debug builds allocate every match arm’s locals in compile_expr_into_inner’s frame — measured in the tens of KiB per nesting level as the compiler grows — so 64 keeps the worst case well inside a default 2 MiB test-thread stack while still exceeding any realistic expression depth. (An explicit-work-stack compiler would remove the native-stack coupling entirely; tracked as future work.)
MAX_REGISTERS_PER_FRAME
Hard cap on registers a single frame may claim. Generous for real programs; prevents a pathological frame from claiming the whole register file.
MAX_REGISTER_FILE
Hard cap on the total register file across all live frames. Deep recursion hits this and errors instead of consuming unbounded memory.
NATIVE_TIER_THRESHOLD
Calls before a function is considered hot.
NO_SITE
The site_id a pc range with no active Stmt::Site marker carries — append-only, like every other wire-visible sentinel in this file.
REGION_TIER_THRESHOLD
Back-edge crossings before a Main loop is considered hot.
SOME_BINDING_MARKER
WebAssembly code generation from VM bytecode: the shared byte emitter (wasm::encode + wasm::func, always built) plus the WS6 browser WASM-JIT tier (wasm::region_jit, behind the wasm-jit feature). The direct AOT backend (largo build --emit wasm) consumes the same emitter. The “field name” a Some arm’s binding carries, in place of a real field.

Traits§

NativeFn
A natively-compiled function: integer registers in, integer result out. depth is the LIVE LOGOS frame count at the call (the callee’s own frame included) — native self-calls count against the same MAX_CALL_DEPTH the bytecode enforces.
NativeTier
A backend that can try to compile one VM function to native code.
RegionFn

Functions§

branch_entropy
Shannon entropy of a two-outcome branch profile, in bits (EXODIA 3.3). 0.0 = perfectly predictable (the hardware branch predictor wins; Tier-1 code is fine), 1.0 = a coin flip (Tier-2 should restructure the branch away). Zero samples are zero entropy.
compile_and_run
Compile a statement block to bytecode and run it, returning captured output.
install_native_tier
Install tier as the process-wide native tier. Idempotent: the first install wins and later calls return false.
installed_native_tier
The installed process-wide tier, if any.
run_nanos
RUN-ONLY wall-time — the MIN nanoseconds over iters executions of the CHIP bytecode on the register VM, compiled ONCE (so parse / compile / stdlib-prelude load are excluded). This is the fair host counterpart to the FPGA soft-core’s on-chip cycle counter, which also measures execution only — and it runs the SAME compile_for_chip bytecode the silicon executes, so VM-vs-FPGA is one instruction stream, host CPU vs custom silicon. None if the program does not compile to the chip subset.
run_tiers_strict
Run a ## Test body’s COMPUTATION on the bytecode VM for the --tiers all differential (Wave 13): the test-only statements (Expect/ForAll/…) compile as no-ops, so the VM executes exactly the surrounding computation.
run_to_outcome
Compile and run, preserving partial output alongside any error — the shape the differential harness compares against the tree-walker (which also keeps the lines emitted before a runtime error). types carries the discovery pass’s struct definitions (for default-fill on construction).
run_to_outcome_bg
run_to_outcome_with_args with BACKGROUND native compilation (HOTSWAP §6): hot functions compile on a worker thread while the interpreter keeps running bytecode, then their chains are drained + published. Requires a process-installed tier (the worker needs a &'static backend); with none installed it runs pure bytecode. Drains outstanding compiles before returning so the native tier engages deterministically for the differential gates.
run_to_outcome_located
run_to_outcome, plus the failure-site id in force at the point an Err propagated from (Wave 3: “runtime failures carry a location”) — None on success, or when the failure happened outside any Stmt::Site marker (## Main/## Test’s own top-level statements carry none). compile.rs::locate_runtime_failure is the one place this id becomes a rendered file:line:col.
run_to_outcome_observed
run_to_outcome in the OBSERVED profile (Wave 13): Note/Warn/Record/ During lower to Op::Obs, so the VM emits the SAME observation event stream the tree-walker does (into the observe channel — separate from program output). The dev/test differential entry; the compiled/release tiers keep the elided profile. Program output is byte-identical to run_to_outcome.
run_to_outcome_with_args
run_to_outcome with the program argument vector for the args() system native (full argv; index 0 is the program name) and an optional caller-supplied native tier. A Some(tier) overrides the process-wide installed tier — differential suites use a private tier per program so its compile counters are isolated from every other test in the binary.

Type Aliases§

Reg