mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 11:15:43 -05:00
feat(const): add opaque_to_cc property, to control CC
This commit is contained in:
parent
4dca7df629
commit
80b08e03cb
15 changed files with 43 additions and 3 deletions
|
|
@ -165,6 +165,8 @@ end = struct
|
||||||
| Cell_is a, Cell_is b ->
|
| Cell_is a, Cell_is b ->
|
||||||
a.x = b.x && a.y = b.y && Cell.equal a.value b.value
|
a.x = b.x && a.y = b.y && Cell.equal a.value b.value
|
||||||
| _ -> false
|
| _ -> false
|
||||||
|
|
||||||
|
let opaque_to_cc _ = false
|
||||||
end : Const.DYN_OPS)
|
end : Const.DYN_OPS)
|
||||||
|
|
||||||
module Sat = Sidekick_sat
|
module Sat = Sidekick_sat
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,8 @@ let ops =
|
||||||
| Select s -> Hash.combine2 594 (Select.hash s)
|
| Select s -> Hash.combine2 594 (Select.hash s)
|
||||||
| Is_a c -> Hash.combine2 595 (Cstor.hash c)
|
| Is_a c -> Hash.combine2 595 (Cstor.hash c)
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
|
|
||||||
|
let opaque_to_cc _ = false
|
||||||
end : Const.DYN_OPS)
|
end : Const.DYN_OPS)
|
||||||
|
|
||||||
let data tst d : Term.t =
|
let data tst d : Term.t =
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ let ops : Const.ops =
|
||||||
| C_or -> Hash.int 426
|
| C_or -> Hash.int 426
|
||||||
| C_imply -> Hash.int 427
|
| C_imply -> Hash.int 427
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
|
|
||||||
|
let opaque_to_cc _ = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
(* ### view *)
|
(* ### view *)
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,8 @@ let ops : Const.ops =
|
||||||
| Op o -> Op.hash o
|
| Op o -> Op.hash o
|
||||||
| Mult_by q -> Hash.(combine2 135 (Sidekick_zarith.Rational.hash q))
|
| Mult_by q -> Hash.(combine2 135 (Sidekick_zarith.Rational.hash q))
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
|
|
||||||
|
let opaque_to_cc _ = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
let real tst = Ty.real tst
|
let real tst = Ty.real tst
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ let ops_ty : Const.ops =
|
||||||
| Ty_int -> Hash.int 3
|
| Ty_int -> Hash.int 3
|
||||||
| Ty_uninterpreted u -> Hash.combine2 10 (ID.hash u.id))
|
| Ty_uninterpreted u -> Hash.combine2 10 (ID.hash u.id))
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
|
|
||||||
|
let opaque_to_cc _ = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
open struct
|
open struct
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ let ops =
|
||||||
let hash = function
|
let hash = function
|
||||||
| Uconst c -> Hash.combine2 522660 (hash c)
|
| Uconst c -> Hash.combine2 522660 (hash c)
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
|
|
||||||
|
let opaque_to_cc _ = false
|
||||||
end : Const.DYN_OPS)
|
end : Const.DYN_OPS)
|
||||||
|
|
||||||
let[@inline] make uc_id uc_ty : t = { uc_id; uc_ty }
|
let[@inline] make uc_id uc_ty : t = { uc_id; uc_ty }
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ module type DYN_OPS = sig
|
||||||
val pp : view Fmt.printer
|
val pp : view Fmt.printer
|
||||||
val equal : view -> view -> bool
|
val equal : view -> view -> bool
|
||||||
val hash : view -> int
|
val hash : view -> int
|
||||||
|
val opaque_to_cc : view -> bool
|
||||||
end
|
end
|
||||||
|
|
||||||
type ops = (module DYN_OPS)
|
type ops = (module DYN_OPS)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ module type DYN_OPS = sig
|
||||||
val pp : view Fmt.printer
|
val pp : view Fmt.printer
|
||||||
val equal : view -> view -> bool
|
val equal : view -> view -> bool
|
||||||
val hash : view -> int
|
val hash : view -> int
|
||||||
|
val opaque_to_cc : view -> bool
|
||||||
end
|
end
|
||||||
|
|
||||||
type ops = (module DYN_OPS)
|
type ops = (module DYN_OPS)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ let ops : Const.ops =
|
||||||
let hash = function
|
let hash = function
|
||||||
| Str s -> CCHash.string s
|
| Str s -> CCHash.string s
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
|
|
||||||
|
let opaque_to_cc _ = false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
let make name ~ty : Const.t = Const.make (Str name) ops ~ty
|
let make name ~ty : Const.t = Const.make (Str name) ops ~ty
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ let ops : const_ops =
|
||||||
| C_true -> Fmt.string out "true"
|
| C_true -> Fmt.string out "true"
|
||||||
| C_false -> Fmt.string out "false"
|
| C_false -> Fmt.string out "false"
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
|
|
||||||
|
let opaque_to_cc _ = false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
let bool store = const store @@ Const.make C_bool ops ~ty:(type_ store)
|
let bool store = const store @@ Const.make C_bool ops ~ty:(type_ store)
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,15 @@ type const_view = ..
|
||||||
|
|
||||||
module type DYN_CONST_OPS = sig
|
module type DYN_CONST_OPS = sig
|
||||||
val pp : const_view Fmt.printer
|
val pp : const_view Fmt.printer
|
||||||
|
(** Pretty-print constant *)
|
||||||
val equal : const_view -> const_view -> bool
|
val equal : const_view -> const_view -> bool
|
||||||
|
(** Equality of constant with any other constant *)
|
||||||
val hash : const_view -> int
|
val hash : const_view -> int
|
||||||
|
(** Hash constant *)
|
||||||
|
val opaque_to_cc : const_view -> bool
|
||||||
|
(** If true, congruence closure will not apply for applications of this
|
||||||
|
constant. In other words, [c t1…tn] will appear to the congruence
|
||||||
|
closure as a single opaque term with no subterms. *)
|
||||||
end
|
end
|
||||||
|
|
||||||
type const_ops = (module DYN_CONST_OPS)
|
type const_ops = (module DYN_CONST_OPS)
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,14 @@ let view_as_cc (t : Term.t) : _ CC_view.t =
|
||||||
| Term.E_const { Const.c_view = T_builtins.C_ite; _ }, [ _ty; a; b; c ] ->
|
| Term.E_const { Const.c_view = T_builtins.C_ite; _ }, [ _ty; a; b; c ] ->
|
||||||
View.If (a, b, c)
|
View.If (a, b, c)
|
||||||
| Term.E_const { Const.c_view = T_builtins.C_not; _ }, [ a ] -> View.Not a
|
| Term.E_const { Const.c_view = T_builtins.C_not; _ }, [ a ] -> View.Not a
|
||||||
|
| Term.E_const { Const.c_ops = (module OP); c_view; _ }, _
|
||||||
|
when OP.opaque_to_cc c_view ->
|
||||||
|
(* this constant hides its arguments *)
|
||||||
|
View.Opaque t
|
||||||
| _ ->
|
| _ ->
|
||||||
(match Term.view t with
|
(match Term.view t with
|
||||||
| Term.E_app (f, a) -> View.App_ho (f, a)
|
| Term.E_app (f, a) -> View.App_ho (f, a)
|
||||||
| Term.E_const { Const.c_view = T_builtins.C_true; _ } -> View.Bool true
|
| Term.E_const { Const.c_view = T_builtins.C_true; _ } -> View.Bool true
|
||||||
| Term.E_const { Const.c_view = T_builtins.C_false; _ } -> View.Bool false
|
| Term.E_const { Const.c_view = T_builtins.C_false; _ } -> View.Bool false
|
||||||
|
| Term.E_app_fold _ -> View.Opaque t
|
||||||
| _ -> View.Opaque t)
|
| _ -> View.Opaque t)
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ type Const.view +=
|
||||||
gensym_id: int; (** Id of the gensym *)
|
gensym_id: int; (** Id of the gensym *)
|
||||||
pre: string; (** Printing prefix *)
|
pre: string; (** Printing prefix *)
|
||||||
ty: ty;
|
ty: ty;
|
||||||
|
opaque_to_cc: bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
let ops =
|
let ops =
|
||||||
|
|
@ -26,6 +27,10 @@ let ops =
|
||||||
let pp out = function
|
let pp out = function
|
||||||
| Fresh { id; pre; _ } -> Fmt.fprintf out "$%s[%d]" pre id
|
| Fresh { id; pre; _ } -> Fmt.fprintf out "$%s[%d]" pre id
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
|
|
||||||
|
let opaque_to_cc = function
|
||||||
|
| Fresh f -> f.opaque_to_cc
|
||||||
|
| _ -> assert false
|
||||||
end : Const.DYN_OPS)
|
end : Const.DYN_OPS)
|
||||||
|
|
||||||
type t = { tst: Term.store; self_id: int; mutable fresh: int }
|
type t = { tst: Term.store; self_id: int; mutable fresh: int }
|
||||||
|
|
@ -38,11 +43,13 @@ let create tst : t =
|
||||||
incr id_;
|
incr id_;
|
||||||
{ tst; self_id; fresh = 0 }
|
{ tst; self_id; fresh = 0 }
|
||||||
|
|
||||||
let fresh_term (self : t) ~pre (ty : ty) : Term.t =
|
let fresh_term ?(opaque_to_cc = false) (self : t) ~pre (ty : ty) : Term.t =
|
||||||
let id = self.fresh in
|
let id = self.fresh in
|
||||||
self.fresh <- 1 + self.fresh;
|
self.fresh <- 1 + self.fresh;
|
||||||
let c =
|
let c =
|
||||||
Term.const self.tst
|
Term.const self.tst
|
||||||
@@ Const.make (Fresh { id; gensym_id = self.self_id; pre; ty }) ops ~ty
|
@@ Const.make
|
||||||
|
(Fresh { id; gensym_id = self.self_id; pre; ty; opaque_to_cc })
|
||||||
|
ops ~ty
|
||||||
in
|
in
|
||||||
c
|
c
|
||||||
|
|
|
||||||
|
|
@ -15,5 +15,5 @@ type t
|
||||||
val create : Term.store -> t
|
val create : Term.store -> t
|
||||||
(** New (stateful) generator instance. *)
|
(** New (stateful) generator instance. *)
|
||||||
|
|
||||||
val fresh_term : t -> pre:string -> ty -> term
|
val fresh_term : ?opaque_to_cc:bool -> t -> pre:string -> ty -> term
|
||||||
(** Make a fresh term of the given type *)
|
(** Make a fresh term of the given type *)
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,9 @@ end = struct
|
||||||
let pp out = function
|
let pp out = function
|
||||||
| I i -> Fmt.int out i
|
| I i -> Fmt.int out i
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
|
|
||||||
|
(* irrelevant *)
|
||||||
|
let opaque_to_cc _ = true
|
||||||
end : Const.DYN_OPS)
|
end : Const.DYN_OPS)
|
||||||
|
|
||||||
let make tst i : Lit.t =
|
let make tst i : Lit.t =
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue