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
impl SpecModel
Sourcepub fn load(
spec: &Path,
cfg: &Path,
opts: &TraceOptions,
) -> Result<Self, ApiError>
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.
Sourcepub fn from_source(
file: &str,
source: &str,
cfg: &str,
opts: &TraceOptions,
) -> Result<Self, ApiError>
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.
Sourcepub fn model_values(&self) -> &[String]
pub fn model_values(&self) -> &[String]
The configuration’s model value names.
Sourcepub fn validate(&self, doc: &TraceDoc) -> Report
pub fn validate(&self, doc: &TraceDoc) -> Report
Validates a trace document (either format). A TLC document needs its
ending set (TraceDoc::with_ending).
Sourcepub fn try_validate_sample(
&self,
doc: &TraceDoc,
) -> Result<Report, ValidationRunError>
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.
Sourcepub fn read(&self, doc: &TraceDoc) -> (Report, Option<Trace>)
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).
Sourcepub fn try_validate(&self, doc: &TraceDoc) -> Result<Report, ValidationRunError>
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.
Sourcepub fn try_read(
&self,
doc: &TraceDoc,
) -> Result<(Report, Option<Trace>), ValidationRunError>
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
Sourcepub fn initial_invariant_class(
&self,
doc: &TraceDoc,
control: Option<Arc<dyn HostControl>>,
) -> Result<(Report, Option<InitialInvariantClass>), ValidationRunError>
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.
Sourcepub fn invariant_error_class(
&self,
doc: &TraceDoc,
control: Option<Arc<dyn HostControl>>,
) -> Result<(Report, Option<InvariantErrorClass>), ValidationRunError>
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.
Sourcepub fn initial_error_stage(
&self,
control: Option<Arc<dyn HostControl>>,
) -> Result<(Report, Option<InitialErrorStage>), ValidationRunError>
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.
Sourcepub fn validate_trace(&self, trace: &Trace) -> Report
pub fn validate_trace(&self, trace: &Trace) -> Report
Validates a trace already read against this model.
Sourcepub fn mutants(&self, trace: &Trace) -> Vec<Mutant>
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.
Sourcepub fn mutants_with_mode(&self, trace: &Trace, mode: ControlMode) -> Vec<Mutant>
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§impl SpecModel
impl SpecModel
Sourcepub fn controls(&self, doc: &TraceDoc) -> Controls
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.
Sourcepub fn controls_with_mode(&self, doc: &TraceDoc, mode: ControlMode) -> Controls
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);