Skip to content

Commit

Permalink
Fix some counterexaple production (#323)
Browse files Browse the repository at this point in the history
* Fix SMT solver resets

* Fix counterexample printing
  • Loading branch information
NatKarmios authored Dec 11, 2024
1 parent 17c9089 commit 9d7ee36
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
44 changes: 30 additions & 14 deletions GillianCore/command_line/s_interpreter_console.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module Make
(SState : SState.S with type init_data = ID.t)
(S_interpreter : G_interpreter.S
with type annot = PC.Annot.t
and type state_t = SState.t)
and type state_t = SState.t
and type state_err_t = SState.err_t)
(Gil_parsing : Gil_parsing.S with type annot = PC.Annot.t) : Console.S =
struct
module Common_args = Common_args.Make (PC)
Expand All @@ -35,12 +36,23 @@ struct
open ChangeTracker

let counter_example res =
let error_state =
let error_state, errors =
match res with
| Exec_res.RFail f -> f.error_state
| Exec_res.RFail { error_state; errors; _ } -> (error_state, errors)
| _ -> failwith "Expected failure"
in
let subst = SState.sat_check_f error_state [] in
let f =
errors
|> List.find_map (function
| Exec_err.EState StateErr.(EPure f) -> Some f
| _ -> None)
in
let fs =
match f with
| Some f -> [ Formula.Not f ]
| None -> []
in
let subst = SState.sat_check_f error_state fs in
subst

let run_main prog init_data =
Expand Down Expand Up @@ -76,11 +88,13 @@ struct
let total_time = Sys.time () -. !start_time in
Printf.printf "Total time (Compilation + Symbolic testing): %fs\n"
total_time;
if success then (
Fmt.pr "%a@\n@?" (Fmt.styled `Green Fmt.string) "Success!";
exit 0)
else (
Fmt.pr "%a@\n@?" (Fmt.styled `Red Fmt.string) "Errors occured!";
if success then
let () = Fmt.pr "%a@\n@?" (Fmt.styled `Green Fmt.string) "Success!" in
exit 0
else
let () =
Fmt.pr "%a@\n@?" (Fmt.styled `Red Fmt.string) "Errors occured!"
in
let first_error =
List.find
(function
Expand All @@ -94,11 +108,13 @@ struct
~none:(Fmt.any "Couldn't produce counter-example")
SVal.SESubst.pp)
counter_example;
Fmt.pr "Here's an example of final error state: %a@\n@?"
(Exec_res.pp SState.pp S_interpreter.pp_state_vt
S_interpreter.pp_err_t)
first_error;
exit 1)
let () =
Fmt.pr "Here's an example of final error state: %a@\n@?"
(Exec_res.pp SState.pp S_interpreter.pp_state_vt
S_interpreter.pp_err_t)
first_error
in
exit 1

let run_incr source_files prog init_data =
(* Only re-run program if transitive callees of main proc have changed *)
Expand Down
2 changes: 0 additions & 2 deletions GillianCore/engine/general_semantics/general/g_interpreter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,6 @@ struct
Fmt.(option ~none:(any "CANNOT CREATE MODEL") ESubst.pp)
failing_model
in
if not (Exec_mode.is_biabduction_exec !Config.current_exec_mode) then
Printf.printf "%s" msg;
L.normal (fun m -> m "%s" msg);
Res_list.error_with err

Expand Down
2 changes: 1 addition & 1 deletion GillianCore/smt/smt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ let exec_sat' (fs : Formula.Set.t) (gamma : typenv) : sexp option =
(Fmt.iter ~sep:(Fmt.any "@\n") Formula.Set.iter Formula.pp)
fs pp_typenv gamma)
in
let () = reset_solver () in
let encoded_assertions = encode_assertions fs gamma in
let () = if !Config.dump_smt then Dump.dump fs gamma encoded_assertions in
let () = List.iter cmd !builtin_funcs in
Expand Down Expand Up @@ -1026,7 +1027,6 @@ let exec_sat' (fs : Formula.Set.t) (gamma : typenv) : sexp option =
| Sat -> Some (get_model solver)
| Unsat -> None
in
let () = reset_solver () in
ret

let exec_sat (fs : Formula.Set.t) (gamma : typenv) : sexp option =
Expand Down

0 comments on commit 9d7ee36

Please sign in to comment.