pub struct DcWasmSession { /* private fields */ }Expand description
Pure-compute WebAssembly execution state machine (step() -> StatusCode) backed by
either tinywasm (with portable bytecode compute-quota instrumentation) or a
bit-for-bit equivalent Guix-style compiled safe-Rust substitute.
Owns a persistent worker thread whose call stack, locals, linear memory, tables,
and globals survive across step() calls and mid-step compute-quota pauses without
re-executing earlier instructions.
Implementations§
Source§impl DcWasmSession
impl DcWasmSession
Sourcepub fn from_wasm_bytes(
wasm_bytes: &[u8],
initial_input: &DcMstr,
most_recent_node_id: Option<u128>,
) -> Result<Self>
pub fn from_wasm_bytes( wasm_bytes: &[u8], initial_input: &DcMstr, most_recent_node_id: Option<u128>, ) -> Result<Self>
Instantiates a pure-compute DcWasmSession from compiled .wasm module bytes,
loading initial_input and most_recent_node_id (Dc 641) into linear memory
using DcWasmResourceLimits::default().
§Errors
Returns an error if parsing, instrumenting, or instantiating the module fails,
if the module exports neither "step" nor "main", or if writing the initial
input into linear memory fails.
Sourcepub fn from_wasm_bytes_with_limits(
wasm_bytes: &[u8],
initial_input: &DcMstr,
most_recent_node_id: Option<u128>,
resource_limits: DcWasmResourceLimits,
) -> Result<Self>
pub fn from_wasm_bytes_with_limits( wasm_bytes: &[u8], initial_input: &DcMstr, most_recent_node_id: Option<u128>, resource_limits: DcWasmResourceLimits, ) -> Result<Self>
Instantiates a pure-compute DcWasmSession from compiled .wasm module bytes
with explicit DcWasmResourceLimits using DcWasmExecutionBackend::Auto.
§Errors
Returns an error if parsing, instrumenting, or instantiating the module fails,
if initial memory exceeds resource_limits.max_memory_pages, if the module exports
neither "step" nor "main", or if writing the initial input into linear memory fails.
Sourcepub fn from_wasm_bytes_with_limits_and_backend(
wasm_bytes: &[u8],
initial_input: &DcMstr,
most_recent_node_id: Option<u128>,
resource_limits: DcWasmResourceLimits,
backend: DcWasmExecutionBackend,
) -> Result<Self>
pub fn from_wasm_bytes_with_limits_and_backend( wasm_bytes: &[u8], initial_input: &DcMstr, most_recent_node_id: Option<u128>, resource_limits: DcWasmResourceLimits, backend: DcWasmExecutionBackend, ) -> Result<Self>
Instantiates a pure-compute DcWasmSession from compiled .wasm module bytes
with explicit DcWasmResourceLimits and DcWasmExecutionBackend.
§Errors
Returns an error if parsing, instrumenting, or instantiating the module fails,
if initial memory/tables exceed resource_limits, if the module exports neither
"step" nor "main", or if writing the initial input into linear memory fails.
Sourcepub fn from_substitute_descriptor_with_limits(
desc: WasmSubstituteDescriptor,
initial_input: &DcMstr,
most_recent_node_id: Option<u128>,
resource_limits: DcWasmResourceLimits,
) -> Result<Self>
pub fn from_substitute_descriptor_with_limits( desc: WasmSubstituteDescriptor, initial_input: &DcMstr, most_recent_node_id: Option<u128>, resource_limits: DcWasmResourceLimits, ) -> Result<Self>
Instantiates a DcWasmSession directly from a pre-resolved native
[WasmSubstituteDescriptor], skipping WebAssembly binary compilation and
hashing when the graph revision closure already matches a linked substitute.
§Errors
Returns an error if initial memory or table counts exceed resource_limits,
if the start section traps, or if writing initial_input into memory fails.
Sourcepub fn from_dc_wasm(
wasm_doc: &DcMstr,
initial_input: &DcMstr,
most_recent_node_id: Option<u128>,
) -> Result<Self>
pub fn from_dc_wasm( wasm_doc: &DcMstr, initial_input: &DcMstr, most_recent_node_id: Option<u128>, ) -> Result<Self>
Assembles a Dc-WASM document (Dc 1927 "Begin WASM program"..Dc 1928 "End WASM program"
or wasm_routine) using the default syntax resolver and instantiates a DcWasmSession.
§Errors
Returns an error if assembling or instantiating the Dc-WASM program fails.
Sourcepub fn from_dc_wasm_with_resolver(
wasm_doc: &DcMstr,
initial_input: &DcMstr,
most_recent_node_id: Option<u128>,
resolver: &dyn SyntaxRuleResolver,
) -> Result<Self>
pub fn from_dc_wasm_with_resolver( wasm_doc: &DcMstr, initial_input: &DcMstr, most_recent_node_id: Option<u128>, resolver: &dyn SyntaxRuleResolver, ) -> Result<Self>
Assembles a Dc-WASM document (Dc 1927 "Begin WASM program"..Dc 1928 "End WASM program"
or wasm_routine) using resolver and instantiates a DcWasmSession.
§Errors
Returns an error if assembling or instantiating the Dc-WASM program fails.
Sourcepub fn from_dc_wasm_with_limits(
wasm_doc: &DcMstr,
initial_input: &DcMstr,
most_recent_node_id: Option<u128>,
resolver: &dyn SyntaxRuleResolver,
resource_limits: DcWasmResourceLimits,
) -> Result<Self>
pub fn from_dc_wasm_with_limits( wasm_doc: &DcMstr, initial_input: &DcMstr, most_recent_node_id: Option<u128>, resolver: &dyn SyntaxRuleResolver, resource_limits: DcWasmResourceLimits, ) -> Result<Self>
Assembles a Dc-WASM document (Dc 1927 "Begin WASM program"..Dc 1928 "End WASM program"
or wasm_routine) using resolver and instantiates a DcWasmSession with explicit
DcWasmResourceLimits.
§Errors
Returns an error if assembling or instantiating the Dc-WASM program fails.
Sourcepub const fn used_native_substitute(&self) -> bool
pub const fn used_native_substitute(&self) -> bool
Returns true if this session is backed by a registered native substitute.
Sourcepub fn instrumented_wasm_bytes(&self) -> &[u8] ⓘ
pub fn instrumented_wasm_bytes(&self) -> &[u8] ⓘ
Returns the portable instrumented .wasm bytes executed by this session.
Because compute-quota accounting is embedded in standard WebAssembly bytecode,
running these bytes on any compliant WASM runtime (tinywasm, V8/Node WebAssembly,
Wasmtime, etc.) produces identical interruption points and state transitions.
Sourcepub const fn resource_limits(&self) -> DcWasmResourceLimits
pub const fn resource_limits(&self) -> DcWasmResourceLimits
Returns the active DcWasmResourceLimits for this session.
Sourcepub fn set_resource_limits(&mut self, limits: DcWasmResourceLimits)
pub fn set_resource_limits(&mut self, limits: DcWasmResourceLimits)
Updates the DcWasmResourceLimits enforced by this session.
Sourcepub fn with_resource_limits(self, limits: DcWasmResourceLimits) -> Self
pub fn with_resource_limits(self, limits: DcWasmResourceLimits) -> Self
Builder-style method returning self with updated DcWasmResourceLimits.
Attaches a SharedWasmTaskQuota so that this session shares its compute and
cumulative output quota with other sessions in the same evaluation task.
§Errors
Returns an error if the shared quota mutex is poisoned or if start already
exceeded the shared task’s remaining compute quota.
Returns true if this session is attached to a SharedWasmTaskQuota.
Returns a clone of the attached SharedWasmTaskQuota, if any.
Builder-style method attaching a SharedWasmTaskQuota.
§Errors
Returns an error if Self::set_shared_task_quota fails.
Sourcepub fn increase_compute_quota(&mut self, additional_units: u64)
pub fn increase_compute_quota(&mut self, additional_units: u64)
Increases the session’s compute quota allowance by additional_units.
When called after a WasmResourceInterruption::ComputeQuotaExhausted pause,
the next Self::step call resumes the paused computation with the increased
quota without repeating earlier step side effects.
Sourcepub const fn remaining_compute_quota(&self) -> u64
pub const fn remaining_compute_quota(&self) -> u64
Returns the remaining compute quota units currently available to this session.
Sourcepub const fn current_compute_quota_limit(&self) -> u64
pub const fn current_compute_quota_limit(&self) -> u64
Returns the active compute quota limit (initial allowance plus any granted increases).
Sourcepub const fn last_interrupted_op_ordinal(&self) -> Option<u64>
pub const fn last_interrupted_op_ordinal(&self) -> Option<u64>
Returns the 1-based ordinal of the operation that triggered the most recent
WasmResourceInterruption::ComputeQuotaExhausted, if any.
Sourcepub const fn last_interrupted_op_required_cost(&self) -> Option<u64>
pub const fn last_interrupted_op_required_cost(&self) -> Option<u64>
Returns the compute unit cost required by the operation that triggered the most recent
WasmResourceInterruption::ComputeQuotaExhausted, if any.
Sourcepub fn exported_global_i32(&self, name: &str) -> Option<i32>
pub fn exported_global_i32(&self, name: &str) -> Option<i32>
Returns the value of an exported i32 global by name, if present.
Sourcepub fn exported_global_i64(&self, name: &str) -> Option<i64>
pub fn exported_global_i64(&self, name: &str) -> Option<i64>
Returns the value of an exported i64 global by name, if present.
Sourcepub fn read_memory(&mut self, offset: usize, len: usize) -> Result<Vec<u8>>
pub fn read_memory(&mut self, offset: usize, len: usize) -> Result<Vec<u8>>
Reads len bytes starting at offset from exported "memory".
§Errors
Returns an error if exported "memory" is missing or offset..offset + len is out of bounds.
Sourcepub const fn last_step_instructions(&self) -> u64
pub const fn last_step_instructions(&self) -> u64
Returns the number of portable compute units consumed during the most recent step() call.
Sourcepub const fn total_instructions_executed(&self) -> u64
pub const fn total_instructions_executed(&self) -> u64
Returns the cumulative number of portable compute units consumed across this session.
Sourcepub const fn cumulative_output_bytes(&self) -> usize
pub const fn cumulative_output_bytes(&self) -> usize
Returns the cumulative number of output bytes decoded across all step() calls in this session.
Sourcepub const fn last_resource_interruption(
&self,
) -> Option<&WasmResourceInterruption>
pub const fn last_resource_interruption( &self, ) -> Option<&WasmResourceInterruption>
Returns the most recent WasmResourceInterruption raised by this session, if any.
Sourcepub fn current_input(&self) -> &DcMstr
pub fn current_input(&self) -> &DcMstr
Returns the most recent input document provided to Self::provide_input.
Sourcepub fn current_memory_pages(&mut self) -> Result<usize>
pub fn current_memory_pages(&mut self) -> Result<usize>
Returns the current number of 64 KiB pages allocated across the session store’s linear memories.
§Errors
Returns an error if the exported "memory" cannot be accessed.
Sourcepub fn current_table_elements(&self) -> usize
pub fn current_table_elements(&self) -> usize
Returns the total number of table elements currently allocated across the session store.
Sourcepub const fn base_io_offset(&self) -> usize
pub const fn base_io_offset(&self) -> usize
Returns the byte offset (input_ptr) where the host places the input payload in linear memory.
Sourcepub fn provide_input(&mut self, input: &DcMstr) -> Result<()>
pub fn provide_input(&mut self, input: &DcMstr) -> Result<()>
Writes a new input DcMstr payload into WASM linear memory and updates the
32-byte mailbox header at 0..32.
Used both for initial document loading and for supplying the response/mock Dc document
before resuming after WasmStepOutcome::RequestCapability.
§Errors
Returns an error if linear memory cannot grow to accommodate the input and output buffers
within DcWasmResourceLimits::max_memory_pages.
Sourcepub fn provide_capability_response(&mut self, response: &DcMstr) -> Result<()>
pub fn provide_capability_response(&mut self, response: &DcMstr) -> Result<()>
Validates and writes a capability response DcMstr into WASM linear memory,
enforcing DcWasmResourceLimits::max_capability_payload_bytes before
writing the response into the guest mailbox.
§Errors
Returns WasmResourceInterruption::CapabilityPayloadTooLarge if the capability
response payload exceeds max_capability_payload_bytes, or an error if writing
the payload into linear memory fails.
Sourcepub fn step(&mut self) -> Result<WasmStepOutcome>
pub fn step(&mut self) -> Result<WasmStepOutcome>
Executes one pure-compute quantum by calling the module’s exported "step" (or "main")
function (or resuming its live suspended continuation after a compute-quota increase)
and decoding the output DcMstring from linear memory according to the returned
WasmStepStatus.
§Errors
Returns an error if the WASM function traps, exhausts its portable compute quota, returns an invalid status code, exceeds single-step or cumulative output byte budgets, or writes an out-of-bounds or malformed Dc output slice.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DcWasmSession
impl RefUnwindSafe for DcWasmSession
impl Send for DcWasmSession
impl Sync for DcWasmSession
impl Unpin for DcWasmSession
impl UnwindSafe for DcWasmSession
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, U> ExactFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> ExactFrom<T> for Uwhere
U: TryFrom<T>,
fn exact_from(value: T) -> U
§impl<T, U> ExactInto<U> for Twhere
U: ExactFrom<T>,
impl<T, U> ExactInto<U> for Twhere
U: ExactFrom<T>,
fn exact_into(self) -> U
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
fn overflowing_into(self) -> (U, bool)
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);