author | wenzelm |
Thu, 29 Oct 2009 16:59:12 +0100 | |
changeset 33316 | 6a72af4e84b8 |
parent 33312 | 6ca8a7984fd9 |
child 33522 | 737589bb9bb8 |
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 |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
4 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
5 |
Central manager component for ATP threads. |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
6 |
*) |
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 |
signature ATP_MANAGER = |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
9 |
sig |
32937
34f66c9dd8a2
structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents:
32936
diff
changeset
|
10 |
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
|
11 |
val get_atps: unit -> string list |
34f66c9dd8a2
structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents:
32936
diff
changeset
|
12 |
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
|
13 |
val full_types: bool Unsynchronized.ref |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
14 |
val kill: unit -> unit |
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
15 |
val info: unit -> unit |
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
16 |
val messages: int option -> unit |
32936 | 17 |
val add_prover: string * ATP_Wrapper.prover -> theory -> theory |
32995 | 18 |
val get_prover: theory -> string -> ATP_Wrapper.prover option |
28484 | 19 |
val print_provers: theory -> unit |
28571 | 20 |
val sledgehammer: string list -> Proof.state -> unit |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
21 |
end; |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
22 |
|
32936 | 23 |
structure ATP_Manager: ATP_MANAGER = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
24 |
struct |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
25 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
26 |
(** preferences **) |
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
27 |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
28 |
val message_store_limit = 20; |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
29 |
val message_display_limit = 5; |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
30 |
|
32937
34f66c9dd8a2
structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents:
32936
diff
changeset
|
31 |
val atps = Unsynchronized.ref "e spass remote_vampire"; |
34f66c9dd8a2
structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents:
32936
diff
changeset
|
32 |
fun get_atps () = String.tokens (Symbol.is_ascii_blank o String.str) (! atps); |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
33 |
|
32740 | 34 |
val timeout = Unsynchronized.ref 60; |
35 |
val full_types = Unsynchronized.ref false; |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
36 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
37 |
val _ = |
30982 | 38 |
ProofGeneralPgip.add_preference Preferences.category_proof |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
39 |
(Preferences.string_pref atps |
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
40 |
"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
|
41 |
|
30982 | 42 |
val _ = |
43 |
ProofGeneralPgip.add_preference Preferences.category_proof |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
44 |
(Preferences.int_pref timeout |
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
45 |
"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
|
46 |
|
31791 | 47 |
val _ = |
48 |
ProofGeneralPgip.add_preference Preferences.category_proof |
|
49 |
(Preferences.bool_pref full_types |
|
50 |
"ATP: full types" "ATPs will use full type information"); |
|
51 |
||
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
52 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
53 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
54 |
(** thread management **) |
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
55 |
|
28582 | 56 |
(* data structures over threads *) |
57 |
||
32939 | 58 |
structure Thread_Heap = Heap |
28582 | 59 |
( |
60 |
type elem = Time.time * Thread.thread; |
|
61 |
fun ord ((a, _), (b, _)) = Time.compare (a, b); |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
62 |
); |
28582 | 63 |
|
31368 | 64 |
fun lookup_thread xs = AList.lookup Thread.equal xs; |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
65 |
fun delete_thread xs = AList.delete Thread.equal xs; |
31368 | 66 |
fun update_thread xs = AList.update Thread.equal xs; |
28582 | 67 |
|
68 |
||
69 |
(* state of thread manager *) |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
70 |
|
32938 | 71 |
type state = |
72 |
{manager: Thread.thread option, |
|
73 |
timeout_heap: Thread_Heap.T, |
|
28582 | 74 |
active: (Thread.thread * (Time.time * Time.time * string)) list, |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
75 |
cancelling: (Thread.thread * (Time.time * string)) list, |
29620 | 76 |
messages: string list, |
77 |
store: string list}; |
|
28582 | 78 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
79 |
fun make_state manager timeout_heap active cancelling messages store : state = |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
80 |
{manager = manager, timeout_heap = timeout_heap, active = active, |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
81 |
cancelling = cancelling, messages = messages, store = store}; |
28582 | 82 |
|
32938 | 83 |
val global_state = Synchronized.var "atp_manager" |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
84 |
(make_state NONE Thread_Heap.empty [] [] [] []); |
28582 | 85 |
|
31368 | 86 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
87 |
(* unregister ATP thread *) |
28582 | 88 |
|
33312 | 89 |
fun unregister message thread = Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
90 |
(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
|
91 |
(case lookup_thread active thread of |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
92 |
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
|
93 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
94 |
val active' = delete_thread thread active; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
95 |
val cancelling' = (thread, (Time.now (), description)) :: cancelling; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
96 |
val message' = description ^ "\n" ^ message; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
97 |
val messages' = message' :: messages; |
29620 | 98 |
val store' = message' :: |
99 |
(if length store <= message_store_limit then store |
|
32938 | 100 |
else #1 (chop message_store_limit store)); |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
101 |
in make_state manager timeout_heap active' cancelling' messages' store' end |
30800 | 102 |
| NONE => state)); |
28582 | 103 |
|
104 |
||
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
105 |
(* main manager thread -- only one may exist *) |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
106 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
107 |
val min_wait_time = Time.fromMilliseconds 300; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
108 |
val max_wait_time = Time.fromSeconds 10; |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
109 |
|
29620 | 110 |
fun print_new_messages () = |
32938 | 111 |
let val msgs = Synchronized.change_result global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
112 |
(fn {manager, timeout_heap, active, cancelling, messages, store} => |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
113 |
(messages, make_state manager timeout_heap active cancelling [] store)) |
30800 | 114 |
in |
32938 | 115 |
if null msgs then () |
116 |
else priority ("Sledgehammer: " ^ space_implode "\n\n" msgs) |
|
30800 | 117 |
end; |
29620 | 118 |
|
32938 | 119 |
fun check_thread_manager () = Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
120 |
(fn state as {manager, timeout_heap, active, cancelling, messages, store} => |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
121 |
if (case manager of SOME thread => Thread.isActive thread | NONE => false) then state |
32938 | 122 |
else let val manager = SOME (SimpleThread.fork false (fn () => |
123 |
let |
|
124 |
fun time_limit timeout_heap = |
|
125 |
(case try Thread_Heap.min timeout_heap of |
|
126 |
NONE => Time.+ (Time.now (), max_wait_time) |
|
127 |
| SOME (time, _) => time); |
|
28582 | 128 |
|
32938 | 129 |
(*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
|
130 |
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
|
131 |
let val (timeout_threads, timeout_heap') = |
32938 | 132 |
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
|
133 |
in |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
134 |
if null timeout_threads andalso null cancelling |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
135 |
then NONE |
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
136 |
else |
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
137 |
let |
32938 | 138 |
val _ = List.app (SimpleThread.interrupt o #1) cancelling; |
139 |
val cancelling' = filter (Thread.isActive o #1) cancelling; |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
140 |
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
|
141 |
in SOME (map #2 timeout_threads, state') end |
32938 | 142 |
end; |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
143 |
in |
32938 | 144 |
while Synchronized.change_result global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
145 |
(fn state as {timeout_heap, active, cancelling, messages, store, ...} => |
32938 | 146 |
if null active andalso null cancelling andalso null messages |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
147 |
then (false, make_state NONE timeout_heap active cancelling messages store) |
32938 | 148 |
else (true, state)) |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
149 |
do |
32938 | 150 |
(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
|
151 |
|> these |
33312 | 152 |
|> List.app (unregister "Interrupted (reached timeout)"); |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
153 |
print_new_messages (); |
32938 | 154 |
(*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
|
155 |
OS.Process.sleep min_wait_time) |
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
156 |
end)) |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
157 |
in make_state manager timeout_heap active cancelling messages store end); |
28582 | 158 |
|
159 |
||
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
160 |
(* register ATP thread *) |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
161 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
162 |
fun register birth_time death_time (thread, desc) = |
32938 | 163 |
(Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
164 |
(fn {manager, timeout_heap, active, cancelling, messages, store} => |
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
165 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
166 |
val timeout_heap' = Thread_Heap.insert (death_time, thread) timeout_heap; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
167 |
val active' = update_thread (thread, (birth_time, death_time, desc)) active; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
168 |
val state' = make_state manager timeout_heap' active' cancelling messages store; |
32938 | 169 |
in state' end); |
30798 | 170 |
check_thread_manager ()); |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
171 |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
172 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
173 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
174 |
(** user commands **) |
28582 | 175 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
176 |
(* kill *) |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
177 |
|
32938 | 178 |
fun kill () = Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
179 |
(fn {manager, timeout_heap, active, cancelling, messages, store} => |
32938 | 180 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
181 |
val killing = map (fn (th, (_, _, desc)) => (th, (Time.now (), desc))) active; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
182 |
val state' = make_state manager timeout_heap [] (killing @ cancelling) messages store; |
32938 | 183 |
in state' end); |
28582 | 184 |
|
185 |
||
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
186 |
(* info *) |
28582 | 187 |
|
32938 | 188 |
fun seconds time = string_of_int (Time.toSeconds time) ^ "s"; |
189 |
||
28582 | 190 |
fun info () = |
191 |
let |
|
32938 | 192 |
val {active, cancelling, ...} = Synchronized.value global_state; |
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
193 |
|
32938 | 194 |
val now = Time.now (); |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
195 |
fun running_info (_, (birth_time, death_time, desc)) = |
32938 | 196 |
"Running: " ^ seconds (Time.- (now, birth_time)) ^ " -- " ^ |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
197 |
seconds (Time.- (death_time, now)) ^ " to live:\n" ^ desc; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
198 |
fun cancelling_info (_, (deadth_time, desc)) = |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
199 |
"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
|
200 |
|
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
201 |
val running = |
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
202 |
if null active then "No ATPs running." |
32938 | 203 |
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
|
204 |
val interrupting = |
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
205 |
if null cancelling then "" |
32938 | 206 |
else |
207 |
space_implode "\n\n" |
|
208 |
("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
|
209 |
|
28582 | 210 |
in writeln (running ^ "\n" ^ interrupting) end; |
211 |
||
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
212 |
fun messages opt_limit = |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
213 |
let |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
214 |
val limit = the_default message_display_limit opt_limit; |
32938 | 215 |
val {store, ...} = Synchronized.value global_state; |
216 |
val header = |
|
217 |
"Recent ATP messages" ^ |
|
218 |
(if length store <= limit then ":" else " (" ^ string_of_int limit ^ " displayed):"); |
|
219 |
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
|
220 |
|
28582 | 221 |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
222 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
223 |
(** The Sledgehammer **) |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
224 |
|
28582 | 225 |
(* named provers *) |
28484 | 226 |
|
28582 | 227 |
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
|
228 |
|
28582 | 229 |
structure Provers = TheoryDataFun |
230 |
( |
|
32938 | 231 |
type T = (ATP_Wrapper.prover * stamp) Symtab.table; |
232 |
val empty = Symtab.empty; |
|
233 |
val copy = I; |
|
234 |
val extend = I; |
|
28582 | 235 |
fun merge _ tabs : T = Symtab.merge (eq_snd op =) tabs |
32938 | 236 |
handle Symtab.DUP dup => err_dup_prover dup; |
28582 | 237 |
); |
28484 | 238 |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32824
diff
changeset
|
239 |
fun add_prover (name, prover) thy = |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
240 |
Provers.map (Symtab.update_new (name, (prover, stamp ()))) thy |
28582 | 241 |
handle Symtab.DUP dup => err_dup_prover dup; |
242 |
||
32995 | 243 |
fun get_prover thy name = |
244 |
Option.map #1 (Symtab.lookup (Provers.get thy) name); |
|
245 |
||
28582 | 246 |
fun print_provers thy = Pretty.writeln |
247 |
(Pretty.strs ("external provers:" :: sort_strings (Symtab.keys (Provers.get thy)))); |
|
28571 | 248 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
249 |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
250 |
(* start prover thread *) |
28484 | 251 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
252 |
fun start_prover name birth_time death_time i proof_state = |
32947
3c19b98a35cd
ATP_Manager.get_prover: canonical argument order;
wenzelm
parents:
32941
diff
changeset
|
253 |
(case get_prover (Proof.theory_of proof_state) name of |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
254 |
NONE => warning ("Unknown external prover: " ^ quote name) |
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
30982
diff
changeset
|
255 |
| SOME prover => |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
256 |
let |
33292 | 257 |
val {context = ctxt, facts, goal} = Proof.raw_goal proof_state; (* FIXME Proof.goal *) |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
258 |
val desc = |
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
259 |
"external prover " ^ quote name ^ " for subgoal " ^ string_of_int i ^ ":\n" ^ |
32938 | 260 |
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
|
261 |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
262 |
val _ = SimpleThread.fork true (fn () => |
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
263 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
264 |
val _ = register birth_time death_time (Thread.self (), desc); |
33292 | 265 |
val problem = ATP_Wrapper.problem_of_goal (! full_types) i (ctxt, (facts, goal)); |
33312 | 266 |
val message = #message (prover (! timeout) problem) |
33316 | 267 |
handle Res_HOL_Clause.TOO_TRIVIAL => (* FIXME !? *) |
33312 | 268 |
"Empty clause: Try this command: " ^ Markup.markup Markup.sendback "apply metis" |
269 |
| ERROR msg => ("Error: " ^ msg); |
|
270 |
val _ = unregister message (Thread.self ()); |
|
33220
11a1af478dac
SimpleThread.fork: uniform handling of outermost Interrupt, which is not an error and should not produce exception trace;
wenzelm
parents:
32996
diff
changeset
|
271 |
in () end) |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
272 |
in () end); |
28582 | 273 |
|
274 |
||
275 |
(* sledghammer for first subgoal *) |
|
276 |
||
277 |
fun sledgehammer names proof_state = |
|
278 |
let |
|
32938 | 279 |
val provers = if null names then get_atps () else names; |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
280 |
val birth_time = Time.now (); |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
281 |
val death_time = Time.+ (birth_time, Time.fromSeconds (! timeout)); |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
282 |
val _ = kill (); (*RACE wrt. other invocations of sledgehammer*) |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
283 |
val _ = List.app (fn name => start_prover name birth_time death_time 1 proof_state) provers; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
284 |
in () end; |
28582 | 285 |
|
286 |
||
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
287 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
288 |
(** Isar command syntax **) |
28582 | 289 |
|
290 |
local structure K = OuterKeyword and P = OuterParse in |
|
291 |
||
292 |
val _ = |
|
293 |
OuterSyntax.improper_command "atp_kill" "kill all managed provers" K.diag |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
294 |
(Scan.succeed (Toplevel.no_timing o Toplevel.imperative kill)); |
28582 | 295 |
|
296 |
val _ = |
|
297 |
OuterSyntax.improper_command "atp_info" "print information about managed provers" K.diag |
|
298 |
(Scan.succeed (Toplevel.no_timing o Toplevel.imperative info)); |
|
299 |
||
300 |
val _ = |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
301 |
OuterSyntax.improper_command "atp_messages" "print recent messages issued by managed provers" K.diag |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
302 |
(Scan.option (P.$$$ "(" |-- P.nat --| P.$$$ ")") >> |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
303 |
(fn limit => Toplevel.no_timing o Toplevel.imperative (fn () => messages limit))); |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
304 |
|
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
305 |
val _ = |
28582 | 306 |
OuterSyntax.improper_command "print_atps" "print external provers" K.diag |
307 |
(Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory o |
|
308 |
Toplevel.keep (print_provers o Toplevel.theory_of))); |
|
309 |
||
310 |
val _ = |
|
311 |
OuterSyntax.command "sledgehammer" "call all automatic theorem provers" K.diag |
|
312 |
(Scan.repeat P.xname >> (fn names => Toplevel.no_timing o Toplevel.unknown_proof o |
|
30800 | 313 |
Toplevel.keep (sledgehammer names o Toplevel.proof_of))); |
28582 | 314 |
|
315 |
end; |
|
316 |
||
317 |
end; |
|
30537 | 318 |