Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime { /* private fields */ }
Expand description

Bound runtime: dense buffers, topo order, intern tables, stateful rune storage.

Sole executable artifact after bind. Sample senses through PortWriter, settle with Self::loom, then read Self::outbox.

Implementations§

Source§

impl Runtime

Source

pub fn bind(weave: Weave, opts: BindOpts) -> Result<Self, BindError>

Validate and consume a weave into dense executable state.

§Errors

Returns BindError when budget validation fails, dense capacity is exceeded, a port cannot be resolved, or topo order cannot be built.

Source

pub fn reseed(&mut self, seed: Seed)

Restore PRNG stream (room retry). Same mix as bind: seed ^ fnv(weave.id) | 1.

Source

pub fn sense_id(&self, name: &str) -> Option<SenseId>

Resolve a SignalIn author name to a dense sense id (setup only).

Source

pub fn required_sense(&self, name: &str) -> Result<SenseId, RecipeResolveError>

Resolve a required SignalIn knot for a typed recipe port.

Source

pub fn knot_id(&self, name: &str) -> Option<KnotHandle>

Resolve an author knot name for checked tooling access.

Source

pub fn required_knot( &self, name: &str, ) -> Result<KnotHandle, RecipeResolveError>

Resolve a required author knot for a typed recipe port.

Source

pub fn path_id(&self, path: &str) -> Option<HostPathId>

Resolve a SignalOut path string interned at bind.

Source

pub fn required_path( &self, path: &str, ) -> Result<HostPathId, RecipeResolveError>

Resolve a required SignalOut path for a typed recipe port.

Source

pub fn cmd_id(&self, name: &str) -> Option<CmdId>

Resolve an EmitCommand name interned at bind.

Source

pub fn required_command(&self, name: &str) -> Result<CmdId, RecipeResolveError>

Resolve a required EmitCommand name for a typed recipe port.

Source

pub fn path_name(&self, id: HostPathId) -> Result<&str, HandleError>

Interned path string for a dense host path id.

Source

pub fn cmd_name(&self, id: CmdId) -> Result<&str, HandleError>

Interned emit command name for a dense command id.

Source

pub fn begin_frame(&mut self, time: HostTime)

Start a frame: set tick and clear acts and dropped-emit telemetry.

Source

pub fn port_writer(&mut self) -> PortWriter<'_>

Borrow for host sense writes (set_sense with dense ids only).

Source

pub fn outbox(&self) -> Outbox<'_>

Read-only view of acts and dropped-emit telemetry for this frame.

Source

pub fn outbox_signals_capacity(&self) -> usize

Capacity of the SignalOut outbox buffer (reserved at bind).

Source

pub fn delay_buf_len(&self) -> usize

Length of the flat delay ring (sized at bind).

Source

pub fn get_port_checked( &self, knot: KnotHandle, slot: PortSlot, ) -> Result<Signal, HandleError>

Safe OOB-tolerant read (returns ZERO past end). Used by tests and host tooling.

Source

pub fn set_port_checked( &mut self, knot: KnotHandle, slot: PortSlot, v: Signal, ) -> Result<(), HandleError>

Safe OOB-tolerant write (no-op past end). Used by tests and host tooling.

Source

pub fn kind_tag_count(&self) -> usize

Number of bind-time kind tags (equals knot count after successful bind).

Bind-shape introspection for tests and tooling — not used on the settle hot path.

Source

pub fn clear_port_index_count(&self) -> usize

Flat clear-index count (all In ports across the weave).

Bind-shape introspection for tests and tooling — not used on the settle hot path.

Source

pub fn inbound_edge_count(&self) -> usize

CSR inbound edge count.

Bind-shape introspection for tests and tooling — not used on the settle hot path.

Source§

impl Runtime

Source

pub fn loom(&mut self)

One settle pass. Never panics. No topology alloc after bind.

Order: zero unwired inputs → seed Constant / SignalIn / OnStart → topological eval of non-sense knots → acts append to the outbox.

Source§

impl Runtime

Source

pub fn bind_with_preset( weave: Weave, opts: BindOpts, preset: &RuntimePreset, ) -> Result<Self, PresetError>

Bind a runtime then apply every named preset entry atomically.

Source

pub fn inspect_state(&self) -> RuntimeStateReport

Inspect the current runtime through stable authored names.

Source

pub fn inspect_checkpoint( &self, state: &RuntimeState, ) -> Result<RuntimeStateReport, RestoreError>

Validate and inspect a checkpoint without mutating this runtime.

Source

pub fn bind_restored( weave: Weave, opts: BindOpts, state: &RuntimeState, ) -> Result<Self, BindRestoreError>

Bind a completely fresh runtime and atomically restore a checkpoint.

This is the recommended disk-load path. The returned runtime has an empty outbox: effects from the checkpoint frame were already applied by the host before it was saved.

Source

pub fn snapshot(&self) -> RuntimeState

Snapshot every mutable value needed for deterministic continuation.

Capture only after loom and host apply, before the next Runtime::begin_frame. Outbox effects are deliberately excluded; restore resumes stateful memory with an empty outbox.

§Examples
use wyrd::{weave, BindOpts, HostTime, KnotKind, Runtime, SignalDomain, ONE, ZERO};

let weave = weave! {
    id: "snapshot.docs";
    knots {
        input = KnotKind::signal_in(SignalDomain::Bool);
        output = KnotKind::signal_out("snapshot.output", SignalDomain::Bool);
    }
    threads { input.out -> output.in; }
}?;
let mut runtime = Runtime::bind(weave.clone(), BindOpts::default())?;
let input = runtime.required_sense("input")?;

runtime.begin_frame(HostTime { tick: 1 });
runtime.port_writer().set_sense(input, ONE)?;
runtime.loom();
let state = runtime.snapshot();

runtime.begin_frame(HostTime { tick: 2 });
runtime.port_writer().set_sense(input, ZERO)?;
runtime.loom();
assert_eq!(runtime.outbox().signals()[0].value, ZERO);

let restored = Runtime::bind_restored(weave, BindOpts::default(), &state)?;
assert!(restored.outbox().signals().is_empty());
Source

pub fn snapshot_into(&self, state: &mut RuntimeState)

Refresh an existing snapshot while reusing its owned buffer capacity.

Every field is overwritten, so state may come from an incompatible runtime. Reuse is best-effort: buffers allocate when their retained capacity is too small and may retain a previous high-water capacity.

Source

pub fn restore(&mut self, state: &RuntimeState) -> Result<(), RestoreError>

Restore a compatible snapshot without changing runtime-local handles.

Every compatibility and shape check runs before any mutable runtime field is assigned, so a rejected restore leaves the runtime unchanged.

§Errors

Returns RestoreError when the format version, executable fingerprint, buffer shape, or saved outbox handles are incompatible.

Source

pub const fn state_format_version() -> u32

Format version emitted by Self::snapshot.

Source

pub const fn runtime_fingerprint(&self) -> u64

Deterministic immutable compatibility fingerprint for this runtime.

Auto Trait Implementations§

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
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, 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.