wip: make it compile

This commit is contained in:
Simon Cruanes 2022-08-08 21:52:47 -04:00
parent 7d59846d72
commit fc5ce9bf87
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
12 changed files with 29 additions and 41 deletions

View file

@ -69,8 +69,6 @@ type t = {
count_solve: int Stat.counter; (* config: Config.t *) count_solve: int Stat.counter; (* config: Config.t *)
} }
type solver = t
(** {2 Main} *) (** {2 Main} *)
type theory = Theory.t type theory = Theory.t
@ -117,7 +115,6 @@ let create arg ?(stat = Stat.global) ?size ~proof ~theories tst () : t =
self self
let[@inline] solver self = self.solver let[@inline] solver self = self.solver
let[@inline] cc self = Solver_internal.cc self.si
let[@inline] stats self = self.stat let[@inline] stats self = self.stat
let[@inline] tst self = Solver_internal.tst self.si let[@inline] tst self = Solver_internal.tst self.si
let[@inline] proof self = self.proof let[@inline] proof self = self.proof

View file

@ -14,6 +14,8 @@ type t
val registry : t -> Registry.t val registry : t -> Registry.t
(** A solver contains a registry so that theories can share data *) (** A solver contains a registry so that theories can share data *)
type theory = Theory.t
val mk_theory : val mk_theory :
name:string -> name:string ->
create_and_setup:(Solver_internal.t -> 'th) -> create_and_setup:(Solver_internal.t -> 'th) ->

View file

