| author | huffman |
| Thu, 18 Jun 2009 11:52:37 -0700 | |
| changeset 31715 | 2eb55a82acd9 |
| parent 31409 | d8537ba165b5 |
| child 31752 | 19a5f1c8a844 |
| permissions | -rw-r--r-- |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
1 |
(* Title: HOL/Tools/atp_manager.ML |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
2 |
Author: Fabian Immler, TU Muenchen |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
3 |
|
| 28571 | 4 |
ATP threads are registered here. |
5 |
Threads with the same birth-time are seen as one group. |
|
6 |
All threads of a group are killed when one thread of it has been successful, |
|
7 |
or after a certain time, |
|
8 |
or when the maximum number of threads exceeds; then the oldest thread is killed. |
|
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
9 |
*) |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
10 |
|
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
11 |
signature ATP_MANAGER = |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
12 |
sig |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
13 |
val get_atps: unit -> string |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
14 |
val set_atps: string -> unit |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
15 |
val get_max_atps: unit -> int |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
16 |
val set_max_atps: int -> unit |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
17 |
val get_timeout: unit -> int |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
18 |
val set_timeout: int -> unit |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
19 |
val kill: unit -> unit |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
20 |
val info: unit -> unit |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
21 |
val messages: int option -> unit |
|
31409
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
31368
diff
changeset
|
22 |
type prover = int -> (thm * (string * int)) list option -> |
|
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
31368
diff
changeset
|
23 |
(int Symtab.table * bool Symtab.table) option -> string -> int -> |
|
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
31368
diff
changeset
|
24 |
Proof.context * (thm list * thm) -> |
|
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
31368
diff
changeset
|
25 |
bool * string * string * string vector * (int Symtab.table * bool Symtab.table) |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
26 |
val add_prover: string -> prover -> theory -> theory |
| 28484 | 27 |
val print_provers: theory -> unit |
|
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
30982
diff
changeset
|
28 |
val get_prover: string -> theory -> prover option |
| 28571 | 29 |
val sledgehammer: string list -> Proof.state -> unit |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
30 |
end; |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
31 |
|
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
32 |
structure AtpManager: ATP_MANAGER = |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
33 |
struct |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
34 |
|
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
35 |
(** preferences **) |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
36 |
|
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
37 |
val message_store_limit = 20; |
|
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
38 |
val message_display_limit = 5; |
|
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
39 |
|
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
40 |
local |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
41 |
|
| 29598 | 42 |
val atps = ref "e remote_vampire"; |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
43 |
val max_atps = ref 5; (* ~1 means infinite number of atps *) |
| 29784 | 44 |
val timeout = ref 60; |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
45 |
|
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
46 |
in |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
47 |
|
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
48 |
fun get_atps () = CRITICAL (fn () => ! atps); |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
49 |
fun set_atps str = CRITICAL (fn () => atps := str); |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
50 |
|
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
51 |
fun get_max_atps () = CRITICAL (fn () => ! max_atps); |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
52 |
fun set_max_atps number = CRITICAL (fn () => max_atps := number); |
|
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 |
fun get_timeout () = CRITICAL (fn () => ! timeout); |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
55 |
fun set_timeout time = CRITICAL (fn () => timeout := time); |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
56 |
|
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
57 |
val _ = |
| 30982 | 58 |
ProofGeneralPgip.add_preference Preferences.category_proof |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
59 |
(Preferences.string_pref atps |
|
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
60 |
"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
|
61 |
|
| 30982 | 62 |
val _ = |
63 |
ProofGeneralPgip.add_preference Preferences.category_proof |
|
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
64 |
(Preferences.int_pref max_atps |
|
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
65 |
"ATP: maximum number" "How many provers may run in parallel"); |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
66 |
|
| 30982 | 67 |
val _ = |
68 |
ProofGeneralPgip.add_preference Preferences.category_proof |
|
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
69 |
(Preferences.int_pref timeout |
|
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
70 |
"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
|
71 |
|
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
72 |
end; |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
73 |
|
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
74 |
|
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
75 |
|
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
76 |
(** thread management **) |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
77 |
|
| 28582 | 78 |
(* data structures over threads *) |
79 |
||
80 |
structure ThreadHeap = HeapFun |
|
81 |
( |
|
82 |
type elem = Time.time * Thread.thread; |
|
83 |
fun ord ((a, _), (b, _)) = Time.compare (a, b); |
|
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
84 |
); |
| 28582 | 85 |
|
| 31368 | 86 |
fun lookup_thread xs = AList.lookup Thread.equal xs; |
87 |
fun delete_thread xs = AList.delete Thread.equal xs; |
|
88 |
fun update_thread xs = AList.update Thread.equal xs; |
|
| 28582 | 89 |
|
90 |
||
91 |
(* state of thread manager *) |
|
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
92 |
|
| 28582 | 93 |
datatype T = State of |
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
94 |
{managing_thread: Thread.thread option,
|
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
95 |
timeout_heap: ThreadHeap.T, |
| 28582 | 96 |
oldest_heap: ThreadHeap.T, |
97 |
active: (Thread.thread * (Time.time * Time.time * string)) list, |
|
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
98 |
cancelling: (Thread.thread * (Time.time * Time.time * string)) list, |
| 29620 | 99 |
messages: string list, |
100 |
store: string list}; |
|
| 28582 | 101 |
|
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
102 |
fun make_state managing_thread timeout_heap oldest_heap active cancelling messages store = |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
103 |
State {managing_thread = managing_thread, timeout_heap = timeout_heap, oldest_heap = oldest_heap,
|
| 29620 | 104 |
active = active, cancelling = cancelling, messages = messages, store = store}; |
| 28582 | 105 |
|
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
106 |
val state = Synchronized.var "atp_manager" |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
107 |
(make_state NONE ThreadHeap.empty ThreadHeap.empty [] [] [] []); |
| 28582 | 108 |
|
| 31368 | 109 |
|
|
29150
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
110 |
(* unregister thread *) |
| 28582 | 111 |
|
| 29620 | 112 |
fun unregister (success, message) thread = Synchronized.change state |
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
113 |
(fn state as State {managing_thread, timeout_heap, oldest_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
|
114 |
(case lookup_thread active thread of |
|
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
115 |
SOME (birthtime, _, description) => |
|
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
116 |
let |
|
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
117 |
val (group, active') = |
|
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
118 |
if success then List.partition (fn (_, (tb, _, _)) => tb = birthtime) active |
|
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
119 |
else List.partition (fn (th, _) => Thread.equal (th, thread)) active |
| 28582 | 120 |
|
|
29150
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
121 |
val now = Time.now () |
|
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
122 |
val cancelling' = |
| 29620 | 123 |
fold (fn (th, (tb, _, desc)) => update_thread (th, (tb, now, desc))) group cancelling |
| 28582 | 124 |
|
| 29620 | 125 |
val message' = description ^ "\n" ^ message ^ |
| 29596 | 126 |
(if length group <= 1 then "" |
127 |
else "\nInterrupted " ^ string_of_int (length group - 1) ^ " other group members") |
|
| 29620 | 128 |
val store' = message' :: |
129 |
(if length store <= message_store_limit then store |
|
130 |
else #1 (chop message_store_limit store)) |
|
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
131 |
in make_state |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
132 |
managing_thread timeout_heap oldest_heap active' cancelling' (message' :: messages) store' |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
133 |
end |
| 30800 | 134 |
| NONE => state)); |
| 28582 | 135 |
|
136 |
||
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
137 |
(* kill excessive atp threads *) |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
138 |
|
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
139 |
fun excessive_atps active = |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
140 |
let val max = get_max_atps () |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
141 |
in length active > max andalso max > ~1 end; |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
142 |
|
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
143 |
local |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
144 |
|
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
145 |
fun kill_oldest () = |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
146 |
let exception Unchanged in |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
147 |
Synchronized.change_result state |
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
148 |
(fn State {managing_thread, timeout_heap, oldest_heap, active, cancelling, messages, store} =>
|
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
149 |
if ThreadHeap.is_empty oldest_heap orelse not (excessive_atps active) |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
150 |
then raise Unchanged |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
151 |
else |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
152 |
let val ((_, oldest_thread), oldest_heap') = ThreadHeap.min_elem oldest_heap |
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
153 |
in (oldest_thread, |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
154 |
make_state managing_thread timeout_heap oldest_heap' active cancelling messages store) end) |
| 29620 | 155 |
|> unregister (false, "Interrupted (maximum number of ATPs exceeded)") |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
156 |
handle Unchanged => () |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
157 |
end; |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
158 |
|
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
159 |
in |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
160 |
|
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
161 |
fun kill_excessive () = |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
162 |
let val State {active, ...} = Synchronized.value state
|
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
163 |
in if excessive_atps active then (kill_oldest (); kill_excessive ()) else () end; |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
164 |
|
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
165 |
end; |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
166 |
|
| 29620 | 167 |
fun print_new_messages () = |
168 |
let val to_print = Synchronized.change_result state |
|
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
169 |
(fn State {managing_thread, timeout_heap, oldest_heap, active, cancelling, messages, store} =>
|
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
170 |
(messages, make_state managing_thread timeout_heap oldest_heap active cancelling [] store)) |
| 30800 | 171 |
in |
172 |
if null to_print then () |
|
173 |
else priority ("Sledgehammer: " ^ space_implode "\n\n" to_print)
|
|
174 |
end; |
|
| 29620 | 175 |
|
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
176 |
|
| 30800 | 177 |
(* start a watching thread -- only one may exist *) |
| 28582 | 178 |
|
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
179 |
fun check_thread_manager () = Synchronized.change state |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
180 |
(fn State {managing_thread, timeout_heap, oldest_heap, active, cancelling, messages, store} =>
|
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
181 |
if (case managing_thread of SOME thread => Thread.isActive thread | NONE => false) |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
182 |
then make_state managing_thread timeout_heap oldest_heap active cancelling messages store |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
183 |
else let val managing_thread = SOME (SimpleThread.fork false (fn () => |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
184 |
let |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
185 |
val min_wait_time = Time.fromMilliseconds 300 |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
186 |
val max_wait_time = Time.fromSeconds 10 |
| 28582 | 187 |
|
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
188 |
(* wait for next thread to cancel, or maximum*) |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
189 |
fun time_limit (State {timeout_heap, ...}) =
|
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
190 |
(case try ThreadHeap.min timeout_heap of |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
191 |
NONE => SOME (Time.+ (Time.now (), max_wait_time)) |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
192 |
| SOME (time, _) => SOME time) |
| 28582 | 193 |
|
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
194 |
(* action: find threads whose timeout is reached, and interrupt cancelling threads *) |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
195 |
fun action (State {managing_thread, timeout_heap, oldest_heap, active, cancelling,
|
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
196 |
messages, store}) = |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
197 |
let val (timeout_threads, timeout_heap') = |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
198 |
ThreadHeap.upto (Time.now (), Thread.self ()) timeout_heap |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
199 |
in |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
200 |
if null timeout_threads andalso null cancelling andalso not (excessive_atps active) |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
201 |
then NONE |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
202 |
else |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
203 |
let |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
204 |
val _ = List.app (SimpleThread.interrupt o #1) cancelling |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
205 |
val cancelling' = filter (Thread.isActive o #1) cancelling |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
206 |
val state' = make_state |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
207 |
managing_thread timeout_heap' oldest_heap active cancelling' messages store |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
208 |
in SOME (map #2 timeout_threads, state') end |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
209 |
end |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
210 |
in |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
211 |
while Synchronized.change_result state |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
212 |
(fn st as |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
213 |
State {managing_thread, timeout_heap, oldest_heap, active, cancelling, messages, store} =>
|
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
214 |
if (null active) andalso (null cancelling) andalso (null messages) |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
215 |
then (false, make_state NONE timeout_heap oldest_heap active cancelling messages store) |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
216 |
else (true, st)) |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
217 |
do |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
218 |
(Synchronized.timed_access state time_limit action |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
219 |
|> these |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
220 |
|> List.app (unregister (false, "Interrupted (reached timeout)")); |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
221 |
kill_excessive (); |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
222 |
print_new_messages (); |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
223 |
(*give threads time to respond to interrupt*) |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
224 |
OS.Process.sleep min_wait_time) |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
225 |
end)) |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
226 |
in make_state managing_thread timeout_heap oldest_heap active cancelling messages store end); |
| 28582 | 227 |
|
228 |
||
229 |
(* thread is registered here by sledgehammer *) |
|
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
230 |
|
| 28582 | 231 |
fun register birthtime deadtime (thread, desc) = |
| 30798 | 232 |
(Synchronized.change state |
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
233 |
(fn State {managing_thread, timeout_heap, oldest_heap, active, cancelling, messages, store} =>
|
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
234 |
let |
|
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
235 |
val timeout_heap' = ThreadHeap.insert (deadtime, thread) timeout_heap |
|
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
236 |
val oldest_heap' = ThreadHeap.insert (birthtime, thread) oldest_heap |
|
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
237 |
val active' = update_thread (thread, (birthtime, deadtime, desc)) active |
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
238 |
in make_state managing_thread timeout_heap' oldest_heap' active' cancelling messages store end); |
| 30798 | 239 |
check_thread_manager ()); |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
240 |
|
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
241 |
|
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
242 |
|
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
243 |
(** user commands **) |
| 28582 | 244 |
|
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
245 |
(* kill: move all threads to cancelling *) |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
246 |
|
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
247 |
fun kill () = Synchronized.change state |
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
248 |
(fn State {managing_thread, timeout_heap, oldest_heap, active, cancelling, messages, store} =>
|
| 28582 | 249 |
let val formerly_active = map (fn (th, (tb, _, desc)) => (th, (tb, Time.now (), desc))) active |
|
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
250 |
in make_state |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
251 |
managing_thread timeout_heap oldest_heap [] (formerly_active @ cancelling) messages store |
|
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
252 |
end); |
| 28582 | 253 |
|
254 |
||
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
255 |
(* ATP info *) |
| 28582 | 256 |
|
257 |
fun info () = |
|
258 |
let |
|
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
259 |
val State {active, cancelling, ...} = Synchronized.value state
|
|
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
260 |
|
| 28571 | 261 |
fun running_info (_, (birth_time, dead_time, desc)) = "Running: " |
|
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
262 |
^ (string_of_int o Time.toSeconds) (Time.- (Time.now (), birth_time)) |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
263 |
^ " s -- " |
|
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
264 |
^ (string_of_int o Time.toSeconds) (Time.- (dead_time, Time.now ())) |
| 28571 | 265 |
^ " s to live:\n" ^ desc |
266 |
fun cancelling_info (_, (_, dead_time, desc)) = "Trying to interrupt thread since " |
|
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
267 |
^ (string_of_int o Time.toSeconds) (Time.- (Time.now (), dead_time)) |
| 28571 | 268 |
^ " s:\n" ^ desc |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
269 |
|
|
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
270 |
val running = |
|
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
271 |
if null active then "No ATPs running." |
|
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
272 |
else space_implode "\n\n" ("Running ATPs:" :: map running_info active)
|
|
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
273 |
val interrupting = |
|
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
274 |
if null cancelling then "" |
|
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
275 |
else space_implode "\n\n" |
|
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
276 |
("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
|
277 |
|
| 28582 | 278 |
in writeln (running ^ "\n" ^ interrupting) end; |
279 |
||
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
280 |
fun messages opt_limit = |
|
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
281 |
let |
|
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
282 |
val limit = the_default message_display_limit opt_limit; |
| 29620 | 283 |
val State {store = msgs, ...} = Synchronized.value state
|
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
284 |
val header = "Recent ATP messages" ^ |
|
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
285 |
(if length msgs <= limit then ":" else " (" ^ string_of_int limit ^ " displayed):");
|
| 29116 | 286 |
in writeln (space_implode "\n\n" (header :: #1 (chop limit msgs))) end; |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
287 |
|
| 28582 | 288 |
|
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
289 |
|
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
290 |
(** The Sledgehammer **) |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
291 |
|
| 28582 | 292 |
(* named provers *) |
| 28484 | 293 |
|
|
31409
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
31368
diff
changeset
|
294 |
type prover = int -> (thm * (string * int)) list option -> |
|
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
31368
diff
changeset
|
295 |
(int Symtab.table * bool Symtab.table) option -> string -> int -> |
|
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
31368
diff
changeset
|
296 |
Proof.context * (thm list * thm) -> |
|
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
31368
diff
changeset
|
297 |
bool * string * string * string vector * (int Symtab.table * bool Symtab.table) |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
298 |
|
| 28582 | 299 |
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
|
300 |
|
| 28582 | 301 |
structure Provers = TheoryDataFun |
302 |
( |
|
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
303 |
type T = (prover * stamp) Symtab.table |
| 28582 | 304 |
val empty = Symtab.empty |
305 |
val copy = I |
|
306 |
val extend = I |
|
307 |
fun merge _ tabs : T = Symtab.merge (eq_snd op =) tabs |
|
|
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
308 |
handle Symtab.DUP dup => err_dup_prover dup |
| 28582 | 309 |
); |
| 28484 | 310 |
|
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
311 |
fun add_prover name prover thy = |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
312 |
Provers.map (Symtab.update_new (name, (prover, stamp ()))) thy |
| 28582 | 313 |
handle Symtab.DUP dup => err_dup_prover dup; |
314 |
||
315 |
fun print_provers thy = Pretty.writeln |
|
316 |
(Pretty.strs ("external provers:" :: sort_strings (Symtab.keys (Provers.get thy))));
|
|
| 28571 | 317 |
|
|
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
30982
diff
changeset
|
318 |
fun get_prover name thy = case Symtab.lookup (Provers.get thy) name of |
|
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
30982
diff
changeset
|
319 |
NONE => NONE |
|
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
30982
diff
changeset
|
320 |
| SOME (prover, _) => SOME prover; |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
321 |
|
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
322 |
(* start prover thread *) |
| 28484 | 323 |
|
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
324 |
fun start_prover name birthtime deadtime i proof_state = |
|
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
30982
diff
changeset
|
325 |
(case get_prover name (Proof.theory_of proof_state) of |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
326 |
NONE => warning ("Unknown external prover: " ^ quote name)
|
|
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
30982
diff
changeset
|
327 |
| SOME prover => |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
328 |
let |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
329 |
val (ctxt, (_, goal)) = Proof.get_goal proof_state |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
330 |
val desc = |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
331 |
"external prover " ^ quote name ^ " for subgoal " ^ string_of_int i ^ ":\n" ^ |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
332 |
Syntax.string_of_term ctxt (Thm.term_of (Thm.cprem_of goal i)) |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
333 |
val _ = SimpleThread.fork true (fn () => |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
334 |
let |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
335 |
val _ = register birthtime deadtime (Thread.self (), desc) |
|
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
30982
diff
changeset
|
336 |
val result = |
|
31409
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
31368
diff
changeset
|
337 |
let val (success, message, _, _, _) = |
|
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
31368
diff
changeset
|
338 |
prover (get_timeout ()) NONE NONE name i (Proof.get_goal proof_state) |
|
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
30982
diff
changeset
|
339 |
in (success, message) end |
| 28835 | 340 |
handle ResHolClause.TOO_TRIVIAL |
341 |
=> (true, "Empty clause: Try this command: " ^ Markup.markup Markup.sendback "apply metis") |
|
342 |
| ERROR msg |
|
343 |
=> (false, "Error: " ^ msg) |
|
| 29620 | 344 |
val _ = unregister result (Thread.self ()) |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
345 |
in () end handle Interrupt => ()) |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
346 |
in () end); |
| 28582 | 347 |
|
348 |
||
349 |
(* sledghammer for first subgoal *) |
|
350 |
||
351 |
fun sledgehammer names proof_state = |
|
352 |
let |
|
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
353 |
val provers = |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
354 |
if null names then String.tokens (Symbol.is_ascii_blank o String.str) (get_atps ()) |
| 28582 | 355 |
else names |
356 |
val birthtime = Time.now () |
|
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
357 |
val deadtime = Time.+ (birthtime, Time.fromSeconds (get_timeout ())) |
|
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
358 |
in List.app (fn name => start_prover name birthtime deadtime 1 proof_state) provers end; |
| 28582 | 359 |
|
360 |
||
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
361 |
|
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
362 |
(** Isar command syntax **) |
| 28582 | 363 |
|
364 |
local structure K = OuterKeyword and P = OuterParse in |
|
365 |
||
366 |
val _ = |
|
367 |
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
|
368 |
(Scan.succeed (Toplevel.no_timing o Toplevel.imperative kill)); |
| 28582 | 369 |
|
370 |
val _ = |
|
371 |
OuterSyntax.improper_command "atp_info" "print information about managed provers" K.diag |
|
372 |
(Scan.succeed (Toplevel.no_timing o Toplevel.imperative info)); |
|
373 |
||
374 |
val _ = |
|
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
375 |
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
|
376 |
(Scan.option (P.$$$ "(" |-- P.nat --| P.$$$ ")") >>
|
|
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
377 |
(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
|
378 |
|
|
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
379 |
val _ = |
| 28582 | 380 |
OuterSyntax.improper_command "print_atps" "print external provers" K.diag |
381 |
(Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory o |
|
382 |
Toplevel.keep (print_provers o Toplevel.theory_of))); |
|
383 |
||
384 |
val _ = |
|
385 |
OuterSyntax.command "sledgehammer" "call all automatic theorem provers" K.diag |
|
386 |
(Scan.repeat P.xname >> (fn names => Toplevel.no_timing o Toplevel.unknown_proof o |
|
| 30800 | 387 |
Toplevel.keep (sledgehammer names o Toplevel.proof_of))); |
| 28582 | 388 |
|
389 |
end; |
|
390 |
||
391 |
end; |
|
| 30537 | 392 |