src/HOL/Tools/ATP/watcher.ML
author paulson
Mon Oct 10 15:35:29 2005 +0200 (2005-10-10)
changeset 17819 1241e5d31d5b
parent 17774 0ecfb66ea072
child 18680 677e2bdd75f0
permissions -rw-r--r--
small tidy-up of utility functions
paulson@15789
     1
(*  Title:      Watcher.ML
paulson@15789
     2
    ID:         $Id$
paulson@15789
     3
    Author:     Claire Quigley
paulson@15789
     4
    Copyright   2004  University of Cambridge
quigley@15642
     5
 *)
quigley@15642
     6
paulson@17764
     7
(*  The watcher process starts a resolution process when it receives a     *)
quigley@15642
     8
(*  message from Isabelle                                                  *)
quigley@15642
     9
(*  Signals Isabelle, puts output of child into pipe to Isabelle,          *)
quigley@15642
    10
(*  and removes dead processes.  Also possible to kill all the resolution  *)
quigley@15642
    11
(*  processes currently running.                                           *)
quigley@15642
    12
paulson@17305
    13
signature WATCHER =
paulson@17305
    14
sig
paulson@17305
    15
paulson@17305
    16
(*  Send request to Watcher for multiple spasses to be called for filenames in arg       *)
paulson@17568
    17
