Solver

Struct Solver 

Source
pub struct Solver<'ctx, B> { /* private fields */ }
Expand description

The Solver type handles all interaction with Z3. It mimics interacting with Z3 via the subset of the SMTLIB 2.0 format we care about.

For example:

let cfg = Config::new();
let ctx = Context::new(cfg);
let mut solver = Solver::<B64>::new(&ctx);
// (declare-const v0 Bool)
solver.add(DeclareConst(x, Ty::Bool));
// (assert v0)
solver.add(Assert(Var(x)));
// (check-sat)
assert!(solver.check_sat() == SmtResult::Sat)

The other thing the Solver type does is maintain a trace of interactions with Z3, which can be checkpointed and replayed by another solver. This Checkpoint type is safe to be sent between threads.

For example:

let point = {
    let cfg = Config::new();
    let ctx = Context::new(cfg);
    let mut solver = Solver::<B64>::new(&ctx);
    solver.add(DeclareConst(x, Ty::Bool));
    solver.add(Assert(Var(x)));
    solver.add(Assert(Not(Box::new(Var(x)))));
    checkpoint(&mut solver)
};
let cfg = Config::new();
let ctx = Context::new(cfg);
let mut solver = Solver::from_checkpoint(&ctx, point);
assert!(solver.check_sat() == SmtResult::Unsat);

Implementations§

Source§

impl<'ctx, B: BV> Solver<'ctx, B>

Source

pub fn new(ctx: &'ctx Context) -> Self

Source

pub fn fresh(&mut self) -> Sym

Source

pub fn get_enum(&mut self, size: usize) -> usize

Source

pub fn length(&mut self, v: Sym) -> Option<u32>

Source

pub fn is_bitvector(&mut self, v: Sym) -> bool

Source

pub fn add(&mut self, def: Def)

Source

pub fn declare_const(&mut self, ty: Ty) -> Sym

Source

pub fn define_const(&mut self, exp: Exp) -> Sym

Source

pub fn assert_eq(&mut self, lhs: Exp, rhs: Exp)

Source

pub fn cycle_count(&mut self)

Source

pub fn get_cycle_count(&self) -> i128

Source

pub fn add_event(&mut self, event: Event<B>)

Source

pub fn from_checkpoint(ctx: &'ctx Context, _: Checkpoint<B>) -> Self

Source

pub fn check_sat_with(&mut self, exp: &Exp) -> SmtResult

Source

pub fn trace(&self) -> &Trace<B>

Source

pub fn check_sat(&mut self) -> SmtResult

Source

pub fn dump_solver(&mut self, filename: &str)

Source

pub fn dump_solver_with(&mut self, filename: &str, exp: &Exp)

Source

pub fn exp_to_str(&mut self, exp: &Exp) -> String

Trait Implementations§

Source§

impl<'ctx, B> Drop for Solver<'ctx, B>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'ctx, B> Freeze for Solver<'ctx, B>

§

impl<'ctx, B> RefUnwindSafe for Solver<'ctx, B>
where B: RefUnwindSafe,

§

impl<'ctx, B> !Send for Solver<'ctx, B>

§

impl<'ctx, B> !Sync for Solver<'ctx, B>

§

impl<'ctx, B> Unpin for Solver<'ctx, B>
where B: Unpin,

§

impl<'ctx, B> UnwindSafe for Solver<'ctx, B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.