pub fn verify(chunk: &Chunk) -> Result<(), VerifyError>Expand description
Verify structural invariants of chunk. See VerifyError for what is
checked. This does not perform full dataflow/register-liveness
verification (unlike, say, the JVM verifier) — v0 trades that off
against implementation complexity.
Register facts that are settled statically:
VerifyError::ArityExceedsRegisters— a table property: such a function cannot be entered at all.- The destination / gather windows of
Call,Spawn,CallNative,CallNativeFrom, andStartChild— checked against the enclosing function’snum_registers. These are the multi-register gathers the hot loop (and the return path) address as a span; a single out-of-range register is still cheap to trap at runtime, but a window that reaches past the frame is the same class of fact as the pack windows below, so it settles here too.
Single-register operands stay per-step checks in the VM (cheap: an array
index against a fixed small register file, not worth statically proving
away in full). Sorting is not needed for validity: skipping verify on
compiler-generated bytecode is fine, but it is mandatory before loading
anything that crossed a trust boundary (a plugin, a network-fetched
module, see design notes §24 capability/sandboxing).
Opcode::CallNative targets are deliberately not range-checked
here: native functions live in a byteflow_vm::NativeTable supplied by
the embedder at Vm construction time, entirely outside this crate’s
(and this Chunk’s) knowledge. An out-of-range CallNative is instead
caught at runtime as Fault::BadNative.