Skip to main content

SpecModel

Struct SpecModel 

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

A specification bound to its configuration, with immutable original inputs for private startup reconstruction on every validation.

Implementations§

Source§

impl SpecModel

Source

pub fn load( spec: &Path, cfg: &Path, opts: &TraceOptions, ) -> Result<Self, ApiError>

Loads the specification rooted at spec and binds it to the configuration file cfg.

§Errors

ApiError::Io if a file cannot be read, ApiError::Rejected if the specification or configuration has errors, and ApiError::Unsupported if dive cannot bind it exactly.

Source

pub fn from_source( file: &str, source: &str, cfg: &str, opts: &TraceOptions, ) -> Result<Self, ApiError>

Binds specification source text (the root module; others come from the search path) to configuration text.

§Errors

As SpecModel::load.

Source

pub fn model(&self) -> &Model

The bound model.

Source

pub fn model_values(&self) -> &[String]

The configuration’s model value names.

Source

pub fn validate(&self, doc: &TraceDoc) -> Report

Validates a trace document (either format). A TLC document needs its ending set (TraceDoc::with_ending).

Source

pub fn try_validate_sample( &self, doc: &TraceDoc, ) -> Result<Report, ValidationRunError>

Independently checks every finite sampled row, including configured constraints, invariants and implied finite properties, on fresh source. Unlike ordinary behavior validity, this operation rejects a prefix that passed a deciding safety violation. It proves no exhaustive result. A deadlock ending is checked as a simulation deadlock: no successor of the last state satisfies every constraint.

let report = source.try_validate_sample(word)?;
§Errors

Typed interruption, resource exhaustion or isolated validation failure.

Source

pub fn read(&self, doc: &TraceDoc) -> (Report, Option<Trace>)

Validates a trace document and also returns the trace as read (see dive_trace::validate_doc).

Source

pub fn try_validate(&self, doc: &TraceDoc) -> Result<Report, ValidationRunError>

Validates with resource/execution exceptions outside the report. Endpoint documents require this fallible entrypoint; no resource failure is relabeled as a completed unsupported validation result.

let report = model.try_validate(doc)?;
§Errors

Resource exhaustion, typed interruption, control conflict or isolated thread failure; in each case there is no completed validation report.

Source

pub fn try_read( &self, doc: &TraceDoc, ) -> Result<(Report, Option<Trace>), ValidationRunError>

Reads through fresh private source reconstruction with fallible transport. Other document forms retain their existing reading semantics.

§Errors

As Self::try_validate.

Source

pub fn initial_invariant_class( &self, doc: &TraceDoc, control: Option<Arc<dyn HostControl>>, ) -> Result<(Report, Option<InitialInvariantClass>), ValidationRunError>

Validates a named invariant-error word and separately reconstructs its actual first-Init diagnostic classification on a fresh private runtime. A valid word alone does not grant a deciding-wrapper certificate.

let (word, class) = model.initial_invariant_class(doc, None)?;
if let Some(class) = class {
    assert_eq!(class.deciding_code(), 2147);
}
§Errors

Resource exhaustion, actual host interruption, control conflict or isolated thread failure; no completed class proof is returned then.

Source

pub fn invariant_error_class( &self, doc: &TraceDoc, control: Option<Arc<dyn HostControl>>, ) -> Result<(Report, Option<InvariantErrorClass>), ValidationRunError>

Validates a named successor invariant error and separately executes its bounded Init/source admission and diagnostic lifecycle on a fresh runtime. Ordinary word validity alone grants no diagnostic identity.

§Errors

Actual interruption, resource/internal failure, control or thread failure.

Source

pub fn initial_error_stage( &self, control: Option<Arc<dyn HostControl>>, ) -> Result<(Report, Option<InitialErrorStage>), ValidationRunError>

Independently reconstructs the actual first initial error stage on a fresh source-bound runtime. Header fields do not select this route. An invariant-receiver stage still needs its auxiliary word and separate Self::initial_invariant_class proof before a wrapper is established.

§Errors

Actual interruption, resource, binding, control or isolated-thread failure.

Source

pub fn validate_trace(&self, trace: &Trace) -> Report

Validates a trace already read against this model.

Source

pub fn mutants(&self, trace: &Trace) -> Vec<Mutant>

The by-construction invalid mutants of a valid shortest trace (dive_trace::mutate): negative controls, without random redraws.

Source

pub fn mutants_with_mode(&self, trace: &Trace, mode: ControlMode) -> Vec<Mutant>

The invalid-by-construction mutants supported by the known valid counterexample’s explicit producer contract. This does not infer shortestness or explore alternative paths.

Source

pub fn to_doc(&self, trace: &Trace) -> Result<TraceDoc, ApiError>

The trace in dive’s format.

§Errors

If a value has no JSON form.

Source§

impl SpecModel

Source

pub fn controls(&self, doc: &TraceDoc) -> Controls

Runs the controls on a known valid shortest BFS counterexample.

Compatibility wrapper for Self::controls_with_mode with ControlMode::ShortestBfs. Other producers must select their mode explicitly.

Source

pub fn controls_with_mode(&self, doc: &TraceDoc, mode: ControlMode) -> Controls

Runs positive, document round-trip and negative controls using the known valid counterexample’s explicit producer contract. Every generated mutant must be invalid both directly and through dive’s format; an empty negative suite receives no coverage credit.

use dive_api::trace::{ControlMode, Ending, SpecModel, TraceDoc, TraceOptions};
use serde_json::json;

let model = SpecModel::from_source("Loop.tla",
    "---- MODULE Loop ----\nVARIABLE x\nInit == x=0\nNext == x'=0 \\/ x'=1\nInv == x=0\n====\n",
    "INIT Init\nNEXT Next\nINVARIANT Inv\n", &TraceOptions::default())?;
let doc = TraceDoc::behavior(vec![json!({"x":0}), json!({"x":0}), json!({"x":1})])?
    .with_ending(Ending::Invariant("Inv".to_owned()));
let controls = model.controls_with_mode(&doc, ControlMode::Counterexample);
assert!(controls.failures().is_empty());
let (_, trace) = model.read(&doc);
let mutants = model.mutants_with_mode(&trace.ok_or("trace missing")?, ControlMode::Counterexample);
assert_eq!(mutants.len(), 3);

Trait Implementations§

Source§

impl Clone for SpecModel

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpecModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.