feat: embed micro theories in theories, fix th-distinct

This commit is contained in:
Simon Cruanes 2019-03-22 20:37:30 -05:00
parent 14992f07ec
commit 632bec0e66
3 changed files with 18 additions and 6 deletions

View file

@ -80,6 +80,8 @@ module type S = sig
val pop_levels : t -> int -> unit val pop_levels : t -> int -> unit
val cc_th : t -> CC.Theory.t list
(**/**) (**/**)
val check_invariants : t -> unit val check_invariants : t -> unit
(**/**) (**/**)
@ -98,6 +100,7 @@ let make
?(mk_model=fun _ _ m -> m) ?(mk_model=fun _ _ m -> m)
?(push_level=fun _ -> ()) ?(push_level=fun _ -> ())
?(pop_levels=fun _ _ -> ()) ?(pop_levels=fun _ _ -> ())
?(cc_th=fun _->[])
~name ~name
~final_check ~final_check
~create ~create
@ -114,5 +117,6 @@ let make
let check_invariants = check_invariants let check_invariants = check_invariants
let push_level = push_level let push_level = push_level
let pop_levels = pop_levels let pop_levels = pop_levels
let cc_th = cc_th
end in end in
(module A : S) (module A : S)

View file

@ -154,6 +154,8 @@ let (module Th) = th in
Log.debugf 2 Log.debugf 2
(fun k-> k "(@[th_combine.add_th@ :name %S@])" Th.name); (fun k-> k "(@[th_combine.add_th@ :name %S@])" Th.name);
let st = Th.create self.tst in let st = Th.create self.tst in
(* add micro theories *)
List.iter (CC.add_th (cc self)) (Th.cc_th st);
(* re-pack as a [Theory.t1] *) (* re-pack as a [Theory.t1] *)
self.theories <- (Th_state ((module Th),st)) :: self.theories self.theories <- (Th_state ((module Th),st)) :: self.theories

View file

@ -45,19 +45,19 @@ module Make(A : ARG with type Lit.t = Sidekick_smt.Lit.t
type lit = A.Lit.t type lit = A.Lit.t
type data = term IM.t (* "distinct" lit -> term appearing under it*) type data = term IM.t (* "distinct" lit -> term appearing under it*)
let pp_data out m =
Fmt.fprintf out
"{@[%a@]}" Fmt.(seq ~sep:(return ",@ ") @@ pair Lit.pp T.pp) (IM.to_seq m)
let key : (term,lit,data) Sidekick_cc.Key.t = let key : (term,lit,data) Sidekick_cc.Key.t =
let merge m1 m2 = let merge m1 m2 =
IM.merge_safe m1 m2 IM.merge_safe m1 m2
~f:(fun _ pair -> match pair with ~f:(fun _ pair -> match pair with
| `Left x | `Right x -> Some x | `Left x | `Right x -> Some x
| `Both (x,_) -> Some x) | `Both (x,_) -> Some x)
and eq = IM.equal T.equal and eq = IM.equal T.equal in
and pp out m =
Fmt.fprintf out
"{@[%a@]}" Fmt.(seq ~sep:(return ",@ ") @@ pair Lit.pp T.pp) (IM.to_seq m)
in
Sidekick_cc.Key.create Sidekick_cc.Key.create
~pp ~pp:pp_data
~name:"distinct" ~name:"distinct"
~merge ~eq () ~merge ~eq ()
@ -69,6 +69,9 @@ module Make(A : ARG with type Lit.t = Sidekick_smt.Lit.t
exception E_exit exception E_exit
let on_merge cc n1 m1 n2 m2 expl12 = let on_merge cc n1 m1 n2 m2 expl12 =
Log.debugf 5
(fun k->k "(@[th_distinct.on_merge@ @[:n1 %a@ :map2 %a@]@ @[:n2 %a@ :map2 %a@]@])"
CC.N.pp n1 pp_data m1 CC.N.pp n2 pp_data m2);
try try
let _i = let _i =
IM.merge IM.merge
@ -148,11 +151,14 @@ module Make(A : ARG with type Lit.t = Sidekick_smt.Lit.t
| None -> () | None -> ()
| Some subs -> process_lit st acts lit t subs) | Some subs -> process_lit st acts lit t subs)
let cc_th = let module T = Micro(CC) in T.th
let th = let th =
Sidekick_smt.Theory.make Sidekick_smt.Theory.make
~name:"distinct" ~name:"distinct"
~partial_check ~partial_check
~final_check:(fun _ _ _ -> ()) ~final_check:(fun _ _ _ -> ())
~cc_th:(fun _ -> [cc_th])
~create () ~create ()
end end