author | blanchet |
Mon, 19 Apr 2010 15:15:21 +0200 | |
changeset 36223 | 217ca1273786 |
parent 36220 | f3655a3ae1ab |
child 36226 | ed7306094efe |
permissions | -rw-r--r-- |
32327
0971cc0b6a57
src/HOL/Tools/ATP_Manager as separate component, with (almost) everything in one place;
wenzelm
parents:
31793
diff
changeset
|
1 |
(* Title: HOL/Tools/ATP_Manager/atp_manager.ML |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
2 |
Author: Fabian Immler, TU Muenchen |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
3 |
Author: Makarius |
35969 | 4 |
Author: Jasmin Blanchette, TU Muenchen |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
5 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
6 |
Central manager component for ATP threads. |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
7 |
*) |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
8 |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
9 |
signature ATP_MANAGER = |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
10 |
sig |
35969 | 11 |
type relevance_override = Sledgehammer_Fact_Filter.relevance_override |
12 |
type params = |
|
13 |
{debug: bool, |
|
14 |
verbose: bool, |
|
36143
6490319b1703
added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents:
36064
diff
changeset
|
15 |
overlord: bool, |
35969 | 16 |
atps: string list, |
17 |
full_types: bool, |
|
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
18 |
respect_no_atp: bool, |
35969 | 19 |
relevance_threshold: real, |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
20 |
convergence: real, |
36220
f3655a3ae1ab
rename Sledgehammer "theory_const" option to "theory_relevant", now that I understand better what it does
blanchet
parents:
36184
diff
changeset
|
21 |
theory_relevant: bool option, |
35969 | 22 |
higher_order: bool option, |
23 |
follow_defs: bool, |
|
24 |
isar_proof: bool, |
|
36064
48aec67c284f
added "modulus" and "sorts" options to control Sledgehammer's Isar proof output
blanchet
parents:
36063
diff
changeset
|
25 |
modulus: int, |
48aec67c284f
added "modulus" and "sorts" options to control Sledgehammer's Isar proof output
blanchet
parents:
36063
diff
changeset
|
26 |
sorts: bool, |
35969 | 27 |
timeout: Time.time, |
28 |
minimize_timeout: Time.time} |
|
35867 | 29 |
type problem = |
35969 | 30 |
{subgoal: int, |
31 |
goal: Proof.context * (thm list * thm), |
|
32 |
relevance_override: relevance_override, |
|
33 |
axiom_clauses: (thm * (string * int)) list option, |
|
34 |
filtered_clauses: (thm * (string * int)) list option} |
|
35867 | 35 |
type prover_result = |
35969 | 36 |
{success: bool, |
37 |
message: string, |
|
36223
217ca1273786
make Sledgehammer's minimizer also minimize Isar proofs
blanchet
parents:
36220
diff
changeset
|
38 |
conjecture_pos: int * int, |
35969 | 39 |
relevant_thm_names: string list, |
40 |
atp_run_time_in_msecs: int, |
|
41 |
proof: string, |
|
42 |
internal_thm_names: string Vector.vector, |
|
43 |
filtered_clauses: (thm * (string * int)) list} |
|
44 |
type prover = params -> Time.time -> problem -> prover_result |
|
35867 | 45 |
|
32937
34f66c9dd8a2
structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents:
32936
diff
changeset
|
46 |
val atps: string Unsynchronized.ref |
34f66c9dd8a2
structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents:
32936
diff
changeset
|
47 |
val timeout: int Unsynchronized.ref |
34f66c9dd8a2
structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents:
32936
diff
changeset
|
48 |
val full_types: bool Unsynchronized.ref |
35969 | 49 |
val kill_atps: unit -> unit |
50 |
val running_atps: unit -> unit |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
51 |
val messages: int option -> unit |
35867 | 52 |
val add_prover: string * prover -> theory -> theory |
53 |
val get_prover: theory -> string -> prover option |
|
35969 | 54 |
val available_atps: theory -> unit |
55 |
val sledgehammer: params -> int -> relevance_override -> Proof.state -> unit |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
56 |
end; |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
57 |
|
35865 | 58 |
structure ATP_Manager : ATP_MANAGER = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
59 |
struct |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
60 |
|
36063
cdc6855a6387
make Sledgehammer output "by" vs. "apply", "qed" vs. "next", and any necessary "prefer"
blanchet
parents:
36059
diff
changeset
|
61 |
open Sledgehammer_Fact_Filter |
cdc6855a6387
make Sledgehammer output "by" vs. "apply", "qed" vs. "next", and any necessary "prefer"
blanchet
parents:
36059
diff
changeset
|
62 |
open Sledgehammer_Proof_Reconstruct |
35969 | 63 |
|
64 |
(** parameters, problems, results, and provers **) |
|
65 |
||
66 |
type params = |
|
67 |
{debug: bool, |
|
68 |
verbose: bool, |
|
36143
6490319b1703
added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents:
36064
diff
changeset
|
69 |
overlord: bool, |
35969 | 70 |
atps: string list, |
71 |
full_types: bool, |
|
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
72 |
respect_no_atp: bool, |
35969 | 73 |
relevance_threshold: real, |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
74 |
convergence: real, |
36220
f3655a3ae1ab
rename Sledgehammer "theory_const" option to "theory_relevant", now that I understand better what it does
blanchet
parents:
36184
diff
changeset
|
75 |
theory_relevant: bool option, |
35969 | 76 |
higher_order: bool option, |
77 |
follow_defs: bool, |
|
78 |
isar_proof: bool, |
|
36064
48aec67c284f
added "modulus" and "sorts" options to control Sledgehammer's Isar proof output
blanchet
parents:
36063
diff
changeset
|
79 |
modulus: int, |
48aec67c284f
added "modulus" and "sorts" options to control Sledgehammer's Isar proof output
blanchet
parents:
36063
diff
changeset
|
80 |
sorts: bool, |
35969 | 81 |
timeout: Time.time, |
82 |
minimize_timeout: Time.time} |
|
35867 | 83 |
|
84 |
type problem = |
|
35969 | 85 |
{subgoal: int, |
86 |
goal: Proof.context * (thm list * thm), |
|
87 |
relevance_override: relevance_override, |
|
88 |
axiom_clauses: (thm * (string * int)) list option, |
|
89 |
filtered_clauses: (thm * (string * int)) list option}; |
|
35867 | 90 |
|
91 |
type prover_result = |
|
35969 | 92 |
{success: bool, |
93 |
message: string, |
|
36223
217ca1273786
make Sledgehammer's minimizer also minimize Isar proofs
blanchet
parents:
36220
diff
changeset
|
94 |
conjecture_pos: int * int, |
35969 | 95 |
relevant_thm_names: string list, |
96 |
atp_run_time_in_msecs: int, |
|
97 |
proof: string, |
|
98 |
internal_thm_names: string Vector.vector, |
|
99 |
filtered_clauses: (thm * (string * int)) list}; |
|
35867 | 100 |
|
35969 | 101 |
type prover = params -> Time.time -> problem -> prover_result; |
35867 | 102 |
|
103 |
||
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
104 |
(** preferences **) |
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
105 |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
106 |
val message_store_limit = 20; |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
107 |
val message_display_limit = 5; |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
108 |
|
32937
34f66c9dd8a2
structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents:
32936
diff
changeset
|
109 |
val atps = Unsynchronized.ref "e spass remote_vampire"; |
32740 | 110 |
val timeout = Unsynchronized.ref 60; |
111 |
val full_types = Unsynchronized.ref false; |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
112 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
113 |
val _ = |
30982 | 114 |
ProofGeneralPgip.add_preference Preferences.category_proof |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
115 |
(Preferences.string_pref atps |
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
116 |
"ATP: provers" "Default automatic provers (separated by whitespace)"); |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
117 |
|
30982 | 118 |
val _ = |
119 |
ProofGeneralPgip.add_preference Preferences.category_proof |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
120 |
(Preferences.int_pref timeout |
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
121 |
"ATP: timeout" "ATPs will be interrupted after this time (in seconds)"); |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
122 |
|
31791 | 123 |
val _ = |
124 |
ProofGeneralPgip.add_preference Preferences.category_proof |
|
125 |
(Preferences.bool_pref full_types |
|
126 |
"ATP: full types" "ATPs will use full type information"); |
|
127 |
||
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
128 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
129 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
130 |
(** thread management **) |
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
131 |
|
28582 | 132 |
(* data structures over threads *) |
133 |
||
32939 | 134 |
structure Thread_Heap = Heap |
28582 | 135 |
( |
136 |
type elem = Time.time * Thread.thread; |
|
137 |
fun ord ((a, _), (b, _)) = Time.compare (a, b); |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
138 |
); |
28582 | 139 |
|
31368 | 140 |
fun lookup_thread xs = AList.lookup Thread.equal xs; |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
141 |
fun delete_thread xs = AList.delete Thread.equal xs; |
31368 | 142 |
fun update_thread xs = AList.update Thread.equal xs; |
28582 | 143 |
|
144 |
||
145 |
(* state of thread manager *) |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
146 |
|
32938 | 147 |
type state = |
148 |
{manager: Thread.thread option, |
|
149 |
timeout_heap: Thread_Heap.T, |
|
28582 | 150 |
active: (Thread.thread * (Time.time * Time.time * string)) list, |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
151 |
cancelling: (Thread.thread * (Time.time * string)) list, |
29620 | 152 |
messages: string list, |
153 |
store: string list}; |
|
28582 | 154 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
155 |
fun make_state manager timeout_heap active cancelling messages store : state = |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
156 |
{manager = manager, timeout_heap = timeout_heap, active = active, |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
157 |
cancelling = cancelling, messages = messages, store = store}; |
28582 | 158 |
|
32938 | 159 |
val global_state = Synchronized.var "atp_manager" |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
160 |
(make_state NONE Thread_Heap.empty [] [] [] []); |
28582 | 161 |
|
31368 | 162 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
163 |
(* unregister ATP thread *) |
28582 | 164 |
|
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
165 |
fun unregister ({verbose, ...} : params) message thread = |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
166 |
Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
167 |
(fn state as {manager, timeout_heap, active, cancelling, messages, store} => |
29150
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
168 |
(case lookup_thread active thread of |
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
169 |
SOME (birth_time, _, description) => |
29150
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
170 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
171 |
val active' = delete_thread thread active; |
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
172 |
val now = Time.now () |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
173 |
val cancelling' = (thread, (now, description)) :: cancelling; |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
174 |
val message' = |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
175 |
description ^ "\n" ^ message ^ |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
176 |
(if verbose then |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
177 |
"Total time: " ^ Int.toString (Time.toMilliseconds |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
178 |
(Time.- (now, birth_time))) ^ " ms.\n" |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
179 |
else |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
180 |
"") |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
181 |
val messages' = message' :: messages; |
29620 | 182 |
val store' = message' :: |
183 |
(if length store <= message_store_limit then store |
|
32938 | 184 |
else #1 (chop message_store_limit store)); |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
185 |
in make_state manager timeout_heap active' cancelling' messages' store' end |
30800 | 186 |
| NONE => state)); |
28582 | 187 |
|
188 |
||
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
189 |
(* main manager thread -- only one may exist *) |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
190 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
191 |
val min_wait_time = Time.fromMilliseconds 300; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
192 |
val max_wait_time = Time.fromSeconds 10; |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
193 |
|
29620 | 194 |
fun print_new_messages () = |
32938 | 195 |
let val msgs = Synchronized.change_result global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
196 |
(fn {manager, timeout_heap, active, cancelling, messages, store} => |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
197 |
(messages, make_state manager timeout_heap active cancelling [] store)) |
30800 | 198 |
in |
32938 | 199 |
if null msgs then () |
200 |
else priority ("Sledgehammer: " ^ space_implode "\n\n" msgs) |
|
30800 | 201 |
end; |
29620 | 202 |
|
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
203 |
fun check_thread_manager params = Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
204 |
(fn state as {manager, timeout_heap, active, cancelling, messages, store} => |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
205 |
if (case manager of SOME thread => Thread.isActive thread | NONE => false) then state |
33604
d4220df6fde2
Toplevel.thread provides Isar-style exception output;
wenzelm
parents:
33522
diff
changeset
|
206 |
else let val manager = SOME (Toplevel.thread false (fn () => |
32938 | 207 |
let |
208 |
fun time_limit timeout_heap = |
|
209 |
(case try Thread_Heap.min timeout_heap of |
|
210 |
NONE => Time.+ (Time.now (), max_wait_time) |
|
211 |
| SOME (time, _) => time); |
|
28582 | 212 |
|
32938 | 213 |
(*action: find threads whose timeout is reached, and interrupt cancelling threads*) |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
214 |
fun action {manager, timeout_heap, active, cancelling, messages, store} = |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
215 |
let val (timeout_threads, timeout_heap') = |
32938 | 216 |
Thread_Heap.upto (Time.now (), Thread.self ()) timeout_heap; |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
217 |
in |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
218 |
if null timeout_threads andalso null cancelling |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
219 |
then NONE |
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
220 |
else |
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
221 |
let |
32938 | 222 |
val _ = List.app (SimpleThread.interrupt o #1) cancelling; |
223 |
val cancelling' = filter (Thread.isActive o #1) cancelling; |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
224 |
val state' = make_state manager timeout_heap' active cancelling' messages store; |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
225 |
in SOME (map #2 timeout_threads, state') end |
32938 | 226 |
end; |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
227 |
in |
32938 | 228 |
while Synchronized.change_result global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
229 |
(fn state as {timeout_heap, active, cancelling, messages, store, ...} => |
32938 | 230 |
if null active andalso null cancelling andalso null messages |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
231 |
then (false, make_state NONE timeout_heap active cancelling messages store) |
32938 | 232 |
else (true, state)) |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
233 |
do |
32938 | 234 |
(Synchronized.timed_access global_state (SOME o time_limit o #timeout_heap) action |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
235 |
|> these |
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
236 |
|> List.app (unregister params "Timed out."); |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
237 |
print_new_messages (); |
32938 | 238 |
(*give threads some time to respond to interrupt*) |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
239 |
OS.Process.sleep min_wait_time) |
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
240 |
end)) |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
241 |
in make_state manager timeout_heap active cancelling messages store end); |
28582 | 242 |
|
243 |
||
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
244 |
(* register ATP thread *) |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
245 |
|
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
246 |
fun register params birth_time death_time (thread, desc) = |
32938 | 247 |
(Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
248 |
(fn {manager, timeout_heap, active, cancelling, messages, store} => |
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
249 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
250 |
val timeout_heap' = Thread_Heap.insert (death_time, thread) timeout_heap; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
251 |
val active' = update_thread (thread, (birth_time, death_time, desc)) active; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
252 |
val state' = make_state manager timeout_heap' active' cancelling messages store; |
32938 | 253 |
in state' end); |
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
254 |
check_thread_manager params); |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
255 |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
256 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
257 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
258 |
(** user commands **) |
28582 | 259 |
|
35969 | 260 |
(* kill ATPs *) |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
261 |
|
35969 | 262 |
fun kill_atps () = Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
263 |
(fn {manager, timeout_heap, active, cancelling, messages, store} => |
32938 | 264 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
265 |
val killing = map (fn (th, (_, _, desc)) => (th, (Time.now (), desc))) active; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
266 |
val state' = make_state manager timeout_heap [] (killing @ cancelling) messages store; |
32938 | 267 |
in state' end); |
28582 | 268 |
|
269 |
||
35969 | 270 |
(* running_atps *) |
28582 | 271 |
|
32938 | 272 |
fun seconds time = string_of_int (Time.toSeconds time) ^ "s"; |
273 |
||
35969 | 274 |
fun running_atps () = |
28582 | 275 |
let |
32938 | 276 |
val {active, cancelling, ...} = Synchronized.value global_state; |
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
277 |
|
32938 | 278 |
val now = Time.now (); |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
279 |
fun running_info (_, (birth_time, death_time, desc)) = |
32938 | 280 |
"Running: " ^ seconds (Time.- (now, birth_time)) ^ " -- " ^ |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
281 |
seconds (Time.- (death_time, now)) ^ " to live:\n" ^ desc; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
282 |
fun cancelling_info (_, (deadth_time, desc)) = |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
283 |
"Trying to interrupt thread since " ^ seconds (Time.- (now, deadth_time)) ^ ":\n" ^ desc; |
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
284 |
|
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
285 |
val running = |
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
286 |
if null active then "No ATPs running." |
32938 | 287 |
else space_implode "\n\n" ("Running ATPs:" :: map running_info active); |
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
288 |
val interrupting = |
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
289 |
if null cancelling then "" |
32938 | 290 |
else |
291 |
space_implode "\n\n" |
|
292 |
("Trying to interrupt the following ATPs:" :: map cancelling_info cancelling); |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
293 |
|
28582 | 294 |
in writeln (running ^ "\n" ^ interrupting) end; |
295 |
||
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
296 |
fun messages opt_limit = |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
297 |
let |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
298 |
val limit = the_default message_display_limit opt_limit; |
32938 | 299 |
val {store, ...} = Synchronized.value global_state; |
300 |
val header = |
|
301 |
"Recent ATP messages" ^ |
|
302 |
(if length store <= limit then ":" else " (" ^ string_of_int limit ^ " displayed):"); |
|
303 |
in writeln (space_implode "\n\n" (header :: #1 (chop limit store))) end; |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
304 |
|
28582 | 305 |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
306 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
307 |
(** The Sledgehammer **) |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
308 |
|
28582 | 309 |
(* named provers *) |
28484 | 310 |
|
28582 | 311 |
fun err_dup_prover name = error ("Duplicate prover: " ^ quote name); |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
312 |
|
33522 | 313 |
structure Provers = Theory_Data |
28582 | 314 |
( |
35867 | 315 |
type T = (prover * stamp) Symtab.table; |
32938 | 316 |
val empty = Symtab.empty; |
317 |
val extend = I; |
|
33522 | 318 |
fun merge data : T = Symtab.merge (eq_snd op =) data |
32938 | 319 |
handle Symtab.DUP dup => err_dup_prover dup; |
28582 | 320 |
); |
28484 | 321 |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32824
diff
changeset
|
322 |
fun add_prover (name, prover) thy = |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
323 |
Provers.map (Symtab.update_new (name, (prover, stamp ()))) thy |
28582 | 324 |
handle Symtab.DUP dup => err_dup_prover dup; |
325 |
||
32995 | 326 |
fun get_prover thy name = |
327 |
Option.map #1 (Symtab.lookup (Provers.get thy) name); |
|
328 |
||
35969 | 329 |
fun available_atps thy = Pretty.writeln |
330 |
(Pretty.strs ("ATPs:" :: sort_strings (Symtab.keys (Provers.get thy)))); |
|
28571 | 331 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
332 |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
333 |
(* start prover thread *) |
28484 | 334 |
|
35969 | 335 |
fun start_prover (params as {timeout, ...}) birth_time death_time i |
336 |
relevance_override proof_state name = |
|
32947
3c19b98a35cd
ATP_Manager.get_prover: canonical argument order;
wenzelm
parents:
32941
diff
changeset
|
337 |
(case get_prover (Proof.theory_of proof_state) name of |
36181
2156a7392885
tell the user that Sledgehammer kills its siblings
blanchet
parents:
36167
diff
changeset
|
338 |
NONE => warning ("Unknown ATP: " ^ quote name) |
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
30982
diff
changeset
|
339 |
| SOME prover => |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
340 |
let |
35592
768d17f54125
use regular Proof.goal (which is what methods usually see) and prevent sledgehammer from crashing;
wenzelm
parents:
35569
diff
changeset
|
341 |
val {context = ctxt, facts, goal} = Proof.goal proof_state; |
36063
cdc6855a6387
make Sledgehammer output "by" vs. "apply", "qed" vs. "next", and any necessary "prefer"
blanchet
parents:
36059
diff
changeset
|
342 |
val n = Logic.count_prems (prop_of goal) |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
343 |
val desc = |
35969 | 344 |
"ATP " ^ quote name ^ " for subgoal " ^ string_of_int i ^ ":\n" ^ |
32938 | 345 |
Syntax.string_of_term ctxt (Thm.term_of (Thm.cprem_of goal i)); |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
346 |
|
33604
d4220df6fde2
Toplevel.thread provides Isar-style exception output;
wenzelm
parents:
33522
diff
changeset
|
347 |
val _ = Toplevel.thread true (fn () => |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
348 |
let |
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
349 |
val _ = register params birth_time death_time (Thread.self (), desc) |
35969 | 350 |
val problem = |
351 |
{subgoal = i, goal = (ctxt, (facts, goal)), |
|
352 |
relevance_override = relevance_override, axiom_clauses = NONE, |
|
353 |
filtered_clauses = NONE} |
|
354 |
val message = #message (prover params timeout problem) |
|
36063
cdc6855a6387
make Sledgehammer output "by" vs. "apply", "qed" vs. "next", and any necessary "prefer"
blanchet
parents:
36059
diff
changeset
|
355 |
handle Sledgehammer_HOL_Clause.TRIVIAL => |
cdc6855a6387
make Sledgehammer output "by" vs. "apply", "qed" vs. "next", and any necessary "prefer"
blanchet
parents:
36059
diff
changeset
|
356 |
metis_line i n [] |
33312 | 357 |
| ERROR msg => ("Error: " ^ msg); |
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
358 |
val _ = unregister params message (Thread.self ()); |
35569 | 359 |
in () end); |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
360 |
in () end); |
28582 | 361 |
|
362 |
||
35969 | 363 |
(* Sledgehammer the given subgoal *) |
28582 | 364 |
|
35969 | 365 |
fun sledgehammer (params as {atps, timeout, ...}) i relevance_override |
366 |
proof_state = |
|
28582 | 367 |
let |
35969 | 368 |
val birth_time = Time.now () |
369 |
val death_time = Time.+ (birth_time, timeout) |
|
36181
2156a7392885
tell the user that Sledgehammer kills its siblings
blanchet
parents:
36167
diff
changeset
|
370 |
val _ = kill_atps () (* RACE w.r.t. other invocations of Sledgehammer *) |
35969 | 371 |
val _ = priority "Sledgehammering..." |
372 |
val _ = List.app (start_prover params birth_time death_time i |
|
373 |
relevance_override proof_state) atps |
|
374 |
in () end |
|
28582 | 375 |
|
376 |
end; |