Skip to content
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

Remove alt-ergo-lib pin and make it compile with 2.6.0 #308

Merged
merged 2 commits into from
Mar 7, 2025
Merged
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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

## v0.6.1

### Changed

- Removed alt-ergo-lib pin and disabled model generation for the alt-ergo solver

### Fixed

- Fixes model parsing in the JSON format.
Expand Down
1 change: 1 addition & 0 deletions doc/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
(enabled_if
(and
%{lib-available:z3}
(not %{lib-available:alt-ergo-lib})
(not %{lib-available:bitwuzla-cxx})
(not %{lib-available:colibri2.core})
(not %{lib-available:cvc5})))
Expand Down
1 change: 1 addition & 0 deletions dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(enabled_if
(and
%{lib-available:z3}
(not %{lib-available:alt-ergo-lib})
(not %{lib-available:bitwuzla-cxx})
(not %{lib-available:colibri2.core})
(not %{lib-available:cvc5}))))
1 change: 0 additions & 1 deletion smtml.opam
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ available: arch != "arm32" & arch != "x86_32"
pin-depends: [
["colibri2.0.4.0" "git+https://git.frama-c.com/pub/colibrics.git#e15e6fc52b1f4e9a015b630a1f377d203ed9ec5b"]
["colibrilib.0.4.0" "git+https://git.frama-c.com/pub/colibrics.git#e15e6fc52b1f4e9a015b630a1f377d203ed9ec5b"]
["alt-ergo-lib.2.6.0" "git+https://github.com/OCamlPro/alt-ergo.git#7ee96296a5de9588a4d585b3b8abec35f4755425"]
["cvc5.dev" "git+https://github.com/formalsec/ocaml-cvc5.git#b7aade52d49a19d646036d7e6aac09039c3e95cf"]
["benchpress.dev" "git+https://github.com/sneeuwballen/benchpress.git#7f44cdd9f0511afcce2c9ad3c04cc9b72919bcff"]
["extunix.0.4.3" "git+https://github.com/filipeom/extunix.git#ff54e8cc7ec9cdc7171861d74d85f326dbcec62e"]
Expand Down
1 change: 0 additions & 1 deletion smtml.opam.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ available: arch != "arm32" & arch != "x86_32"
pin-depends: [
["colibri2.0.4.0" "git+https://git.frama-c.com/pub/colibrics.git#e15e6fc52b1f4e9a015b630a1f377d203ed9ec5b"]
["colibrilib.0.4.0" "git+https://git.frama-c.com/pub/colibrics.git#e15e6fc52b1f4e9a015b630a1f377d203ed9ec5b"]
["alt-ergo-lib.2.6.0" "git+https://github.com/OCamlPro/alt-ergo.git#7ee96296a5de9588a4d585b3b8abec35f4755425"]
["cvc5.dev" "git+https://github.com/formalsec/ocaml-cvc5.git#b7aade52d49a19d646036d7e6aac09039c3e95cf"]
["benchpress.dev" "git+https://github.com/sneeuwballen/benchpress.git#7f44cdd9f0511afcce2c9ad3c04cc9b72919bcff"]
["extunix.0.4.3" "git+https://github.com/filipeom/extunix.git#ff54e8cc7ec9cdc7171861d74d85f326dbcec62e"]
Expand Down
163 changes: 84 additions & 79 deletions src/smtml/altergo_mappings.default.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module Fresh = struct
if ConstMap.mem c sym_acc then sym_acc
else
let mk_res =
AEL.Translate.make dummy_file []
AEL.D_cnf.make dummy_file []
(mk_dstmt (`Decls [ `Term_decl c ]))
in
match mk_res with
Expand All @@ -112,7 +112,7 @@ module Fresh = struct
let mk_cmds sym_acc e_acc el =
let new_syms, stl = exprl_stmtl el in
let sym_acc = mk_decls new_syms sym_acc in
let mk_res = AEL.Translate.make dummy_file e_acc stl in
let mk_res = AEL.D_cnf.make dummy_file e_acc stl in
(sym_acc, mk_res)

let add s el =
Expand Down Expand Up @@ -193,18 +193,18 @@ module Fresh = struct
| Tbitv n -> Ty_bitv n
| _ -> assert false

let sym_to_aeid Symbol.{ ty; name; _ } : AEL.Id.typed =
let _sym_to_aeid Symbol.{ ty; name; _ } : AEL.Id.typed =
match name with
| Simple s ->
let name = AEL.Hstring.make s in
(name, [], ty_to_aety ty)
| Indexed _ -> assert false

let aeid_to_sym ((hs, tyl, ty) : AEL.Id.typed) =
let _aeid_to_sym ((hs, tyl, ty) : AEL.Id.typed) =
assert (match tyl with [] -> true | _ -> false);
Symbol.make (aety_to_ty ty) (AEL.Hstring.view hs)

let ae_expr_to_value e : Value.t =
let _ae_expr_to_value e : Value.t =
match AEL.Expr.term_view e with
| { f = True; _ } -> True
| { f = False; _ } -> False
Expand All @@ -216,7 +216,7 @@ module Fresh = struct
| _ ->
Fmt.failwith "Altergo_mappings: ae_expr_to_value(%a)" AEL.Expr.print e

let ae_expr_to_dvalue e : DM.Value.t =
let _ae_expr_to_dvalue e : DM.Value.t =
match AEL.Expr.term_view e with
| { f = True; _ } -> DM.Bool.mk true
| { f = False; _ } -> DM.Bool.mk false
Expand All @@ -226,7 +226,7 @@ module Fresh = struct
| _ ->
Fmt.failwith "Altergo_mappings: ae_expr_to_dvalue(%a)" AEL.Expr.print e

let dvalue_to_value (ty : Ty.t) (v : DM.Value.t) : Value.t =
let _dvalue_to_value (ty : Ty.t) (v : DM.Value.t) : Value.t =
match DM.Value.extract ~ops:DM.Bool.ops v with
| Some true -> True
| Some false -> False
Expand All @@ -245,78 +245,83 @@ module Fresh = struct
Fmt.failwith "Altergo_mappings: dvalue_to_value(%a)"
DM.Value.print v ) ) )

