1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//! `dive-trace`: the counterexample format and the independent trace
//! validator.
//!
//! The validator checks a counterexample *as data* against a bound
//! [`dive_model::Model`]: that its first state satisfies the initial
//! predicate, that every step satisfies the next-state relation, evaluated as
//! a predicate over the two given states, that the states the search must
//! have explored are inside the model and violate nothing earlier, and that
//! the trace ends as it claims. It shares only the dive-eval evaluator, the
//! value library and the binding stage with the checker, never the search,
//! store or liveness graph. This is deliberate: code such as the scoped
//! temporal walk in [`mod@temporal`] duplicates what `dive-liveness` does
//! rather than sharing it, so that a checker bug cannot also hide itself from
//! validation. Whether a state has a successor (`ENABLED`, deadlock and
//! fairness) is the dive-eval evaluator's `ENABLED`; the states and
//! steps of the counterexample are still replayed and checked here.
//!
//! Named pure periodic words (`TraceDoc::with_properties`) also check all
//! behavior temporal conjuncts and the complete violated-property set.
//! Fairness is decided with the dive-eval evaluator's `ENABLED`. VIEW/symmetry
//! closing evidence and unnamed periodic claims from older documents remain explicit
//! refusals.
//!
//! - [`mod@format`]: the versioned trace format (also TLC's `-dumpTrace json`).
//! - [`value_json`]: dive's tagged JSON values, with documented representation
//! and mixed-set round-trip limitations.
//! - [`validate()`]: the checks, giving [`Validation::Valid`],
//! [`Validation::Invalid`] (the first failing state and check) or
//! [`Validation::Unsupported`] (naming what cannot be checked). A random
//! draw is refused by name ([`RANDOM_UNSUPPORTED`]), and so is a string
//! created at run time when strings follow encounter order
//! ([`RUNTIME_NAMES_UNSUPPORTED`]).
//! TLC register reads and writes are refused ([`REGISTERS_UNSUPPORTED`])
//! because their contents can depend on evaluations outside the trace.
//! [`Session`] reconstructs immutable source/config inputs privately and
//! supports startup registers through a single-candidate Init operation;
//! every later register access retains that refusal.
//! - [`tlc`]: reading TLC's lossy JSON by interpretation.
//! - [`mutate`]: by-construction invalid mutants, the negative controls.
//!
//! Evaluation recurses on the caller's stack: run validation on a thread
//! with [`dive_eval::RECOMMENDED_STACK`], as `dive-api` does.
//!
//! # Example
//!
//! ```
//! use std::sync::Arc;
//! use dive_trace::{TraceDoc, Validation, validate_doc};
//!
//! let src = "---- MODULE M ----\nEXTENDS Naturals\nVARIABLE x\n\
//! Init == x = 0\nNext == x' = x + 1\nInv == x < 2\n====\n";
//! let analysis = dive_sema::analyze_source("M.tla", src, &dive_sema::Options::default());
//! let ir = Arc::new(dive_ir::lower(&analysis).unwrap());
//! let cfg = dive_config::parse("INIT Init\nNEXT Next\nINVARIANT Inv\n").into_config().unwrap();
//! let model = dive_model::bind(ir, &cfg, &dive_model::BindOptions::tlc()).unwrap();
//!
//! let doc = TraceDoc::parse(r#"{"format": "dive-trace", "version": 1, "variables": ["x"],
//! "states": [{"action": null, "values": {"x": 0}},
//! {"action": {"name": "Next"}, "values": {"x": 1}},
//! {"action": {"name": "Next"}, "values": {"x": 2}}],
//! "ending": {"kind": "invariant", "name": "Inv"}}"#).unwrap();
//! let (report, _) = validate_doc(&model, &doc, &cfg.model_values);
//! assert_eq!(report.validation, Validation::Valid);
//!
//! // Skipping a state is not a step of the specification.
//! let doc = TraceDoc::behavior(vec![
//! serde_json::json!({"x": 0}),
//! serde_json::json!({"x": 2}),
//! ]).unwrap();
//! let (report, _) = validate_doc(&model, &doc, &cfg.model_values);
//! let Validation::Invalid(failure) = report.validation else { panic!() };
//! assert_eq!((failure.state, failure.check), (1, dive_trace::Check::Next));
//! ```
use Model;
pub use ;
pub use ;
pub use ;
pub use InvariantErrorClass;
pub use Session;
pub use ;
pub use ;
/// Reads a document in either format against `model` and validates it.
/// `model_values` are the configuration's model value names
/// (`dive_config::ModelConfig::model_values`), which reading TLC's format
/// needs. Returns the report and the trace as read (for a TLC document, the
/// interpretation the verdict is about; see [`tlc`]). Random draws are refused
/// by name ([`RANDOM_UNSUPPORTED`]).