use core::fmt;
use crate::{Arm, Error, Model, Report, engine::Engine};
pub const DEFAULT_STEP_LIMIT: u64 = 1 << 24;
pub const DEFAULT_WITNESS_LIMIT: usize = 16;
pub struct Checker<T> {
engine: Engine<T>,
step_limit: u64,
witness_limit: usize,
}
impl<T: Clone> Checker<T> {
#[must_use]
pub fn new() -> Checker<T> {
Checker {
engine: Engine::new(),
step_limit: DEFAULT_STEP_LIMIT,
witness_limit: DEFAULT_WITNESS_LIMIT,
}
}
#[must_use]
pub fn with_step_limit(mut self, limit: u64) -> Checker<T> {
self.step_limit = limit;
self
}
#[must_use]
pub fn with_witness_limit(mut self, limit: usize) -> Checker<T> {
self.witness_limit = limit.max(1);
self
}
#[must_use]
pub fn step_limit(&self) -> u64 {
self.step_limit
}
#[must_use]
pub fn witness_limit(&self) -> usize {
self.witness_limit
}
pub fn check<M: Model<Ty = T>>(
&mut self,
model: &M,
ty: &T,
arms: &[Arm],
) -> Result<Report<T>, Error> {
self.engine
.check(model, ty, arms, self.step_limit, self.witness_limit)
}
}
impl<T: Clone> Default for Checker<T> {
fn default() -> Checker<T> {
Checker::new()
}
}
impl<T> fmt::Debug for Checker<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Checker")
.field("step_limit", &self.step_limit)
.field("witness_limit", &self.witness_limit)
.finish_non_exhaustive()
}
}