@ -1,8 +1,8 @@
(** {2 Conversion into {!Term.t}} *) (** {2 Conversion into {!Term.t}} *)
open Sidekick_core
module Profile = Sidekick_util.Profile module Profile = Sidekick_util.Profile
open! Sidekick_base open! Sidekick_base
module SBS = Sidekick_base_solver
[@@@ocaml.warning "-32"] [@@@ocaml.warning "-32"]
@ -10,12 +10,11 @@ type 'a or_error = ('a, string) CCResult.t
module E = CCResult module E = CCResult
module Fmt = CCFormat module Fmt = CCFormat
module Solver = SBS.Solver module Solver = Sidekick_smt_solver.Solver
module Check_cc = struct module Check_cc = struct
module Lit = Solver.Solver_internal.Lit module SI = Sidekick_smt_solver.Solver_internal
module SI = Solver.Solver_internal module MCC = Sidekick_mini_cc
module MCC = Sidekick_mini_cc.Make (SBS.Solver_arg)
let pp_c out c = Fmt.fprintf out "(@[%a@])" (Util.pp_list ~sep:" " Lit.pp) c let pp_c out c = Fmt.fprintf out "(@[%a@])" (Util.pp_list ~sep:" " Lit.pp) c
@ -30,7 +29,7 @@ module Check_cc = struct
let check_conflict si _cc (confl : Lit.t list) : unit = let check_conflict si _cc (confl : Lit.t list) : unit =
Log.debugf 15 (fun k -> k "(@[check-cc-conflict@ %a@])" pp_c confl); Log.debugf 15 (fun k -> k "(@[check-cc-conflict@ %a@])" pp_c confl);
let tst = SI.tst si in let tst = SI.tst si in
let cc = MCC.create tst in let cc = MCC.create_default tst in
(* add [¬confl] and check it's unsat *) (* add [¬confl] and check it's unsat *)
List.iter (fun lit -> add_cc_lit cc @@ Lit.neg lit) confl; List.iter (fun lit -> add_cc_lit cc @@ Lit.neg lit) confl;
if MCC.check_sat cc then if MCC.check_sat cc then
@ -46,7 +45,7 @@ module Check_cc = struct
Log.debugf 15 (fun k -> Log.debugf 15 (fun k ->
k "(@[check-cc-prop@ %a@ :reason %a@])" Lit.pp p pp_and reason); k "(@[check-cc-prop@ %a@ :reason %a@])" Lit.pp p pp_and reason);
let tst = SI.tst si in let tst = SI.tst si in
let cc = MCC.create tst in let cc = MCC.create_default tst in
(* add [reason & ¬lit] and check it's unsat *) (* add [reason & ¬lit] and check it's unsat *)
List.iter (add_cc_lit cc) reason; List.iter (add_cc_lit cc) reason;
add_cc_lit cc (Lit.neg p); add_cc_lit cc (Lit.neg p);
@ -62,10 +61,8 @@ module Check_cc = struct
let theory = let theory =
Solver.mk_theory ~name:"cc-check" Solver.mk_theory ~name:"cc-check"
~create_and_setup:(fun si -> ~create_and_setup:(fun si ->
let n_calls = let n_calls = Stat.mk_int (SI.stats si) "check-cc.call" in
Stat.mk_int (Solver.Solver_internal.stats si) "check-cc.call" SI.on_cc_conflict si (fun { cc; th; c } ->
in
Solver.Solver_internal.on_cc_conflict si (fun { cc; th; c } ->
if not th then ( if not th then (
Stat.incr n_calls; Stat.incr n_calls;
check_conflict si cc c check_conflict si cc c
@ -184,7 +181,7 @@ let solve ?gc:_ ?restarts:_ ?proof_file ?(pp_model = false) ?(check = false)
| Solver.Sat m -> | Solver.Sat m ->
if pp_model then if pp_model then
(* TODO: use actual {!Model} in the solver? or build it afterwards *) (* TODO: use actual {!Model} in the solver? or build it afterwards *)
Format.printf "(@[<hv1>model@ %a@])@." Solver.Model.pp m; Format.printf "(@[<hv1>model@ %a@])@." Sidekick_smt_solver.Model.pp m;
(* TODO (* TODO
if check then ( if check then (
Solver.check_model s; Solver.check_model s;
@ -210,12 +207,16 @@ let solve ?gc:_ ?restarts:_ ?proof_file ?(pp_model = false) ?(check = false)
| Some step_id -> | Some step_id ->
let proof = Solver.proof s in let proof = Solver.proof s in
let proof_quip = let proof_quip =
Profile.with_ "proof.to-quip" @@ fun () -> Profile.with_ "proof.to-quip" @@ fun () -> assert false
Proof_quip.of_proof proof ~unsat:step_id (* TODO
Proof_quip.of_proof proof ~unsat:step_id
*)
in in
Profile.with_ "proof.write-file" @@ fun () -> Profile.with_ "proof.write-file" @@ fun () ->
with_file_out file @@ fun oc -> with_file_out file @@ fun oc ->
Proof_quip.output oc proof_quip; (* TODO
Proof_quip.output oc proof_quip;
*)
flush oc) flush oc)
| _ -> ()); | _ -> ());
@ -248,7 +249,7 @@ let process_stmt ?gc ?restarts ?(pp_cnf = false) ?proof_file ?pp_model
(* TODO: more? *) (* TODO: more? *)
in in
let add_step r = Solver.Proof_trace.add_step (Solver.proof solver) r in let add_step r = Proof_trace.add_step (Solver.proof solver) r in
match stmt with match stmt with
| Statement.Stmt_set_logic logic -> | Statement.Stmt_set_logic logic ->
@ -283,7 +284,7 @@ let process_stmt ?gc ?restarts ?(pp_cnf = false) ?proof_file ?pp_model
if pp_cnf then Format.printf "(@[<hv1>assert@ %a@])@." Term.pp t; if pp_cnf then Format.printf "(@[<hv1>assert@ %a@])@." Term.pp t;
let lit = Solver.mk_lit_t solver t in let lit = Solver.mk_lit_t solver t in
Solver.add_clause solver [| lit |] Solver.add_clause solver [| lit |]
(add_step @@ Proof.Rule_sat.sat_input_clause (Iter.singleton lit)); (add_step @@ fun () -> Proof_sat.sat_input_clause [ lit ]);
E.return () E.return ()
| Statement.Stmt_assert_clause c_ts -> | Statement.Stmt_assert_clause c_ts ->
if pp_cnf then if pp_cnf then
@ -293,16 +294,16 @@ let process_stmt ?gc ?restarts ?(pp_cnf = false) ?proof_file ?pp_model
(* proof of assert-input + preprocessing *) (* proof of assert-input + preprocessing *)
let pr = let pr =
let tst = Solver.tst solver in add_step @@ fun () ->
let lits = Iter.of_list c_ts |> Iter.map (Lit.atom tst) in let lits = List.map Lit.atom c_ts in
add_step @@ Proof.Rule_sat.sat_input_clause lits Proof_sat.sat_input_clause lits
in in
Solver.add_clause solver (CCArray.of_list c) pr; Solver.add_clause solver (CCArray.of_list c) pr;
E.return () E.return ()
| Statement.Stmt_get_model -> | Statement.Stmt_get_model ->
(match Solver.last_res solver with (match Solver.last_res solver with
| Some (Solver.Sat m) -> Fmt.printf "%a@." Solver.Model.pp m | Some (Solver.Sat m) -> Fmt.printf "%a@." Sidekick_smt_solver.Model.pp m
| _ -> Error.errorf "cannot access model"); | _ -> Error.errorf "cannot access model");
E.return () E.return ()
| Statement.Stmt_get_value l -> | Statement.Stmt_get_value l ->
@ -311,7 +312,7 @@ let process_stmt ?gc ?restarts ?(pp_cnf = false) ?proof_file ?pp_model
let l = let l =
List.map List.map
(fun t -> (fun t ->
match Solver.Model.eval m t with match Sidekick_smt_solver.Model.eval m t with
| None -> Error.errorf "cannot evaluate %a" Term.pp t | None -> Error.errorf "cannot evaluate %a" Term.pp t
| Some u -> t, u) | Some u -> t, u)
l l

View file

@ -1,14 +1,7 @@
(** {1 Process Statements} *) (** {1 Process Statements} *)
open Sidekick_base open Sidekick_base
module Solver = Sidekick_smt_solver.Solver
module Solver :
Sidekick_smt_solver.S
with type T.Term.t = Term.t
and type T.Term.store = Term.store
and type T.Ty.t = Ty.t
and type T.Ty.store = Ty.store
and type Proof_trace.t = Proof.t
val th_bool : Solver.theory val th_bool : Solver.theory
val th_data : Solver.theory val th_data : Solver.theory

View file

@ -2,5 +2,5 @@
(name sidekick_smtlib) (name sidekick_smtlib)
(public_name sidekick-bin.smtlib) (public_name sidekick-bin.smtlib)
(libraries containers zarith sidekick.core sidekick.util sidekick-base (libraries containers zarith sidekick.core sidekick.util sidekick-base
smtlib-utils sidekick.tef) sidekick.mini-cc smtlib-utils sidekick.tef)
(flags :standard -warn-error -a+8 -open Sidekick_util)) (flags :standard -warn-error -a+8 -open Sidekick_util))

View file

@ -3,7 +3,7 @@
(modules run_tests) (modules run_tests)
(modes native) (modes native)
(libraries containers alcotest qcheck sidekick.util sidekick_test_simplex (libraries containers alcotest qcheck sidekick.util sidekick_test_simplex
sidekick_test_util sidekick_test_minicc) sidekick_test_util)
(flags :standard -warn-error -a+8 -color always)) (flags :standard -warn-error -a+8 -color always))
(rule (rule

View file

@ -1,10 +1,5 @@
let tests : unit Alcotest.test list = let tests : unit Alcotest.test list =
List.flatten List.flatten @@ [ [ Sidekick_test_simplex.tests ]; Sidekick_test_util.tests ]
@@ [
[ Sidekick_test_simplex.tests ];
[ Sidekick_test_minicc.tests ];
Sidekick_test_util.tests;
]
let props = let props =
List.flatten [ Sidekick_test_simplex.props; Sidekick_test_util.props ] List.flatten [ Sidekick_test_simplex.props; Sidekick_test_util.props ]