wip: cleanup cc

This commit is contained in:
Simon Cruanes 2019-02-22 18:54:56 -06:00
parent de1cc952a5
commit 77a5475862
4 changed files with 14 additions and 55 deletions

View file

@ -17,15 +17,12 @@ let field_usr2 = Bits.mk_field()
let () = Bits.freeze()
type payload = Congruence_closure_intf.payload = ..
module Make(A: ARG) = struct
type term = A.Term.t
type term_state = A.Term.state
type lit = A.Lit.t
type fun_ = A.Fun.t
type proof = A.Proof.t
type value = A.Value.t
type model = A.Model.t
(** Actions available to the theory *)
@ -47,7 +44,6 @@ module Make(A: ARG) = struct
mutable n_size: int; (* size of the class *)
mutable n_as_lit: lit option; (* TODO: put into payload? and only in root? *)
mutable n_expl: explanation_forest_link; (* the rooted forest for explanations *)
mutable n_payload: payload list; (* list of theory payloads *)
(* TODO: make a micro theory and move this inside *)
mutable n_tags: (node * explanation) Util.Int_map.t;
(* "distinct" tags (i.e. set of `(distinct t1…tn)` terms this belongs to *)
@ -81,7 +77,6 @@ module Make(A: ARG) = struct
let[@inline] equal (n1:t) n2 = T.equal n1.n_term n2.n_term
let[@inline] hash n = T.hash n.n_term
let[@inline] term n = n.n_term
let[@inline] payload n = n.n_payload
let[@inline] pp out n = T.pp out n.n_term
let[@inline] as_lit n = n.n_as_lit
@ -94,7 +89,6 @@ module Make(A: ARG) = struct
n_as_lit=None; (* TODO: provide a method to do it *)
n_root=n;
n_expl=FL_none;
n_payload=[];
n_next=n;
n_size=1;
n_tags=Util.Int_map.empty;
@ -120,35 +114,6 @@ module Make(A: ARG) = struct
assert (is_root n);
Bag.to_seq n.n_parents
type nonrec payload = payload = ..
let set_payload ?(can_erase=fun _->false) n e =
let rec aux = function
| [] -> [e]
| e' :: tail when can_erase e' -> e :: tail
| e' :: tail -> e' :: aux tail
in
n.n_payload <- aux n.n_payload
let payload_find ~f:p n =
let[@unroll 2] rec aux = function
| [] -> None
| e1 :: tail ->
match p e1 with
| Some _ as res -> res
| None -> aux tail
in
aux n.n_payload
let payload_pred ~f:p n =
begin match n.n_payload with
| [] -> false
| e :: _ when p e -> true
| _ :: e :: _ when p e -> true
| _ :: _ :: e :: _ when p e -> true
| l -> List.exists p l
end
let[@inline] get_field f t = Bits.get f t.n_bits
let[@inline] set_field f b t = t.n_bits <- Bits.set f b t.n_bits
end

View file

@ -3,8 +3,6 @@
module type ARG = Congruence_closure_intf.ARG
module type S = Congruence_closure_intf.S
type payload = Congruence_closure_intf.payload = ..
module Make(A: ARG)
: S with type term = A.Term.t
and type lit = A.Lit.t

View file

@ -1,10 +1,7 @@
module type ARG = CC_types.FULL
(** Theory-extensible payloads in the equivalence classes *)
type payload = ..
module type S = sig
module type S0 = sig
type term_state
type term
type fun_
@ -53,24 +50,18 @@ module type S = sig
val iter_parents : t -> t Sequence.t
(** Traverse the parents of the class.
Invariant: [is_root n] (see {!find} below) *)
type nonrec payload = payload = ..
val payload_find: f:(payload -> 'a option) -> t -> 'a option
val payload_pred: f:(payload -> bool) -> t -> bool
val set_payload : ?can_erase:(payload -> bool) -> t -> payload -> unit
(** Add given payload
@param can_erase if provided, checks whether an existing value
is to be replaced instead of adding a new entry *)
end
module Expl : sig
type t
val pp : t Fmt.printer
(* TODO: expose constructors for micro theories to use *)
val mk_reduction : t
val mk_congruence : N.t -> N.t -> t
val mk_merge : N.t -> N.t -> t
val mk_merges : (N.t * N.t) list -> t
val mk_lit : lit -> t
val mk_lits : lit list -> t
end
type node = N.t
@ -150,3 +141,10 @@ module type S = sig
val pp_full : t Fmt.printer
(**/**)
end
module type S = sig
include S0
end

View file

@ -7,8 +7,6 @@ type ('f, 't, 'ts) view = ('f, 't, 'ts) CC_types.view =
| Eq of 't * 't
| Opaque of 't (* do not enter *)
type payload = Congruence_closure.payload = ..
module CC_types = CC_types
(** Parameter for the congruence closure *)