dive-core 0.1.0

The dive execution core for TLA+: value store, plan compiler, interpreter and successor generation
Documentation
//! Random draws (`TLC!RandomElement`): the run's streams, which the engine
//! supplies.
//!
//! The core defines the interface only. `dive-api` implements it with
//! `dive-stdlib`'s seeded streams and `dive-store`'s TLC state fingerprint,
//! so that the core's draws continue the streams start-up evaluation drew
//! from.

use dive_ir::StdOp;
use dive_value::{Ctx, Value};

use crate::Error;
use crate::handle::Handle;
use crate::heap::Heap;

/// A random stream in use: the startup stream, or one expanded state's.
pub trait DrawStream: Send + std::fmt::Debug {
    /// Applies the random operator `op` to `args`, drawing from the stream.
    ///
    /// # Errors
    /// TLC's evaluation error of the operator, or a refusal.
    fn draw(&mut self, op: StdOp, args: &[Value], ctx: Ctx) -> Result<Value, Error>;
}

/// The run's random streams.
pub trait Draws: Send + Sync {
    /// The startup stream, where the constant definitions and `ASSUME`s
    /// left it: `Init` draws from it.
    fn startup(&self) -> Box<dyn DrawStream>;

    /// The stream for expanding the state whose variables (in IR order)
    /// are `vars`: TLC's `fingerprint(state) ^ seed`, or dive's replayable
    /// stream keyed by the fingerprint.
    ///
    /// # Errors
    /// A state that cannot be converted or fingerprinted.
    fn state(&self, heap: &mut Heap, vars: &[Handle]) -> Result<Box<dyn DrawStream>, Error>;
}

/// The run's `TLCSet`/`TLCGet` registers: the
/// dive-eval evaluator's, which constant definitions and `ASSUME`s wrote.
pub trait Registers: Send + Sync {
    /// Applies `TLCSet(key, value)` or `TLCGet(key)` to evaluated
    /// arguments. `TLCGet("level")` never reaches it.
    ///
    /// # Errors
    /// TLC's evaluation error, or a refusal.
    fn call(&self, op: StdOp, args: &[Value]) -> Result<Value, Error>;
}