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