pub struct VM<I = (), G = (), P = NoopPersistence, Nu = DefaultVerificationModel>where
P: PersistenceModel,{ /* private fields */ }Expand description
The choreographic VM.
Manages coroutines, sessions (which own type state), and a scheduler. Multiple choreographies can be loaded into a single VM, each in its own session namespace — justified by separation logic.
Implementations§
Source§impl VM
impl VM
Sourcepub fn load_choreography_owned(
&mut self,
image: &CodeImage,
owner_id: impl Into<String>,
) -> Result<OwnedSession, VMError>
pub fn load_choreography_owned( &mut self, image: &CodeImage, owner_id: impl Into<String>, ) -> Result<OwnedSession, VMError>
Preferred choreography open path that immediately claims session ownership.
Third-party host integrations use this owned helper so subsequent session-local mutation flows through an explicit ownership capability.
§Errors
Returns a VMError if the choreography cannot be loaded or the initial
ownership claim fails.
Source§impl<I, G, P, Nu> VM<I, G, P, Nu>where
P: PersistenceModel,
impl<I, G, P, Nu> VM<I, G, P, Nu>where
P: PersistenceModel,
Sourcepub fn new_with_models(config: VMConfig) -> Self
pub fn new_with_models(config: VMConfig) -> Self
Create a VM for arbitrary persistence/verification model parameters.
Sourcepub fn persistent_state(&self) -> &P::PState
pub fn persistent_state(&self) -> &P::PState
Borrow the persistent state tracked by the configured persistence model.
Sourcepub fn persistent_state_mut(&mut self) -> &mut P::PState
pub fn persistent_state_mut(&mut self) -> &mut P::PState
Mutably borrow persistent state.
Sourcepub fn bridge_guard_layer_for_participant<B>(
&self,
bridge: &B,
participant: &I::ParticipantId,
) -> LayerId
pub fn bridge_guard_layer_for_participant<B>( &self, bridge: &B, participant: &I::ParticipantId, ) -> LayerId
Resolve guard-layer capability for a participant via bridge binding.
Sourcepub fn bridge_verifying_key_for_participant<B>(
&self,
bridge: &B,
participant: &I::ParticipantId,
) -> Nu::VerifyingKey
pub fn bridge_verifying_key_for_participant<B>( &self, bridge: &B, participant: &I::ParticipantId, ) -> Nu::VerifyingKey
Resolve participant verification key via bridge binding.
§impl VM
impl VM
pub fn step(
&mut self,
handler: &dyn EffectHandler,
) -> Result<StepResult, VMError>
pub fn step( &mut self, handler: &dyn EffectHandler, ) -> Result<StepResult, VMError>
Execute one scheduler step: pick a coroutine, run one instruction.
§Errors
Returns a VMError if a coroutine faults.
pub fn step_round(
&mut self,
handler: &dyn EffectHandler,
n: usize,
) -> Result<StepResult, VMError>
pub fn step_round( &mut self, handler: &dyn EffectHandler, n: usize, ) -> Result<StepResult, VMError>
Execute one scheduler round through the canonical kernel API.
§Errors
Returns a VMError if a coroutine faults.
pub fn run_concurrent(
&mut self,
handler: &dyn EffectHandler,
max_rounds: usize,
concurrency: usize,
) -> Result<RunStatus, VMError>
pub fn run_concurrent( &mut self, handler: &dyn EffectHandler, max_rounds: usize, concurrency: usize, ) -> Result<RunStatus, VMError>
Run the VM until all coroutines complete or an error occurs, with concurrency N.
max_rounds prevents infinite loops.
§Errors
Returns a VMError if any coroutine faults.
pub fn run(
&mut self,
handler: &dyn EffectHandler,
max_steps: usize,
) -> Result<RunStatus, VMError>
pub fn run( &mut self, handler: &dyn EffectHandler, max_steps: usize, ) -> Result<RunStatus, VMError>
Run the VM until all coroutines complete or an error occurs.
max_steps prevents infinite loops.
§Errors
Returns a VMError if any coroutine faults.
pub fn run_replay(
&mut self,
fallback: &dyn EffectHandler,
replay_trace: &[EffectTraceEntry],
max_steps: usize,
) -> Result<RunStatus, VMError>
pub fn run_replay( &mut self, fallback: &dyn EffectHandler, replay_trace: &[EffectTraceEntry], max_steps: usize, ) -> Result<RunStatus, VMError>
Run with replayed effect outcomes captured from a prior execution.
The fallback handler is only used for optional hooks not encoded in
replay entries.
§Errors
Returns a VMError if replay data is exhausted/mismatched or a coroutine faults.
Run with replayed effect outcomes using shared trace storage.
Accepts an Arc-backed trace to avoid cloning when callers already hold
shared replay buffers.
§Errors
Returns a VMError if replay data is exhausted/mismatched or a coroutine faults.
pub fn run_concurrent_replay(
&mut self,
fallback: &dyn EffectHandler,
replay_trace: &[EffectTraceEntry],
max_rounds: usize,
concurrency: usize,
) -> Result<RunStatus, VMError>
pub fn run_concurrent_replay( &mut self, fallback: &dyn EffectHandler, replay_trace: &[EffectTraceEntry], max_rounds: usize, concurrency: usize, ) -> Result<RunStatus, VMError>
Run concurrently with replayed effect outcomes.
§Errors
Returns a VMError if replay data is exhausted/mismatched or a coroutine faults.
Run concurrently with replayed outcomes using shared trace storage.
§Errors
Returns a VMError if replay data is exhausted/mismatched or a coroutine faults.
pub fn reap_closed_sessions(&mut self) -> Vec<ClosedSessionSummary>
pub fn reap_closed_sessions(&mut self) -> Vec<ClosedSessionSummary>
Reap closed sessions once all associated coroutines are terminal.
pub fn role_symbol_count(&self) -> usize
pub fn role_symbol_count(&self) -> usize
Number of interned role symbols.
pub fn label_symbol_count(&self) -> usize
pub fn label_symbol_count(&self) -> usize
Number of interned label symbols.
pub fn handler_symbol_count(&self) -> usize
pub fn handler_symbol_count(&self) -> usize
Number of interned handler symbols.
pub fn edge_symbol_count(&self) -> usize
pub fn edge_symbol_count(&self) -> usize
Number of interned edge symbols.
pub fn last_sched_step(&self) -> Option<&SchedStepDebug>
pub fn last_sched_step(&self) -> Option<&SchedStepDebug>
Last scheduler-dispatched step metadata, if any coroutine ran.
pub fn scheduler_step_count(&self) -> usize
pub fn scheduler_step_count(&self) -> usize
Scheduler-dispatched step counter.
pub fn coroutine_count(&self) -> usize
pub fn coroutine_count(&self) -> usize
Number of coroutine records in the VM.
pub fn next_session_id(&self) -> SessionId
pub fn next_session_id(&self) -> SessionId
Next session identifier reserved for allocation.
pub fn session_count(&self) -> usize
pub fn session_count(&self) -> usize
Number of active sessions in the VM.
pub fn live_session_count(&self) -> usize
pub fn live_session_count(&self) -> usize
Number of sessions still resident in the VM, including closed ones.
§impl VM
impl VM
pub fn memory_usage(&self) -> VmMemoryUsage
pub fn memory_usage(&self) -> VmMemoryUsage
Approximate retained state for the VM runtime.
pub fn output_condition_checks(&self) -> &[OutputConditionCheck]
pub fn output_condition_checks(&self) -> &[OutputConditionCheck]
Get recorded output-condition verification checks.
pub fn effect_trace(&self) -> &[EffectTraceEntry]
pub fn effect_trace(&self) -> &[EffectTraceEntry]
Get recorded effect-trace entries.
pub fn delegation_audit_log(&self) -> &[DelegationAuditRecord]
pub fn delegation_audit_log(&self) -> &[DelegationAuditRecord]
Get recorded delegation audit records.
Get recorded authority witness audit records.
pub fn semantic_audit_log(&self) -> Vec<SemanticAuditRecord>
pub fn semantic_audit_log(&self) -> Vec<SemanticAuditRecord>
Get canonical semantic audit records derived from authority, delegation, failure, and effect/interface traces.
pub fn communication_replay_root(&self) -> Hash
pub fn communication_replay_root(&self) -> Hash
Deterministic communication replay-state root.
pub fn communication_consumption_artifacts(
&self,
) -> &[CommunicationConsumptionArtifact]
pub fn communication_consumption_artifacts( &self, ) -> &[CommunicationConsumptionArtifact]
Receive-boundary replay-consumption artifacts.
pub fn drain_obs_trace(&mut self) -> Vec<ObsEvent>
pub fn drain_obs_trace(&mut self) -> Vec<ObsEvent>
Drain retained observable events in canonical insertion order.
pub fn drain_effect_trace(&mut self) -> Vec<EffectTraceEntry>
pub fn drain_effect_trace(&mut self) -> Vec<EffectTraceEntry>
Drain retained effect-trace entries in canonical insertion order.
pub fn drain_output_condition_checks(&mut self) -> Vec<OutputConditionCheck>
pub fn drain_output_condition_checks(&mut self) -> Vec<OutputConditionCheck>
Drain retained output-condition diagnostics in canonical insertion order.
pub fn drain_delegation_audit_log(&mut self) -> Vec<DelegationAuditRecord>
pub fn drain_delegation_audit_log(&mut self) -> Vec<DelegationAuditRecord>
Drain retained delegation audit records in canonical insertion order.
Drain retained authority witness audit records in canonical insertion order.
pub fn drain_communication_consumption_artifacts(
&mut self,
) -> Vec<CommunicationConsumptionArtifact>
pub fn drain_communication_consumption_artifacts( &mut self, ) -> Vec<CommunicationConsumptionArtifact>
Drain retained communication replay-consumption artifacts in canonical insertion order.
pub fn canonical_replay_fragment(&self) -> CanonicalReplayFragmentV1
pub fn canonical_replay_fragment(&self) -> CanonicalReplayFragmentV1
Canonical replay/state fragment for deterministic diffing and snapshots.
pub fn crashed_sites(&self) -> &BTreeSet<SiteId>
pub fn crashed_sites(&self) -> &BTreeSet<SiteId>
Crashed sites currently active in topology state.
pub fn partitioned_edges(&self) -> &BTreeSet<(SiteId, SiteId)>
pub fn partitioned_edges(&self) -> &BTreeSet<(SiteId, SiteId)>
Partitioned site-links currently active in topology state.
pub fn corrupted_edges(&self) -> &BTreeMap<(SiteId, SiteId), CorruptionType>
pub fn corrupted_edges(&self) -> &BTreeMap<(SiteId, SiteId), CorruptionType>
Corrupted directed edges currently active in topology state.
pub fn timed_out_sites(&self) -> &BTreeMap<SiteId, u64>
pub fn timed_out_sites(&self) -> &BTreeMap<SiteId, u64>
Active site timeouts.
§impl VM
impl VM
pub fn coroutine_program_len(&self, id: usize) -> Option<usize>
pub fn coroutine_program_len(&self, id: usize) -> Option<usize>
Program length for a coroutine by id.
pub fn unique_program_count(&self) -> usize
pub fn unique_program_count(&self) -> usize
Number of unique immutable programs retained by the VM.
pub fn coroutine_mut(&mut self, id: usize) -> Option<&mut Coroutine>
pub fn coroutine_mut(&mut self, id: usize) -> Option<&mut Coroutine>
Get a mutable coroutine by ID.
pub fn session_coroutines(&self, sid: SessionId) -> Vec<&Coroutine>
pub fn session_coroutines(&self, sid: SessionId) -> Vec<&Coroutine>
Get all coroutines for a session.
pub fn sessions(&self) -> &SessionStore
pub fn sessions(&self) -> &SessionStore
Access the session store.
pub fn wf_vm_state(&self) -> Result<(), String>
pub fn wf_vm_state(&self) -> Result<(), String>
Runtime well-formedness predicate used by debug assertions.
§Errors
Returns a description of the invariant violation if the VM state is invalid.
pub fn inject_message(
&mut self,
sid: SessionId,
from: &str,
to: &str,
value: Value,
) -> Result<EnqueueResult, VMError>
pub fn inject_message( &mut self, sid: SessionId, from: &str, to: &str, value: Value, ) -> Result<EnqueueResult, VMError>
Inject a message directly into a session buffer.
Used by simulation middleware (network/fault injection) to deliver in-flight messages without executing a VM send instruction.
§Errors
Returns an error if the session does not exist.
pub fn coroutines(&self) -> &[Coroutine]
pub fn coroutines(&self) -> &[Coroutine]
Access all coroutines.
pub fn pause_role(&mut self, role: &str)
pub fn pause_role(&mut self, role: &str)
Pause execution for all coroutines of a role.
pub fn resume_role(&mut self, role: &str)
pub fn resume_role(&mut self, role: &str)
Resume execution for all coroutines of a role.
pub fn set_paused_roles(&mut self, roles: &BTreeSet<String>)
pub fn set_paused_roles(&mut self, roles: &BTreeSet<String>)
Replace the paused role set.
pub fn paused_roles(&self) -> &BTreeSet<String>
pub fn paused_roles(&self) -> &BTreeSet<String>
Access paused roles.
§impl VM
impl VM
pub fn mark_owner_died(
&mut self,
sid: SessionId,
owner_id: &str,
) -> Result<CancellationWitness, OwnershipError>
pub fn mark_owner_died( &mut self, sid: SessionId, owner_id: &str, ) -> Result<CancellationWitness, OwnershipError>
Fault a session because the current owner died.
§Errors
Returns an OwnershipError if the live owner no longer matches.
pub fn cancel_abandoned_transfer(
&mut self,
receipt: &OwnershipReceipt,
) -> Result<CancellationWitness, OwnershipError>
pub fn cancel_abandoned_transfer( &mut self, receipt: &OwnershipReceipt, ) -> Result<CancellationWitness, OwnershipError>
Cancel a session because a staged transfer was abandoned.
§Errors
Returns an OwnershipError if the receipt no longer matches the staged transfer.
pub fn fault_failed_transfer_commit(
&mut self,
receipt: &OwnershipReceipt,
reason: impl Into<String>,
) -> Result<(), OwnershipError>
pub fn fault_failed_transfer_commit( &mut self, receipt: &OwnershipReceipt, reason: impl Into<String>, ) -> Result<(), OwnershipError>
Fault a session because a staged transfer could not commit.
§Errors
Returns an OwnershipError if the receipt no longer matches the staged transfer.