Skip to content

Commit a32d875

Browse files
committed
Adds is_available flag to know which solvers are installed
1 parent feefe1f commit a32d875

13 files changed

+55
-7
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Added
44

5+
- Adds `Solver_dispacher.{is_available|available_solvers|solver}` to check
6+
availability of installed solvers
57
- Model generation for Bitwuzla
68

79
### Changed

lib/bitwuzla_mappings.default.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ end
412412
include (
413413
Mappings.Make (struct
414414
module Make () = Fresh_bitwuzla (Bitwuzla_cxx.Make ())
415+
416+
let is_available = true
417+
415418
include Fresh_bitwuzla (Bitwuzla_cxx)
416419
end) :
417420
S_with_fresh )

lib/colibri2_mappings.default.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,4 +1065,6 @@ module Fresh = struct
10651065
end
10661066
end
10671067
1068+
let is_available = true
1069+
10681070
include Fresh.Make ()

lib/cvc5_mappings.default.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ end
426426

427427
module Cvc5_with_make : Mappings_intf.M_with_make = struct
428428
module Make () = Fresh_cvc5 ()
429+
430+
let is_available = true
431+
429432
include Fresh_cvc5 ()
430433
end
431434

lib/mappings.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,5 +686,7 @@ module Make (M_with_make : M_with_make) : S_with_fresh = struct
686686
module Make () = Make_ (M_with_make.Make ())
687687
end
688688

689+
let is_available = M_with_make.is_available
690+
689691
include Make_ (M_with_make)
690692
end

lib/mappings.nop.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ module Nop = struct
349349
end
350350
end
351351

352+
let is_available = false
353+
352354
include Make ()
353355
end
354356

lib/mappings_intf.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ end
367367
module type M_with_make = sig
368368
module Make () : M
369369

370+
val is_available : bool
371+
370372
include M
371373
end
372374

@@ -439,5 +441,7 @@ module type S_with_fresh = sig
439441
module Make () : S
440442
end
441443

444+
val is_available : bool
445+
442446
include S
443447
end

lib/solver_dispatcher.ml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
11
(* TODO: put this in some other more appropriate module? *)
22
type solver_type =
33
| Z3_solver
4-
| Cvc5_solver
5-
| Colibri2_solver
64
| Bitwuzla_solver
5+
| Colibri2_solver
6+
| Cvc5_solver
77

88
let mappings_of_solver : solver_type -> (module Mappings_intf.S_with_fresh) =
99
function
1010
| Z3_solver -> (module Z3_mappings)
11-
| Cvc5_solver -> (module Cvc5_mappings)
12-
| Colibri2_solver -> (module Colibri2_mappings)
1311
| Bitwuzla_solver -> (module Bitwuzla_mappings)
12+
| Colibri2_solver -> (module Colibri2_mappings)
13+
| Cvc5_solver -> (module Cvc5_mappings)
1414

1515
let solver_type_of_string (s : string) :
1616
(solver_type, [> `Msg of string ]) result =
1717
match String.map Char.lowercase_ascii s with
1818
| "z3" -> Ok Z3_solver
19-
| "colibri2" -> Ok Colibri2_solver
2019
| "bitwuzla" -> Ok Bitwuzla_solver
20+
| "colibri2" -> Ok Colibri2_solver
2121
| "cvc5" -> Ok Cvc5_solver
2222
| s -> Error (`Msg (Format.sprintf "unknown solver %s" s))
2323

24+
let is_available : solver_type -> bool = function
25+
| Z3_solver -> Z3_mappings.is_available
26+
| Bitwuzla_solver -> Bitwuzla_mappings.is_available
27+
| Colibri2_solver -> Colibri2_mappings.is_available
28+
| Cvc5_solver -> Cvc5_mappings.is_available
29+
30+
(** List of all available solvers *)
31+
let available_solvers : solver_type list =
32+
List.filter is_available
33+
[ Z3_solver; Bitwuzla_solver; Colibri2_solver; Cvc5_solver ]
34+
35+
(** Returns first available solver or errors when none exist *)
36+
let solver : ((module Mappings_intf.S_with_fresh), [> `Msg of string ]) result =
37+
match available_solvers with
38+
| [] -> Error (`Msg "no available solver")
39+
| solver :: _ -> Ok (mappings_of_solver solver)
40+
2441
let pp_solver_type fmt = function
2542
| Z3_solver -> Format.fprintf fmt "Z3"
26-
| Cvc5_solver -> Format.fprintf fmt "CVC5"
27-
| Colibri2_solver -> Format.fprintf fmt "Colibri2"
2843
| Bitwuzla_solver -> Format.fprintf fmt "Bitwuzla"
44+
| Colibri2_solver -> Format.fprintf fmt "Colibri2"
45+
| Cvc5_solver -> Format.fprintf fmt "cvc5"

lib/z3_mappings.default.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,4 +816,6 @@ module Fresh = struct
816816
end
817817
end
818818

819+
let is_available = true
820+
819821
include Fresh.Make ()

lib/z3_mappings2.default.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ module M = struct
472472
end
473473
end
474474

475+
let is_available = true
476+
475477
include Make ()
476478
end
477479

test/test_bitwuzla.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
open Smtml
22
open Smtml_tests
3+
4+
let () = assert Bitwuzla_mappings.is_available
5+
36
module Test_solver_params =
47
Test_solver_params.Make (Bitwuzla_mappings.Fresh.Make ())
58
module Test_bv = Test_bv.Make (Bitwuzla_mappings)

test/test_colibri2.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
open Smtml
22
open Smtml_tests
3+
4+
let () = assert Colibri2_mappings.is_available
5+
36
module Test_solver_params = Test_solver_params.Make (Colibri2_mappings)
47
module Test_solver = Test_solver.Make (Colibri2_mappings)
58
module Test_bv = Test_bv.Make (Colibri2_mappings)

test/test_z3.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
open Smtml
22
open Smtml_tests
3+
4+
let () = assert Z3_mappings.is_available
5+
36
module Test_solver_params = Test_solver_params.Make (Z3_mappings.Fresh.Make ())
47
module Test_solver = Test_solver.Make (Z3_mappings.Fresh.Make ())
58
module Test_bv = Test_bv.Make (Z3_mappings.Fresh.Make ())

0 commit comments

Comments
 (0)