author | blanchet |
Tue, 27 Apr 2010 18:01:41 +0200 | |
changeset 36482 | 1281be23bd23 |
parent 36473 | 8a5c99a1c965 |
child 36489 | 2b2a2c55d787 |
permissions | -rw-r--r-- |
32327
0971cc0b6a57
src/HOL/Tools/ATP_Manager as separate component, with (almost) everything in one place;
wenzelm
parents:
31793
diff
changeset
|
1 |
(* Title: HOL/Tools/ATP_Manager/atp_manager.ML |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
2 |
Author: Fabian Immler, TU Muenchen |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
3 |
Author: Makarius |
35969 | 4 |
Author: Jasmin Blanchette, TU Muenchen |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
5 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
6 |
Central manager component for ATP threads. |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
7 |
*) |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
8 |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
9 |
signature ATP_MANAGER = |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
10 |
sig |
36393
be73a2b2443b
support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents:
36392
diff
changeset
|
11 |
type name_pool = Sledgehammer_HOL_Clause.name_pool |
35969 | 12 |
type relevance_override = Sledgehammer_Fact_Filter.relevance_override |
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
13 |
type minimize_command = Sledgehammer_Proof_Reconstruct.minimize_command |
35969 | 14 |
type params = |
15 |
{debug: bool, |
|
16 |
verbose: bool, |
|
36143
6490319b1703
added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents:
36064
diff
changeset
|
17 |
overlord: bool, |
35969 | 18 |
atps: string list, |
19 |
full_types: bool, |
|
36235
61159615a0c5
added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents:
36231
diff
changeset
|
20 |
explicit_apply: bool, |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
21 |
respect_no_atp: bool, |
35969 | 22 |
relevance_threshold: real, |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
23 |
convergence: real, |
36220
f3655a3ae1ab
rename Sledgehammer "theory_const" option to "theory_relevant", now that I understand better what it does
blanchet
parents:
36184
diff
changeset
|
24 |
theory_relevant: bool option, |
35969 | 25 |
follow_defs: bool, |
26 |
isar_proof: bool, |
|
36400
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset
|
27 |
shrink_factor: int, |
36064
48aec67c284f
added "modulus" and "sorts" options to control Sledgehammer's Isar proof output
blanchet
parents:
36063
diff
changeset
|
28 |
sorts: bool, |
35969 | 29 |
timeout: Time.time, |
30 |
minimize_timeout: Time.time} |
|
35867 | 31 |
type problem = |
35969 | 32 |
{subgoal: int, |
33 |
goal: Proof.context * (thm list * thm), |
|
34 |
relevance_override: relevance_override, |
|
35 |
axiom_clauses: (thm * (string * int)) list option, |
|
36 |
filtered_clauses: (thm * (string * int)) list option} |
|
36370
a4f601daa175
centralized ATP-specific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset
|
37 |
datatype failure = |
a4f601daa175
centralized ATP-specific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset
|
38 |
Unprovable | TimedOut | OutOfResources | OldSpass | MalformedOutput | |
a4f601daa175
centralized ATP-specific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset
|
39 |
UnknownError |
35867 | 40 |
type prover_result = |
36370
a4f601daa175
centralized ATP-specific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset
|
41 |
{outcome: failure option, |
35969 | 42 |
message: string, |
36393
be73a2b2443b
support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents:
36392
diff
changeset
|
43 |
pool: name_pool option, |
35969 | 44 |
relevant_thm_names: string list, |
45 |
atp_run_time_in_msecs: int, |
|
36369
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset
|
46 |
output: string, |
35969 | 47 |
proof: string, |
48 |
internal_thm_names: string Vector.vector, |
|
36400
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset
|
49 |
conjecture_shape: int list list, |
35969 | 50 |
filtered_clauses: (thm * (string * int)) list} |
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
51 |
type prover = |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
52 |
params -> minimize_command -> Time.time -> problem -> prover_result |
35867 | 53 |
|
35969 | 54 |
val kill_atps: unit -> unit |
55 |
val running_atps: unit -> unit |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
56 |
val messages: int option -> unit |
35867 | 57 |
val add_prover: string * prover -> theory -> theory |
36379
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
58 |
val get_prover: theory -> string -> prover |
35969 | 59 |
val available_atps: theory -> unit |
36373
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36372
diff
changeset
|
60 |
val start_prover_thread: |
36482
1281be23bd23
added total goal count as argument + message when killing ATPs
blanchet
parents:
36473
diff
changeset
|
61 |
params -> Time.time -> Time.time -> int -> int -> relevance_override |
36373
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36372
diff
changeset
|
62 |
-> (string -> minimize_command) -> Proof.state -> string -> unit |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
63 |
end; |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
64 |
|
35865 | 65 |
structure ATP_Manager : ATP_MANAGER = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
66 |
struct |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
67 |
|
36229
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
68 |
open Sledgehammer_Util |
36063
cdc6855a6387
make Sledgehammer output "by" vs. "apply", "qed" vs. "next", and any necessary "prefer"
blanchet
parents:
36059
diff
changeset
|
69 |
open Sledgehammer_Fact_Filter |
cdc6855a6387
make Sledgehammer output "by" vs. "apply", "qed" vs. "next", and any necessary "prefer"
blanchet
parents:
36059
diff
changeset
|
70 |
open Sledgehammer_Proof_Reconstruct |
35969 | 71 |
|
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
72 |
(** problems, results, provers, etc. **) |
35969 | 73 |
|
74 |
type params = |
|
75 |
{debug: bool, |
|
76 |
verbose: bool, |
|
36143
6490319b1703
added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents:
36064
diff
changeset
|
77 |
overlord: bool, |
35969 | 78 |
atps: string list, |
79 |
full_types: bool, |
|
36235
61159615a0c5
added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents:
36231
diff
changeset
|
80 |
explicit_apply: bool, |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
81 |
respect_no_atp: bool, |
35969 | 82 |
relevance_threshold: real, |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
83 |
convergence: real, |
36220
f3655a3ae1ab
rename Sledgehammer "theory_const" option to "theory_relevant", now that I understand better what it does
blanchet
parents:
36184
diff
changeset
|
84 |
theory_relevant: bool option, |
35969 | 85 |
follow_defs: bool, |
86 |
isar_proof: bool, |
|
36400
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset
|
87 |
shrink_factor: int, |
36064
48aec67c284f
added "modulus" and "sorts" options to control Sledgehammer's Isar proof output
blanchet
parents:
36063
diff
changeset
|
88 |
sorts: bool, |
35969 | 89 |
timeout: Time.time, |
90 |
minimize_timeout: Time.time} |
|
35867 | 91 |
|
92 |
type problem = |
|
35969 | 93 |
{subgoal: int, |
94 |
goal: Proof.context * (thm list * thm), |
|
95 |
relevance_override: relevance_override, |
|
96 |
axiom_clauses: (thm * (string * int)) list option, |
|
97 |
filtered_clauses: (thm * (string * int)) list option}; |
|
35867 | 98 |
|
36370
a4f601daa175
centralized ATP-specific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset
|
99 |
datatype failure = |
a4f601daa175
centralized ATP-specific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset
|
100 |
Unprovable | TimedOut | OutOfResources | OldSpass | MalformedOutput | |
a4f601daa175
centralized ATP-specific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset
|
101 |
UnknownError |
a4f601daa175
centralized ATP-specific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset
|
102 |
|
35867 | 103 |
type prover_result = |
36370
a4f601daa175
centralized ATP-specific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset
|
104 |
{outcome: failure option, |
35969 | 105 |
message: string, |
36393
be73a2b2443b
support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents:
36392
diff
changeset
|
106 |
pool: name_pool option, |
35969 | 107 |
relevant_thm_names: string list, |
108 |
atp_run_time_in_msecs: int, |
|
36369
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset
|
109 |
output: string, |
35969 | 110 |
proof: string, |
111 |
internal_thm_names: string Vector.vector, |
|
36400
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset
|
112 |
conjecture_shape: int list list, |
35969 | 113 |
filtered_clauses: (thm * (string * int)) list}; |
35867 | 114 |
|
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
115 |
type prover = |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
116 |
params -> minimize_command -> Time.time -> problem -> prover_result |
35867 | 117 |
|
118 |
||
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
119 |
(** preferences **) |
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
120 |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
121 |
val message_store_limit = 20; |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
122 |
val message_display_limit = 5; |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
123 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
124 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
125 |
(** thread management **) |
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
126 |
|
28582 | 127 |
(* data structures over threads *) |
128 |
||
32939 | 129 |
structure Thread_Heap = Heap |
28582 | 130 |
( |
131 |
type elem = Time.time * Thread.thread; |
|
132 |
fun ord ((a, _), (b, _)) = Time.compare (a, b); |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
133 |
); |
28582 | 134 |
|
31368 | 135 |
fun lookup_thread xs = AList.lookup Thread.equal xs; |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
136 |
fun delete_thread xs = AList.delete Thread.equal xs; |
31368 | 137 |
fun update_thread xs = AList.update Thread.equal xs; |
28582 | 138 |
|
139 |
||
140 |
(* state of thread manager *) |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
141 |
|
32938 | 142 |
type state = |
143 |
{manager: Thread.thread option, |
|
144 |
timeout_heap: Thread_Heap.T, |
|
28582 | 145 |
active: (Thread.thread * (Time.time * Time.time * string)) list, |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
146 |
cancelling: (Thread.thread * (Time.time * string)) list, |
29620 | 147 |
messages: string list, |
148 |
store: string list}; |
|
28582 | 149 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
150 |
fun make_state manager timeout_heap active cancelling messages store : state = |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
151 |
{manager = manager, timeout_heap = timeout_heap, active = active, |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
152 |
cancelling = cancelling, messages = messages, store = store}; |
28582 | 153 |
|
32938 | 154 |
val global_state = Synchronized.var "atp_manager" |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
155 |
(make_state NONE Thread_Heap.empty [] [] [] []); |
28582 | 156 |
|
31368 | 157 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
158 |
(* unregister ATP thread *) |
28582 | 159 |
|
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
160 |
fun unregister ({verbose, ...} : params) message thread = |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
161 |
Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
162 |
(fn state as {manager, timeout_heap, active, cancelling, messages, store} => |
29150
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
163 |
(case lookup_thread active thread of |
36379
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
164 |
SOME (birth_time, _, desc) => |
29150
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
165 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
166 |
val active' = delete_thread thread active; |
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
167 |
val now = Time.now () |
36379
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
168 |
val cancelling' = (thread, (now, desc)) :: cancelling; |
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
169 |
val message' = |
36379
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
170 |
desc ^ "\n" ^ message ^ |
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
171 |
(if verbose then |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
172 |
"Total time: " ^ Int.toString (Time.toMilliseconds |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
173 |
(Time.- (now, birth_time))) ^ " ms.\n" |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
174 |
else |
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
175 |
"") |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
176 |
val messages' = message' :: messages; |
29620 | 177 |
val store' = message' :: |
178 |
(if length store <= message_store_limit then store |
|
32938 | 179 |
else #1 (chop message_store_limit store)); |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
180 |
in make_state manager timeout_heap active' cancelling' messages' store' end |
30800 | 181 |
| NONE => state)); |
28582 | 182 |
|
183 |
||
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
184 |
(* main manager thread -- only one may exist *) |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
185 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
186 |
val min_wait_time = Time.fromMilliseconds 300; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
187 |
val max_wait_time = Time.fromSeconds 10; |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
188 |
|
36229
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
189 |
(* This is a workaround for Proof General's off-by-a-few sendback display bug, |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
190 |
whereby "pr" in "proof" is not highlighted. *) |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
191 |
val break_into_chunks = |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
192 |
map (replace_all "\n\n" "\000") #> maps (space_explode "\000") |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
193 |
|
29620 | 194 |
fun print_new_messages () = |
36229
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
195 |
case Synchronized.change_result global_state |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
196 |
(fn {manager, timeout_heap, active, cancelling, messages, store} => |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
197 |
(messages, make_state manager timeout_heap active cancelling [] |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
198 |
store)) of |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
199 |
[] => () |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
200 |
| msgs => |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
201 |
msgs |> break_into_chunks |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
202 |
|> (fn msg :: msgs => "Sledgehammer: " ^ msg :: msgs) |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
203 |
|> List.app priority |
29620 | 204 |
|
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
205 |
fun check_thread_manager params = Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
206 |
(fn state as {manager, timeout_heap, active, cancelling, messages, store} => |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
207 |
if (case manager of SOME thread => Thread.isActive thread | NONE => false) then state |
33604
d4220df6fde2
Toplevel.thread provides Isar-style exception output;
wenzelm
parents:
33522
diff
changeset
|
208 |
else let val manager = SOME (Toplevel.thread false (fn () => |
32938 | 209 |
let |
210 |
fun time_limit timeout_heap = |
|
211 |
(case try Thread_Heap.min timeout_heap of |
|
212 |
NONE => Time.+ (Time.now (), max_wait_time) |
|
213 |
| SOME (time, _) => time); |
|
28582 | 214 |
|
32938 | 215 |
(*action: find threads whose timeout is reached, and interrupt cancelling threads*) |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
216 |
fun action {manager, timeout_heap, active, cancelling, messages, store} = |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
217 |
let val (timeout_threads, timeout_heap') = |
32938 | 218 |
Thread_Heap.upto (Time.now (), Thread.self ()) timeout_heap; |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
219 |
in |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
220 |
if null timeout_threads andalso null cancelling |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
221 |
then NONE |
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
222 |
else |
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
223 |
let |
32938 | 224 |
val _ = List.app (SimpleThread.interrupt o #1) cancelling; |
225 |
val cancelling' = filter (Thread.isActive o #1) cancelling; |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
226 |
val state' = make_state manager timeout_heap' active cancelling' messages store; |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
227 |
in SOME (map #2 timeout_threads, state') end |
32938 | 228 |
end; |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
229 |
in |
32938 | 230 |
while Synchronized.change_result global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
231 |
(fn state as {timeout_heap, active, cancelling, messages, store, ...} => |
32938 | 232 |
if null active andalso null cancelling andalso null messages |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
233 |
then (false, make_state NONE timeout_heap active cancelling messages store) |
32938 | 234 |
else (true, state)) |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
235 |
do |
32938 | 236 |
(Synchronized.timed_access global_state (SOME o time_limit o #timeout_heap) action |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
237 |
|> these |
36370
a4f601daa175
centralized ATP-specific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset
|
238 |
|> List.app (unregister params "Timed out.\n"); |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
239 |
print_new_messages (); |
32938 | 240 |
(*give threads some time to respond to interrupt*) |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
241 |
OS.Process.sleep min_wait_time) |
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
242 |
end)) |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
243 |
in make_state manager timeout_heap active cancelling messages store end); |
28582 | 244 |
|
245 |
||
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
246 |
(* register ATP thread *) |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
247 |
|
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
248 |
fun register params birth_time death_time (thread, desc) = |
32938 | 249 |
(Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
250 |
(fn {manager, timeout_heap, active, cancelling, messages, store} => |
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
251 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
252 |
val timeout_heap' = Thread_Heap.insert (death_time, thread) timeout_heap; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
253 |
val active' = update_thread (thread, (birth_time, death_time, desc)) active; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
254 |
val state' = make_state manager timeout_heap' active' cancelling messages store; |
32938 | 255 |
in state' end); |
36184
54a9c0679079
output total time taken by Sledgehammer if "verbose" is set
blanchet
parents:
36181
diff
changeset
|
256 |
check_thread_manager params); |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
257 |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
258 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
259 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
260 |
(** user commands **) |
28582 | 261 |
|
35969 | 262 |
(* kill ATPs *) |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
263 |
|
35969 | 264 |
fun kill_atps () = Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
265 |
(fn {manager, timeout_heap, active, cancelling, messages, store} => |
32938 | 266 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
267 |
val killing = map (fn (th, (_, _, desc)) => (th, (Time.now (), desc))) active; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
268 |
val state' = make_state manager timeout_heap [] (killing @ cancelling) messages store; |
36482
1281be23bd23
added total goal count as argument + message when killing ATPs
blanchet
parents:
36473
diff
changeset
|
269 |
val _ = if null active then () |
1281be23bd23
added total goal count as argument + message when killing ATPs
blanchet
parents:
36473
diff
changeset
|
270 |
else priority "Killed active Sledgehammer threads." |
32938 | 271 |
in state' end); |
28582 | 272 |
|
273 |
||
35969 | 274 |
(* running_atps *) |
28582 | 275 |
|
32938 | 276 |
fun seconds time = string_of_int (Time.toSeconds time) ^ "s"; |
277 |
||
35969 | 278 |
fun running_atps () = |
28582 | 279 |
let |
32938 | 280 |
val {active, cancelling, ...} = Synchronized.value global_state; |
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
281 |
|
32938 | 282 |
val now = Time.now (); |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
283 |
fun running_info (_, (birth_time, death_time, desc)) = |
32938 | 284 |
"Running: " ^ seconds (Time.- (now, birth_time)) ^ " -- " ^ |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
285 |
seconds (Time.- (death_time, now)) ^ " to live:\n" ^ desc; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
286 |
fun cancelling_info (_, (deadth_time, desc)) = |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
287 |
"Trying to interrupt thread since " ^ seconds (Time.- (now, deadth_time)) ^ ":\n" ^ desc; |
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
288 |
|
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
289 |
val running = |
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
290 |
if null active then "No ATPs running." |
32938 | 291 |
else space_implode "\n\n" ("Running ATPs:" :: map running_info active); |
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
292 |
val interrupting = |
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
293 |
if null cancelling then "" |
32938 | 294 |
else |
295 |
space_implode "\n\n" |
|
296 |
("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
|
297 |
|
36229
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
298 |
in priority (running ^ "\n" ^ interrupting) end; |
28582 | 299 |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
300 |
fun messages opt_limit = |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
301 |
let |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
302 |
val limit = the_default message_display_limit opt_limit; |
32938 | 303 |
val {store, ...} = Synchronized.value global_state; |
304 |
val header = |
|
305 |
"Recent ATP messages" ^ |
|
306 |
(if length store <= limit then ":" else " (" ^ string_of_int limit ^ " displayed):"); |
|
36229
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
307 |
in List.app priority (header :: break_into_chunks (#1 (chop limit store))) end |
28582 | 308 |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
309 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
310 |
(** The Sledgehammer **) |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
311 |
|
28582 | 312 |
(* named provers *) |
28484 | 313 |
|
36229
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
314 |
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
|
315 |
|
36379
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
316 |
structure Data = Theory_Data |
28582 | 317 |
( |
35867 | 318 |
type T = (prover * stamp) Symtab.table; |
32938 | 319 |
val empty = Symtab.empty; |
320 |
val extend = I; |
|
33522 | 321 |
fun merge data : T = Symtab.merge (eq_snd op =) data |
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
322 |
handle Symtab.DUP name => err_dup_prover name; |
28582 | 323 |
); |
28484 | 324 |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32824
diff
changeset
|
325 |
fun add_prover (name, prover) thy = |
36379
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
326 |
Data.map (Symtab.update_new (name, (prover, stamp ()))) thy |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
327 |
handle Symtab.DUP name => err_dup_prover name; |
28582 | 328 |
|
32995 | 329 |
fun get_prover thy name = |
36379
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
330 |
case Symtab.lookup (Data.get thy) name of |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
331 |
SOME (prover, _) => prover |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
332 |
| NONE => error ("Unknown ATP: " ^ name) |
32995 | 333 |
|
36229
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
334 |
fun available_atps thy = |
c95fab3f9cc5
workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in "proof" is not highlighted
blanchet
parents:
36226
diff
changeset
|
335 |
priority ("Available ATPs: " ^ |
36379
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
336 |
commas (sort_strings (Symtab.keys (Data.get thy))) ^ ".") |
28571 | 337 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
338 |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
339 |
(* start prover thread *) |
28484 | 340 |
|
36482
1281be23bd23
added total goal count as argument + message when killing ATPs
blanchet
parents:
36473
diff
changeset
|
341 |
fun start_prover_thread (params as {timeout, ...}) birth_time death_time i n |
36373
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36372
diff
changeset
|
342 |
relevance_override minimize_command proof_state name = |
36379
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
343 |
let |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
344 |
val prover = get_prover (Proof.theory_of proof_state) name |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
345 |
val {context = ctxt, facts, goal} = Proof.goal proof_state; |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
346 |
val desc = |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
347 |
"ATP " ^ quote name ^ " for subgoal " ^ string_of_int i ^ ":\n" ^ |
36392 | 348 |
Syntax.string_of_term ctxt (Thm.term_of (Thm.cprem_of goal i)); |
36379
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
349 |
val _ = Toplevel.thread true (fn () => |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
350 |
let |
36379
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
351 |
val _ = register params birth_time death_time (Thread.self (), desc) |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
352 |
val problem = |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
353 |
{subgoal = i, goal = (ctxt, (facts, goal)), |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
354 |
relevance_override = relevance_override, axiom_clauses = NONE, |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
355 |
filtered_clauses = NONE} |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
356 |
val message = |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
357 |
#message (prover params (minimize_command name) timeout problem) |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
358 |
handle Sledgehammer_HOL_Clause.TRIVIAL => metis_line i n [] |
36383 | 359 |
| ERROR message => "Error: " ^ message ^ "\n" |
36379
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
360 |
val _ = unregister params message (Thread.self ()); |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
361 |
in () end) |
20ef039bccff
make "ATP_Manager.get_prover" a total function, since we always want to show the same error text
blanchet
parents:
36373
diff
changeset
|
362 |
in () end |
28582 | 363 |
|
364 |
end; |