author | paulson |
Tue, 26 Jun 2007 18:32:24 +0200 | |
changeset 23507 | 13a9f54175ad |
parent 23139 | aa899bce7c3b |
permissions | -rw-r--r-- |
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 | 5 |
*) |
6 |
||
17764 | 7 |
(* The watcher process starts a resolution process when it receives a *) |
15642 | 8 |
(* message from Isabelle *) |
9 |
(* Signals Isabelle, puts output of child into pipe to Isabelle, *) |
|
10 |
(* and removes dead processes. Also possible to kill all the resolution *) |
|
11 |
(* processes currently running. *) |
|
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 | 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 |
|
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
19 |
val callResProvers : 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
|
20 |
|
17764 | 21 |
(* 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
|
22 |
val callSlayer : TextIO.outstream -> unit |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
23 |
|
20871
da3a43cdbe8d
Fixed the printing of the used theorems by maintaining separate lists for each subgoal.
paulson
parents:
20762
diff
changeset
|
24 |
(* 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
|
25 |
val createWatcher : |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
26 |
Proof.context * thm * string Vector.vector list -> |
20871
da3a43cdbe8d
Fixed the printing of the used theorems by maintaining separate lists for each subgoal.
paulson
parents:
20762
diff
changeset
|
27 |
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
|
28 |
val killWatcher : Posix.Process.pid -> unit |
19239 | 29 |
val killChild : ('a, 'b) Unix.proc -> OS.Process.status |
21977 | 30 |
val command_sep : char |
17764 | 31 |
val setting_sep : char |
19239 | 32 |
val reapAll : unit -> unit |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
33 |
end |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
34 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
35 |
|
15642 | 36 |
|
37 |
structure Watcher: WATCHER = |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
38 |
struct |
15642 | 39 |
|
17764 | 40 |
(*Field separators, used to pack items onto a text line*) |
41 |
val command_sep = #"\t" |
|
42 |
and setting_sep = #"%"; |
|
43 |
||
15642 | 44 |
val goals_being_watched = ref 0; |
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 |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
48 |
fun trace s = if !Output.debugging then File.append (File.tmp_path trace_path) s |
17690
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 |
|
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
51 |
(*Representation of a watcher process*) |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
52 |
type proc = {pid : Posix.Process.pid, |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
53 |
instr : TextIO.instream, |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
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 |
|
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
56 |
(*Representation of a child (ATP) process*) |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
57 |
type cmdproc = { |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
58 |
prover: string, (* Name of the resolution prover used, e.g. "spass"*) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
59 |
file: string, (* The file containing the goal for the ATP 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, |
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
61 |
instr : TextIO.instream, (*Output of the child process *) |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
62 |
outstr : TextIO.outstream}; (*Input to the 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, |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
72 |
name = name, |
16039
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 |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
86 |
|
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
87 |
(* Send request to Watcher for a vampire to be called for filename in arg*) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
88 |
fun callResProver (toWatcherStr, arg) = |
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
89 |
(TextIO.output (toWatcherStr, arg^"\n"); |
17231 | 90 |
TextIO.flushOut toWatcherStr) |
15642 | 91 |
|
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
92 |
(* Send request to Watcher for multiple provers to be called*) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
93 |
fun callResProvers (toWatcherStr, []) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
94 |
(TextIO.output (toWatcherStr, "End of calls\n"); TextIO.flushOut toWatcherStr) |
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
95 |
| callResProvers (toWatcherStr, |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
96 |
(prover,proverCmd,settings,probfile) :: args) = |
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
97 |
(trace (space_implode ", " (["\ncallResProvers:", prover, proverCmd, probfile])); |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
98 |
(*Uses a special character to separate items sent to watcher*) |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
99 |
TextIO.output (toWatcherStr, |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
100 |
space_implode (str command_sep) [prover, proverCmd, settings, probfile, "\n"]); |
20416 | 101 |
inc goals_being_watched; |
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
102 |
TextIO.flushOut toWatcherStr; |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
103 |
callResProvers (toWatcherStr,args)) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
104 |
|
15642 | 105 |
|
17764 | 106 |
(*Send message to watcher to kill currently running vampires. NOT USED and possibly |
107 |
buggy. Note that killWatcher kills the entire process group anyway.*) |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
108 |
fun callSlayer toWatcherStr = (TextIO.output (toWatcherStr, "Kill children\n"); |
15642 | 109 |
TextIO.flushOut toWatcherStr) |
110 |
||
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
111 |
|
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
112 |
(* Get commands from Isabelle*) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
113 |
fun getCmds (toParentStr, fromParentStr, cmdList) = |
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
114 |
let val thisLine = the_default "" (TextIO.inputLine fromParentStr) |
16475 | 115 |
in |
17764 | 116 |
trace("\nGot command from parent: " ^ thisLine); |
17568 | 117 |
if thisLine = "End of calls\n" orelse thisLine = "" then cmdList |
17422 | 118 |
else if thisLine = "Kill children\n" |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
119 |
then (TextIO.output (toParentStr,thisLine); |
17568 | 120 |
TextIO.flushOut toParentStr; |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
121 |
[("","Kill children",[],"")]) |
17746 | 122 |
else |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
123 |
let val [prover,proverCmd,settingstr,probfile,_] = |
17764 | 124 |
String.tokens (fn c => c = command_sep) thisLine |
125 |
val settings = String.tokens (fn c => c = setting_sep) settingstr |
|
17746 | 126 |
in |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
127 |
trace ("\nprover: " ^ prover ^ " prover path: " ^ proverCmd ^ |
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
128 |
"\n problem file: " ^ probfile); |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
129 |
getCmds (toParentStr, fromParentStr, |
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
130 |
(prover, proverCmd, settings, probfile)::cmdList) |
17746 | 131 |
end |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
132 |
handle Bind => |
18796 | 133 |
(trace "\ngetCmds: command parsing failed!"; |
17764 | 134 |
getCmds (toParentStr, fromParentStr, cmdList)) |
16475 | 135 |
end |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
136 |
|
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
137 |
|
17774 | 138 |
(*Get Io-descriptor for polling of an input stream*) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
139 |
fun getInIoDesc someInstr = |
15642 | 140 |
let val (rd, buf) = TextIO.StreamIO.getReader(TextIO.getInstream someInstr) |
15702
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
15684
diff
changeset
|
141 |
val _ = TextIO.output (TextIO.stdOut, buf) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
142 |
val ioDesc = |
15642 | 143 |
case rd |
17774 | 144 |
of TextPrimIO.RD{ioDesc = SOME iod, ...} => SOME iod |
15642 | 145 |
| _ => NONE |
146 |
in (* since getting the reader will have terminated the stream, we need |
|
147 |
* to build a new stream. *) |
|
148 |
TextIO.setInstream(someInstr, TextIO.StreamIO.mkInstream(rd, buf)); |
|
149 |
ioDesc |
|
150 |
end |
|
151 |
||
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
152 |
fun pollChild fromStr = |
17774 | 153 |
case getInIoDesc fromStr of |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
154 |
SOME iod => |
17774 | 155 |
(case OS.IO.pollDesc iod of |
156 |
SOME pd => |
|
157 |
let val pd' = OS.IO.pollIn pd in |
|
158 |
case OS.IO.poll ([pd'], SOME (Time.fromSeconds 2)) of |
|
159 |
[] => false |
|
160 |
| pd''::_ => OS.IO.isIn pd'' |
|
161 |
end |
|
162 |
| NONE => false) |
|
163 |
| NONE => false |
|
164 |
||
15642 | 165 |
|
166 |
(*************************************) |
|
167 |
(* Set up a Watcher Process *) |
|
168 |
(*************************************) |
|
169 |
||
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
170 |
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
|
171 |
|
17774 | 172 |
val killChildren = List.app (ignore o killChild o #proc_handle) : cmdproc list -> unit; |
173 |
||
174 |
fun killWatcher (toParentStr, procList) = |
|
175 |
(trace "\nWatcher timeout: Killing proof processes"; |
|
176 |
TextIO.output(toParentStr, "Timeout: Killing proof processes!\n"); |
|
177 |
TextIO.flushOut toParentStr; |
|
178 |
killChildren procList; |
|
179 |
Posix.Process.exit 0w0); |
|
17502 | 180 |
|
17774 | 181 |
(* take an instream and poll its underlying reader for input *) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
182 |
fun pollParentInput (fromParentIOD, fromParentStr, toParentStr) = |
17774 | 183 |
case OS.IO.pollDesc fromParentIOD of |
184 |
SOME pd => |
|
185 |
(case OS.IO.poll ([OS.IO.pollIn pd], SOME (Time.fromSeconds 2)) of |
|
186 |
[] => NONE |
|
187 |
| pd''::_ => if OS.IO.isIn pd'' |
|
188 |
then SOME (getCmds (toParentStr, fromParentStr, [])) |
|
189 |
else NONE) |
|
190 |
| NONE => NONE; |
|
17568 | 191 |
|
17583
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
192 |
(*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
|
193 |
fun number_from_filename s = |
23507 | 194 |
let val numbers = "xxx" :: String.tokens (not o Char.isDigit) s |
195 |
in valOf (Int.fromString (List.last numbers)) end |
|
196 |
handle Option => (trace ("\nWatcher could not read subgoal nunber! " ^ s); |
|
197 |
error ("Watcher could not read subgoal nunber! " ^ s)); |
|
17583
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
198 |
|
19449
b07e3bca20c9
fix to spacing in switches, for Vampire under SML/NJ
paulson
parents:
19239
diff
changeset
|
199 |
(*Call ATP. Settings should be a list of strings ["-t 300", "-m 100000"], |
b07e3bca20c9
fix to spacing in switches, for Vampire under SML/NJ
paulson
parents:
19239
diff
changeset
|
200 |
which we convert below to ["-t", "300", "-m", "100000"] using String.tokens. |
b07e3bca20c9
fix to spacing in switches, for Vampire under SML/NJ
paulson
parents:
19239
diff
changeset
|
201 |
Otherwise, the SML/NJ version of Unix.execute will escape the spaces, and |
b07e3bca20c9
fix to spacing in switches, for Vampire under SML/NJ
paulson
parents:
19239
diff
changeset
|
202 |
Vampire will reject the switches.*) |
17774 | 203 |
fun execCmds [] procList = procList |
204 |
| execCmds ((prover,proverCmd,settings,file)::cmds) procList = |
|
205 |
let val _ = trace ("\nAbout to execute command: " ^ proverCmd ^ " " ^ file) |
|
19449
b07e3bca20c9
fix to spacing in switches, for Vampire under SML/NJ
paulson
parents:
19239
diff
changeset
|
206 |
val settings' = List.concat (map (String.tokens Char.isSpace) settings) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
207 |
val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc = |
19449
b07e3bca20c9
fix to spacing in switches, for Vampire under SML/NJ
paulson
parents:
19239
diff
changeset
|
208 |
Unix.execute(proverCmd, settings' @ [file]) |
17774 | 209 |
val (instr, outstr) = Unix.streamsOf childhandle |
210 |
val newProcList = {prover=prover, file=file, proc_handle=childhandle, |
|
211 |
instr=instr, outstr=outstr} :: procList |
|
212 |
val _ = trace ("\nFinished at " ^ |
|
213 |
Date.toString(Date.fromTimeLocal(Time.now()))) |
|
214 |
in execCmds cmds newProcList end |
|
215 |
||
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
216 |
fun checkChildren (ctxt, th, thm_names_list) toParentStr children = |
17774 | 217 |
let fun check [] = [] (* no children to check *) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
218 |
| check (child::children) = |
20871
da3a43cdbe8d
Fixed the printing of the used theorems by maintaining separate lists for each subgoal.
paulson
parents:
20762
diff
changeset
|
219 |
let val {prover, file, proc_handle, instr=childIn, ...} : cmdproc = child |
17774 | 220 |
val _ = trace ("\nprobfile = " ^ file) |
20871
da3a43cdbe8d
Fixed the printing of the used theorems by maintaining separate lists for each subgoal.
paulson
parents:
20762
diff
changeset
|
221 |
val sgno = number_from_filename file (*subgoal number*) |
da3a43cdbe8d
Fixed the printing of the used theorems by maintaining separate lists for each subgoal.
paulson
parents:
20762
diff
changeset
|
222 |
val thm_names = List.nth(thm_names_list, sgno-1); |
17774 | 223 |
val ppid = Posix.ProcEnv.getppid() |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
224 |
in |
17774 | 225 |
if pollChild childIn |
226 |
then (* check here for prover label on child*) |
|
227 |
let val _ = trace ("\nInput available from child: " ^ file) |
|
228 |
val childDone = (case prover of |
|
21977 | 229 |
"vampire" => ResReconstruct.checkVampProofFound |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
230 |
(childIn, toParentStr, ppid, file, ctxt, th, sgno, thm_names) |
21977 | 231 |
| "E" => ResReconstruct.checkEProofFound |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
232 |
(childIn, toParentStr, ppid, file, ctxt, th, sgno, thm_names) |
21977 | 233 |
| "spass" => ResReconstruct.checkSpassProofFound |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
234 |
(childIn, toParentStr, ppid, file, ctxt, th, sgno, thm_names) |
17774 | 235 |
| _ => (trace ("\nBad prover! " ^ prover); true) ) |
236 |
in |
|
19239 | 237 |
if childDone (*ATP has reported back (with success OR failure)*) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
238 |
then (Unix.reap proc_handle; |
22130 | 239 |
if !Output.debugging then () else OS.FileSys.remove file; |
17774 | 240 |
check children) |
241 |
else child :: check children |
|
242 |
end |
|
243 |
else (trace "\nNo child output"; child :: check children) |
|
244 |
end |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
245 |
in |
17774 | 246 |
trace ("\nIn checkChildren, length of queue: " ^ Int.toString(length children)); |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
247 |
check children |
17774 | 248 |
end; |
249 |
||
250 |
||
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
251 |
fun setupWatcher (ctxt, th, thm_names_list) = |
16061 | 252 |
let |
22012
adf68479ae1b
Proof.context now sent to watcher and used in type inference step of proof reconstruction
paulson
parents:
21977
diff
changeset
|
253 |
val checkc = checkChildren (ctxt, th, thm_names_list) |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
254 |
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
|
255 |
val p2 = Posix.IO.pipe() |
17764 | 256 |
(****** 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
|
257 |
fun startWatcher procList = |
17774 | 258 |
case Posix.Process.fork() of |
259 |
SOME pid => pid (* parent - i.e. main Isabelle process *) |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
260 |
| NONE => |
17774 | 261 |
let (* child - i.e. watcher *) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
262 |
val oldchildin = #infd p1 |
17774 | 263 |
val fromParent = Posix.FileSys.wordToFD 0w0 |
264 |
val oldchildout = #outfd p2 |
|
265 |
val toParent = Posix.FileSys.wordToFD 0w1 |
|
266 |
val fromParentIOD = Posix.FileSys.fdToIOD fromParent |
|
267 |
val fromParentStr = openInFD ("_exec_in_parent", fromParent) |
|
268 |
val toParentStr = openOutFD ("_exec_out_parent", toParent) |
|
269 |
val pid = Posix.ProcEnv.getpid() |
|
270 |
val () = Posix.ProcEnv.setpgid {pid = SOME pid, pgid = SOME pid} |
|
271 |
(*set process group id: allows killing all children*) |
|
272 |
val () = trace "\nsubgoals forked to startWatcher" |
|
273 |
val limit = ref 200; (*don't let watcher run forever*) |
|
274 |
(*Watcher Loop : Check running ATP processes for output*) |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
275 |
fun keepWatching procList = |
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
276 |
(trace ("\npollParentInput. Limit = " ^ Int.toString (!limit) ^ |
17774 | 277 |
" length(procList) = " ^ Int.toString(length procList)); |
278 |
OS.Process.sleep (Time.fromMilliseconds 100); limit := !limit - 1; |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
279 |
if !limit < 0 then killWatcher (toParentStr, procList) |
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
280 |
else |
17774 | 281 |
case pollParentInput(fromParentIOD, fromParentStr, toParentStr) of |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
282 |
SOME [(_,"Kill children",_,_)] => |
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
283 |
(trace "\nReceived Kill command"; |
17774 | 284 |
killChildren procList; keepWatching []) |
285 |
| SOME cmds => (* deal with commands from Isabelle process *) |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
286 |
if length procList < 40 then (* Execute locally *) |
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
287 |
let val _ = trace("\nCommands from parent: " ^ |
17774 | 288 |
Int.toString(length cmds)) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
289 |
val newProcList' = checkc toParentStr (execCmds cmds procList) |
17774 | 290 |
in trace "\nCommands executed"; keepWatching newProcList' end |
291 |
else (* Execute remotely [FIXME: NOT REALLY] *) |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
292 |
let val newProcList' = checkc toParentStr (execCmds cmds procList) |
17774 | 293 |
in keepWatching newProcList' end |
294 |
| NONE => (* No new input from Isabelle *) |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
295 |
(trace "\nNothing from parent..."; |
22012
adf68479ae1b
Proof.context now sent to watcher and used in type inference step of proof reconstruction
paulson
parents:
21977
diff
changeset
|
296 |
keepWatching(checkc toParentStr procList))) |
17774 | 297 |
handle exn => (*FIXME: exn handler is too general!*) |
298 |
(trace ("\nkeepWatching exception handler: " ^ Toplevel.exn_message exn); |
|
299 |
keepWatching procList); |
|
300 |
in |
|
301 |
(*** Sort out pipes ********) |
|
302 |
Posix.IO.close (#outfd p1); Posix.IO.close (#infd p2); |
|
303 |
Posix.IO.dup2{old = oldchildin, new = fromParent}; |
|
304 |
Posix.IO.close oldchildin; |
|
305 |
Posix.IO.dup2{old = oldchildout, new = toParent}; |
|
306 |
Posix.IO.close oldchildout; |
|
307 |
keepWatching (procList) |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
308 |
end; |
15642 | 309 |
|
16061 | 310 |
val _ = TextIO.flushOut TextIO.stdOut |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
311 |
val pid = startWatcher [] |
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
312 |
(* communication streams to watcher*) |
16061 | 313 |
val instr = openInFD ("_exec_in", #infd p2) |
314 |
val outstr = openOutFD ("_exec_out", #outfd p1) |
|
17568 | 315 |
in |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
316 |
(* close the child-side fds*) |
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
317 |
Posix.IO.close (#outfd p2); Posix.IO.close (#infd p1); |
17568 | 318 |
(* set the fds close on exec *) |
319 |
Posix.IO.setfd (#infd p2, Posix.IO.FD.flags [Posix.IO.FD.cloexec]); |
|
320 |
Posix.IO.setfd (#outfd p1, Posix.IO.FD.flags [Posix.IO.FD.cloexec]); |
|
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
321 |
{pid = pid, instr = instr, outstr = outstr} |
17568 | 322 |
end; |
15642 | 323 |
|
324 |
||
325 |
||
326 |
(**********************************************************) |
|
327 |
(* Start a watcher and set up signal handlers *) |
|
328 |
(**********************************************************) |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
329 |
|
19239 | 330 |
(*Signal handler to tidy away zombie processes*) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
331 |
fun reapAll() = |
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
332 |
(case Posix.Process.waitpid_nh(Posix.Process.W_ANY_CHILD, []) of |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
333 |
SOME _ => reapAll() | NONE => ()) |
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
334 |
handle OS.SysErr _ => () |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
335 |
|
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
336 |
(*FIXME: does the main process need something like this? |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
337 |
IsaSignal.signal (IsaSignal.chld, IsaSignal.SIG_HANDLE reap)??*) |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
338 |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
339 |
fun killWatcher pid = |
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
340 |
(goals_being_watched := 0; |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
341 |
Posix.Process.kill(Posix.Process.K_GROUP pid, Posix.Signal.kill); |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
342 |
reapAll()); |
17488
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
343 |
|
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
344 |
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
|
345 |
(TextIO.closeIn instr; TextIO.closeOut outstr; |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
346 |
Posix.Process.waitpid(Posix.Process.W_CHILD pid, [])) |
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
347 |
handle OS.SysErr _ => () |
15642 | 348 |
|
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
349 |
fun string_of_subgoal th i = |
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
350 |
string_of_cterm (List.nth(cprems_of th, i-1)) |
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
351 |
handle Subscript => "Subgoal number out of range!" |
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
352 |
|
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
353 |
fun prems_string_of th = space_implode "\n" (map string_of_cterm (cprems_of th)) |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
354 |
|
22012
adf68479ae1b
Proof.context now sent to watcher and used in type inference step of proof reconstruction
paulson
parents:
21977
diff
changeset
|
355 |
fun createWatcher (ctxt, th, thm_names_list) = |
adf68479ae1b
Proof.context now sent to watcher and used in type inference step of proof reconstruction
paulson
parents:
21977
diff
changeset
|
356 |
let val {pid=childpid, instr=childin, outstr=childout} = setupWatcher (ctxt,th,thm_names_list) |
17435 | 357 |
fun decr_watched() = |
17502 | 358 |
(goals_being_watched := !goals_being_watched - 1; |
17435 | 359 |
if !goals_being_watched = 0 |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
360 |
then |
22130 | 361 |
(Output.debug (fn () => ("\nReaping a watcher, childpid = " ^ string_of_pid childpid)); |
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
362 |
killWatcher childpid (*???; reapWatcher (childpid, childin, childout)*) ) |
17435 | 363 |
else ()) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
364 |
fun proofHandler _ = |
18796 | 365 |
let val _ = trace("\nIn signal handler for pid " ^ string_of_pid childpid) |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
366 |
val outcome = ResReconstruct.restore_newlines (the_default "" (TextIO.inputLine childin)) |
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
367 |
val probfile = the_default "" (TextIO.inputLine childin) |
17773
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
368 |
val sgno = number_from_filename probfile |
a7258e1020b7
more tidying. Fixed process management bugs and race condition
paulson
parents:
17772
diff
changeset
|
369 |
val text = string_of_subgoal th sgno |
18796 | 370 |
fun report s = priority ("Subgoal " ^ Int.toString sgno ^ ": " ^ s); |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
371 |
in |
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
372 |
Output.debug (fn () => ("In signal handler. outcome = \"" ^ outcome ^ |
18796 | 373 |
"\"\nprobfile = " ^ probfile ^ |
22130 | 374 |
"\nGoals being watched: "^ Int.toString (!goals_being_watched))); |
20762 | 375 |
if String.isPrefix "Invalid" outcome |
18796 | 376 |
then (report ("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
|
377 |
decr_watched()) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
378 |
else if String.isPrefix "Failure" outcome |
18796 | 379 |
then (report ("Proof attempt failed:\n" ^ text); |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22130
diff
changeset
|
380 |
decr_watched()) |
17216 | 381 |
(* 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
|
382 |
else if String.isPrefix "Success" outcome |
18796 | 383 |
then (report (outcome ^ text); |
17435 | 384 |
decr_watched()) |
17216 | 385 |
(* if proof translation failed *) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
386 |
else if String.isPrefix "Translation failed" outcome |
18796 | 387 |
then (report (outcome ^ text); |
17435 | 388 |
decr_watched()) |
18796 | 389 |
else (report "System error in proof handler"; |
17435 | 390 |
decr_watched()) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
391 |
end |
22130 | 392 |
in Output.debug (fn () => ("subgoals forked to createWatcher: "^ prems_string_of th)); |
18796 | 393 |
IsaSignal.signal (IsaSignal.usr2, IsaSignal.SIG_HANDLE proofHandler); |
17216 | 394 |
(childin, childout, childpid) |
395 |
end |
|
15642 | 396 |
|
397 |
end (* structure Watcher *) |