Skip to main content

tpt_telos_verifier/
lib.rs

1//! tpt-telos formal verifier (QF_LRA).
2//!
3//! Provides a self-contained SMT-style engine that decides whether a set of
4//! linear arithmetic constraints is unsatisfiable, and uses it to prove that
5//! each `ensures` clause and invariant of a function follows from its
6//! `requires` and `mutate state` assignments.
7//!
8//! The default solver is an internal Fourier-Motzkin variable elimination
9//! engine. When the `z3` feature is enabled, an alternative Z3-backed solver
10//! is available via [`SolverBackend::Z3`].
11
12pub mod cluster;
13pub mod solver;
14pub mod verify;
15
16#[cfg(feature = "z3")]
17pub mod z3_solver;
18
19pub use solver::{
20    counterexample, entails, model, negate, satisfies_model, unsat, unsat_checked, Model,
21};
22pub use verify::{is_unsat, verify, CheckResult, VerificationResult};
23
24/// The solver backend to use for verification.
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
26pub enum SolverBackend {
27    /// Built-in Fourier-Motzkin variable elimination (default, no external
28    /// dependencies).
29    #[default]
30    FourierMotzkin,
31    /// Z3 SMT solver (requires the `z3` feature and the Z3 shared library
32    /// to be installed).
33    #[cfg(feature = "z3")]
34    Z3,
35}
36
37/// Global solver backend setting. Defaults to Fourier-Motzkin.
38static mut SOLVER_BACKEND: SolverBackend = SolverBackend::FourierMotzkin;
39
40/// Set the global solver backend.
41///
42/// # Safety
43///
44/// This uses a static mutable variable and is not thread-safe. Call only
45/// during single-threaded initialization (e.g., at CLI startup).
46pub fn set_solver_backend(backend: SolverBackend) {
47    // SAFETY: called during single-threaded CLI initialization.
48    unsafe {
49        SOLVER_BACKEND = backend;
50    }
51}
52
53/// Get the current solver backend.
54pub fn solver_backend() -> SolverBackend {
55    // SAFETY: read is atomic on all supported platforms for single-word enums.
56    unsafe { SOLVER_BACKEND }
57}