src/HOL/Tools/ATP_Manager/atp_manager.ML
author blanchet
Tue, 27 Apr 2010 18:01:41 +0200
changeset 36482 1281be23bd23
parent 36473 8a5c99a1c965
child 36489 2b2a2c55d787
permissions -rw-r--r--
added total goal count as argument + message when killing ATPs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
     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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    14
  type params =
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    15
    {debug: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    18
     atps: string list,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    25
     follow_defs: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    29
     timeout: Time.time,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    30
     minimize_timeout: Time.time}
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    31
  type problem =
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    32
    {subgoal: int,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    33
     goal: Proof.context * (thm list * thm),
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    34
     relevance_override: relevance_override,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    35
     axiom_clauses: (thm * (string * int)) list option,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    44
     relevant_thm_names: string list,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    47
     proof: string,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    53
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    54
  val kill_atps: unit -> unit
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35826
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    71
36281
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
    72
(** problems, results, provers, etc. **)
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    73
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    74
type params =
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    75
  {debug: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    78
   atps: string list,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    85
   follow_defs: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    89
   timeout: Time.time,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    90
   minimize_timeout: Time.time}
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    91
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    92
type problem =
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    93
  {subgoal: int,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    94
   goal: Proof.context * (thm list * thm),
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    95
   relevance_override: relevance_override,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    96
   axiom_clauses: (thm * (string * int)) list option,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    97
   filtered_clauses: (thm * (string * int)) list option};
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    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
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
   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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   107
   relevant_thm_names: string list,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   110
   proof: string,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   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
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   113
   filtered_clauses: (thm * (string * int)) list};
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
   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
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
   117
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   127
(* data structures over threads *)
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   128
32939
1b5a401c78cb renamed functor HeapFun to Heap;
wenzelm
parents: 32938
diff changeset
   129
structure Thread_Heap = Heap
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   130
(
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   131
  type elem = Time.time * Thread.thread;
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   134
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31037
diff changeset
   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
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31037
diff changeset
   137
fun update_thread xs = AList.update Thread.equal xs;
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   138
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   139
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   140
(* state of thread manager *)
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
   141
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   142
type state =
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   143
 {manager: Thread.thread option,
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   144
  timeout_heap: Thread_Heap.T,
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   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
dc1257eaa4f2 moved all output to watcher-thread
immler@in.tum.de
parents: 29598
diff changeset
   147
  messages: string list,
dc1257eaa4f2 moved all output to watcher-thread
immler@in.tum.de
parents: 29598
diff changeset
   148
  store: string list};
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   153
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   156
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31037
diff changeset
   157
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   158
(* unregister ATP thread *)
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   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
dc1257eaa4f2 moved all output to watcher-thread
immler@in.tum.de
parents: 29598
diff changeset
   177
          val store' = message' ::
dc1257eaa4f2 moved all output to watcher-thread
immler@in.tum.de
parents: 29598
diff changeset
   178
            (if length store <= message_store_limit then store
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
95cbadcd47fc tuned spacing and formatting;
wenzelm
parents: 30798
diff changeset
   181
    | NONE => state));
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   182
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   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
dc1257eaa4f2 moved all output to watcher-thread
immler@in.tum.de
parents: 29598
diff changeset
   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
dc1257eaa4f2 moved all output to watcher-thread
immler@in.tum.de
parents: 29598
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   209
      let
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   210
        fun time_limit timeout_heap =
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   211
          (case try Thread_Heap.min timeout_heap of
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   212
            NONE => Time.+ (Time.now (), max_wait_time)
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   213
          | SOME (time, _) => time);
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   214
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   224
                val _ = List.app (SimpleThread.interrupt o #1) cancelling;
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   228
          end;
30830
263064c4d0c3 included managing_thread in state of AtpManager:
immler@in.tum.de
parents: 30800
diff changeset
   229
      in
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   234
            else (true, state))
30830
263064c4d0c3 included managing_thread in state of AtpManager:
immler@in.tum.de
parents: 30800
diff changeset
   235
        do
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   244
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   261
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   262
(* kill ATPs *)
28586
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   263
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   271
    in state' end);
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   272
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   273
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   274
(* running_atps *)
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   275
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   276
fun seconds time = string_of_int (Time.toSeconds time) ^ "s";
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   277
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   278
fun running_atps () =
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   279
  let
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   294
      else
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   295
        space_implode "\n\n"
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   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
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   303
    val {store, ...} = Synchronized.value global_state;
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   304
    val header =
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   305
      "Recent ATP messages" ^
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   312
(* named provers *)
28484
4ed9239b09c1 misc simplifcation and tuning;
wenzelm
parents: 28478
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   317
(
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
   318
  type T = (prover * stamp) Symtab.table;
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   319
  val empty = Symtab.empty;
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   320
  val extend = I;
33522
737589bb9bb8 adapted Theory_Data;
wenzelm
parents: 33316
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   323
);
28484
4ed9239b09c1 misc simplifcation and tuning;
wenzelm
parents: 28478
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   328
32995
wenzelm
parents: 32954
diff changeset
   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
wenzelm
parents: 32954
diff changeset
   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
47d88239658d ** Update from Fabian **
wenzelm
parents: 28543
diff changeset
   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
4ed9239b09c1 misc simplifcation and tuning;
wenzelm
parents: 28478
diff changeset
   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
c00c57850eb7 cosmetics: rename internal functions
blanchet
parents: 36383
diff changeset
   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
6adf1068ac0f better error reporting;
blanchet
parents: 36379
diff changeset
   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
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   363
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   364
end;