src/HOL/Tools/ATP_Manager/atp_manager.ML
author blanchet
Mon, 29 Mar 2010 12:01:00 +0200
changeset 36058 8256d5a185bd
parent 35969 c9565298df9e
child 36059 ab3dfdeb9603
permissions -rw-r--r--
added "respect_no_atp" and "convergence" options to Sledgehammer; these were previously hard-coded in "sledgehammer_fact_filter.ML"
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
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    11
  type relevance_override = Sledgehammer_Fact_Filter.relevance_override
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    12
  type params =
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    13
    {debug: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    14
     verbose: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    15
     atps: string list,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    16
     full_types: bool,
36058
8256d5a185bd added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents: 35969
diff changeset
    17
     respect_no_atp: bool,
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    18
     relevance_threshold: real,
36058
8256d5a185bd added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents: 35969
diff changeset
    19
     convergence: real,
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    20
     higher_order: bool option,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    21
     follow_defs: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    22
     isar_proof: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    23
     timeout: Time.time,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    24
     minimize_timeout: Time.time}
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    25
  type problem =
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    26
    {subgoal: int,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    27
     goal: Proof.context * (thm list * thm),
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    28
     relevance_override: relevance_override,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    29
     axiom_clauses: (thm * (string * int)) list option,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    30
     filtered_clauses: (thm * (string * int)) list option}
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    31
  type prover_result =
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    32
    {success: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    33
     message: string,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    34
     relevant_thm_names: string list,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    35
     atp_run_time_in_msecs: int,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    36
     proof: string,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    37
     internal_thm_names: string Vector.vector,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    38
     filtered_clauses: (thm * (string * int)) list}
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    39
  type prover = params -> Time.time -> problem -> prover_result
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    40
32937
34f66c9dd8a2 structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents: 32936
diff changeset
    41
  val atps: string Unsynchronized.ref
34f66c9dd8a2 structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents: 32936
diff changeset
    42
  val timeout: int Unsynchronized.ref
34f66c9dd8a2 structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents: 32936
diff changeset
    43
  val full_types: bool Unsynchronized.ref
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    44
  val kill_atps: unit -> unit
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    45
  val running_atps: unit -> unit
29112
f2b45eea6dac added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents: 28835
diff changeset
    46
  val messages: int option -> unit
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    47
  val add_prover: string * prover -> theory -> theory
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    48
  val get_prover: theory -> string -> prover option
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    49
  val available_atps: theory -> unit
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    50
  val sledgehammer: params -> int -> relevance_override -> Proof.state -> unit
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
    51
end;
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
    52
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35826
diff changeset
    53
structure ATP_Manager : ATP_MANAGER =
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
    54
struct
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
    55
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    56
type relevance_override = Sledgehammer_Fact_Filter.relevance_override
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    57
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    58
(** parameters, problems, results, and provers **)
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    59
36058
8256d5a185bd added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents: 35969
diff changeset
    60
(* TODO: "theory_const" *)
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    61
type params =
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    62
  {debug: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    63
   verbose: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    64
   atps: string list,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    65
   full_types: bool,
36058
8256d5a185bd added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents: 35969
diff changeset
    66
   respect_no_atp: bool,
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    67
   relevance_threshold: real,
36058
8256d5a185bd added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents: 35969
diff changeset
    68
   convergence: real,
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    69
   higher_order: bool option,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    70
   follow_defs: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    71
   isar_proof: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    72
   timeout: Time.time,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    73
   minimize_timeout: Time.time}
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    74
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    75
type problem =
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    76
  {subgoal: int,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    77
   goal: Proof.context * (thm list * thm),
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    78
   relevance_override: relevance_override,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    79
   axiom_clauses: (thm * (string * int)) list option,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    80
   filtered_clauses: (thm * (string * int)) list option};
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    81
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    82
type prover_result =
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    83
  {success: bool,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    84
   message: string,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    85
   relevant_thm_names: string list,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    86
   atp_run_time_in_msecs: int,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    87
   proof: string,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    88
   internal_thm_names: string Vector.vector,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    89
   filtered_clauses: (thm * (string * int)) list};
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    90
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
    91
