refactor: make proof production lazy

This commit is contained in:
Simon Cruanes 2021-03-19 17:26:30 -04:00
parent d665f83c65
commit 3aadb055b6
3 changed files with 13 additions and 11 deletions

View file

@ -698,7 +698,7 @@ module type SOLVER = sig
type res =
| Sat of Model.t
| Unsat of {
proof: proof option;
proof: proof option lazy_t;
unsat_core: Atom.t list lazy_t;
}
| Unknown of Unknown.t

View file

@ -593,7 +593,7 @@ module Make(A : ARG)
type res =
| Sat of Model.t
| Unsat of {
proof: proof option;
proof: proof option lazy_t;
unsat_core: Atom.t list lazy_t;
}
| Unknown of Unknown.t
@ -653,13 +653,13 @@ module Make(A : ARG)
do_on_exit ();
Sat m
| Sat_solver.Unsat us ->
let proof =
let proof = lazy (
try
let pr = us.get_proof () in
if check then Sat_solver.Proof.check pr;
Some pr
with Msat.Solver_intf.No_proof -> None
in
) in
let unsat_core = lazy (us.Msat.unsat_assumptions ()) in
do_on_exit ();
Unsat {proof; unsat_core}

View file

@ -178,15 +178,16 @@ let solve
*)
let t3 = Sys.time () -. t2 in
Format.printf "Sat (%.3f/%.3f/%.3f)@." t1 (t2-.t1) t3;
| Solver.Unsat {proof=None;_} ->
Format.printf "Unsat (%.3f/%.3f/-)@." t1 (t2-.t1);
| Solver.Unsat {proof=Some p;_} ->
| Solver.Unsat {proof;_} ->
if check then (
Profile.with_ "unsat.check" (fun () -> Solver.Proof.check p);
match proof with
| lazy (Some p) ->
Profile.with_ "unsat.check" (fun () -> Solver.Proof.check p);
| _ -> ()
);
begin match dot_proof with
| None -> ()
| Some file ->
begin match dot_proof, proof with
| None, _ -> ()
| Some file, lazy (Some p) ->
Profile.with_ "dot.proof" @@ fun () ->
CCIO.with_out file
(fun oc ->
@ -194,6 +195,7 @@ let solve
let fmt = Format.formatter_of_out_channel oc in
Solver.Proof.pp_dot fmt p;
Format.pp_print_flush fmt (); flush oc)
| _ -> ()
end;
let t3 = Sys.time () -. t2 in
Format.printf "Unsat (%.3f/%.3f/%.3f)@." t1 (t2-.t1) t3;