(* callResProvers (outstreamtoWatcher, prover name,prover-command, (settings,file) list *)
paulson@17305
    18
paulson@17773
    19
val callResProvers : TextIO.outstream * (string*string*string*string) list -> unit
paulson@17305
    20
paulson@17764
    21
(* Send message to watcher to kill resolution provers *)
paulson@17305
    22
val callSlayer : TextIO.outstream -> unit
paulson@17305
    23
paulson@17305
    24
(* Start a watcher and set up signal handlers             *)
paulson@17484
    25
val createWatcher : 
paulson@17484
    26
    thm * (ResClause.clause * thm) Array.array -> 
paulson@17484
    27
    TextIO.instream * TextIO.outstream * Posix.Process.pid
paulson@17305
    28
val killWatcher : Posix.Process.pid -> unit
paulson@17764
    29
val setting_sep : char
paulson@17305
    30
end
paulson@17305
    31
paulson@17305
    32
quigley@15642
    33
quigley@15642
    34
structure Watcher: WATCHER =
paulson@17484
    35
struct
quigley@15642
    36
paulson@17764
    37
(*Field separators, used to pack items onto a text line*)
paulson@17764
    38
val command_sep = #"\t"
paulson@17764
    39
and setting_sep = #"%";
paulson@17764
    40
quigley@15642
    41
val goals_being_watched = ref 0;
quigley@15642
    42
paulson@17583
    43
val trace_path = Path.basic "watcher_trace";
paulson@17583
    44
paulson@17690
    45
fun trace s = if !Output.show_debug_msgs then File.append (File.tmp_path trace_path) s 
paulson@17690
    46
              else ();
paulson@17583
    47
paulson@17773
    48
(*Representation of a watcher process*)
paulson@17773
    49
type proc = {pid : Posix.Process.pid,
paulson@17773
    50
             instr : TextIO.instream,
paulson@17773
    51
             outstr : TextIO.outstream};
quigley@16039
    52
paulson@17773
    53
(*Representation of a child (ATP) process*)
paulson@17773
    54
type cmdproc = {
paulson@17773
    55
        prover: string,       (* Name of the resolution prover used, e.g. "spass"*)
paulson@17773
    56
        file:  string,        (* The file containing the goal for the ATP to prove *)     
quigley@16039
    57
        proc_handle : (TextIO.instream,TextIO.outstream) Unix.proc,
paulson@17773
    58
        instr : TextIO.instream,     (*Output of the child process *)
paulson@17773
    59
        outstr : TextIO.outstream};  (*Input to the child process *)
quigley@16039
    60
quigley@16039
    61
quigley@16039
    62
fun fdReader (name : string, fd : Posix.IO.file_desc) =
quigley@16039
    63
	  Posix.IO.mkTextReader {initBlkMode = true,name = name,fd = fd };
quigley@16039
    64
quigley@16039
    65
fun fdWriter (name, fd) =
quigley@16039
    66
          Posix.IO.mkTextWriter {
quigley@16039
    67
	      appendMode = false,
quigley@16039
    68
              initBlkMode = true,
quigley@16039
    69
              name = name,  
quigley@16039
    70
              chunkSize=4096,
paulson@17317
    71
              fd = fd};
quigley@16039
    72
quigley@16039
    73
fun openOutFD (name, fd) =
quigley@16039
    74
	  TextIO.mkOutstream (
quigley@16039
    75
	    TextIO.StreamIO.mkOutstream (
quigley@16039
    76
	      fdWriter (name, fd), IO.BLOCK_BUF));
quigley@16039
    77
quigley@16039
    78
fun openInFD (name, fd) =
quigley@16039
    79
	  TextIO.mkInstream (
quigley@16039
    80
	    TextIO.StreamIO.mkInstream (
quigley@16039
    81
	      fdReader (name, fd), ""));
quigley@16039
    82
quigley@15642
    83
                            
paulson@17773
    84
(*  Send request to Watcher for a vampire to be called for filename in arg*)
paulson@17231
    85
fun callResProver (toWatcherStr,  arg) = 
paulson@17317
    86
      (TextIO.output (toWatcherStr, arg^"\n"); 
paulson@17231
    87
       TextIO.flushOut toWatcherStr)
quigley@15642
    88
paulson@17773
    89
(*  Send request to Watcher for multiple provers to be called*)
paulson@16475
    90
fun callResProvers (toWatcherStr,  []) = 
paulson@17317
    91
      (TextIO.output (toWatcherStr, "End of calls\n");  TextIO.flushOut toWatcherStr)
paulson@17773
    92
  | callResProvers (toWatcherStr,
paulson@17772
    93
                    (prover,proverCmd,settings,probfile)  ::  args) =
paulson@17773
    94
      (trace (space_implode ", " (["\ncallResProvers:", prover, proverCmd, probfile]));
paulson@17773
    95
       (*Uses a special character to separate items sent to watcher*)
paulson@17773
    96
       TextIO.output (toWatcherStr,
paulson@17773
    97
          space_implode (str command_sep) [prover, proverCmd, settings, probfile, "\n"]);
paulson@17773
    98
       goals_being_watched := (!goals_being_watched) + 1;
paulson@17773
    99
       TextIO.flushOut toWatcherStr;
paulson@17773
   100
       callResProvers (toWatcherStr,args))
quigley@16357
   101
                                                
quigley@15642
   102
paulson@17764
   103
(*Send message to watcher to kill currently running vampires. NOT USED and possibly
paulson@17764
   104
  buggy. Note that killWatcher kills the entire process group anyway.*)
paulson@17764
   105
fun callSlayer toWatcherStr = (TextIO.output (toWatcherStr, "Kill children\n"); 
quigley@15642
   106
                            TextIO.flushOut toWatcherStr)
quigley@15642
   107
paulson@17746
   108
                    
paulson@17773
   109
(* Get commands from Isabelle*)
paulson@17764
   110
fun getCmds (toParentStr, fromParentStr, cmdList) = 
paulson@16475
   111
  let val thisLine = TextIO.inputLine fromParentStr 
paulson@16475
   112
  in
paulson@17764
   113
     trace("\nGot command from parent: " ^ thisLine);
paulson@17568
   114
     if thisLine = "End of calls\n" orelse thisLine = "" then cmdList
paulson@17422
   115
     else if thisLine = "Kill children\n"
paulson@17764
   116
     then (TextIO.output (toParentStr,thisLine); 
paulson@17568
   117
	   TextIO.flushOut toParentStr;
paulson@17772
   118
	   [("","Kill children",[],"")])
paulson@17746
   119
     else
paulson@17772
   120
       let val [prover,proverCmd,settingstr,probfile,_] = 
paulson@17764
   121
                   String.tokens (fn c => c = command_sep) thisLine
paulson@17764
   122
           val settings = String.tokens (fn c => c = setting_sep) settingstr
paulson@17746
   123
       in
paulson@17772
   124
           trace ("\nprover: " ^ prover ^ "  prover path: " ^ proverCmd ^
paulson@17772
   125
                  "\n  problem file: " ^ probfile);
paulson@17746
   126
           getCmds (toParentStr, fromParentStr, 
paulson@17772
   127
                    (prover, proverCmd, settings, probfile)::cmdList) 
paulson@17746
   128
       end
paulson@17764
   129
       handle Bind => 
paulson@17764
   130
          (trace "getCmds: command parsing failed!";
paulson@17764
   131
           getCmds (toParentStr, fromParentStr, cmdList))
paulson@16475
   132
  end
paulson@16475
   133
	    
quigley@16357
   134
                                                                  
paulson@17774
   135
(*Get Io-descriptor for polling of an input stream*)
quigley@15642
   136
fun getInIoDesc someInstr = 
quigley@15642
   137
    let val (rd, buf) = TextIO.StreamIO.getReader(TextIO.getInstream someInstr)
paulson@15702
   138
        val _ = TextIO.output (TextIO.stdOut, buf)
quigley@15642
   139
        val ioDesc = 
quigley@15642
   140
	    case rd
paulson@17774
   141
	      of TextPrimIO.RD{ioDesc = SOME iod, ...} => SOME iod
quigley@15642
   142
	       | _ => NONE
quigley@15642
   143
     in (* since getting the reader will have terminated the stream, we need
quigley@15642
   144
	 * to build a new stream. *)
quigley@15642
   145
	TextIO.setInstream(someInstr, TextIO.StreamIO.mkInstream(rd, buf));
quigley@15642
   146
	ioDesc
quigley@15642
   147
    end
quigley@15642
   148
paulson@17774
   149
fun pollChild fromStr = 
paulson@17774
   150
   case getInIoDesc fromStr of
paulson@17774
   151
     SOME iod => 
paulson@17774
   152
       (case OS.IO.pollDesc iod of
paulson@17774
   153
	  SOME pd =>
paulson@17774
   154
	      let val pd' = OS.IO.pollIn pd in
paulson@17774
   155
		case OS.IO.poll ([pd'], SOME (Time.fromSeconds 2)) of
paulson@17774
   156
		    [] => false
paulson@17774
   157
		  | pd''::_ => OS.IO.isIn pd''
paulson@17774
   158
	      end
paulson@17774
   159
	 | NONE => false)
paulson@17774
   160
   | NONE => false
paulson@17774
   161
quigley@15642
   162
quigley@15642
   163
(*************************************)
quigley@15642
   164
(*  Set up a Watcher Process         *)
quigley@15642
   165
(*************************************)
quigley@15642
   166
paulson@17525
   167
fun killChild proc = (Unix.kill(proc, Posix.Signal.kill); Unix.reap proc);
paulson@17525
   168
paulson@17774
   169
val killChildren = List.app (ignore o killChild o #proc_handle) : cmdproc list -> unit;
paulson@17774
   170
paulson@17774
   171
fun killWatcher (toParentStr, procList) =
paulson@17774
   172
      (trace "\nWatcher timeout: Killing proof processes";
paulson@17774
   173
       TextIO.output(toParentStr, "Timeout: Killing proof processes!\n");
paulson@17774
   174
       TextIO.flushOut toParentStr;
paulson@17774
   175
       killChildren procList;
paulson@17774
   176
       Posix.Process.exit 0w0);
paulson@17502
   177
paulson@17774
   178
(* take an instream and poll its underlying reader for input *)
paulson@17774
   179
fun pollParentInput (fromParentIOD, fromParentStr, toParentStr) = 
paulson@17774
   180
  case OS.IO.pollDesc fromParentIOD of
paulson@17774
   181
     SOME pd =>
paulson@17774
   182
	(case OS.IO.poll ([OS.IO.pollIn pd], SOME (Time.fromSeconds 2)) of
paulson@17774
   183
	     [] => NONE
paulson@17774
   184
	   | pd''::_ => if OS.IO.isIn pd''
paulson@17774
   185
			then SOME (getCmds (toParentStr, fromParentStr, []))
paulson@17774
   186
			else NONE)
paulson@17774
   187
  | NONE => NONE;
paulson@17568
   188
paulson@17583
   189
(*get the number of the subgoal from the filename: the last digit string*)
paulson@17583
   190
fun number_from_filename s =
paulson@17583
   191
  case String.tokens (not o Char.isDigit) s of
paulson@17772
   192
      [] => (trace ("\nWatcher could not read subgoal nunber! " ^ s); 
paulson@17772
   193
             raise ERROR)
paulson@17583
   194
    | numbers => valOf (Int.fromString (List.last numbers));
paulson@17583
   195
paulson@17774
   196
(* call ATP.  Settings should be a list of strings  ["-t300", "-m100000"]*)
paulson@17774
   197
fun execCmds [] procList = procList
paulson@17774
   198
  | execCmds ((prover,proverCmd,settings,file)::cmds) procList  =
paulson@17774
   199
      let val _ = trace ("\nAbout to execute command: " ^ proverCmd ^ " " ^ file)
paulson@17774
   200
	  val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc  = 
paulson@17774
   201
	       Unix.execute(proverCmd, settings@[file])
paulson@17774
   202
	  val (instr, outstr) = Unix.streamsOf childhandle
paulson@17774
   203
	  val newProcList = {prover=prover, file=file, proc_handle=childhandle,
paulson@17774
   204
			     instr=instr, outstr=outstr} :: procList
paulson@17774
   205
	  val _ = trace ("\nFinished at " ^
paulson@17774
   206
			 Date.toString(Date.fromTimeLocal(Time.now())))
paulson@17774
   207
      in execCmds cmds newProcList end
paulson@17774
   208
paulson@17774
   209
fun checkChildren (th, clause_arr, toParentStr, children) = 
paulson@17774
   210
  let fun check [] = []  (* no children to check *)
paulson@17774
   211
	| check (child::children) = 
paulson@17774
   212
	   let val {prover, file, proc_handle, instr=childIn, ...} : cmdproc =
paulson@17774
   213
		   child
paulson@17774
   214
	       val _ = trace ("\nprobfile = " ^ file)
paulson@17774
   215
	       val sgno = number_from_filename file
paulson@17774
   216
	       val ppid = Posix.ProcEnv.getppid()
paulson@17774
   217
	   in 
paulson@17774
   218
	     if pollChild childIn
paulson@17774
   219
	     then (* check here for prover label on child*)
paulson@17774
   220
	       let val _ = trace ("\nInput available from child: " ^ file)
paulson@17774
   221
		   val childDone = (case prover of
paulson@17774
   222
		       "vampire" => AtpCommunication.checkVampProofFound
paulson@17774
   223
			    (childIn, toParentStr, ppid, file, clause_arr)  
paulson@17774
   224
		     | "E" => AtpCommunication.checkEProofFound
paulson@17774
   225
			    (childIn, toParentStr, ppid, file, clause_arr)             
paulson@17774
   226
		     | "spass" => AtpCommunication.checkSpassProofFound
paulson@17774
   227
			    (childIn, toParentStr, ppid, file, th, sgno,clause_arr)  
paulson@17774
   228
		     | _ => (trace ("\nBad prover! " ^ prover); true) )
paulson@17774
   229
		in
paulson@17774
   230
		 if childDone (*child has found a proof and transferred it*)
paulson@17774
   231
		 then (Unix.reap proc_handle; OS.FileSys.remove file;
paulson@17774
   232
		       check children)
paulson@17774
   233
		 else child :: check children
paulson@17774
   234
	      end
paulson@17774
   235
	    else (trace "\nNo child output";  child :: check children)
paulson@17774
   236
	   end
paulson@17774
   237
  in 
paulson@17774
   238
    trace ("\nIn checkChildren, length of queue: " ^  Int.toString(length children));
paulson@17774
   239
    check children 
paulson@17774
   240
  end;
paulson@17774
   241
paulson@17774
   242
paulson@17774
   243
fun setupWatcher (th,clause_arr) = 
paulson@16061
   244
  let
paulson@17772
   245
    val p1 = Posix.IO.pipe()   (*pipes for communication between parent and watcher*)
paulson@17772
   246
    val p2 = Posix.IO.pipe()
paulson@17764
   247
    (****** fork a watcher process and get it set up and going ******)
paulson@17317
   248
    fun startWatcher procList =
paulson@17774
   249
      case  Posix.Process.fork() of
paulson@17774
   250
         SOME pid => pid (* parent - i.e. main Isabelle process *)
paulson@17774
   251
       | NONE => 
paulson@17774
   252
          let            (* child - i.e. watcher  *)
paulson@17774
   253
	    val oldchildin = #infd p1  
paulson@17774
   254
	    val fromParent = Posix.FileSys.wordToFD 0w0
paulson@17774
   255
	    val oldchildout = #outfd p2
paulson@17774
   256
	    val toParent = Posix.FileSys.wordToFD 0w1
paulson@17774
   257
	    val fromParentIOD = Posix.FileSys.fdToIOD fromParent
paulson@17774
   258
	    val fromParentStr = openInFD ("_exec_in_parent", fromParent)
paulson@17774
   259
	    val toParentStr = openOutFD ("_exec_out_parent", toParent)
paulson@17774
   260
	    val pid = Posix.ProcEnv.getpid()
paulson@17774
   261
	    val () = Posix.ProcEnv.setpgid {pid = SOME pid, pgid = SOME pid}
paulson@17774
   262
		     (*set process group id: allows killing all children*)
paulson@17774
   263
	    val () = trace "\nsubgoals forked to startWatcher"
paulson@17774
   264
	    val limit = ref 200;  (*don't let watcher run forever*)
paulson@17774
   265
	    (*Watcher Loop : Check running ATP processes for output*)
paulson@17774
   266
	    fun keepWatching procList = 
paulson@17774
   267
	      (trace ("\npollParentInput. Limit = " ^ Int.toString (!limit) ^ 
paulson@17774
   268
				"  length(procList) = " ^ Int.toString(length procList));
paulson@17774
   269
	       OS.Process.sleep (Time.fromMilliseconds 100);  limit := !limit - 1;
paulson@17774
   270
	       if !limit < 0 then killWatcher (toParentStr, procList) 
paulson@17774
   271
	       else 
paulson@17774
   272
	       case pollParentInput(fromParentIOD, fromParentStr, toParentStr) of
paulson@17774
   273
		  SOME [(_,"Kill children",_,_)] => 
paulson@17774
   274
		    (trace "\nReceived Kill command"; 
paulson@17774
   275
		     killChildren procList; keepWatching [])
paulson@17774
   276
		| SOME cmds => (*  deal with commands from Isabelle process *)
paulson@17774
   277
		    if length procList < 40 then    (* Execute locally  *)                    
paulson@17774
   278
		      let val _ = trace("\nCommands from parent: " ^ 
paulson@17774
   279
					Int.toString(length cmds))
paulson@17774
   280
			  val newProcList' = checkChildren(th, clause_arr, toParentStr, 
paulson@17774
   281
						execCmds cmds procList) 
paulson@17774
   282
		      in trace "\nCommands executed"; keepWatching newProcList' end
paulson@17774
   283
		    else  (* Execute remotely [FIXME: NOT REALLY]  *)
paulson@17774
   284
		      let val newProcList' = checkChildren (th, clause_arr, toParentStr, 
paulson@17774
   285
						execCmds cmds procList) 
paulson@17774
   286
		      in keepWatching newProcList' end
paulson@17774
   287
		| NONE => (* No new input from Isabelle *)
paulson@17774
   288
		    (trace "\nNothing from parent...";  
paulson@17774
   289
		     keepWatching(checkChildren(th, clause_arr, toParentStr, procList))))
paulson@17774
   290
	     handle exn => (*FIXME: exn handler is too general!*)
paulson@17774
   291
	       (trace ("\nkeepWatching exception handler: " ^ Toplevel.exn_message exn);
paulson@17774
   292
		keepWatching procList);
paulson@17774
   293
	  in
paulson@17774
   294
	    (*** Sort out pipes ********)
paulson@17774
   295
	    Posix.IO.close (#outfd p1);  Posix.IO.close (#infd p2);
paulson@17774
   296
	    Posix.IO.dup2{old = oldchildin, new = fromParent};
paulson@17774
   297
	    Posix.IO.close oldchildin;
paulson@17774
   298
	    Posix.IO.dup2{old = oldchildout, new = toParent};
paulson@17774
   299
	    Posix.IO.close oldchildout;
paulson@17774
   300
	    keepWatching (procList)
paulson@17774
   301
	  end; 
quigley@15642
   302
paulson@16061
   303
    val _ = TextIO.flushOut TextIO.stdOut
paulson@17772
   304
    val pid = startWatcher []
paulson@17772
   305
    (* communication streams to watcher*)
paulson@16061
   306
    val instr = openInFD ("_exec_in", #infd p2)
paulson@16061
   307
    val outstr = openOutFD ("_exec_out", #outfd p1)
paulson@17568
   308
  in
paulson@17772
   309
   (* close the child-side fds*)
paulson@17772
   310
    Posix.IO.close (#outfd p2);  Posix.IO.close (#infd p1);
paulson@17568
   311
    (* set the fds close on exec *)
paulson@17568
   312
    Posix.IO.setfd (#infd p2, Posix.IO.FD.flags [Posix.IO.FD.cloexec]);
paulson@17568
   313
    Posix.IO.setfd (#outfd p1, Posix.IO.FD.flags [Posix.IO.FD.cloexec]);
paulson@17773
   314
    {pid = pid, instr = instr, outstr = outstr}
paulson@17568
   315
  end;
quigley@15642
   316
quigley@15642
   317
quigley@15642
   318
quigley@15642
   319
(**********************************************************)
quigley@15642
   320
(* Start a watcher and set up signal handlers             *)
quigley@15642
   321
(**********************************************************)
quigley@16039
   322
paulson@17773
   323
fun reapAll s = (*Signal handler to tidy away dead processes*)
paulson@17773
   324
     (case Posix.Process.waitpid_nh(Posix.Process.W_ANY_CHILD, []) of
paulson@17773
   325
	  SOME _ => reapAll s | NONE => ()) 
paulson@17773
   326
     handle OS.SysErr _ => ()
paulson@17773
   327
paulson@17773
   328
(*FIXME: does the main process need something like this?
paulson@17773
   329
    IsaSignal.signal (IsaSignal.chld, IsaSignal.SIG_HANDLE reap)??*)
paulson@17773
   330
paulson@17773
   331
fun killWatcher pid = 
paulson@17773
   332
  (goals_being_watched := 0;
paulson@17773
   333
   Posix.Process.kill(Posix.Process.K_GROUP pid, Posix.Signal.kill);
paulson@17773
   334
   reapAll());
paulson@17488
   335
paulson@17772
   336
fun reapWatcher(pid, instr, outstr) = ignore
paulson@17484
   337
  (TextIO.closeIn instr; TextIO.closeOut outstr;
paulson@17772
   338
   Posix.Process.waitpid(Posix.Process.W_CHILD pid, []))
paulson@17772
   339
  handle OS.SysErr _ => ()
quigley@15642
   340
paulson@17772
   341
fun string_of_subgoal th i =
paulson@17772
   342
    string_of_cterm (List.nth(cprems_of th, i-1))
paulson@17772
   343
    handle Subscript => "Subgoal number out of range!"
paulson@17772
   344
paulson@17773
   345
fun prems_string_of th = space_implode "\n" (map string_of_cterm (cprems_of th))
paulson@17773
   346
paulson@17772
   347
fun createWatcher (th, clause_arr) =
paulson@17773
   348
 let val {pid=childpid, instr=childin, outstr=childout} = setupWatcher (th,clause_arr)
paulson@17435
   349
     fun decr_watched() =
paulson@17502
   350
	  (goals_being_watched := !goals_being_watched - 1;
paulson@17435
   351
	   if !goals_being_watched = 0
paulson@17435
   352
	   then 
paulson@17819
   353
	     (debug ("\nReaping a watcher, childpid = " ^ string_of_pid childpid);
paulson@17773
   354
	      killWatcher childpid (*???; reapWatcher (childpid, childin, childout)*) )
paulson@17435
   355
	    else ())
paulson@17772
   356
     val _ = debug ("subgoals forked to createWatcher: "^ prems_string_of th);
paulson@17484
   357
     fun proofHandler n = 
paulson@17484
   358
       let val outcome = TextIO.inputLine childin
paulson@17772
   359
	   val probfile = TextIO.inputLine childin
paulson@17773
   360
	   val sgno = number_from_filename probfile
paulson@17773
   361
	   val text = string_of_subgoal th sgno
paulson@17484
   362
	   val _ = debug ("In signal handler. outcome = \"" ^ outcome ^ 
paulson@17772
   363
		        "\"\nprobfile = " ^ probfile ^
paulson@17773
   364
		        "\nGoals being watched: "^  Int.toString (!goals_being_watched))
paulson@17502
   365
       in 
paulson@17502
   366
	 if String.isPrefix "[" outcome (*indicates a proof reconstruction*)
paulson@17772
   367
	 then (priority (Recon_Transfer.apply_res_thm outcome);
paulson@17435
   368
	       decr_watched())
paulson@17484
   369
	 else if String.isPrefix "Invalid" outcome
paulson@17772
   370
	 then (priority ("Subgoal is not provable:\n" ^ text);
paulson@17484
   371
	       decr_watched())
paulson@17484
   372
	 else if String.isPrefix "Failure" outcome
paulson@17772
   373
	 then (priority ("Proof attempt failed:\n" ^ text);
paulson@17435
   374
	       decr_watched()) 
paulson@17216
   375
	(* print out a list of rules used from clasimpset*)
paulson@17484
   376
	 else if String.isPrefix "Success" outcome
paulson@17772
   377
	 then (priority (outcome ^ text);
paulson@17435
   378
	       decr_watched())
paulson@17216
   379
	  (* if proof translation failed *)
paulson@17484
   380
	 else if String.isPrefix "Translation failed" outcome
paulson@17772
   381
	 then (priority (outcome ^ text);
paulson@17435
   382
	       decr_watched())
paulson@17690
   383
	 else (priority "System error in proof handler";
paulson@17435
   384
	       decr_watched())
paulson@17484
   385
       end
paulson@17484
   386
 in IsaSignal.signal (IsaSignal.usr2, IsaSignal.SIG_HANDLE proofHandler);
paulson@17216
   387
    (childin, childout, childpid)
paulson@17216
   388
  end
quigley@15642
   389
quigley@15642
   390
end (* structure Watcher *)