dive_runtime/classify.rs
1//! TLC's error classes for another engine's error endings.
2//!
3//! The Core execution engine finds
4//! where an evaluation error ends a search and reproduces the error with the
5//! evaluator (`dive-eval`). It then classifies the error by its site with
6//! this crate's table (`class.rs`), so that Core reports TLC's class, message
7//! and exit. These are thin public views of that table;
8//! the rules and their evidence are documented there.
9
10use dive_eval::EvalError;
11
12use crate::class;
13use crate::result::{ErrorSite, Verdict};
14
15/// An error raised at `site` while exploring, as TLC classifies it.
16/// `name` is the invariant, constraint or property, where there is one.
17#[must_use]
18pub fn search_error(e: &EvalError, site: ErrorSite, name: Option<&str>) -> Verdict {
19 class::search_error(e, site, name)
20}
21
22/// An `ASSUME` that fails to evaluate, as TLC classifies it
23/// (`TLC_ASSUMPTION_EVALUATION_ERROR`, or the error's own class). `message`
24/// is the evaluator's text of the error.
25#[must_use]
26pub fn assumption_error(e: &EvalError, message: String) -> Verdict {
27 class::assumption_error(e, message)
28}
29
30/// An error raised while generating or checking the initial states. `state`
31/// is TLC's text of the initial state being checked, for an error in a
32/// check of a state, and `None` for an error while generating them.
33#[must_use]
34pub fn init_error(v: Verdict, state: Option<&str>) -> Verdict {
35 class::init_error(v, state, None)
36}
37
38/// Classifies a failed check of an actual initial state, including the bounded
39/// diagnostic replay of a pure invariant's newly constructed value receiver.
40/// The replay retains the role's real scope and all previously computed values;
41/// unrelated, effectful or stored-receiver failures gain no source authority.
42#[must_use]
43pub fn initial_check_error(
44 model: &dive_model::Model,
45 verdict: Verdict,
46 state: &[Option<dive_value::Value>],
47) -> Verdict {
48 let diagnostic = crate::diagnostic::initial_value_method_replay(model, &verdict, state, None);
49 let text = crate::diagnostic::state_text(model, state, model.evaluator.options().ctx);
50 class::init_error(verdict, Some(&text), diagnostic.as_ref())
51}
52
53/// An invariant that failed to evaluate on a state outside the model, which
54/// TLC's replay checks again: the replay decides.
55#[must_use]
56pub fn recurring(v: Verdict) -> Verdict {
57 class::recurring(v)
58}
59
60/// The class once TLC's call-stack replay meets the further error `e2`
61/// after an invariant failed to evaluate on a new state.
62#[must_use]
63pub fn replay_error(v: Verdict, e2: &EvalError) -> Verdict {
64 class::replay_error(v, e2)
65}