type prover = params -> Time.time -> problem -> prover_result;
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    92
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
    93
28586
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
    94
(** preferences **)
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
    95
29112
f2b45eea6dac added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents: 28835
diff changeset
    96
val message_store_limit = 20;
f2b45eea6dac added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents: 28835
diff changeset
    97
val message_display_limit = 5;
f2b45eea6dac added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents: 28835
diff changeset
    98
32937
34f66c9dd8a2 structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents: 32936
diff changeset
    99
val atps = Unsynchronized.ref "e spass remote_vampire";
32740
9dd0a2f83429 explicit indication of Unsynchronized.ref;
wenzelm
parents: 32510
diff changeset
   100
val timeout = Unsynchronized.ref 60;
9dd0a2f83429 explicit indication of Unsynchronized.ref;
wenzelm
parents: 32510
diff changeset
   101
val full_types = Unsynchronized.ref false;
28586
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   102
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   103
val _ =
30982
7882a1268a48 use predefined preferences categories;
wenzelm
parents: 30830
diff changeset
   104
  ProofGeneralPgip.add_preference Preferences.category_proof
28586
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   105
    (Preferences.string_pref atps
28589
581b2ab9827a adding preferences is now permissive, no error handling here;
wenzelm
parents: 28586
diff changeset
   106
      "ATP: provers" "Default automatic provers (separated by whitespace)");
28586
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   107
30982
7882a1268a48 use predefined preferences categories;
wenzelm
parents: 30830
diff changeset
   108
val _ =
7882a1268a48 use predefined preferences categories;
wenzelm
parents: 30830
diff changeset
   109
  ProofGeneralPgip.add_preference Preferences.category_proof
28586
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   110
    (Preferences.int_pref timeout
28589
581b2ab9827a adding preferences is now permissive, no error handling here;
wenzelm
parents: 28586
diff changeset
   111
      "ATP: timeout" "ATPs will be interrupted after this time (in seconds)");
28586
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   112
31791
c9a1caf218c8 New ATP option: full types
nipkow
parents: 31752
diff changeset
   113
val _ =
c9a1caf218c8 New ATP option: full types
nipkow
parents: 31752
diff changeset
   114
  ProofGeneralPgip.add_preference Preferences.category_proof
c9a1caf218c8 New ATP option: full types
nipkow
parents: 31752
diff changeset
   115
    (Preferences.bool_pref full_types
c9a1caf218c8 New ATP option: full types
nipkow
parents: 31752
diff changeset
   116
      "ATP: full types" "ATPs will use full type information");
c9a1caf218c8 New ATP option: full types
nipkow
parents: 31752
diff changeset
   117
28586
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   118
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   119
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   120
(** thread management **)
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   121
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   122
(* data structures over threads *)
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   123
32939
1b5a401c78cb renamed functor HeapFun to Heap;
wenzelm
parents: 32938
diff changeset
   124
structure Thread_Heap = Heap
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   125
(
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   126
  type elem = Time.time * Thread.thread;
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   127
  fun ord ((a, _), (b, _)) = Time.compare (a, b);
28595
67e3945b53f1 add_prover: plain prover function, without thread;
wenzelm
parents: 28589
diff changeset
   128
);
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   129
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31037
diff changeset
   130
fun lookup_thread xs = AList.lookup Thread.equal xs;
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   131
fun delete_thread xs = AList.delete Thread.equal xs;
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31037
diff changeset
   132
