11//! Not a SAT solver, but a prover. There's a difference.
22use thiserror:: Error ;
33
4- use std:: { collections:: VecDeque , env, fmt:: Display , io:: { self , Write } , path:: Path , process:: { self , Command } , time:: Duration } ;
4+ use std:: {
5+ collections:: VecDeque ,
6+ env,
7+ fmt:: Display ,
8+ io:: { self , Write } ,
9+ path:: Path ,
10+ process:: { self , Command } ,
11+ time:: Duration ,
12+ } ;
513
614use tempfile:: NamedTempFile ;
715
@@ -23,6 +31,7 @@ pub enum CommandError {
2331 #[ error( "Process execution failed: {0}" ) ]
2432 ProcessError ( #[ from] io:: Error ) ,
2533}
34+
2635pub enum SolverType {
2736 Z3 ,
2837 SWINE ,
@@ -37,13 +46,11 @@ pub enum ProveResult<'ctx> {
3746}
3847
3948/// Execute swine-z3 on the file located at file_path
40- fn execute_swine ( file_path : & Path ) -> Result < SatResult , CommandError > {
49+ fn execute_swine ( file_path : & Path ) -> Result < SatResult , CommandError > {
4150 match env:: var ( "SWINE" ) {
4251 // Use "export SWINE=<path_for_swine>" to set the path for swine in the SWINE variable.
4352 Ok ( swine) => {
44- let output = Command :: new ( swine)
45- . arg ( file_path)
46- . output ( ) ;
53+ let output = Command :: new ( swine) . arg ( file_path) . output ( ) ;
4754
4855 match output {
4956 Ok ( output) => {
@@ -57,18 +64,14 @@ fn execute_swine(file_path: &Path) -> Result<SatResult, CommandError>{
5764 Ok ( SatResult :: Unknown )
5865 }
5966 }
60- Err ( e) => {
61- Err ( CommandError :: ProcessError ( e) )
62- }
67+ Err ( e) => Err ( CommandError :: ProcessError ( e) ) ,
6368 }
6469 }
65- Err ( e) => {
66- Err ( CommandError :: EnvVarError ( e) )
67- }
70+ Err ( e) => Err ( CommandError :: EnvVarError ( e) ) ,
6871 }
6972}
7073
71- /// In order to execute the program, it is necessary to remove lines that
74+ /// In order to execute the program, it is necessary to remove lines that
7275/// contain a forall quantifier or the declaration of the exponential function (exp).
7376fn remove_lines_for_swine ( input : & str ) -> String {
7477 let mut output = String :: new ( ) ;
@@ -167,7 +170,11 @@ impl<'ctx> Prover<'ctx> {
167170
168171 /// Do the SAT check, but consider a check with no provables to be a
169172 /// [`ProveResult::Proof`].
170- pub fn check_proof_assuming ( & mut self , assumptions : & [ Bool < ' ctx > ] , solver_type : SolverType ) -> ProveResult < ' ctx > {
173+ pub fn check_proof_assuming (
174+ & mut self ,
175+ assumptions : & [ Bool < ' ctx > ] ,
176+ solver_type : SolverType ,
177+ ) -> ProveResult < ' ctx > {
171178 if self . min_level_with_provables . is_none ( ) {
172179 return ProveResult :: Proof ;
173180 }
@@ -180,9 +187,11 @@ impl<'ctx> Prover<'ctx> {
180187 smtlib. add_check_sat ( ) ;
181188 let smtlib = smtlib. into_string ( ) ;
182189 let mut smt_file: NamedTempFile = NamedTempFile :: new ( ) . unwrap ( ) ;
183- smt_file. write_all ( remove_lines_for_swine ( & smtlib) . as_bytes ( ) ) . unwrap ( ) ;
190+ smt_file
191+ . write_all ( remove_lines_for_swine ( & smtlib) . as_bytes ( ) )
192+ . unwrap ( ) ;
184193 let file_path = smt_file. path ( ) ;
185-
194+
186195 res = execute_swine ( file_path) . unwrap_or_else ( |e| {
187196 eprintln ! ( "{}" , e) ;
188197 process:: exit ( 1 )
@@ -192,7 +201,7 @@ impl<'ctx> Prover<'ctx> {
192201 SatResult :: Unknown => {
193202 // TODO: Determine the correct reason for Unknown
194203 ProveResult :: Unknown ( ReasonUnknown :: Other ( "unknown" . to_string ( ) ) )
195- } ,
204+ }
196205 SatResult :: Sat => {
197206 // TODO: Get the model from the output of SWINE
198207 println ! ( "The Result of SWINE: sat" ) ;
0 commit comments