Skip to content

Commit

Permalink
try to use a global cache
Browse files Browse the repository at this point in the history
  • Loading branch information
zapashcanon committed Feb 22, 2025
1 parent 0df34b2 commit 2ae28d5
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/symbolic/solver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,38 @@ let fresh solver () =
let module Mapping = (val Smtml.Solver_dispatcher.mappings_of_solver solver)
in
let module Mapping = Mapping.Fresh.Make () in
let module Batch = Smtml.Solver.Cached (Mapping) in
let module Batch = Smtml.Solver.Batch (Mapping) in
let solver = Batch.create ~logic:QF_BVFP () in
S ((module Batch), solver)

let check (S (solver_module, s)) pc =
Stats.start_span "check" "solver";
let module Solver = (val solver_module) in
let check = Solver.check_set s pc in
Stats.close_span ();
check
let check =
let module Cache = Smtml.Cache.Strong in
let cache = Cache.create 512 in
let lock = Mutex.create () in
fun (S (solver_module, s)) pc ->
Mutex.lock lock;
let satisfiability = Cache.find_opt cache pc in
Mutex.unlock lock;
Stats.start_span "check" "solver";
let check =
match satisfiability with
| Some satisfiability -> satisfiability
| None ->
let module Solver = (val solver_module) in
let satisfiability = Solver.check_set s pc in
Mutex.lock lock;
Cache.add cache pc satisfiability;
Mutex.unlock lock;
satisfiability
in
Stats.close_span ();
check

let model (S (solver_module, s)) ~symbols ~pc =
Stats.start_span "model" "solver";
let module Solver = (val solver_module) in
let model =
(* we don't memoïze this call, because check_set *must* be used before calling model *)
match Solver.check_set s pc with
| `Sat -> begin
match Solver.model ?symbols s with
Expand Down

0 comments on commit 2ae28d5

Please sign in to comment.