let cgraph_to_value hs g =
match (g : AEL.ModelMap.graph) with
| Free e -> e
| C c when AEL.ModelMap.M.cardinal c = 1 -> (
match AEL.ModelMap.M.min_binding c with [], e -> e | _ -> assert false )
| C c ->
(* Currently, there are no uninterpred functions in the tests/benchs,
therefore this is ok, but it should be fixed in the future *)
Fmt.failwith "Altergo_mappings: no value for %a (%a)" AEL.Id.pp hs
(fun fmt m ->
AEL.ModelMap.M.iter
(fun k v ->
Fmt.pf fmt "[%a] -> %a; "
(Fmt.list ~sep:Fmt.comma AEL.Expr.print)
k AEL.Expr.print v )
m )
c

let value (Model ((module Sat), m) : model) (e : Expr.t) : Value.t =
match Sat.get_model m with
| None -> Fmt.failwith "Altergo_mappings: no value for (%a)" Expr.pp e
| Some AEL.Models.{ model; _ } ->
let m =
AEL.ModelMap.fold
(fun ((hs, _, _) as id) g acc ->
let e = cgraph_to_value hs g in
let tcst = Dolmenexpr_to_expr.tcst_of_symbol (aeid_to_sym id) in
DM.Model.Cst.add tcst (ae_expr_to_dvalue e) acc )
model DM.Model.empty
in
let env =
DM.Env.mk m
~builtins:
(DM.Eval.builtins
[ DM.Core.builtins
; DM.Bool.builtins
; DM.Int.builtins
; DM.Rat.builtins
; DM.Real.builtins
; DM.Bitv.builtins
(* ; Array.builtins
; Fp.builtins *)
] )
in
let v = DM.Eval.eval env (encode_expr e) in
dvalue_to_value (Expr.ty e) v

