use std::time::Duration;
use dive_eval::EvalError;
use dive_store::StoreMode;
use dive_value::Value;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ErrorSite {
Startup,
Assumption,
Init,
Next,
Constraint,
ActionConstraint,
View,
Fingerprint,
Invariant,
ImpliedInit,
ImpliedAction,
Postcondition,
}
impl ErrorSite {
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::Startup => "startup",
Self::Assumption => "assumption",
Self::Init => "initial-states",
Self::Next => "next-state",
Self::Constraint => "constraint",
Self::ActionConstraint => "action-constraint",
Self::View => "view",
Self::Fingerprint => "fingerprint",
Self::Invariant => "invariant",
Self::ImpliedInit => "implied-init",
Self::ImpliedAction => "implied-action",
Self::Postcondition => "postcondition",
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Verdict {
Success,
InvariantViolated {
property: String,
initial: bool,
},
PropertyViolatedInitially {
property: String,
},
ActionPropertyViolated {
property: String,
},
Deadlock,
AssumptionFalse {
property: String,
message: String,
},
PostconditionFalse {
property: String,
message: String,
},
ModelError {
code: u32,
name: String,
message: String,
},
NotCompletelySpecified {
initial: bool,
variables: Vec<String>,
message: String,
initial_candidate: Option<PartialState>,
},
EvaluationError {
site: ErrorSite,
code: u32,
name: &'static str,
reported: u32,
message: String,
verified: bool,
cause: EvalError,
invariant: Option<String>,
},
Unsupported {
feature: String,
},
ResourceLimit {
message: String,
},
Stopped(Box<crate::budget::Stopped>),
BudgetMeasurement {
error: crate::budget::MeasurementError,
},
InternalError {
message: String,
},
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TlcClass {
pub code: u32,
pub name: String,
pub exit: u8,
pub reported: u32,
pub verified: bool,
}
impl Verdict {
#[must_use]
pub const fn kind(&self) -> &'static str {
match self {
Self::Success => "success",
Self::InvariantViolated { .. } => "invariant-violation",
Self::PropertyViolatedInitially { .. } => "property-violation",
Self::ActionPropertyViolated { .. } => "action-property-violation",
Self::Deadlock => "deadlock",
Self::AssumptionFalse { .. } => "assumption-failure",
Self::PostconditionFalse { .. } => "postcondition-failure",
Self::ModelError { .. } => "model-error",
Self::NotCompletelySpecified { .. } => "incomplete-state",
Self::EvaluationError { code: 2132, .. } => "assertion-failure",
Self::EvaluationError {
code: 2178 | 2265, ..
} => "overflow",
Self::EvaluationError { .. } => "evaluation-error",
Self::Unsupported { .. } => "unsupported",
Self::ResourceLimit { .. } => "resource-limit",
Self::Stopped(_) => "stopped",
Self::InternalError { .. } | Self::BudgetMeasurement { .. } => "internal-error",
}
}
#[must_use]
pub fn property(&self) -> Option<&str> {
match self {
Self::InvariantViolated { property, .. }
| Self::PropertyViolatedInitially { property }
| Self::ActionPropertyViolated { property }
| Self::PostconditionFalse { property, .. }
| Self::AssumptionFalse { property, .. } => Some(property),
_ => None,
}
}
#[must_use]
pub const fn is_verdict(&self) -> bool {
!matches!(
self,
Self::Unsupported { .. }
| Self::ResourceLimit { .. }
| Self::Stopped(_)
| Self::BudgetMeasurement { .. }
| Self::InternalError { .. }
)
}
#[must_use]
pub fn tlc(&self) -> Option<TlcClass> {
let class = |code: u32, name: &str, verified: bool| TlcClass {
code,
name: name.to_owned(),
exit: tlc_exit_status(code),
reported: code,
verified,
};
Some(match self {
Self::Success => class(2193, "TLC_SUCCESS", true),
Self::InvariantViolated { initial: true, .. } => {
class(2107, "TLC_INVARIANT_VIOLATED_INITIAL", true)
}
Self::InvariantViolated { initial: false, .. } => {
class(2110, "TLC_INVARIANT_VIOLATED_BEHAVIOR", true)
}
Self::PropertyViolatedInitially { .. } => {
class(2108, "TLC_PROPERTY_VIOLATED_INITIAL", true)
}
Self::ActionPropertyViolated { .. } => {
class(2112, "TLC_ACTION_PROPERTY_VIOLATED_BEHAVIOR", true)
}
Self::Deadlock => class(2114, "TLC_DEADLOCK_REACHED", true),
Self::AssumptionFalse { .. } => class(2104, "TLC_ASSUMPTION_FALSE", true),
Self::PostconditionFalse { .. } => class(2404, "TLC_POSTCONDITION_FALSE", true),
Self::ModelError { code, name, .. } => class(*code, name, *code != 2115),
Self::NotCompletelySpecified { initial: true, .. } => {
class(2102, "TLC_INITIAL_STATE", true)
}
Self::NotCompletelySpecified { initial: false, .. } => {
class(2109, "TLC_STATE_NOT_COMPLETELY_SPECIFIED_NEXT", true)
}
Self::EvaluationError {
site,
code,
name,
reported,
verified,
cause,
..
} => {
if crate::class::init_primary_general(*site, *code, *reported, *verified, cause) {
TlcClass {
code: 1000,
name: "GENERAL".to_owned(),
exit: 75,
reported: 1000,
verified: true,
}
} else {
TlcClass {
reported: *reported,
..class(*code, name, *verified)
}
}
}
Self::Unsupported { .. }
| Self::ResourceLimit { .. }
| Self::Stopped(_)
| Self::BudgetMeasurement { .. }
| Self::InternalError { .. } => {
return None;
}
})
}
}
#[must_use]
pub const fn tlc_exit_status(code: u32) -> u8 {
match code {
2193 => 0,
2253 => 77,
2103 | 2109 | 2115 | 2147 => 75,
2111 | 2146 => 76,
2107 | 2110 => 12,
2108 | 2112 | 2113 | 2116 => 13,
2114 => 11,
2104 | 2105 | 2404 | 2405 | 2780 => 10,
2132 => 14,
2171 | 3002 => 150,
2222..=2245 | 2272..=2274 | 2280 | 2281 | 5001..=5007 => 151,
_ => 255,
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Stats {
pub generated: u64,
pub distinct: u64,
pub left_on_queue: u64,
pub depth: u64,
pub initial_generated: u64,
}
#[derive(Clone, Debug)]
pub struct TraceState {
pub label: String,
pub action: Option<String>,
pub values: Vec<Value>,
pub text: Option<String>,
pub partial: Option<PartialState>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PartialState {
pub values: Vec<Option<Value>>,
pub expression: dive_ir::ExprId,
}
#[derive(Clone, Debug, Default)]
pub struct Counterexample {
pub states: Vec<TraceState>,
}
#[derive(Clone, Debug)]
pub struct DiagnosticWitness {
#[doc(hidden)]
pub states: Vec<TraceState>,
}
impl DiagnosticWitness {
#[must_use]
pub fn states(&self) -> &[TraceState] {
&self.states
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Collision {
pub optimistic: String,
pub actual: Option<String>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct PredecessorUsage {
pub storage: dive_store::predecessor::Usage,
pub failures: Vec<String>,
pub deciding_event_before_failure: Option<String>,
pub cleanup_completed: bool,
}
#[derive(Clone, Debug)]
pub struct CheckResult {
pub symmetry_liveness: Option<dive_model::SymmetryLivenessResolution>,
pub seen: Option<crate::SeenUsage>,
pub frontier: crate::FrontierUsage,
pub predecessor: PredecessorUsage,
pub verdict: Verdict,
pub binding_model_error: bool,
pub stats: Option<Stats>,
pub tlc_prints_stats: bool,
pub counterexample: Option<Counterexample>,
pub diagnostic_witness: Option<DiagnosticWitness>,
pub collision: Option<Collision>,
pub store: StoreMode,
pub fp_index: Option<usize>,
pub tlc_fingerprints: bool,
pub var_names: Vec<String>,
pub tlc_var_order: Vec<usize>,
pub output: Vec<String>,
pub warnings: Vec<(u32, String)>,
pub notes: Vec<String>,
pub workers: Workers,
pub elapsed: Duration,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Workers {
pub requested: usize,
pub used: usize,
pub sequential: bool,
pub reason: Option<String>,
}
impl Workers {
#[must_use]
pub const fn one() -> Self {
Self {
requested: 1,
used: 1,
sequential: false,
reason: None,
}
}
}