fun update_thread xs = AList.update Thread.equal xs;
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   133
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   134
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   135
(* state of thread manager *)
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
   136
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   137
type state =
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   138
 {manager: Thread.thread option,
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   139
  timeout_heap: Thread_Heap.T,
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   140
  active: (Thread.thread * (Time.time * Time.time * string)) list,
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   141
  cancelling: (Thread.thread * (Time.time * string)) list,
29620
dc1257eaa4f2 moved all output to watcher-thread
immler@in.tum.de
parents: 29598
diff changeset
   142
  messages: string list,
dc1257eaa4f2 moved all output to watcher-thread
immler@in.tum.de
parents: 29598
diff changeset
   143
  store: string list};
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   144
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   145
fun make_state manager timeout_heap active cancelling messages store : state =
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   146
  {manager = manager, timeout_heap = timeout_heap, active = active,
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   147
    cancelling = cancelling, messages = messages, store = store};
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   148
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   149
val global_state = Synchronized.var "atp_manager"
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   150
  (make_state NONE Thread_Heap.empty [] [] [] []);
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   151
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31037
diff changeset
   152
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   153
(* unregister ATP thread *)
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   154
33312
6ca8a7984fd9 unregister: eliminated unused status;
wenzelm
parents: 33292
diff changeset
   155
