Skip to content

Commit 9a0db09

Browse files
committed
Add SolverType attribute to Prover struct and SMT solver options
1 parent 9120d44 commit 9a0db09

File tree

8 files changed

+49
-21
lines changed

8 files changed

+49
-21
lines changed

src/driver.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use crate::{
5353
vcgen::Vcgen,
5454
},
5555
version::write_detailed_version_info,
56-
DebugOptions, SliceOptions, SliceVerifyMethod, VerifyCommand, VerifyError,
56+
DebugOptions, SliceOptions, SliceVerifyMethod, VerifyCommand, VerifyError, SMTSolverType,
5757
};
5858

5959
use ariadne::ReportKind;
@@ -64,7 +64,7 @@ use z3::{
6464
};
6565
use z3rro::{
6666
probes::ProbeSummary,
67-
prover::{ProveResult, Prover},
67+
prover::{ProveResult, Prover, SolverType},
6868
smtlib::Smtlib,
6969
util::{PrefixWriter, ReasonUnknown},
7070
};
@@ -695,7 +695,7 @@ impl<'ctx> SmtVcUnit<'ctx> {
695695
let span = info_span!("SAT check");
696696
let _entered = span.enter();
697697

698-
let prover = mk_valid_query_prover(limits_ref, ctx, translate, &self.vc);
698+
let prover = mk_valid_query_prover(limits_ref, ctx, translate, &self.vc, options.smt_solver_options.smt_solver);
699699

700700
if options.debug_options.probe {
701701
let goal = Goal::new(ctx, false, false, false);
@@ -797,9 +797,15 @@ fn mk_valid_query_prover<'smt, 'ctx>(
797797
ctx: &'ctx Context,
798798
smt_translate: &TranslateExprs<'smt, 'ctx>,
799799
valid_query: &Bool<'ctx>,
800+
smt_solver: SMTSolverType,
800801
) -> Prover<'ctx> {
802+
let solver_type = match smt_solver {
803+
SMTSolverType::Swine => SolverType::SWINE,
804+
SMTSolverType::Z3 => SolverType::Z3,
805+
};
806+
801807
// create the prover and set the params
802-
let mut prover = Prover::new(ctx);
808+
let mut prover = Prover::new(ctx, solver_type);
803809
if let Some(remaining) = limits_ref.time_left() {
804810
prover.set_timeout(remaining);
805811
}

src/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ pub struct VerifyCommand {
138138

139139
#[command(flatten)]
140140
pub debug_options: DebugOptions,
141+
142+
#[command(flatten)]
143+
pub smt_solver_options: SMTSolverOptions,
141144
}
142145

143146
#[derive(Debug, Args)]
@@ -376,6 +379,22 @@ pub struct DebugOptions {
376379
pub probe: bool,
377380
}
378381

382+
#[derive(Debug, Default, Args)]
383+
#[command(next_help_heading = "SMT Solver Options")]
384+
pub struct SMTSolverOptions {
385+
#[arg(long, default_value = "z3")]
386+
pub smt_solver: SMTSolverType,
387+
}
388+
389+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, ValueEnum)]
390+
pub enum SMTSolverType {
391+
#[default]
392+
#[value(name = "z3")]
393+
Z3,
394+
#[value(name = "swine")]
395+
Swine,
396+
}
397+
379398
#[derive(Debug, Default, Args)]
380399
#[command(next_help_heading = "Slicing Options")]
381400
pub struct SliceOptions {

src/opt/fuzz_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use proptest::{
22
prelude::*,
33
test_runner::{TestCaseResult, TestRunner},
44
};
5-
use z3rro::prover::{ProveResult, Prover};
5+
use z3rro::prover::{ProveResult, Prover, SolverType};
66

77
use crate::{
88
ast::{
@@ -201,7 +201,7 @@ fn prove_equiv(expr: Expr, optimized: Expr, tcx: &TyCtx) -> TestCaseResult {
201201
let smt_ctx = SmtCtx::new(&ctx, tcx);
202202
let mut translate = TranslateExprs::new(&smt_ctx);
203203
let eq_expr_z3 = translate.t_bool(&eq_expr);
204-
let mut prover = Prover::new(&ctx);
204+
let mut prover = Prover::new(&ctx, SolverType::Z3);
205205
translate
206206
.local_scope()
207207
.add_assumptions_to_prover(&mut prover);

src/opt/unfolder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use std::ops::DerefMut;
2626

2727
use z3::SatResult;
28-
use z3rro::prover::Prover;
28+
use z3rro::prover::{Prover, SolverType};
2929

3030
use crate::{
3131
ast::{
@@ -63,7 +63,7 @@ impl<'smt, 'ctx> Unfolder<'smt, 'ctx> {
6363
limits_ref: limits_ref.clone(),
6464
subst: Subst::new(ctx.tcx(), &limits_ref),
6565
translate: TranslateExprs::new(ctx),
66-
prover: Prover::new(ctx.ctx()),
66+
prover: Prover::new(ctx.ctx(), SolverType::Z3),
6767
}
6868
}
6969

src/slicing/solver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<'ctx> SliceSolver<'ctx> {
229229
self.prover.add_assumption(&inactive_formula);
230230
let res = self
231231
.prover
232-
.check_proof_assuming(&active_toggle_values, z3rro::prover::SolverType::SWINE);
232+
.check_proof_assuming(&active_toggle_values);
233233

234234
let mut slice_searcher = SliceModelSearch::new(active_toggle_values.clone());
235235
if let ProveResult::Proof = res {
@@ -607,7 +607,7 @@ fn check_proof_seed<'ctx>(
607607
prover.set_timeout(timeout);
608608

609609
let seed: Vec<_> = seed.iter().cloned().collect();
610-
prover.check_proof_assuming(&seed, z3rro::prover::SolverType::SWINE)
610+
prover.check_proof_assuming(&seed)
611611
}
612612

613613
fn unsat_core_to_seed<'ctx>(

src/slicing/transform_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::time::{Duration, Instant};
55
use itertools::Itertools;
66
use z3rro::{
77
model::SmtEval,
8-
prover::{ProveResult, Prover},
8+
prover::{ProveResult, Prover, SolverType},
99
};
1010

1111
use crate::{
@@ -128,7 +128,7 @@ fn prove_equiv(
128128
let smt_ctx = SmtCtx::new(&ctx, tcx);
129129
let mut translate = TranslateExprs::new(&smt_ctx);
130130
let eq_expr_z3 = translate.t_bool(&eq_expr);
131-
let mut prover = Prover::new(&ctx);
131+
let mut prover = Prover::new(&ctx, SolverType::Z3);
132132
translate
133133
.local_scope()
134134
.add_assumptions_to_prover(&mut prover);

z3rro/src/prover.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub enum CommandError {
3232
ProcessError(#[from] io::Error),
3333
}
3434

35+
#[derive(Debug)]
3536
pub enum SolverType {
3637
Z3,
3738
SWINE,
@@ -127,15 +128,17 @@ pub struct Prover<'ctx> {
127128
level: usize,
128129
/// The minimum level where an assertion was added to the solver.
129130
min_level_with_provables: Option<usize>,
131+
smt_solver: SolverType
130132
}
131133

132134
impl<'ctx> Prover<'ctx> {
133135
/// Create a new prover with the given [`Context`].
134-
pub fn new(ctx: &'ctx Context) -> Self {
136+
pub fn new(ctx: &'ctx Context, solver_type:SolverType) -> Self {
135137
Prover {
136138
solver: Solver::new(ctx),
137139
level: 0,
138140
min_level_with_provables: None,
141+
smt_solver: solver_type,
139142
}
140143
}
141144

@@ -159,23 +162,22 @@ impl<'ctx> Prover<'ctx> {
159162
}
160163

161164
pub fn check_proof(&mut self) -> ProveResult<'ctx> {
162-
self.check_proof_assuming(&[], SolverType::SWINE)
165+
self.check_proof_assuming(&[])
163166
}
164167

165168
/// Do the SAT check, but consider a check with no provables to be a
166169
/// [`ProveResult::Proof`].
167170
pub fn check_proof_assuming(
168171
&mut self,
169172
assumptions: &[Bool<'ctx>],
170-
solver_type: SolverType,
171173
) -> ProveResult<'ctx> {
172174
if self.min_level_with_provables.is_none() {
173175
return ProveResult::Proof;
174176
}
175177

176178
let res;
177179

178-
match solver_type {
180+
match self.smt_solver {
179181
SolverType::SWINE => {
180182
let mut smtlib = self.get_smtlib();
181183
smtlib.add_check_sat();
@@ -198,7 +200,6 @@ impl<'ctx> Prover<'ctx> {
198200
}
199201
SatResult::Sat => {
200202
// TODO: Get the model from the output of SWINE
201-
println!("The Result of SWINE: sat");
202203
process::exit(1)
203204
}
204205
}
@@ -291,7 +292,7 @@ impl<'ctx> Prover<'ctx> {
291292
universal.iter().map(|v| v as &dyn Ast<'ctx>).collect();
292293
let assertions = self.solver.get_assertions();
293294
let theorem = forall_const(ctx, &universal, &[], &Bool::and(ctx, &assertions).not());
294-
let mut res = Prover::new(ctx);
295+
let mut res = Prover::new(ctx, SolverType::Z3);
295296
res.add_assumption(&theorem);
296297
res
297298
}
@@ -306,12 +307,14 @@ impl<'ctx> Prover<'ctx> {
306307
mod test {
307308
use z3::{ast::Bool, Config, Context, SatResult};
308309

310+
use crate::prover::SolverType;
311+
309312
use super::{ProveResult, Prover};
310313

311314
#[test]
312315
fn test_prover() {
313316
let ctx = Context::new(&Config::default());
314-
let mut prover = Prover::new(&ctx);
317+
let mut prover = Prover::new(&ctx, SolverType::Z3);
315318
assert!(matches!(prover.check_proof(), ProveResult::Proof));
316319
assert_eq!(prover.check_sat(), SatResult::Sat);
317320

z3rro/src/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use z3::{ast::Bool, Config, Context, SatResult};
66

7-
use crate::prover::{ProveResult, Prover};
7+
use crate::prover::{ProveResult, Prover, SolverType};
88

99
use super::scope::SmtScope;
1010

@@ -18,7 +18,7 @@ pub fn test_prove(f: impl for<'ctx> FnOnce(&'ctx Context, &mut SmtScope<'ctx>) -
1818
let mut scope = SmtScope::new();
1919
let theorem = f(&ctx, &mut scope);
2020

21-
let mut prover = Prover::new(&ctx);
21+
let mut prover = Prover::new(&ctx, SolverType::Z3);
2222
scope.add_assumptions_to_prover(&mut prover);
2323
assert_eq!(
2424
prover.check_sat(),

0 commit comments

Comments
 (0)