Skip to content

Commit 0d4d98e

Browse files
committed
New exception for wrong model
We raise a new exception `Wrong_model` in `get_value` in order to clarify the API.
1 parent c0195c4 commit 0d4d98e

3 files changed

Lines changed: 32 additions & 25 deletions

File tree

src/bin/common/solving_loop.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ let cmd_on_modes st modes cmd =
103103
let verify_model ~get_value () =
104104
match get_value [Expr.vrai] with
105105
| Some [e] when Expr.equal e Expr.vrai -> ()
106-
| Some [_] | None | exception Sat_solver_sig.Unsat _ ->
106+
| Some [_] | None | exception Sat_solver_util.Wrong_model _ ->
107107
recoverable_error "The model is wrong"
108108
| Some _ ->
109109
(* The length of the output list is the same as the length of the
@@ -831,7 +831,7 @@ let main () =
831831
(l, values)
832832
| None ->
833833
recoverable_error "No model produced, cannot execute get-value."
834-
| exception Sat_solver_sig.Unsat _ ->
834+
| exception Sat_solver_util.Wrong_model _ ->
835835
recoverable_error "The model is wrong, cannot execute get-value."
836836
in
837837

src/lib/reasoners/sat_solver_util.ml

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ let check (type a) (module SAT : S with type t = a) env =
8181
with
8282
| I_dont_know | Sat -> ()
8383

84+
exception Wrong_model of Explanation.t
85+
8486
(* Assert the last computed model in the environment [env].
8587
8688
@raise Unsat if the solver found a contradiction, which means the model
@@ -179,28 +181,30 @@ let get_value (type a) (module SAT : S with type t = a) env l =
179181
(* We have to check the satisfability of the new environment [env] in order
180182
to produce a new model. If this call raise [Unsat], the model is wrong
181183
and we cannot produce model terms for the expressions of [l]. *)
182-
check (module SAT) env;
183-
let* mdl = SAT.get_model env in
184-
let values =
185-
List.map
186-
(fun (v, name) ->
187-
match v, name with
188-
| Some v, None -> v
189-
| None, Some name ->
190-
begin match get_value_in_model (module SAT) env mdl name with
191-
| Some v -> v
192-
| None ->
193-
(* The model generation has to produce a value for each
194-
declared names. If some declared names are missing in the
195-
model, it's a bug. *)
196-
assert false
197-
end
198-
| _ ->
199-
(* This case is excluded by the construction of the list [res]. *)
200-
assert false
201-
) res
202-
in
203-
Some values
184+
try
185+
check (module SAT) env;
186+
let* mdl = SAT.get_model env in
187+
let values =
188+
List.map
189+
(fun (v, name) ->
190+
match v, name with
191+
| Some v, None -> v
192+
| None, Some name ->
193+
begin match get_value_in_model (module SAT) env mdl name with
194+
| Some v -> v
195+
| None ->
196+
(* The model generation has to produce a value for each
197+
declared names. If some declared names are missing in the
198+
model, it's a bug. *)
199+
assert false
200+
end
201+
| _ ->
202+
(* This case is excluded by the construction of the list [res]. *)
203+
assert false
204+
) res
205+
in
206+
Some values
207+
with Unsat ex -> raise_notrace (Wrong_model ex)
204208

205209
let get_assignment (type a) (module SAT : S with type t = a) env =
206210
List.map

src/lib/reasoners/sat_solver_util.mli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ type lbool = False | True | Unknown
3636

3737
val pp_lbool : lbool Fmt.t
3838

39+
exception Wrong_model of Explanation.t
40+
3941
val get_value : 'a sat_module -> 'a -> Expr.t list -> Expr.t list option
4042
(** [get_value (module SAT) env l] returns the model values of the expressions
4143
of [l] in the current generated model of [env].
4244
4345
@return [None] if the model generation is not enabled or the
4446
environment is already unsatisfiable before calling this function.
45-
@raise Unsat if the solver found a contradiction. *)
47+
@raise Wrong_model if the solver found a contradiction in the current
48+
model. *)
4649

4750
val get_assignment : 'a sat_module -> 'a -> Expr.t list -> lbool list
4851
(** [get_assignment (module SAT) env l] returns the status of the literals [l]

0 commit comments

Comments
 (0)