Skip to main content

Vm

Struct Vm 

Source
pub struct Vm<'p> { /* private fields */ }

Implementations§

Source§

impl<'p> Vm<'p>

Source

pub fn new(program: &'p CompiledProgram) -> Self

Source

pub fn record_field_copy_work(&self) -> (usize, usize)

Actual record-field copy work during this VM instance’s lifetime: (copies, elements copied), saturating at usize::MAX.

Source

pub fn install_warm_bytecode(&mut self, fi: usize, fnbc: &FnBytecode) -> bool

Install a re-optimized body as function fi’s warm tier (HOTSWAP §7 / P11): append it to warm_code after program.code, rebasing its 0-relative jumps into that unified pc space, and point warm_entry[fi] at it. Subsequent calls to fi run this body. The body shares the program’s constant pool (a FnBytecode preserves constant indices), so only jumps are relocated.

Source

pub fn with_native_tier(self, tier: &'p dyn NativeTier) -> Self

Install a native tier: hot functions in the integer subset run as JIT-compiled machine code, guarded per call (non-Int args deopt to the bytecode path).

Source

pub fn install_aot_native(&mut self, fi: usize, nf: Box<dyn NativeFn>)

Pre-install an AOT-native function for fi (HOTSWAP §Axis-3): the VM dispatches to it via the existing NativeSlot::Ready path from the first call (it is not Untried, so it skips the hotness threshold and the forge compile). Requires a native tier to be installed (the dispatch is gated on self.tier); on desktop the forge tier is always present alongside. Absent ⇒ the function stays on VM+JIT — the AOT artifact is strictly optional, no gap at the seam.

Source

pub fn with_bg_native_tier(self, tier: &'static dyn NativeTier) -> Self

Install the process tier AND a background compiler (HOTSWAP §6): hot functions are compiled on a worker thread instead of stalling the interpreter. The tier must be &'static (the process-installed forge backend) so it can cross to the worker — &'static dyn NativeTier is Send because NativeTier: Sync. The interpreter still runs the chains and is the sole FnTable writer; the worker only compiles. Falls back to Vm::with_native_tier (synchronous) for a borrowed &'p tier, which cannot be shared with a thread.

Source

pub fn drain_pending_compiles(&mut self)

Block until every outstanding background compile has come back and been published — the determinism hook the differential tests use so the native tier engages predictably regardless of thread scheduling. No-op without a background compiler.

Source

pub fn with_program_args(self, args: Vec<String>) -> Self

Supply the program arguments read by the args() system native. The vector is the full argv (index 0 is the program name), matching the compiled binary’s env::args().

Source

pub fn reinstantiate(&self) -> Vm<'p>

A new instance of the same program, configured as this one was (native tier, policy context, argument vector), with nothing run and no global set — what a browser has after a page reload re-instantiates the module.

Source

pub fn with_policy_ctx( self, registry: &'p PolicyRegistry, interner: &'p Interner, ) -> Self

Provide the policy registry (and the interner its symbols live in) for Check statements.

Source

pub fn program(&self) -> &'p CompiledProgram

The program this machine runs.

Source

pub fn lines(&self) -> &[String]

The output lines, one per Show.

Source

pub fn output(&self) -> String

The output as one string (one trailing newline per Show).

Source

pub fn into_lines(self) -> Vec<String>

Consume the VM, returning its output lines.

Source

pub fn run(&mut self) -> Result<(), String>

Run the whole program to completion (the non-concurrent entry). A concurrent program never reaches here — it is driven through Vm::run_until_block by the scheduler.

Source

pub fn failing_site(&self) -> Option<u32>

The Stmt::Site id in force at the pc a failed run’s Err propagated from (Wave 3: “runtime failures carry a location”) — None outside any component’s action/handler (## Main/## Test own top-level statements, which have no marker), or when the failing pc lies in a hot-swapped warm body site_at was never built to cover. Reads sched_pc, which run_until_block_impl’s dispatch loop saves before every op — the last write it sees before an Err from that op propagates via ? straight out of the loop, so this is only meaningful to call once the caller already has that Err in hand; a successful run’s sched_pc is simply wherever the loop happened to stop.

Source

pub fn invoke_function( &mut self, fi: u16, args: Vec<RuntimeValue>, ) -> Result<RuntimeValue, String>

Call function fi from the host, after the program has run: what a browser does when it calls one of a module’s exports. The call enters through the same path Op::Call takes (native tier, warm body, baseline) and runs against the globals the program left behind.

An Err is the callee’s failure, and it leaves the machine idle and callable with every global exactly as the failure found it — a wasm trap unwinds to the host the same way.

Source

pub fn call_closure( &mut self, callee: &RuntimeValue, args: Vec<RuntimeValue>, ) -> Result<RuntimeValue, String>

Call a closure value from the host: what a browser does when it fires a handler the module handed it earlier (a fetch completion, a listener, a route handler). Same failure contract as Vm::invoke_function.

Source

pub fn run_recording(&mut self) -> Result<(), String>

Run forward to completion WITH reversibility recording, capturing the history tape (retrieve it with Vm::take_journal, then reconstruct the pre-run state with Vm::run_reverse).

A cold path (verification / adiabatic reverse execution): the production Vm::run monomorph (RECORDING = false) dead-strips every recording block, so the 2.5×-C hot loop is byte-for-byte unchanged — this method merely instantiates a separate RECORDING = true copy of the loop that prod never calls. Declines with a clear error (never a silent mis-reverse) if the program uses an op outside the currently-reversible subset (crate::vm::reverse::is_reversible_supported).

Source

pub fn run_recording_mode(&mut self, mode: ReverseMode) -> Result<(), String>

Like Vm::run_recording but at an explicit ReverseMode — the pebbling fidelity ⇄ space ⇄ time point. FullState journals every destroyed value; Observable/Adiabatic compute a per-pc plan and skip journaling scratch the reverse never reads, shrinking the tape toward the Landauer floor.

Source

pub fn run_recording_budgeted( &mut self, mode: ReverseMode, budget: usize, ) -> Result<(), String>

Like Vm::run_recording_mode but with an explicit pebble CHECKPOINT budget (corner 2): budget recomputable chain intermediates are kept journaled, so a reverse read stops its re-walk at the nearest checkpoint instead of the chain root. budget = 0 is exactly Vm::run_recording_mode (the recompute-everything corner).

Source

pub fn recompute_ops(&self) -> usize

The number of recompute re-executions performed by the last reverse pass (corner 2) — the time-cost instrument for the pebble time/space schedule.

Source

pub fn take_journal(&mut self) -> Option<HistoryTape>

Take the history tape recorded by Vm::run_recording.

Source

pub fn run_recording_driven(&mut self) -> Result<(), String>

Run forward to completion WITH recording, DRIVING the task through its concurrency blocks — the single-task reversible-scheduler path. Accumulates one history tape across every slice; a Sleep (virtual time) resumes with nothing. Multi-task/channel blocks are declined here (the coordinator-driven reversible scheduler over several task VMs is the next layer). Declines a program with any op outside the reversible subset before running.

Source

pub fn run_reverse(&mut self, tape: HistoryTape) -> Result<(), String>

Run BACKWARD: reconstruct the EXACT pre-run state by replaying the executed op path in strict reverse order and applying each op’s inverse. The control-flow trace (steps) gives the exact executed sequence — so branches and loops reverse with no special-casing (a loop is just the trace with repeated pcs). A crate::vm::reverse::RevClass::Bijection op self-inverts algebraically with NO data-tape interaction (the zero-garbage core, even inside a loop); every other op that recorded a delta pops it and restores what it destroyed. The data tape stays aligned because journaled ops are visited in exact reverse push order.

Sound because reversing in exact reverse order leaves the machine in each op’s POST-state when its inverse is applied, so every operand the inverse reads holds its forward value.

Source

pub fn take_unhandled(&mut self) -> Option<(String, Option<u32>)>

The failure a page entry the program took itself contained and no handler absorbed, taken by the host that is carrying the page on — whose own record of the page’s failure it becomes (crate::page_host::LoweredCalls::take_unhandled).

Source

pub fn run_keeping_entries(&mut self) -> Result<(), String>

The main program, run to its end with any contained failure left for the host to take (Vm::take_unhandled) rather than made the run’s own: the start of a page a host keeps driving.

Auto Trait Implementations§

§

impl<'p> Freeze for Vm<'p>

§

impl<'p> !RefUnwindSafe for Vm<'p>

§

impl<'p> !Send for Vm<'p>

§

impl<'p> !Sync for Vm<'p>

§

impl<'p> Unpin for Vm<'p>

§

impl<'p> UnsafeUnpin for Vm<'p>

§

impl<'p> !UnwindSafe for Vm<'p>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,