21 type nun_solution = |
21 type nun_solution = |
22 {tys: (ty * tm list) list, |
22 {tys: (ty * tm list) list, |
23 tms: (tm * tm) list} |
23 tms: (tm * tm) list} |
24 |
24 |
25 datatype nun_outcome = |
25 datatype nun_outcome = |
26 Unsat |
26 Unsat of string |
27 | Sat of string * nun_solution |
27 | Sat of string * string * nun_solution |
28 | Unknown of (string * nun_solution) option |
28 | Unknown of (string * string * nun_solution) option |
29 | Timeout |
29 | Timeout |
30 | Nunchaku_Var_Not_Set |
30 | Nunchaku_Var_Not_Set |
31 | Nunchaku_Cannot_Execute |
31 | Nunchaku_Cannot_Execute |
32 | Nunchaku_Not_Found |
32 | Nunchaku_Not_Found |
33 | CVC4_Cannot_Execute |
33 | CVC4_Cannot_Execute |
55 type nun_solution = |
55 type nun_solution = |
56 {tys: (ty * tm list) list, |
56 {tys: (ty * tm list) list, |
57 tms: (tm * tm) list}; |
57 tms: (tm * tm) list}; |
58 |
58 |
59 datatype nun_outcome = |
59 datatype nun_outcome = |
60 Unsat |
60 Unsat of string |
61 | Sat of string * nun_solution |
61 | Sat of string * string * nun_solution |
62 | Unknown of (string * nun_solution) option |
62 | Unknown of (string * string * nun_solution) option |
63 | Timeout |
63 | Timeout |
64 | Nunchaku_Var_Not_Set |
64 | Nunchaku_Var_Not_Set |
65 | Nunchaku_Cannot_Execute |
65 | Nunchaku_Cannot_Execute |
66 | Nunchaku_Not_Found |
66 | Nunchaku_Not_Found |
67 | CVC4_Cannot_Execute |
67 | CVC4_Cannot_Execute |
72 let val {out, err, rc, ...} = Bash.process s in |
72 let val {out, err, rc, ...} = Bash.process s in |
73 ((out, err), rc) |
73 ((out, err), rc) |
74 end; |
74 end; |
75 |
75 |
76 val nunchaku_home_env_var = "NUNCHAKU_HOME"; |
76 val nunchaku_home_env_var = "NUNCHAKU_HOME"; |
|
77 |
|
78 val unknown_solver = "unknown"; |
77 |
79 |
78 val cached_outcome = Synchronized.var "Nunchaku_Tool.cached_outcome" |
80 val cached_outcome = Synchronized.var "Nunchaku_Tool.cached_outcome" |
79 (NONE : ((string list * nun_problem) * nun_outcome) option); |
81 (NONE : ((string list * nun_problem) * nun_outcome) option); |
80 |
82 |
81 fun uncached_solve_nun_problem ({solvers, overlord, specialize, timeout, ...} : tool_params) |
83 fun uncached_solve_nun_problem ({solvers, overlord, specialize, timeout, ...} : tool_params) |
95 val comments = |
97 val comments = |
96 [bash_cmd, "This file was generated by Isabelle (most likely Nunchaku)", timestamp ()]; |
98 [bash_cmd, "This file was generated by Isabelle (most likely Nunchaku)", timestamp ()]; |
97 val prob_str = cat_lines (map (prefix "# ") comments) ^ "\n\n" ^ str_of_nun_problem problem; |
99 val prob_str = cat_lines (map (prefix "# ") comments) ^ "\n\n" ^ str_of_nun_problem problem; |
98 val _ = File.write prob_path prob_str; |
100 val _ = File.write prob_path prob_str; |
99 val ((output, error), code) = bash_output_error bash_cmd; |
101 val ((output, error), code) = bash_output_error bash_cmd; |
|
102 |
|
103 val backend = |
|
104 (case filter_out (curry (op =) "") (split_lines output) of |
|
105 [] => unknown_solver |
|
106 | lines => |
|
107 (case try (unprefix "{backend:") (List.last lines) of |
|
108 NONE => unknown_solver |
|
109 | SOME "" => unknown_solver |
|
110 | SOME s => hd (space_explode "," s))); |
100 in |
111 in |
101 if String.isPrefix "SAT" output then |
112 if String.isPrefix "SAT" output then |
102 (if sound then Sat else Unknown o SOME) (output, {tys = [], tms = []}) |
113 (if sound then Sat else Unknown o SOME) (backend, output, {tys = [], tms = []}) |
103 else if String.isPrefix "UNSAT" output then |
114 else if String.isPrefix "UNSAT" output then |
104 if complete then Unsat else Unknown NONE |
115 if complete then Unsat backend else Unknown NONE |
105 else if String.isSubstring "TIMEOUT" output |
116 else if String.isSubstring "TIMEOUT" output |
106 (* FIXME: temporary *) |
117 (* FIXME: temporary *) |
107 orelse String.isSubstring "kodkod failed (errcode 152)" error then |
118 orelse String.isSubstring "kodkod failed (errcode 152)" error then |
108 Timeout |
119 Timeout |
109 else if String.isPrefix "UNKNOWN" output then |
120 else if String.isPrefix "UNKNOWN" output then |
128 |
139 |
129 fun update_cache () = |
140 fun update_cache () = |
130 Synchronized.change cached_outcome (K (SOME (key, outcome))); |
141 Synchronized.change cached_outcome (K (SOME (key, outcome))); |
131 in |
142 in |
132 (case outcome of |
143 (case outcome of |
133 Unsat => update_cache () |
144 Unsat _ => update_cache () |
134 | Sat _ => update_cache () |
145 | Sat _ => update_cache () |
135 | Unknown _ => update_cache () |
146 | Unknown _ => update_cache () |
136 | _ => ()); |
147 | _ => ()); |
137 outcome |
148 outcome |
138 end) |
149 end) |