src/HOL/Tools/ATP/watcher.ML
author paulson
Thu, 06 Oct 2005 10:14:22 +0200
changeset 17772 818cec5f82a4
parent 17764 fde495b9e24b
child 17773 a7258e1020b7
permissions -rw-r--r--
major simplification: removal of the goalstring argument
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15789
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15787
diff changeset
     1
(*  Title:      Watcher.ML
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15787
diff changeset
     2
    ID:         $Id$
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15787
diff changeset
     3
    Author:     Claire Quigley
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15787
diff changeset
     4
    Copyright   2004  University of Cambridge
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
     5
 *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
     6
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
     7
(*  The watcher process starts a resolution process when it receives a     *)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
     8
(*  message from Isabelle                                                  *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
     9
(*  Signals Isabelle, puts output of child into pipe to Isabelle,          *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    10
(*  and removes dead processes.  Also possible to kill all the resolution  *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    11
(*  processes currently running.                                           *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    12
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    13
signature WATCHER =
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    14
sig
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    15
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    16
(*  Send request to Watcher for multiple spasses to be called for filenames in arg       *)
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
    17
(* callResProvers (outstreamtoWatcher, prover name,prover-command, (settings,file) list *)
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    18
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    19
val callResProvers :
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
    20
    TextIO.outstream * (string*string*string*string) list -> unit
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    21
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    22
(* Send message to watcher to kill resolution provers *)
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    23
val callSlayer : TextIO.outstream -> unit
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    24
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    25
(* Start a watcher and set up signal handlers             *)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    26
val createWatcher : 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    27
    thm * (ResClause.clause * thm) Array.array -> 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    28
    TextIO.instream * TextIO.outstream * Posix.Process.pid
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    29
val killWatcher : Posix.Process.pid -> unit
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    30
val setting_sep : char
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    31
end
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    32
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    33
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    34
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    35
structure Watcher: WATCHER =
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    36
struct
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    37
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    38
(*Field separators, used to pack items onto a text line*)
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    39
val command_sep = #"\t"
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    40
and setting_sep = #"%";
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    41
17488
67376a311a2b further simplification of the Isabelle-ATP linkup
paulson
parents: 17484
diff changeset
    42
open Recon_Transfer
16805
fadf80952202 open ReconPrelim Recon_Transfer;
wenzelm
parents: 16767
diff changeset
    43
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    44
val goals_being_watched = ref 0;
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    45
17583
c272b91b619f removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents: 17568
diff changeset
    46
val trace_path = Path.basic "watcher_trace";
c272b91b619f removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents: 17568
diff changeset
    47
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
    48
fun trace s = if !Output.show_debug_msgs then File.append (File.tmp_path trace_path) s 
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
    49
              else ();
17583
c272b91b619f removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents: 17568
diff changeset
    50
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    51
(*  The result of calling createWatcher  *)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
    52
datatype proc = PROC of {pid : Posix.Process.pid,
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
    53
			 instr : TextIO.instream,
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
    54
			 outstr : TextIO.outstream};
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    55
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    56
(*  The result of calling executeToList  *)
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    57
datatype cmdproc = CMDPROC of {
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
    58
        prover: string,       (* Name of the resolution prover used, e.g. Vampire*)
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
    59
        cmd:  string,         (* The file containing the goal for res prover to prove *)     
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    60
        proc_handle : (TextIO.instream,TextIO.outstream) Unix.proc,
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    61
        instr : TextIO.instream,   (*  Input stream to child process *)
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
    62
        outstr : TextIO.outstream};  (*  Output stream from child process *)
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    63
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    64
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    65
fun fdReader (name : string, fd : Posix.IO.file_desc) =
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    66
	  Posix.IO.mkTextReader {initBlkMode = true,name = name,fd = fd };
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    67
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    68
fun fdWriter (name, fd) =
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    69
          Posix.IO.mkTextWriter {
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    70
	      appendMode = false,
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    71
              initBlkMode = true,
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    72
              name = name,  
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    73
              chunkSize=4096,
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
    74
              fd = fd};
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    75
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    76
fun openOutFD (name, fd) =
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    77
	  TextIO.mkOutstream (
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    78
	    TextIO.StreamIO.mkOutstream (
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    79
	      fdWriter (name, fd), IO.BLOCK_BUF));
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    80
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    81
fun openInFD (name, fd) =
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    82
	  TextIO.mkInstream (
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    83
	    TextIO.StreamIO.mkInstream (
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    84
	      fdReader (name, fd), ""));
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    85
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    86
fun childInfo (PROC{pid,instr,outstr }) = (pid,(instr,outstr));
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    87
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    88
fun cmdstreamsOf (CMDPROC{instr,outstr,...}) = (instr, outstr);
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    89
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
    90
fun cmdInStream (CMDPROC{instr,outstr,...}) = instr;
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    91
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
    92
fun cmdchildInfo (CMDPROC{prover,cmd,proc_handle,instr,outstr}) = 
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
    93
  (prover,(cmd, (instr,outstr)));
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    94
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
    95
fun cmdchildHandle (CMDPROC{prover,cmd,proc_handle,instr,outstr})  = 
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
    96
  proc_handle;
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
    97
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
    98
fun cmdProver (CMDPROC{prover,cmd,proc_handle,instr,outstr}) = prover;
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
    99
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   100
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   101
(*    gets individual args from instream and concatenates them into a list      *)
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
   102
fun getArgs (fromParentStr, toParentStr, ys) =  
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
   103
  let val thisLine = TextIO.input fromParentStr
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
   104
  in ys@[thisLine] end
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   105
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   106
                            
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   107
(*  Send request to Watcher for a vampire to be called for filename in arg      *)
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   108
                   
17231
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17216
diff changeset
   109
fun callResProver (toWatcherStr,  arg) = 
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
   110
      (TextIO.output (toWatcherStr, arg^"\n"); 
17231
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17216
diff changeset
   111
       TextIO.flushOut toWatcherStr)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   112
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   113
(*****************************************************************************************)
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16260
diff changeset
   114
(*  Send request to Watcher for multiple provers to be called for filenames in arg       *)
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16260
diff changeset
   115
(*  need to do the dfg stuff in the watcher, not here! send over the clasimp and stuff files too*)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   116
(*****************************************************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   117
16475
8f3ba52a7937 using TPTP2X_HOME; indentation, etc
paulson
parents: 16357
diff changeset
   118
fun callResProvers (toWatcherStr,  []) = 
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
   119
      (TextIO.output (toWatcherStr, "End of calls\n");  TextIO.flushOut toWatcherStr)
16475
8f3ba52a7937 using TPTP2X_HOME; indentation, etc
paulson
parents: 16357
diff changeset
   120
|   callResProvers (toWatcherStr,
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   121
                    (prover,proverCmd,settings,probfile)  ::  args) =
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   122
      let val _ = trace (space_implode ", " 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   123
		         (["\ncallResProvers:", prover, proverCmd, probfile]))
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   124
      in TextIO.output (toWatcherStr,
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   125
                        (*Uses a special character to separate items sent to watcher*)
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   126
      	                space_implode (str command_sep)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   127
                          [prover, proverCmd, settings, probfile, "\n"]);
16475
8f3ba52a7937 using TPTP2X_HOME; indentation, etc
paulson
parents: 16357
diff changeset
   128
         goals_being_watched := (!goals_being_watched) + 1;
8f3ba52a7937 using TPTP2X_HOME; indentation, etc
paulson
parents: 16357
diff changeset
   129
	 TextIO.flushOut toWatcherStr;
8f3ba52a7937 using TPTP2X_HOME; indentation, etc
paulson
parents: 16357
diff changeset
   130
	 callResProvers (toWatcherStr,args)
8f3ba52a7937 using TPTP2X_HOME; indentation, etc
paulson
parents: 16357
diff changeset
   131
      end   
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16260
diff changeset
   132
                                                
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
   133
                                    
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   134
 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   135
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   136
(*Send message to watcher to kill currently running vampires. NOT USED and possibly
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   137
  buggy. Note that killWatcher kills the entire process group anyway.*)
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   138
fun callSlayer toWatcherStr = (TextIO.output (toWatcherStr, "Kill children\n"); 
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   139
                            TextIO.flushOut toWatcherStr)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   140
17746
af59c748371d fixed the ascii-armouring of goalstring
paulson
parents: 17716
diff changeset
   141
                    
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   142
(**************************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   143
(* Get commands from Isabelle                                 *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   144
(**************************************************************)
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   145
fun getCmds (toParentStr, fromParentStr, cmdList) = 
16475
8f3ba52a7937 using TPTP2X_HOME; indentation, etc
paulson
parents: 16357
diff changeset
   146
  let val thisLine = TextIO.inputLine fromParentStr 
8f3ba52a7937 using TPTP2X_HOME; indentation, etc
paulson
parents: 16357
diff changeset
   147
  in
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   148
     trace("\nGot command from parent: " ^ thisLine);
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   149
     if thisLine = "End of calls\n" orelse thisLine = "" then cmdList
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17317
diff changeset
   150
     else if thisLine = "Kill children\n"
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   151
     then (TextIO.output (toParentStr,thisLine); 
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   152
	   TextIO.flushOut toParentStr;
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   153
	   [("","Kill children",[],"")])
17746
af59c748371d fixed the ascii-armouring of goalstring
paulson
parents: 17716
diff changeset
   154
     else
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   155
       let val [prover,proverCmd,settingstr,probfile,_] = 
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   156
                   String.tokens (fn c => c = command_sep) thisLine
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   157
           val settings = String.tokens (fn c => c = setting_sep) settingstr
17746
af59c748371d fixed the ascii-armouring of goalstring
paulson
parents: 17716
diff changeset
   158
       in
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   159
           trace ("\nprover: " ^ prover ^ "  prover path: " ^ proverCmd ^
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   160
                  "\n  problem file: " ^ probfile);
17746
af59c748371d fixed the ascii-armouring of goalstring
paulson
parents: 17716
diff changeset
   161
           getCmds (toParentStr, fromParentStr, 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   162
                    (prover, proverCmd, settings, probfile)::cmdList) 
17746
af59c748371d fixed the ascii-armouring of goalstring
paulson
parents: 17716
diff changeset
   163
       end
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   164
       handle Bind => 
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   165
          (trace "getCmds: command parsing failed!";
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   166
           getCmds (toParentStr, fromParentStr, cmdList))
16475
8f3ba52a7937 using TPTP2X_HOME; indentation, etc
paulson
parents: 16357
diff changeset
   167
  end
8f3ba52a7937 using TPTP2X_HOME; indentation, etc
paulson
parents: 16357
diff changeset
   168
	    
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16260
diff changeset
   169
                                                                  
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   170
(**************************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   171
(*  Get Io-descriptor for polling of an input stream          *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   172
(**************************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   173
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   174
fun getInIoDesc someInstr = 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   175
    let val (rd, buf) = TextIO.StreamIO.getReader(TextIO.getInstream someInstr)
15702
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 15684
diff changeset
   176
        val _ = TextIO.output (TextIO.stdOut, buf)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   177
        val ioDesc = 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   178
	    case rd
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   179
	      of TextPrimIO.RD{ioDesc = SOME iod, ...} =>SOME iod
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   180
	       | _ => NONE
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   181
     in (* since getting the reader will have terminated the stream, we need
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   182
	 * to build a new stream. *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   183
	TextIO.setInstream(someInstr, TextIO.StreamIO.mkInstream(rd, buf));
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   184
	ioDesc
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   185
    end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   186
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   187
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   188
(*************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   189
(*  Set up a Watcher Process         *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   190
(*************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   191
17716
89932e53f31d moved concat_with_and to watcher.ML
paulson
parents: 17690
diff changeset
   192
(* for tracing: encloses each string element in brackets. *)
89932e53f31d moved concat_with_and to watcher.ML
paulson
parents: 17690
diff changeset
   193
val concat_with_and = space_implode " & " o map (enclose "(" ")");
89932e53f31d moved concat_with_and to watcher.ML
paulson
parents: 17690
diff changeset
   194
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   195
fun prems_string_of th = concat_with_and (map string_of_cterm (cprems_of th))
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   196
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   197
fun killChild proc = (Unix.kill(proc, Posix.Signal.kill); Unix.reap proc);
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   198
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   199
fun killChildren procs = List.app (ignore o killChild) procs;
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   200
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   201
 (*************************************************************)
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   202
 (* take an instream and poll its underlying reader for input *)
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   203
 (*************************************************************)
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   204
 
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   205
 fun pollParentInput (fromParentIOD, fromParentStr, toParentStr) = 
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   206
   case OS.IO.pollDesc fromParentIOD of
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   207
      SOME pd =>
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   208
	 (case OS.IO.poll ([OS.IO.pollIn pd], SOME (Time.fromSeconds 2)) of
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   209
	      [] => NONE
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   210
	    | pd''::_ => if OS.IO.isIn pd''
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   211
	 	         then SOME (getCmds (toParentStr, fromParentStr, []))
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   212
	 	         else NONE)
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   213
   | NONE => NONE;
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   214
17583
c272b91b619f removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents: 17568
diff changeset
   215
(*get the number of the subgoal from the filename: the last digit string*)
c272b91b619f removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents: 17568
diff changeset
   216
fun number_from_filename s =
c272b91b619f removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents: 17568
diff changeset
   217
  case String.tokens (not o Char.isDigit) s of
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   218
      [] => (trace ("\nWatcher could not read subgoal nunber! " ^ s); 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   219
             raise ERROR)
17583
c272b91b619f removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents: 17568
diff changeset
   220
    | numbers => valOf (Int.fromString (List.last numbers));
c272b91b619f removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents: 17568
diff changeset
   221
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   222
fun setupWatcher (thm,clause_arr) = 
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   223
  let
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   224
    val p1 = Posix.IO.pipe()   (*pipes for communication between parent and watcher*)
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   225
    val p2 = Posix.IO.pipe()
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
   226
    fun closep () = 
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   227
	 (Posix.IO.close (#outfd p1); Posix.IO.close (#infd p1);
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   228
	  Posix.IO.close (#outfd p2); Posix.IO.close (#infd p2))
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   229
    (****** fork a watcher process and get it set up and going ******)
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
   230
    fun startWatcher procList =
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   231
     (case  Posix.Process.fork() 
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   232
      of SOME pid => pid (* parent - i.e. main Isabelle process *)
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   233
       | NONE => let                (* child - i.e. watcher  *)
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   234
	  val oldchildin = #infd p1  
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   235
	  val fromParent = Posix.FileSys.wordToFD 0w0
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   236
	  val oldchildout = #outfd p2
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   237
	  val toParent = Posix.FileSys.wordToFD 0w1
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   238
	  val fromParentIOD = Posix.FileSys.fdToIOD fromParent
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   239
	  val fromParentStr = openInFD ("_exec_in_parent", fromParent)
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   240
	  val toParentStr = openOutFD ("_exec_out_parent", toParent)
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   241
	  val pid = Posix.ProcEnv.getpid()
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   242
	  val () = Posix.ProcEnv.setpgid {pid = SOME pid, pgid = SOME pid}
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   243
                   (*set process group id: allows killing all children*)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   244
	  val () = trace "\nsubgoals forked to startWatcher"
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   245
	 
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
   246
	  fun pollChildInput fromStr = 
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   247
	     case getInIoDesc fromStr of
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   248
	       SOME iod => 
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   249
		 (case OS.IO.pollDesc iod of
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   250
		    SOME pd =>
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   251
			let val pd' = OS.IO.pollIn pd in
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   252
			  case OS.IO.poll ([pd'], SOME (Time.fromSeconds 2)) of
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   253
			      [] => false
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   254
			    | pd''::_ => OS.IO.isIn pd''
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   255
			end
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   256
		   | NONE => false)
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   257
	     | NONE => false
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   258
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   259
	  (* Check all ATP processes currently running for output                 *)
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   260
	  fun checkChildren ([], toParentStr) = []  (* no children to check *)
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   261
	  |   checkChildren (childProc::otherChildren, toParentStr) = 
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   262
	       let val _ = trace ("\nIn check child, length of queue:"^
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   263
			          Int.toString (length (childProc::otherChildren)))
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   264
		   val (childInput,childOutput) = cmdstreamsOf childProc
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   265
		   val child_handle = cmdchildHandle childProc
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   266
		   val childCmd = #1(#2(cmdchildInfo childProc)) (*name of problem file*)
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   267
		   val _ = trace ("\nchildCmd = " ^ childCmd)
17583
c272b91b619f removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents: 17568
diff changeset
   268
		   val sg_num = number_from_filename childCmd
17234
12a9393c5d77 further tidying up of Isabelle-ATP link
paulson
parents: 17231
diff changeset
   269
		   val childIncoming = pollChildInput childInput
12a9393c5d77 further tidying up of Isabelle-ATP link
paulson
parents: 17231
diff changeset
   270
		   val parentID = Posix.ProcEnv.getppid()
12a9393c5d77 further tidying up of Isabelle-ATP link
paulson
parents: 17231
diff changeset
   271
		   val prover = cmdProver childProc
12a9393c5d77 further tidying up of Isabelle-ATP link
paulson
parents: 17231
diff changeset
   272
	       in 
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   273
		 if childIncoming
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   274
		 then (* check here for prover label on child*)
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   275
		   let val _ = trace ("\nInput available from child: " ^ childCmd ^ 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   276
				      "\nprover is " ^ prover)
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   277
		       val childDone = (case prover of
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   278
			   "vampire" => AtpCommunication.checkVampProofFound(childInput, toParentStr, parentID, childCmd, clause_arr)  
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   279
		         | "E" => AtpCommunication.checkEProofFound(childInput, toParentStr, parentID, childCmd, clause_arr)             
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   280
			 | "spass" => AtpCommunication.checkSpassProofFound(childInput, toParentStr, parentID, childCmd, thm, sg_num,clause_arr)  
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   281
			 | _ => (trace "\nBad prover!"; true) )
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   282
		    in
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   283
		     if childDone
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   284
		     then (* child has found a proof and transferred it *)
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   285
			(* Remove this child and go on to check others*)
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   286
			(Unix.reap child_handle;
17716
89932e53f31d moved concat_with_and to watcher.ML
paulson
parents: 17690
diff changeset
   287
			 OS.FileSys.remove childCmd;
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   288
			 checkChildren(otherChildren, toParentStr))
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   289
		     else (* Keep this child and go on to check others  *)
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   290
		       childProc :: checkChildren (otherChildren, toParentStr)
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   291
		  end
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   292
		else (trace "\nNo child output";
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   293
		      childProc::(checkChildren (otherChildren, toParentStr)))
17234
12a9393c5d77 further tidying up of Isabelle-ATP link
paulson
parents: 17231
diff changeset
   294
	       end
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   295
17234
12a9393c5d77 further tidying up of Isabelle-ATP link
paulson
parents: 17231
diff changeset
   296
	
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   297
	(* call resolution processes                                        *)
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   298
	(* settings should be a list of strings  ["-t 300", "-m 100000"]    *)
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   299
	(* takes list of (string, string, string list, string)list proclist *)
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   300
	fun execCmds [] procList = procList
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   301
	|   execCmds ((prover,proverCmd,settings,file)::cmds) procList  =
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   302
	      let val _ = trace ("\nAbout to execute command: " ^ proverCmd ^ " " ^ 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   303
	                         file)
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
   304
	          val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc  = 
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   305
		       Unix.execute(proverCmd, settings@[file])
17234
12a9393c5d77 further tidying up of Isabelle-ATP link
paulson
parents: 17231
diff changeset
   306
		  val (instr, outstr) = Unix.streamsOf childhandle
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   307
		  val newProcList = CMDPROC{prover = prover,
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   308
					    cmd = file,
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   309
					    proc_handle = childhandle,
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   310
					    instr = instr,
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   311
					    outstr = outstr} :: procList
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   312
     		  val _ = trace ("\nFinished at " ^
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   313
			         Date.toString(Date.fromTimeLocal(Time.now())))
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   314
	      in execCmds cmds newProcList end
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   315
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   316
         (******** Watcher Loop ********)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   317
         val limit = ref 200;  (*don't let it run forever*)
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   318
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   319
	 fun keepWatching (procList) = 
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17315
diff changeset
   320
	   let fun loop procList =  
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   321
	      let val _ = trace ("\npollParentInput. Limit = " ^ Int.toString (!limit) ^ 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   322
	                         "  length(procList) = " ^ Int.toString (length procList));
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   323
		  val cmdsFromIsa = pollParentInput 
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   324
				     (fromParentIOD, fromParentStr, toParentStr)
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   325
	      in 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   326
		OS.Process.sleep (Time.fromMilliseconds 100);
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   327
		limit := !limit - 1;
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   328
		if !limit = 0 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   329
		then 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   330
		 (trace "\nTimeout: Killing proof processes";
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   331
		  TextIO.output(toParentStr, "Timeout: Killing proof processes!\n");
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   332
		  TextIO.flushOut toParentStr;
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   333
		  killChildren (map cmdchildHandle procList);
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   334
		  Posix.Process.exit 0w0)
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   335
		else case cmdsFromIsa of
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   336
		    SOME [(_,"Kill children",_,_)] => 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   337
		      let val child_handles = map cmdchildHandle procList 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   338
		      in  trace "\nReceived command to kill children";
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   339
			  killChildren child_handles; loop [] 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   340
		      end
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   341
		  | SOME cmds => (*  deal with commands from Isabelle process *)
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   342
		      if length procList < 40
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   343
		      then                        (* Execute locally  *)
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   344
			let 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   345
			  val _ = trace ("\nCommands from parent: " ^ Int.toString(length cmds))
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   346
			  val newProcList = execCmds cmds procList
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   347
			  val newProcList' = checkChildren (newProcList, toParentStr) 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   348
			in
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   349
			  trace "\nCommands executed"; loop newProcList'
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   350
			end
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   351
		      else  (* Execute remotely [FIXME: NOT REALLY]  *)
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   352
			let 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   353
			  val newProcList = execCmds cmds procList
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   354
			  val newProcList' = checkChildren (newProcList, toParentStr) 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   355
			in loop newProcList' end
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   356
		  | NONE => (* No new input from Isabelle *)
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   357
		      let val newProcList = checkChildren (procList, toParentStr)
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   358
		      in
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   359
			trace "\nNothing from parent, still watching"; loop newProcList
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   360
		      end
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   361
	       end
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   362
	   in  loop procList   end
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   363
	 in
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   364
	   (*** Sort out pipes ********)
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   365
	   Posix.IO.close (#outfd p1);  Posix.IO.close (#infd p2);
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   366
	   Posix.IO.dup2{old = oldchildin, new = fromParent};
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   367
	   Posix.IO.close oldchildin;
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   368
	   Posix.IO.dup2{old = oldchildout, new = toParent};
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   369
	   Posix.IO.close oldchildout;
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   370
	   keepWatching (procList)
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   371
	 end);   (* end case *)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   372
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   373
    val _ = TextIO.flushOut TextIO.stdOut
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   374
    val pid = startWatcher []
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   375
    (* communication streams to watcher*)
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   376
    val instr = openInFD ("_exec_in", #infd p2)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   377
    val outstr = openOutFD ("_exec_out", #outfd p1)
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   378
  in
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   379
   (* close the child-side fds*)
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   380
    Posix.IO.close (#outfd p2);  Posix.IO.close (#infd p1);
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   381
    (* set the fds close on exec *)
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   382
    Posix.IO.setfd (#infd p2, Posix.IO.FD.flags [Posix.IO.FD.cloexec]);
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   383
    Posix.IO.setfd (#outfd p1, Posix.IO.FD.flags [Posix.IO.FD.cloexec]);
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   384
    PROC{pid = pid, instr = instr, outstr = outstr}
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   385
  end;
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   386
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   387
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   388
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   389
(**********************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   390
(* Start a watcher and set up signal handlers             *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   391
(**********************************************************)
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15919
diff changeset
   392
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   393
fun killWatcher pid = Posix.Process.kill(Posix.Process.K_GROUP pid, Posix.Signal.kill);
17488
67376a311a2b further simplification of the Isabelle-ATP linkup
paulson
parents: 17484
diff changeset
   394
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   395
fun reapWatcher(pid, instr, outstr) = ignore
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   396
  (TextIO.closeIn instr; TextIO.closeOut outstr;
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   397
   Posix.Process.waitpid(Posix.Process.W_CHILD pid, []))
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   398
  handle OS.SysErr _ => ()
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   399
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   400
fun string_of_subgoal th i =
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   401
    string_of_cterm (List.nth(cprems_of th, i-1))
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   402
    handle Subscript => "Subgoal number out of range!"
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   403
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   404
fun createWatcher (th, clause_arr) =
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   405
 let val (childpid,(childin,childout)) = childInfo (setupWatcher(th,clause_arr))
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   406
     fun decr_watched() =
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   407
	  (goals_being_watched := !goals_being_watched - 1;
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   408
	   if !goals_being_watched = 0
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   409
	   then 
17716
89932e53f31d moved concat_with_and to watcher.ML
paulson
parents: 17690
diff changeset
   410
	     (debug ("\nReaping a watcher, childpid = "^
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   411
		     LargeWord.toString (Posix.Process.pidToWord childpid));
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   412
	      killWatcher childpid; reapWatcher (childpid,childin, childout))
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   413
	    else ())
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   414
     val _ = debug ("subgoals forked to createWatcher: "^ prems_string_of th);
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   415
     fun proofHandler n = 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   416
       let val outcome = TextIO.inputLine childin
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   417
	   val probfile = TextIO.inputLine childin
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   418
	   val sg_num = number_from_filename probfile
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   419
	   val text = string_of_subgoal th sg_num
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   420
	   val _ = debug ("In signal handler. outcome = \"" ^ outcome ^ 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   421
		        "\"\nprobfile = " ^ probfile ^
17568
e93f7510e1e1 trying to limit the looping
paulson
parents: 17525
diff changeset
   422
		        "\ngoals_being_watched: "^  Int.toString (!goals_being_watched))
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   423
       in 
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   424
	 if String.isPrefix "[" outcome (*indicates a proof reconstruction*)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   425
	 then (priority (Recon_Transfer.apply_res_thm outcome);
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   426
	       decr_watched())
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   427
	 else if String.isPrefix "Invalid" outcome
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   428
	 then (priority ("Subgoal is not provable:\n" ^ text);
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   429
	       decr_watched())
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   430
	 else if String.isPrefix "Failure" outcome
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   431
	 then (priority ("Proof attempt failed:\n" ^ text);
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   432
	       decr_watched()) 
17216
df66d8feec63 improved formatting
paulson
parents: 17150
diff changeset
   433
	(* print out a list of rules used from clasimpset*)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   434
	 else if String.isPrefix "Success" outcome
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   435
	 then (priority (outcome ^ text);
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   436
	       decr_watched())
17216
df66d8feec63 improved formatting
paulson
parents: 17150
diff changeset
   437
	  (* if proof translation failed *)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   438
	 else if String.isPrefix "Translation failed" outcome
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   439
	 then (priority (outcome ^ text);
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   440
	       decr_watched())
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   441
	 else (priority "System error in proof handler";
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   442
	       decr_watched())
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   443
       end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   444
 in IsaSignal.signal (IsaSignal.usr2, IsaSignal.SIG_HANDLE proofHandler);
17216
df66d8feec63 improved formatting
paulson
parents: 17150
diff changeset
   445
    (childin, childout, childpid)
df66d8feec63 improved formatting
paulson
parents: 17150
diff changeset
   446
  end
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   447
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   448
end (* structure Watcher *)