fun unregister message thread = Synchronized.change global_state
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   156
  (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
   157
    (case lookup_thread active thread of
35569
wenzelm
parents: 33604
diff changeset
   158
      SOME (_, _, description) =>
29150
8af5ee47f30c unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents: 29116
diff changeset
   159
        let
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   160
          val active' = delete_thread thread active;
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   161
          val cancelling' = (thread, (Time.now (), description)) :: cancelling;
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   162
          val message' = description ^ "\n" ^ message;
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   163
          val messages' = message' :: messages;
29620
dc1257eaa4f2 moved all output to watcher-thread
immler@in.tum.de
parents: 29598
diff changeset
   164
          val store' = message' ::
dc1257eaa4f2 moved all output to watcher-thread
immler@in.tum.de
parents: 29598
diff changeset
   165
            (if length store <= message_store_limit then store
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   166
             else #1 (chop message_store_limit store));
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   167
        in make_state manager timeout_heap active' cancelling' messages' store' end
30800
95cbadcd47fc tuned spacing and formatting;
wenzelm
parents: 30798
diff changeset
   168
    | NONE => state));
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   169
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   170
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   171
(* main manager thread -- only one may exist *)
28595
67e3945b53f1 add_prover: plain prover function, without thread;
wenzelm
parents: 28589
diff changeset
   172
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   173
val min_wait_time = Time.fromMilliseconds 300;
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   174
val max_wait_time = Time.fromSeconds 10;
28595
67e3945b53f1 add_prover: plain prover function, without thread;
wenzelm
parents: 28589
diff changeset
   175
29620
dc1257eaa4f2 moved all output to watcher-thread
immler@in.tum.de
parents: 29598
diff changeset
   176
fun print_new_messages () =
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   177
  let val msgs = Synchronized.change_result global_state
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   178
    (fn {manager, timeout_heap, active, cancelling, messages, store} =>
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   179
      (messages, make_state manager timeout_heap active cancelling [] store))
30800
95cbadcd47fc tuned spacing and formatting;
wenzelm
parents: 30798
diff changeset
   180
  in
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   181
    if null msgs then ()
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   182
    else priority ("Sledgehammer: " ^ space_implode "\n\n" msgs)
30800
95cbadcd47fc tuned spacing and formatting;
wenzelm
parents: 30798
diff changeset
   183
  end;
29620
dc1257eaa4f2 moved all output to watcher-thread
immler@in.tum.de
parents: 29598
diff changeset
   184
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   185
fun check_thread_manager () = Synchronized.change global_state
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   186
  (fn state as {manager, timeout_heap, active, cancelling, messages, store} =>
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   187
    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
   188
    else let val manager = SOME (Toplevel.thread false (fn () =>
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   189
      let
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   190
        fun time_limit timeout_heap =
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   191
          (case try Thread_Heap.min timeout_heap of
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   192
            NONE => Time.+ (Time.now (), max_wait_time)
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   193
          | SOME (time, _) => time);
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   194
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   195
        (*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
   196
        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
   197
          let val (timeout_threads, timeout_heap') =
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   198
            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
   199
          in
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   200
            if null timeout_threads andalso null cancelling
30830
263064c4d0c3 included managing_thread in state of AtpManager:
immler@in.tum.de
parents: 30800
diff changeset
   201
            then NONE
263064c4d0c3 included managing_thread in state of AtpManager:
immler@in.tum.de
parents: 30800
diff changeset
   202
            else
263064c4d0c3 included managing_thread in state of AtpManager:
immler@in.tum.de
parents: 30800
diff changeset
   203
              let
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   204
                val _ = List.app (SimpleThread.interrupt o #1) cancelling;
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   205
                val cancelling' = filter (Thread.isActive o #1) cancelling;
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   206
                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
   207
              in SOME (map #2 timeout_threads, state') end
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   208
          end;
30830
263064c4d0c3 included managing_thread in state of AtpManager:
immler@in.tum.de
parents: 30800
diff changeset
   209
      in
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   210
        while Synchronized.change_result global_state
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   211
          (fn state as {timeout_heap, active, cancelling, messages, store, ...} =>
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   212
            if null active andalso null cancelling andalso null messages
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   213
            then (false, make_state NONE timeout_heap active cancelling messages store)
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   214
            else (true, state))
30830
263064c4d0c3 included managing_thread in state of AtpManager:
immler@in.tum.de
parents: 30800
diff changeset
   215
        do
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   216
          (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
   217
            |> these
33312
6ca8a7984fd9 unregister: eliminated unused status;
wenzelm
parents: 33292
diff changeset
   218
            |> List.app (unregister "Interrupted (reached timeout)");
30830
263064c4d0c3 included managing_thread in state of AtpManager:
immler@in.tum.de
parents: 30800
diff changeset
   219
            print_new_messages ();
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   220
            (*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
   221
            OS.Process.sleep min_wait_time)
263064c4d0c3 included managing_thread in state of AtpManager:
immler@in.tum.de
parents: 30800
diff changeset
   222
      end))
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   223
    in make_state manager timeout_heap active cancelling messages store end);
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   224
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   225
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   226
(* register ATP thread *)
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
   227
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   228
fun register birth_time death_time (thread, desc) =
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   229
 (Synchronized.change global_state
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   230
    (fn {manager, timeout_heap, active, cancelling, messages, store} =>
29112
f2b45eea6dac added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents: 28835
diff changeset
   231
      let
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   232
        val timeout_heap' = Thread_Heap.insert (death_time, thread) timeout_heap;
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   233
        val active' = update_thread (thread, (birth_time, death_time, desc)) active;
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   234
        val state' = make_state manager timeout_heap' active' cancelling messages store;
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   235
      in state' end);
30798
36b41d297d65 terminate watching thread
immler@in.tum.de
parents: 30537
diff changeset
   236
  check_thread_manager ());
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
   237
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
   238
28586
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   239
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   240
(** user commands **)
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   241
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   242
(* kill ATPs *)
28586
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   243
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   244
fun kill_atps () = Synchronized.change global_state
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   245
  (fn {manager, timeout_heap, active, cancelling, messages, store} =>
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   246
    let
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   247
      val killing = map (fn (th, (_, _, desc)) => (th, (Time.now (), desc))) active;
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   248
      val state' = make_state manager timeout_heap [] (killing @ cancelling) messages store;
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   249
    in state' end);
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   250
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   251
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   252
(* running_atps *)
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   253
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   254
fun seconds time = string_of_int (Time.toSeconds time) ^ "s";
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   255
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   256
fun running_atps () =
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   257
  let
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   258
    val {active, cancelling, ...} = Synchronized.value global_state;
29112
f2b45eea6dac added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents: 28835
diff changeset
   259
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   260
    val now = Time.now ();
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   261
    fun running_info (_, (birth_time, death_time, desc)) =
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   262
      "Running: " ^ seconds (Time.- (now, birth_time)) ^ " -- " ^
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   263
        seconds (Time.- (death_time, now)) ^ " to live:\n" ^ desc;
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   264
    fun cancelling_info (_, (deadth_time, desc)) =
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   265
      "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
   266
28589
581b2ab9827a adding preferences is now permissive, no error handling here;
wenzelm
parents: 28586
diff changeset
   267
    val running =
581b2ab9827a adding preferences is now permissive, no error handling here;
wenzelm
parents: 28586
diff changeset
   268
      if null active then "No ATPs running."
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   269
      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
   270
    val interrupting =
581b2ab9827a adding preferences is now permissive, no error handling here;
wenzelm
parents: 28586
diff changeset
   271
      if null cancelling then ""
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   272
      else
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   273
        space_implode "\n\n"
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   274
          ("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
   275
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   276
  in writeln (running ^ "\n" ^ interrupting) end;
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   277
29112
f2b45eea6dac added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents: 28835
diff changeset
   278
fun messages opt_limit =
f2b45eea6dac added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents: 28835
diff changeset
   279
  let
f2b45eea6dac added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents: 28835
diff changeset
   280
    val limit = the_default message_display_limit opt_limit;
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   281
    val {store, ...} = Synchronized.value global_state;
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   282
    val header =
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   283
      "Recent ATP messages" ^
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   284
        (if length store <= limit then ":" else " (" ^ string_of_int limit ^ " displayed):");
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   285
  in writeln (space_implode "\n\n" (header :: #1 (chop limit store))) end;
29112
f2b45eea6dac added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents: 28835
diff changeset
   286
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   287
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
   288
28586
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   289
(** The Sledgehammer **)
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
   290
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   291
(* named provers *)
28484
4ed9239b09c1 misc simplifcation and tuning;
wenzelm
parents: 28478
diff changeset
   292
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   293
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
   294
33522
737589bb9bb8 adapted Theory_Data;
wenzelm
parents: 33316
diff changeset
   295
structure Provers = Theory_Data
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   296
(
35867
16279c4c7a33 move all ATP setup code into ATP_Wrapper
blanchet
parents: 35866
diff changeset
   297
  type T = (prover * stamp) Symtab.table;
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   298
  val empty = Symtab.empty;
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   299
  val extend = I;
33522
737589bb9bb8 adapted Theory_Data;
wenzelm
parents: 33316
diff changeset
   300
  fun merge data : T = Symtab.merge (eq_snd op =) data
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   301
    handle Symtab.DUP dup => err_dup_prover dup;
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   302
);
28484
4ed9239b09c1 misc simplifcation and tuning;
wenzelm
parents: 28478
diff changeset
   303
32864
a226f29d4bdc re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents: 32824
diff changeset
   304
fun add_prover (name, prover) thy =
28595
67e3945b53f1 add_prover: plain prover function, without thread;
wenzelm
parents: 28589
diff changeset
   305
  Provers.map (Symtab.update_new (name, (prover, stamp ()))) thy
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   306
    handle Symtab.DUP dup => err_dup_prover dup;
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   307
32995
wenzelm
parents: 32954
diff changeset
   308
fun get_prover thy name =
wenzelm
parents: 32954
diff changeset
   309
  Option.map #1 (Symtab.lookup (Provers.get thy) name);
wenzelm
parents: 32954
diff changeset
   310
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   311
fun available_atps thy = Pretty.writeln
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   312
  (Pretty.strs ("ATPs:" :: sort_strings (Symtab.keys (Provers.get thy))));
28571
47d88239658d ** Update from Fabian **
wenzelm
parents: 28543
diff changeset
   313
28586
d238b83ba3fc renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents: 28582
diff changeset
   314
28595
67e3945b53f1 add_prover: plain prover function, without thread;
wenzelm
parents: 28589
diff changeset
   315
(* start prover thread *)
28484
4ed9239b09c1 misc simplifcation and tuning;
wenzelm
parents: 28478
diff changeset
   316
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   317
fun start_prover (params as {timeout, ...}) birth_time death_time i
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   318
                 relevance_override proof_state name =
32947
3c19b98a35cd ATP_Manager.get_prover: canonical argument order;
wenzelm
parents: 32941
diff changeset
   319
  (case get_prover (Proof.theory_of proof_state) name of
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   320
    NONE => warning ("Unknown ATP: " ^ quote name)
31037
ac8669134e7a added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents: 30982
diff changeset
   321
  | SOME prover =>
28595
67e3945b53f1 add_prover: plain prover function, without thread;
wenzelm
parents: 28589
diff changeset
   322
      let
35592
768d17f54125 use regular Proof.goal (which is what methods usually see) and prevent sledgehammer from crashing;
wenzelm
parents: 35569
diff changeset
   323
        val {context = ctxt, facts, goal} = Proof.goal proof_state;
28595
67e3945b53f1 add_prover: plain prover function, without thread;
wenzelm
parents: 28589
diff changeset
   324
        val desc =
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   325
          "ATP " ^ quote name ^ " for subgoal " ^ string_of_int i ^ ":\n" ^
32938
63a364ed3f8d misc tuning and clarification;
wenzelm
parents: 32937
diff changeset
   326
            Syntax.string_of_term ctxt (Thm.term_of (Thm.cprem_of goal i));
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   327
33604
d4220df6fde2 Toplevel.thread provides Isar-style exception output;
wenzelm
parents: 33522
diff changeset
   328
        val _ = Toplevel.thread true (fn () =>
28595
67e3945b53f1 add_prover: plain prover function, without thread;
wenzelm
parents: 28589
diff changeset
   329
          let
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
   330
            val _ = register birth_time death_time (Thread.self (), desc);
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   331
            val problem =
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   332
              {subgoal = i, goal = (ctxt, (facts, goal)),
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   333
               relevance_override = relevance_override, axiom_clauses = NONE,
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   334
               filtered_clauses = NONE}
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   335
            val message = #message (prover params timeout problem)
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35826
diff changeset
   336
              handle Sledgehammer_HOL_Clause.TRIVIAL =>   (* FIXME !? *)
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   337
                  "Try this command: " ^
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   338
                  Markup.markup Markup.sendback "by metis" ^ "."
33312
6ca8a7984fd9 unregister: eliminated unused status;
wenzelm
parents: 33292
diff changeset
   339
                | ERROR msg => ("Error: " ^ msg);
6ca8a7984fd9 unregister: eliminated unused status;
wenzelm
parents: 33292
diff changeset
   340
            val _ = unregister message (Thread.self ());
35569
wenzelm
parents: 33604
diff changeset
   341
          in () end);
28595
67e3945b53f1 add_prover: plain prover function, without thread;
wenzelm
parents: 28589
diff changeset
   342
      in () end);
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   343
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   344
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   345
(* Sledgehammer the given subgoal *)
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   346
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   347
fun sledgehammer (params as {atps, timeout, ...}) i relevance_override
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   348
                 proof_state =
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   349
  let
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   350
    val birth_time = Time.now ()
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   351
    val death_time = Time.+ (birth_time, timeout)
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   352
    val _ = kill_atps () (* RACE w.r.t. other invocations of Sledgehammer *)
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   353
    val _ = priority "Sledgehammering..."
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   354
    val _ = List.app (start_prover params birth_time death_time i
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   355
                                   relevance_override proof_state) atps
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
   356
  in () end
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   357
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   358
end;