Skip to content

Replace fresh terms by abstract values in all subterms #1280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/lib/frontend/models.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ let constraints = ref MS.empty
type t = {
propositional : Expr.Set.t;
model : ModelMap.t;
term_values : Expr.t Expr.Map.t
}

let empty = {
propositional = Expr.Set.empty;
model = ModelMap.empty ~suspicious:false [];
term_values = Expr.Map.empty;
}

module Pp_smtlib_term = struct
Expand Down
2 changes: 0 additions & 2 deletions src/lib/frontend/models.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
type t = {
propositional : Expr.Set.t;
model : ModelMap.t;
term_values : Expr.t Expr.Map.t
(** A map from terms to their values in the model. *)
}

val empty : t
Expand Down
6 changes: 3 additions & 3 deletions src/lib/reasoners/adt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,15 @@ module Shostak (X : ALIEN) = struct
in [Adt_rel]. *)
None

let to_model_term r =
let to_model_term abstract r =
match embed r with
| Constr { c_name; c_ty; c_args } ->
let args =
My_list.try_map (fun (_, arg) -> X.to_model_term arg) c_args
My_list.try_map (fun (_, arg) -> X.to_model_term abstract arg) c_args
in
Option.bind args @@ fun args ->
Some (E.mk_constr c_name args c_ty)

| Select _ -> None
| Alien a -> X.to_model_term a
| Alien a -> X.to_model_term abstract a
end
2 changes: 1 addition & 1 deletion src/lib/reasoners/arith.ml
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ module Shostak
cpt := Q.add Q.one (max_constant distincts !cpt);
Some (term_of_cst (Q.to_string !cpt), true)

let to_model_term r =
let to_model_term _abstract r =
match P.is_const (embed r), X.type_info r with
| Some i, Ty.Tint ->
assert (Z.equal (Q.den i) Z.one);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/reasoners/bitv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ module Shostak(X : ALIEN) = struct
let bv = String.make sz '0' in
Some (E.bitv bv (Ty.Tbitv sz), true)

let to_model_term r =
let to_model_term _abstract r =
match embed r with
| [{ bv = Cte b; sz }] ->
let s = Z.format ("%0" ^ string_of_int sz ^ "b") b in
Expand Down
4 changes: 2 additions & 2 deletions src/lib/reasoners/records.ml
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ module Shostak (X : ALIEN) = struct
Some (s, false) (* false <-> not a case-split *)
| _ -> assert false

let to_model_term =
let to_model_term abstract =
let rec to_model_term r =
match r with
| Record (fields, ty) ->
Expand All @@ -414,7 +414,7 @@ module Shostak (X : ALIEN) = struct
Some (E.mk_term Sy.(Op Record) l ty)

| Other (a, _) ->
X.to_model_term a
X.to_model_term abstract a
| Access _ -> None
in fun r -> to_model_term (embed r)
end
18 changes: 12 additions & 6 deletions src/lib/reasoners/shostak.ml
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,20 @@ struct
| Ac _ -> None, false (* SYLVAIN : TODO *)
| Term t -> Some t, true

let to_model_term r =
let to_model_term abstract r =
let res =
match r.v with
| Arith _ -> ARITH.to_model_term r
| Records _ -> RECORDS.to_model_term r
| Bitv _ -> BITV.to_model_term r
| Adt _ -> ADT.to_model_term r
| Term t when Expr.is_model_term t -> Some t
| Arith _ -> ARITH.to_model_term abstract r
| Records _ -> RECORDS.to_model_term abstract r
| Bitv _ -> BITV.to_model_term abstract r
| Adt _ -> ADT.to_model_term abstract r
| Term t when Expr.is_model_term t ->
let Expr.{ f; _ } = Expr.term_view t in
(match f with
| Symbols.Name { ns = Internal | Fresh | Fresh_ac; _ } ->
Some (abstract t)
| _ ->
Some t)
| Ac _ | Term _ -> None
in
Option.bind res @@ fun t ->
Expand Down
35 changes: 12 additions & 23 deletions src/lib/reasoners/sig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,24 @@ module type SHOSTAK = sig
[Some (t, false)], then there must be no context in which
[solve r (fst X.make t)] raises [Unsolvable]. You have been warned! *)

val to_model_term : r -> Expr.t option
(** [to_model_term r] creates a model term if [r] is constant.
The function cannot fail if [r] is a constant (that is statisfied the
predicate [X.is_constant]).

The returned value always satisfies the predicate
[Expr.is_model_term]. See its documentation for more details about
model terms. *)
val to_model_term : (Expr.t -> Expr.t) -> r -> Expr.t option
(** [to_model_term abstract r] creates a model term if [r] is constant.
The function must succeed when [r] is a constant, this is [r] satisfied
the predicate [X.is_constant].

The [abstract] function is used to replace internal or fresh names by
abstract values.

The returned value always satisfies the predicate [Expr.is_model_term].
Refer to its documentation for more details about model terms. *)
end

module type X = sig
type r

val save_cache : unit -> unit
(** saves the module's current cache *)

val reinit_cache : unit -> unit
(** restores the module's cache *)

val make : Expr.t -> r * Expr.t list

Expand All @@ -178,7 +178,7 @@ module type X = sig

val term_embed : Expr.t -> r

val term_extract : r -> Expr.t option * bool (* original term ? *)
val term_extract : r -> Expr.t option * bool

val ac_embed : r ac -> r

Expand All @@ -196,19 +196,8 @@ module type X = sig

val is_solvable_theory_symbol : Symbols.t -> bool

(* the returned bool is true when the returned term in a constant of the
theory. Otherwise, the term contains aliens that should be assigned
(eg. records). In this case, it's a unit fact, not a decision
*)
val assign_value :
r -> r list -> (Expr.t * r) list -> (Expr.t * bool) option

val to_model_term : r -> Expr.t option
(** [to_model_term r] creates a model term if [r] is constant.
The function cannot fail if [r] is a constant (that is statisfied the
predicate [X.is_constant]).

The returned value always satisfies the predicate
[Expr.is_model_term]. See its documentation for more details about
model terms. *)
val to_model_term : (Expr.t -> Expr.t) -> r -> Expr.t option
end
Loading