let values_of_model ?symbols (Model ((module Sat), m)) : Model.t =
match Sat.get_model m with
| None -> assert false
| Some AEL.Models.{ model; _ } -> (
let r = Hashtbl.create 17 in
match symbols with
| None ->
AEL.ModelMap.fold
(fun ((hs, _, _) as aeid) g () ->
let sym = aeid_to_sym aeid in
Hashtbl.add r sym (ae_expr_to_value (cgraph_to_value hs g)) )
model ();
r
| Some syml ->
List.iter
(fun sym ->
let ((hs, _, _) as aeid) = sym_to_aeid sym in
let e =
try cgraph_to_value hs (AEL.ModelMap.find aeid model)
with Not_found ->
Fmt.failwith "Altergo_mappings: no value for %a" AEL.Id.pp hs
in
Hashtbl.add r sym (ae_expr_to_value e) )
syml;
r )
let _cgraph_to_value _hs _g =
(* match (g : AEL.ModelMap.graph) with *)
(* | Free e -> e *)
(* | C c when AEL.ModelMap.M.cardinal c = 1 -> ( *)
(* match AEL.ModelMap.M.min_binding c with [], e -> e | _ -> assert false ) *)
(* | C c -> *)
(* (1* Currently, there are no uninterpred functions in the tests/benchs, *)
(* therefore this is ok, but it should be fixed in the future *1) *)
(* Fmt.failwith "Altergo_mappings: no value for %a (%a)" AEL.Id.pp hs *)
(* (fun fmt m -> *)
(* AEL.ModelMap.M.iter *)
(* (fun k v -> *)
(* Fmt.pf fmt "[%a] -> %a; " *)
(* (Fmt.list ~sep:Fmt.comma AEL.Expr.print) *)
(* k AEL.Expr.print v ) *)
(* m ) *)
(* c *)
assert false (* This function should never be reached *)

let value (Model ((module Sat), _m) : model) (_e : Expr.t) : Value.t =
(* match Sat.get_model m with *)
(* | None -> Fmt.failwith "Altergo_mappings: no value for (%a)" Expr.pp e *)
(* | Some AEL.Models.{ model; _ } -> *)
(* let m = *)
(* AEL.ModelMap.fold *)
(* (fun ((hs, _, _) as id) g acc -> *)
(* let e = cgraph_to_value hs g in *)
(* let tcst = Dolmenexpr_to_expr.tcst_of_symbol (aeid_to_sym id) in *)
(* DM.Model.Cst.add tcst (ae_expr_to_dvalue e) acc ) *)
(* model DM.Model.empty *)
(* in *)
(* let env = *)
(* DM.Env.mk m *)
(* ~builtins: *)
(* (DM.Eval.builtins *)
(* [ DM.Core.builtins *)
(* ; DM.Bool.builtins *)
(* ; DM.Int.builtins *)
(* ; DM.Rat.builtins *)
(* ; DM.Real.builtins *)
(* ; DM.Bitv.builtins *)
(* (1* ; Array.builtins *)
(* ; Fp.builtins *1) *)
(* ] ) *)
(* in *)
(* let v = DM.Eval.eval env (encode_expr e) in *)
(* dvalue_to_value (Expr.ty e) v *)
Fmt.failwith
"Altergo_mappings: model generation is currently unsupported!"

let values_of_model ?symbols:_ (Model ((module Sat), _m)) : Model.t =
(* match Sat.get_model m with *)
(* | None -> assert false *)
(* | Some AEL.Models.{ model; _ } -> ( *)
(* let r = Hashtbl.create 17 in *)
(* match symbols with *)
(* | None -> *)
(* AEL.ModelMap.fold *)
(* (fun ((hs, _, _) as aeid) g () -> *)
(* let sym = aeid_to_sym aeid in *)
(* Hashtbl.add r sym (ae_expr_to_value (cgraph_to_value hs g)) ) *)
(* model (); *)
(* r *)
(* | Some syml -> *)
(* List.iter *)
(* (fun sym -> *)
(* let ((hs, _, _) as aeid) = sym_to_aeid sym in *)
(* let e = *)
(* try cgraph_to_value hs (AEL.ModelMap.find aeid model) *)
(* with Not_found -> *)
(* Fmt.failwith "Altergo_mappings: no value for %a" AEL.Id.pp hs *)
(* in *)
(* Hashtbl.add r sym (ae_expr_to_value e) ) *)
(* syml; *)
(* r ) *)
Fmt.failwith
"Altergo_mappings: model generation is currently unsupported!"

let set_debug _ = ()
end
Expand Down
File renamed without changes.
7 changes: 0 additions & 7 deletions test/solver/test_solver_altergo.expected
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
(model
(x int 0))
(model
(w i32 4)
(x i32 1)
(y i32 2)
(z i32 3))
8 changes: 4 additions & 4 deletions test/solver/test_solver_altergo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let () =
assert Altergo_mappings.is_available;
let module Alt_ergo = Test_solver.Make (Altergo_mappings.Fresh.Make ()) in
Alt_ergo.test_params ();
Alt_ergo.test_cached ();
Alt_ergo.test ();
Alt_ergo.test_bv ();
Alt_ergo.test_lia ()
(* Alt_ergo.test_cached (); *)
(* Alt_ergo.test (); *)
(* Alt_ergo.test_bv (); *)
(* Alt_ergo.test_lia () *)