67904
|
1 |
(*:maxLineLen=78:*)
|
|
2 |
|
|
3 |
theory Server
|
|
4 |
imports Base
|
|
5 |
begin
|
|
6 |
|
|
7 |
chapter \<open>The Isabelle server\<close>
|
|
8 |
|
|
9 |
text \<open>
|
|
10 |
An Isabelle session requires at least two processes, which are both rather
|
|
11 |
heavy: Isabelle/Scala for the system infrastructure and Isabelle/ML for the
|
|
12 |
logic session (e.g.\ HOL). In principle, these processes can be invoked
|
|
13 |
directly on the command-line, e.g.\ via @{tool java}, @{tool scala}, @{tool
|
|
14 |
process}, @{tool console}, but this approach is inadequate for reactive
|
|
15 |
applications that require quick responses from the prover.
|
|
16 |
|
|
17 |
In contrast, the Isabelle server exposes Isabelle/Scala as a
|
|
18 |
``terminate-stay-resident'' application that manages multiple logic
|
|
19 |
\<^emph>\<open>sessions\<close> and concurrent tasks to use \<^emph>\<open>theories\<close>. This provides an
|
|
20 |
analogous to @{ML Thy_Info.use_theories} in Isabelle/ML, but with full
|
|
21 |
concurrency and Isabelle/PIDE markup.
|
|
22 |
|
|
23 |
The client/server arrangement via TCP sockets also opens possibilities for
|
|
24 |
remote Isabelle services that are accessed by local applications, e.g.\ via
|
|
25 |
an SSH tunnel.
|
|
26 |
\<close>
|
|
27 |
|
|
28 |
|
|
29 |
section \<open>Command-line tools\<close>
|
|
30 |
|
|
31 |
subsection \<open>Server \label{sec:tool-server}\<close>
|
|
32 |
|
|
33 |
text \<open>
|
|
34 |
The @{tool_def server} tool manages resident server processes:
|
|
35 |
@{verbatim [display]
|
|
36 |
\<open>Usage: isabelle server [OPTIONS]
|
|
37 |
|
|
38 |
Options are:
|
|
39 |
-L FILE logging on FILE
|
|
40 |
-c console interaction with specified server
|
|
41 |
-l list servers (alternative operation)
|
|
42 |
-n NAME explicit server name (default: isabelle)
|
|
43 |
-p PORT explicit server port
|
|
44 |
-s assume existing server, no implicit startup
|
|
45 |
-x exit specified server (alternative operation)
|
|
46 |
|
|
47 |
Manage resident Isabelle servers.\<close>}
|
|
48 |
|
|
49 |
The main operation of \<^verbatim>\<open>isabelle server\<close> is to ensure that a named server is
|
|
50 |
running, either by finding an already running process (according to the
|
|
51 |
central database file @{path "$ISABELLE_HOME_USER/servers.db"}) or by
|
|
52 |
becoming itself a new server that accepts connections on a particular TCP
|
|
53 |
socket. The server name and its address are printed as initial output line.
|
|
54 |
If another server instance is already running, the current
|
|
55 |
\<^verbatim>\<open>isabelle server\<close> process will terminate; otherwise, it keeps running as a
|
|
56 |
new server process until an explicit \<^verbatim>\<open>shutdown\<close> command is received.
|
|
57 |
Further details of the server socket protocol are explained in
|
|
58 |
\secref{sec:server-protocol}.
|
|
59 |
|
|
60 |
Other server management operations are invoked via options \<^verbatim>\<open>-l\<close> and \<^verbatim>\<open>-x\<close>
|
|
61 |
(see below).
|
|
62 |
|
|
63 |
\<^medskip>
|
|
64 |
Option \<^verbatim>\<open>-n\<close> specifies an alternative server name: at most one process for
|
|
65 |
each name may run, but each server instance supports multiple connections
|
|
66 |
and logic sessions.
|
|
67 |
|
|
68 |
\<^medskip>
|
|
69 |
Option \<^verbatim>\<open>-p\<close> specifies an explicit TCP port for the server socket (which is
|
|
70 |
always on \<^verbatim>\<open>localhost\<close>): the default is to let the operating system assign a
|
|
71 |
free port number.
|
|
72 |
|
|
73 |
\<^medskip>
|
|
74 |
Option \<^verbatim>\<open>-s\<close> strictly assumes that the specified server process is already
|
|
75 |
running, skipping the optional server startup phase.
|
|
76 |
|
|
77 |
\<^medskip>
|
|
78 |
Option \<^verbatim>\<open>-c\<close> connects the console in/out channels after the initial check
|
|
79 |
for a suitable server process. Note that the @{tool client} tool
|
|
80 |
(\secref{sec:tool-client}) provides a more convenient way to do this
|
|
81 |
interactively, together with command-line editor support.
|
|
82 |
|
|
83 |
\<^medskip>
|
|
84 |
Option \<^verbatim>\<open>-l\<close> lists all active server processes with their connection
|
|
85 |
details.
|
|
86 |
|
|
87 |
\<^medskip>
|
|
88 |
Option \<^verbatim>\<open>-x\<close> exits the specified server process by sending it a \<^verbatim>\<open>shutdown\<close>
|
|
89 |
command.
|
|
90 |
|
|
91 |
\<^medskip>
|
|
92 |
Option \<^verbatim>\<open>-L\<close> specifies a log file for exceptional output of internal server
|
|
93 |
and session operations.
|
|
94 |
\<close>
|
|
95 |
|
|
96 |
|
|
97 |
subsection \<open>Client \label{sec:tool-client}\<close>
|
|
98 |
|
|
99 |
text \<open>
|
|
100 |
The @{tool_def client} provides console interaction for Isabelle servers:
|
|
101 |
@{verbatim [display]
|
|
102 |
\<open>Usage: isabelle client [OPTIONS]
|
|
103 |
|
|
104 |
Options are:
|
|
105 |
-n NAME explicit server name
|
|
106 |
-p PORT explicit server port
|
|
107 |
|
|
108 |
Console interaction for Isabelle server (with line-editor).\<close>}
|
|
109 |
|
|
110 |
This is a convenient wrapper to \<^verbatim>\<open>isabelle server -s -c\<close> for interactive
|
|
111 |
experimentation, wrapped into @{setting ISABELLE_LINE_EDITOR} if available.
|
|
112 |
The server name is sufficient for identification, as the client can
|
|
113 |
determine the connection details from the local database of active servers.
|
|
114 |
|
|
115 |
\<^medskip>
|
|
116 |
Option \<^verbatim>\<open>-n\<close> specifies an explicit server name as in @{tool server}.
|
|
117 |
|
|
118 |
\<^medskip>
|
|
119 |
Option \<^verbatim>\<open>-p\<close> specifies an explicit server port as in @{tool server}.
|
|
120 |
\<close>
|
|
121 |
|
|
122 |
|
|
123 |
subsection \<open>Examples\<close>
|
|
124 |
|
|
125 |
text \<open>
|
|
126 |
Ensure that a particular server instance is running in the background:
|
|
127 |
@{verbatim [display] \<open>isabelle server -n test &\<close>}
|
|
128 |
|
|
129 |
Here the first line of output presents the connection details:\<^footnote>\<open>This
|
|
130 |
information may be used in an independent TCP client, while the
|
|
131 |
Isabelle/Scala tool merely needs the server name to access the database of
|
|
132 |
servers.\<close>
|
|
133 |
@{verbatim [display] \<open>server "test" = 127.0.0.1:4711 (password "XYZ")\<close>}
|
|
134 |
|
|
135 |
\<^medskip>
|
|
136 |
List available server processes:
|
|
137 |
@{verbatim [display] \<open>isabelle server -l\<close>}
|
|
138 |
|
|
139 |
\<^medskip>
|
|
140 |
Connect the command-line client to the above test server:
|
|
141 |
@{verbatim [display] \<open>isabelle client -n test\<close>}
|
|
142 |
|
|
143 |
Interaction now works on a line-by-line basis, with commands like \<^verbatim>\<open>help\<close> or
|
|
144 |
\<^verbatim>\<open>echo\<close>. For example, some JSON values may be echoed like this:
|
|
145 |
|
|
146 |
@{verbatim [display]
|
|
147 |
\<open>echo 42
|
|
148 |
echo [1, 2, 3]
|
|
149 |
echo {"a": "text", "b": true, "c": 42}\<close>}
|
|
150 |
|
|
151 |
Closing the connection (via CTRL-D) leaves the server running: it is
|
|
152 |
possible to reconnect again, and have multiple connections at the same time.
|
|
153 |
|
|
154 |
\<^medskip>
|
|
155 |
Finally, exit the named server on the command-line:
|
|
156 |
@{verbatim [display] \<open>isabelle server -n test -x\<close>}
|
|
157 |
\<close>
|
|
158 |
|
|
159 |
|
|
160 |
section \<open>Protocol messages \label{sec:server-protocol}\<close>
|
|
161 |
|
|
162 |
text \<open>
|
|
163 |
The Isabelle server listens on a regular TCP socket, using a line-oriented
|
|
164 |
protocol of structured messages: input \<^emph>\<open>commands\<close> and output \<^emph>\<open>results\<close>
|
|
165 |
(via \<^verbatim>\<open>OK\<close> or \<^verbatim>\<open>ERROR\<close>) are strictly alternating on the toplevel, but
|
|
166 |
commands may also return a \<^emph>\<open>task\<close> identifier to indicate an ongoing
|
|
167 |
asynchronous process that is joined later (via \<^verbatim>\<open>FINISHED\<close> or \<^verbatim>\<open>FAILED\<close>).
|
|
168 |
Asynchronous \<^verbatim>\<open>NOTE\<close> messages may occur at any time: they are independent of
|
|
169 |
the main command-reply protocol.
|
|
170 |
|
|
171 |
For example, the synchronous \<^verbatim>\<open>echo\<close> command immediately returns its
|
|
172 |
argument as \<^verbatim>\<open>OK\<close> result. In contrast, the asynchronous \<^verbatim>\<open>session_build\<close>
|
|
173 |
command returns \<^verbatim>\<open>OK {"task":\<close>\<open>id\<close>\<^verbatim>\<open>}\<close> and continues in the background. It
|
|
174 |
will eventually produce \<^verbatim>\<open>FINISHED {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close> or
|
|
175 |
\<^verbatim>\<open>FAILED {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close> with the final result. Intermediately, it
|
|
176 |
may emit asynchronous messages of the form \<^verbatim>\<open>NOTE {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close>
|
|
177 |
to inform about its progress. Due to the explicit task identifier, the
|
|
178 |
client can show these messages in the proper context, e.g.\ a GUI window for
|
|
179 |
the session build job.
|
|
180 |
|
|
181 |
\medskip Subsequently, the protocol message formats are described in further
|
|
182 |
detail.
|
|
183 |
\<close>
|
|
184 |
|
|
185 |
|
|
186 |
subsection \<open>Byte messages\<close>
|
|
187 |
|
|
188 |
text \<open>
|
|
189 |
The client-server connection is a raw byte-channel for bidirectional
|
|
190 |
communication, but the Isabelle server always works with messages of a
|
|
191 |
particular length. Messages are written as a single chunk that is flushed
|
|
192 |
immediately.
|
|
193 |
|
|
194 |
The message boundary is determined as follows:
|
|
195 |
|
|
196 |
\<^item> A \<^emph>\<open>short message\<close> consists of a single line: it is a sequence of
|
|
197 |
arbitrary bytes excluding CR (13) and LF (10), and terminated by CR-LF or
|
|
198 |
just LF.
|
|
199 |
|
|
200 |
\<^item> A \<^emph>\<open>long message\<close> starts with a single line as above, which consists
|
|
201 |
only of decimal digits: that is interpreted as length of the subsequent
|
|
202 |
block of arbitrary bytes. A final line-terminator may be included here,
|
|
203 |
but is not required.
|
|
204 |
|
|
205 |
Messages in JSON format (see below) always fit on a single line, due to
|
|
206 |
escaping of newline characters within string literals. This is convenient
|
|
207 |
for interactive experimentation, but it can impact performance for very long
|
|
208 |
messages. If the message byte-length is given on the preceding line, the
|
|
209 |
server can read the message efficiently as a single block.
|
|
210 |
\<close>
|
|
211 |
|
|
212 |
|
|
213 |
subsection \<open>Text messages\<close>
|
|
214 |
|
|
215 |
text \<open>
|
|
216 |
Messages are read and written as byte streams (with byte lengths), but the
|
|
217 |
content is always interpreted as plain text in terms of the UTF-8
|
|
218 |
encoding.\<^footnote>\<open>See also the ``UTF-8 Everywhere Manifesto''
|
|
219 |
\<^url>\<open>http://utf8everywhere.org\<close>.\<close>
|
|
220 |
|
|
221 |
Note that line-endings and other formatting characters are invariant wrt.
|
|
222 |
UTF-8 representation of text: thus implementations are free to determine the
|
|
223 |
overall message structure before or after applying the text encoding.
|
|
224 |
\<close>
|
|
225 |
|
|
226 |
|
67917
|
227 |
subsection \<open>Input and output messages \label{sec:input-output-messages}\<close>
|
67904
|
228 |
|
|
229 |
text \<open>
|
|
230 |
Server input and output messages have a uniform format as follows:
|
|
231 |
|
|
232 |
\<^item> \<open>name argument\<close> such that:
|
|
233 |
|
|
234 |
\<^item> \<open>name\<close> is the longest prefix consisting of ASCII letters, digits,
|
|
235 |
``\<^verbatim>\<open>_\<close>'' (underscore), or ``\<^verbatim>\<open>.\<close>'' (dot),
|
|
236 |
|
|
237 |
\<^item> the separator between \<open>name\<close> and \<open>argument\<close> is the longest possible
|
|
238 |
sequence of ASCII blanks (it could be empty, e.g.\ when the argument
|
|
239 |
starts with a quote or bracket),
|
|
240 |
|
|
241 |
\<^item> \<open>argument\<close> is the rest of the message without the line terminator.
|
|
242 |
|
|
243 |
\<^medskip>
|
|
244 |
Input messages are sent from the client to the server. Here the \<open>name\<close>
|
|
245 |
specifies a \<^emph>\<open>server command\<close>: the list of known commands may be
|
|
246 |
retrieved via the \<^verbatim>\<open>help\<close> command.
|
|
247 |
|
|
248 |
\<^medskip>
|
|
249 |
Output messages are sent from the server to the client. Here the \<open>name\<close>
|
|
250 |
specifies the \<^emph>\<open>server reply\<close>, which always has a specific meaning as
|
|
251 |
follows:
|
|
252 |
|
|
253 |
\<^item> synchronous results: \<^verbatim>\<open>OK\<close> or \<^verbatim>\<open>ERROR\<close>
|
|
254 |
\<^item> asynchronous results: \<^verbatim>\<open>FINISHED\<close> or \<^verbatim>\<open>FAILED\<close>
|
|
255 |
\<^item> intermediate notifications: \<^verbatim>\<open>NOTE\<close>
|
|
256 |
|
|
257 |
\<^medskip>
|
|
258 |
The \<open>argument\<close> format is uniform for both input and output messages:
|
|
259 |
|
|
260 |
\<^item> empty argument (Scala type \<^verbatim>\<open>Unit\<close>)
|
|
261 |
\<^item> XML element in YXML notation (Scala type \<^verbatim>\<open>XML.Elem\<close>)
|
|
262 |
\<^item> JSON value (Scala type \<^verbatim>\<open>JSON.T\<close>)
|
|
263 |
|
|
264 |
JSON values may consist of objects (records), arrays (lists), strings,
|
|
265 |
numbers, bools, null.\<^footnote>\<open>See also the official specification
|
|
266 |
\<^url>\<open>https://www.json.org\<close> and unofficial explorations ``Parsing JSON is a
|
|
267 |
Minefield'' \<^url>\<open>http://seriot.ch/parsing_json.php\<close>.\<close> Since JSON requires
|
|
268 |
explicit quotes and backslash-escapes to represent arbitrary text, the YXML
|
|
269 |
notation for XML trees (\secref{sec:yxml-vs-xml}) works better
|
|
270 |
for large messages with a lot of PIDE markup.
|
|
271 |
|
|
272 |
Nonetheless, the most common commands use JSON by default: big chunks of
|
|
273 |
text (theory sources etc.) are taken from the underlying file-system and
|
|
274 |
results are pre-formatted for plain-text output, without PIDE markup
|
|
275 |
information. This is a concession to simplicity: the server imitates the
|
|
276 |
appearance of command-line tools on top of the Isabelle/PIDE infrastructure.
|
|
277 |
\<close>
|
|
278 |
|
|
279 |
|
|
280 |
subsection \<open>Initial password exchange\<close>
|
|
281 |
|
|
282 |
text \<open>
|
|
283 |
Whenever a new client opens the server socket, the initial message needs to
|
|
284 |
be its unique password. The server replies either with \<^verbatim>\<open>OK\<close> (and some
|
|
285 |
information about the Isabelle version) or by silent disconnection of what
|
|
286 |
is considered an illegal connection attempt.
|
|
287 |
|
|
288 |
Server passwords are created as Universally Unique Identifier (UUID) in
|
|
289 |
Isabelle/Scala and stored in a per-user database, with restricted
|
|
290 |
file-system access only for the current user. The Isabelle/Scala server
|
|
291 |
implementation is careful to expose the password only on private output
|
|
292 |
channels, and not on a process command-line (which is accessible to other
|
|
293 |
users, e.g.\ via the \<^verbatim>\<open>ps\<close> command).
|
|
294 |
\<close>
|
|
295 |
|
|
296 |
|
|
297 |
subsection \<open>Synchronous commands\<close>
|
|
298 |
|
|
299 |
text \<open>
|
|
300 |
A \<^emph>\<open>synchronous command\<close> corresponds to regular function application in
|
|
301 |
Isabelle/Scala, with single argument and result (regular or error). Both the
|
|
302 |
argument and the result may consist of type \<^verbatim>\<open>Unit\<close>, \<^verbatim>\<open>XML.Elem\<close>, \<^verbatim>\<open>JSON.T\<close>.
|
|
303 |
An error result typically consists of a JSON object with error message and
|
|
304 |
potentially further fields (this resembles exceptions in Scala).
|
|
305 |
|
|
306 |
These are the protocol exchanges for both cases of command execution:
|
|
307 |
\begin{center}
|
|
308 |
\begin{tabular}{rl}
|
|
309 |
\<^bold>\<open>input:\<close> & \<open>command argument\<close> \\
|
|
310 |
(a) regular \<^bold>\<open>output:\<close> & \<^verbatim>\<open>OK\<close> \<open>result\<close> \\
|
|
311 |
(b) error \<^bold>\<open>output:\<close> & \<^verbatim>\<open>ERROR\<close> \<open>result\<close> \\
|
|
312 |
\end{tabular}
|
|
313 |
\end{center}
|
|
314 |
\<close>
|
|
315 |
|
|
316 |
|
|
317 |
subsection \<open>Asynchronous commands\<close>
|
|
318 |
|
|
319 |
text \<open>
|
|
320 |
An \<^emph>\<open>asynchronous command\<close> corresponds to an ongoing process that finishes
|
|
321 |
or fails eventually, while emitting arbitrary notifications intermediately.
|
|
322 |
Formally, it starts as synchronous command with immediate result \<^verbatim>\<open>OK\<close> and
|
|
323 |
the \<^verbatim>\<open>task\<close> identifier, or an immediate \<^verbatim>\<open>ERROR\<close> that indicates bad command
|
|
324 |
syntax. For a running task, the termination is indicated later by
|
|
325 |
\<^verbatim>\<open>FINISHED\<close> or \<^verbatim>\<open>FAILED\<close>, together with its ultimate result.
|
|
326 |
|
|
327 |
These are the protocol exchanges for various cases of command task
|
|
328 |
execution:
|
|
329 |
|
|
330 |
\begin{center}
|
|
331 |
\begin{tabular}{rl}
|
|
332 |
\<^bold>\<open>input:\<close> & \<open>command argument\<close> \\
|
|
333 |
immediate \<^bold>\<open>output:\<close> & \<^verbatim>\<open>OK {"task":\<close>\<open>id\<close>\<^verbatim>\<open>}\<close> \\
|
|
334 |
intermediate \<^bold>\<open>output:\<close> & \<^verbatim>\<open>NOTE {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close> \\
|
|
335 |
intermediate \<^bold>\<open>output:\<close> & \<^verbatim>\<open>NOTE {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close> \\
|
|
336 |
(a) regular \<^bold>\<open>output:\<close> & \<^verbatim>\<open>FINISHED {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close> \\
|
|
337 |
(b) error \<^bold>\<open>output:\<close> & \<^verbatim>\<open>FAILED {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close> \\[3ex]
|
|
338 |
\<^bold>\<open>input:\<close> & \<open>command argument\<close> \\
|
|
339 |
immediate \<^bold>\<open>output:\<close> & \<^verbatim>\<open>ERROR\<close>~\<open>\<dots>\<close> \\
|
|
340 |
\end{tabular}
|
|
341 |
\end{center}
|
|
342 |
|
|
343 |
All asynchronous messages are decorated with the task identifier that was
|
|
344 |
revealed in the immediate (synchronous) result. Thus it is possible to emit
|
|
345 |
further asynchronous commands and dispatch the mingled stream of
|
|
346 |
asynchronous messages properly.
|
|
347 |
|
|
348 |
The synchronous command \<^verbatim>\<open>cancel\<close>~\<open>id\<close> tells the specified task to terminate
|
67917
|
349 |
prematurely: usually causing a \<^verbatim>\<open>FAILED\<close> result, but this is not guaranteed:
|
|
350 |
the cancel event may come too late or the task may just ignore it.
|
|
351 |
\<close>
|
|
352 |
|
|
353 |
|
|
354 |
section \<open>Server commands and results\<close>
|
|
355 |
|
|
356 |
text \<open>
|
|
357 |
Here follows an overview of particular Isabelle server commands with their
|
|
358 |
results, which are usually represented as JSON values. The general format of
|
|
359 |
input and output messages is described in
|
|
360 |
\secref{sec:input-output-messages}. The relevant Isabelle/Scala source files
|
|
361 |
are:
|
|
362 |
|
|
363 |
\<^medskip>
|
|
364 |
\begin{tabular}{l}
|
|
365 |
\<^file>\<open>$ISABELLE_HOME/src/Pure/Tools/server_commands.scala\<close> \\
|
|
366 |
\<^file>\<open>$ISABELLE_HOME/src/Pure/Tools/server.scala\<close>
|
|
367 |
\end{tabular}
|
|
368 |
\<close>
|
|
369 |
|
|
370 |
|
|
371 |
subsection \<open>Types for JSON values\<close>
|
|
372 |
|
|
373 |
text \<open>
|
|
374 |
In order to specify concrete JSON types for command arguments and result
|
|
375 |
messages, the following type definition language shall be used:
|
|
376 |
|
|
377 |
\<^rail>\<open>
|
|
378 |
@{syntax type_def}: @'type' @{syntax name} '=' @{syntax type}
|
|
379 |
;
|
|
380 |
@{syntax type}: @{syntax name} | @{syntax value} | 'any' | 'null' |
|
|
381 |
'bool' | 'int' | 'long' | 'double' | 'string' | '[' @{syntax type} ']' |
|
|
382 |
'{' (@{syntax field_type} ',' *) '}' |
|
|
383 |
@{syntax type} '\<oplus>' @{syntax type} |
|
|
384 |
@{syntax type} '|' @{syntax type}
|
|
385 |
;
|
|
386 |
@{syntax field_type}: @{syntax name} ('?'?) ':' @{syntax type}
|
|
387 |
\<close>
|
|
388 |
|
|
389 |
This is a simplified version of interfaces in
|
|
390 |
TypeScript.\<^footnote>\<open>\<^url>\<open>https://www.typescriptlang.org/docs/handbook/interfaces.html\<close>\<close>
|
|
391 |
The meaning of these types is specified wrt. the implementation in
|
|
392 |
Isabelle/Scala as follows.
|
|
393 |
|
|
394 |
\<^item> A \<open>name\<close> refers to a type defined elsewhere. The environment of type
|
|
395 |
definitions is given informally: put into proper foundational order, it
|
|
396 |
needs to specify a strongly normalizing system; type definitions may not be
|
|
397 |
recursive.
|
|
398 |
|
|
399 |
\<^item> A \<open>value\<close> in JSON notation represents the singleton type of the given
|
|
400 |
item. For example, the string \<^verbatim>\<open>"error"\<close> can be used is the type for a slot
|
|
401 |
that is guaranteed to contain that constant.
|
|
402 |
|
|
403 |
\<^item> Type \<open>any\<close> is the super type of all other types: it is an untyped slot in
|
|
404 |
the specification and corresponds to \<^verbatim>\<open>Any\<close> or \<^verbatim>\<open>JSON.T\<close> in Isabelle/Scala.
|
|
405 |
|
|
406 |
\<^item> Type \<open>null\<close> is the type of the improper value \<open>null\<close>; it corresponds to
|
|
407 |
type \<^verbatim>\<open>Null\<close> in Scala and is normally not used in Isabelle/Scala.\<^footnote>\<open>See also
|
|
408 |
``Null References: The Billion Dollar Mistake'' by Tony Hoare
|
|
409 |
\<^url>\<open>https://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare\<close>.\<close>
|
|
410 |
|
|
411 |
\<^item> Type \<open>bool\<close> is the type of the truth values \<open>true\<close> and \<open>false\<close>; it
|
|
412 |
corresponds to \<^verbatim>\<open>Boolean\<close> in Scala.
|
|
413 |
|
|
414 |
\<^item> Types \<open>int\<close>, \<open>long\<close>, \<open>double\<close> are specific versions of the generic
|
|
415 |
\<open>number\<close> type, corresponding to \<^verbatim>\<open>Int\<close>, \<^verbatim>\<open>Long\<close>, \<^verbatim>\<open>Double\<close> in Scala, but
|
|
416 |
\<^verbatim>\<open>Long\<close> is limited to 53 bit precision.\<^footnote>\<open>Implementations of JSON typically
|
|
417 |
standardize \<open>number\<close> to \<^verbatim>\<open>Double\<close>, which can absorb \<^verbatim>\<open>Int\<close> faithfully, but
|
|
418 |
not all of \<^verbatim>\<open>Long\<close>.\<close>
|
|
419 |
|
|
420 |
\<^item> Type \<open>string\<close> represents Unicode text; it corresponds to type \<^verbatim>\<open>String\<close> in
|
|
421 |
Scala.
|
|
422 |
|
|
423 |
\<^item> Type \<open>[t]\<close> is the array (or list) type over \<open>t\<close>; it corresponds to
|
|
424 |
\<^verbatim>\<open>List[t]\<close> in Scala. The list type is co-variant as usual (i.e.\ monotonic
|
|
425 |
wrt. the subtype order).
|
|
426 |
|
|
427 |
\<^item> Object types describe the possible content of JSON records, with field
|
|
428 |
names and types. A question mark after a field name means that it is
|
|
429 |
optional: in Scala this could refer to an explicit type \<^verbatim>\<open>Option[t]\<close>. For
|
|
430 |
example, \<open>{a: int, b?: string}\<close> corresponds to a Scala case class with
|
|
431 |
arguments \<^verbatim>\<open>a: Int\<close>, \<^verbatim>\<open>b: Option[String]\<close>.
|
|
432 |
|
|
433 |
Alternatively, optional fields can have a default value. If nothing else is
|
|
434 |
specified, the standard default value is the ``empty'' value of a type,
|
|
435 |
i.e.\ \<^verbatim>\<open>0\<close> for the number types, \<^verbatim>\<open>false\<close> for \<open>bool\<close>, or the empty string,
|
|
436 |
array, object etc.
|
|
437 |
|
|
438 |
Object types are \<^emph>\<open>permissive\<close> in the sense that only the specified field
|
|
439 |
names need to conform to the given types, but unspecified fields may be
|
|
440 |
present as well.
|
|
441 |
|
|
442 |
\<^item> The type expression \<open>t\<^sub>1 \<oplus> t\<^sub>2\<close> only works for two object types with
|
|
443 |
disjoint field names: it is the concatenation of the respective @{syntax
|
|
444 |
field_type} specifications taken together. For example: \<open>{task: string} \<oplus>
|
|
445 |
{ok: bool}\<close> is the equivalent to \<open>{task: string, ok: bool}\<close>.
|
|
446 |
|
|
447 |
\<^item> The type expression \<open>t\<^sub>1 | t\<^sub>2\<close> is the disjoint union of two types, either
|
|
448 |
one of the two cases may occur.
|
|
449 |
|
|
450 |
|
|
451 |
These types correspond to JSON values in an obvious manner, which is not
|
|
452 |
further described here. For example, the JSON array \<^verbatim>\<open>[1, 2, 3]\<close> conforms to
|
|
453 |
types \<open>[int]\<close>, \<open>[long]\<close>, \<open>[double]\<close>, \<open>[any]\<close>, \<open>any\<close>.
|
|
454 |
|
|
455 |
Note that JSON objects require field names to be quoted, but the type
|
|
456 |
language omits quotes for clarity. Thus \<^verbatim>\<open>{"a": 42, "b": "xyz"}\<close> conforms to
|
|
457 |
the type \<open>{a: int, b: string}\<close>, for example.
|
|
458 |
|
|
459 |
\<^medskip>
|
|
460 |
The absence of an argument or result is represented by type \<^verbatim>\<open>Unit\<close> in
|
|
461 |
Isabelle/Scala: it is written as empty text in the message \<open>argument\<close>
|
|
462 |
(\secref{sec:input-output-messages}). This is not part of the JSON language.
|
|
463 |
|
|
464 |
Server replies have name tags like \<^verbatim>\<open>OK\<close>, \<^verbatim>\<open>ERROR\<close>: these are used literally
|
|
465 |
together with type specifications to indicate the particular name with the
|
|
466 |
type of its argument, e.g.\ \<^verbatim>\<open>OK\<close>~\<open>[string]\<close> for a regular result that is a
|
|
467 |
list (JSON array) of strings.
|
|
468 |
|
|
469 |
\<^bigskip>
|
|
470 |
Here are some common type definitions, for use in the subsequent
|
|
471 |
specifications of command arguments and results.
|
|
472 |
|
|
473 |
\<^item> \<^bold>\<open>type\<close>~\<open>position = {line?: int, offset?: int, end_offset?: int, file?:
|
|
474 |
string, id?: long}\<close> describes a source position within Isabelle source text.
|
|
475 |
Only the \<open>line\<close> and \<open>file\<close> fields make immediate sense to external programs.
|
|
476 |
Detailed \<open>offset\<close> and \<open>end_offset\<close> positions are counted according to
|
|
477 |
Isabelle symbols, see @{ML_type Symbol.symbol} in Isabelle/ML @{cite
|
|
478 |
"isabelle-implementation"}. The position \<open>id\<close> belongs to the internal
|
|
479 |
representation of command transactions in the Isabelle/PIDE protocol.
|
|
480 |
|
|
481 |
\<^item> \<^bold>\<open>type\<close>~\<open>message = {kind?: string, message: string, pos?: position}\<close> where
|
|
482 |
the \<open>kind\<close> provides some hint about the role and importance of the message.
|
|
483 |
The main message kinds are \<^verbatim>\<open>writeln\<close> (for regular output), \<^verbatim>\<open>warning\<close>, and
|
|
484 |
\<^verbatim>\<open>error\<close>. The table \<^verbatim>\<open>Markup.messages\<close> in Isabelle/Scala defines further
|
|
485 |
message kinds for more specific applications.
|
|
486 |
|
|
487 |
\<^item> \<^bold>\<open>type\<close>~\<open>error_message = {kind:\<close>~\<^verbatim>\<open>"error"\<close>\<open>, message: string}\<close> refers to
|
|
488 |
error messages in particular. These occur routinely with \<^verbatim>\<open>ERROR\<close> or
|
|
489 |
\<^verbatim>\<open>FAILED\<close> replies, but also as initial command syntax errors (which are
|
|
490 |
omitted in the command specifications below).
|
|
491 |
|
|
492 |
\<^item> \<^bold>\<open>type\<close>~\<open>theory_progress = {kind:\<close>~\<^verbatim>\<open>"writeln"\<close>\<open>, message: string, theory:
|
|
493 |
string, session: string}\<close> reports formal progress in loading theories (e.g.\
|
|
494 |
when building a session image). Apart from a regular output message, it also
|
|
495 |
reveals the formal theory name (e.g.\ \<^verbatim>\<open>HOL.Nat\<close>) and session name (e.g.\
|
|
496 |
\<^verbatim>\<open>HOL\<close>). Note that some rare theory names lack a proper session prefix, e.g.
|
|
497 |
theory \<^verbatim>\<open>Main\<close> in session \<^verbatim>\<open>HOL\<close>.
|
|
498 |
|
|
499 |
\<^item> \<^bold>\<open>type\<close>~\<open>timing = {elapsed: double, cpu: double, gc: double}\<close> refers to
|
|
500 |
common Isabelle timing information in seconds, usually with a precision of
|
|
501 |
three digits after the point (whole milliseconds).
|
|
502 |
|
|
503 |
\<^item> \<^bold>\<open>type\<close>~\<open>uuid = string\<close> refers to a Universally Unique Identifier (UUID)
|
|
504 |
as plain text.\<^footnote>\<open>See \<^url>\<open>https://www.ietf.org/rfc/rfc4122.txt\<close> and
|
|
505 |
\<^url>\<open>https://docs.oracle.com/javase/8/docs/api/java/util/UUID.html\<close>.\<close> Such
|
|
506 |
identifiers are created as private random numbers of the server and only
|
|
507 |
revealed to the client that creates a certain resource (e.g.\ task or
|
|
508 |
session). A client may disclose this information for use in a different
|
|
509 |
client connection: e.g.\ this allows to share sessions between multiple
|
|
510 |
connections.
|
|
511 |
|
|
512 |
Client commands need to provide syntactically wellformed UUIDs: this is
|
|
513 |
trivial to achieve by using only identifiers that have been produced by the
|
|
514 |
server beforehand.
|
|
515 |
|
|
516 |
\<^item> \<^bold>\<open>type\<close>~\<open>task = {task: uuid}\<close> identifies a newly created asynchronous task
|
|
517 |
and thus allows the client to control it by the \<^verbatim>\<open>cancel\<close> command. The same
|
|
518 |
task identification is included in messages and the final result produced by
|
|
519 |
this task.
|
|
520 |
\<close>
|
|
521 |
|
|
522 |
|
|
523 |
subsection \<open>Command \<^verbatim>\<open>help\<close>\<close>
|
|
524 |
|
|
525 |
text \<open>
|
|
526 |
\begin{tabular}{ll}
|
|
527 |
regular result: & \<^verbatim>\<open>OK\<close> \<open>[string]\<close> \\
|
|
528 |
\end{tabular}
|
|
529 |
\<^medskip>
|
|
530 |
|
|
531 |
The \<^verbatim>\<open>help\<close> command has no argument and returns the list of command names
|
|
532 |
known to the server. This is occasionally useful for interactive
|
|
533 |
experimentation (see also @{tool client} in \secref{sec:tool-client}).
|
|
534 |
\<close>
|
|
535 |
|
|
536 |
|
|
537 |
subsection \<open>Command \<^verbatim>\<open>echo\<close>\<close>
|
|
538 |
|
|
539 |
text \<open>
|
|
540 |
\begin{tabular}{ll}
|
|
541 |
argument: & \<open>any\<close> \\
|
|
542 |
regular result: & \<^verbatim>\<open>OK\<close> \<open>any\<close> \\
|
|
543 |
\end{tabular}
|
|
544 |
\<^medskip>
|
|
545 |
|
|
546 |
The \<^verbatim>\<open>echo\<close> command is the identity function: it returns its argument as
|
|
547 |
regular result. This is occasionally useful for testing and interactive
|
|
548 |
experimentation (see also @{tool client} in \secref{sec:tool-client}).
|
|
549 |
|
|
550 |
The type of \<^verbatim>\<open>echo\<close> is actually more general than given above: \<^verbatim>\<open>Unit\<close>,
|
|
551 |
\<^verbatim>\<open>XML.Elem\<close>, \<^verbatim>\<open>JSON.T\<close> are supported uniformly. Note that \<^verbatim>\<open>XML.Elem\<close> might
|
|
552 |
be difficult to type on the console in its YXML syntax
|
|
553 |
(\secref{sec:yxml-vs-xml}).
|
|
554 |
\<close>
|
|
555 |
|
|
556 |
|
|
557 |
subsection \<open>Command \<^verbatim>\<open>shutdown\<close>\<close>
|
|
558 |
|
|
559 |
text \<open>
|
|
560 |
\begin{tabular}{ll}
|
|
561 |
regular result: & \<^verbatim>\<open>OK\<close> \\
|
|
562 |
\end{tabular}
|
|
563 |
\<^medskip>
|
|
564 |
|
|
565 |
The \<^verbatim>\<open>shutdown\<close> command has no argument and result value. It forces a
|
|
566 |
shutdown of the connected server process, stopping all open sessions and
|
|
567 |
closing the server socket. This may disrupt pending commands on other
|
|
568 |
connections!
|
|
569 |
|
|
570 |
\<^medskip>
|
|
571 |
Likewise, the command-line invocation \<^verbatim>\<open>isabelle server -x\<close> opens a server
|
|
572 |
connection and issues a \<^verbatim>\<open>shutdown\<close> command (see also
|
|
573 |
\secref{sec:tool-server}).
|
|
574 |
\<close>
|
|
575 |
|
|
576 |
|
|
577 |
subsection \<open>Command \<^verbatim>\<open>cancel\<close>\<close>
|
|
578 |
|
|
579 |
text \<open>
|
|
580 |
\begin{tabular}{ll}
|
|
581 |
argument: & \<open>uuid\<close> \\
|
|
582 |
regular result: & \<^verbatim>\<open>OK\<close> \\
|
|
583 |
\end{tabular}
|
|
584 |
\<^medskip>
|
|
585 |
|
|
586 |
The command invocation \<^verbatim>\<open>cancel "\<close>\<open>id\<close>\<^verbatim>\<open>"\<close> attempts to cancel the specified
|
|
587 |
task.
|
|
588 |
|
|
589 |
Cancellation is merely a hint that the client prefers an ongoing process to
|
|
590 |
be stopped. The command always succeeds formally, but it may get ignored by
|
|
591 |
a task that is still running, or it might refer to a non-existing or
|
|
592 |
no-longer existing task without producing an error.
|
|
593 |
|
|
594 |
Successful cancellation typically leads to an asynchronous failure of type
|
|
595 |
\<^verbatim>\<open>FAILED {\<close>\<open>task: string, message: \<close>\<^verbatim>\<open>"Interrupt"}\<close> --- or a slightly
|
|
596 |
different message, depending how the task handles the event.
|
|
597 |
\<close>
|
|
598 |
|
|
599 |
|
|
600 |
subsection \<open>Command \<^verbatim>\<open>session_build\<close> \label{sec:command-session-build}\<close>
|
|
601 |
|
|
602 |
text \<open>
|
|
603 |
\begin{tabular}{lll}
|
|
604 |
argument: & \<open>session_build_args\<close> \\
|
|
605 |
immediate result: & \<^verbatim>\<open>OK\<close> \<open>task\<close> \\
|
|
606 |
notifications: & \<^verbatim>\<open>NOTE\<close> \<open>task \<oplus> (theory_progress | message)\<close> \\
|
|
607 |
regular result: & \<^verbatim>\<open>FINISHED\<close> \<open>task \<oplus> session_build_results\<close> \\
|
|
608 |
error result: & \<^verbatim>\<open>FAILED\<close> \<open>task \<oplus> error_message \<oplus> session_build_results\<close> \\[2ex]
|
|
609 |
\end{tabular}
|
|
610 |
|
|
611 |
\begin{tabular}{lll}
|
|
612 |
\<^bold>\<open>type\<close> \<open>session_build_args =\<close> \\
|
|
613 |
\quad\<open>{session: string,\<close> \\
|
|
614 |
\quad~~\<open>preferences?: string,\<close> & \<^bold>\<open>default:\<close> server preferences \\
|
|
615 |
\quad~~\<open>options?: [string],\<close> \\
|
|
616 |
\quad~~\<open>dirs?: [string],\<close> \\
|
|
617 |
\quad~~\<open>ancestor_session?: string,\<close> \\
|
|
618 |
\quad~~\<open>all_known?: bool,\<close> \\
|
|
619 |
\quad~~\<open>focus_session?: bool,\<close> \\
|
|
620 |
\quad~~\<open>required_session?: bool,\<close> \\
|
|
621 |
\quad~~\<open>system_mode?: bool,\<close> \\
|
|
622 |
\quad~~\<open>verbose?: bool}\<close> \\[2ex]
|
|
623 |
|
|
624 |
\<^bold>\<open>type\<close> \<open>session_build_results =\<close> \\
|
|
625 |
\quad\<open>{ok: bool,\<close> \\
|
|
626 |
\quad~~\<open>return_code: int,\<close> \\
|
|
627 |
\quad~~\<open>sessions: [session_build_result]}\<close> \\[2ex]
|
|
628 |
|
|
629 |
\<^bold>\<open>type\<close> \<open>session_build_result =\<close> \\
|
|
630 |
\quad\<open>{session: string,\<close> \\
|
|
631 |
\quad~~\<open>ok: bool,\<close> \\
|
|
632 |
\quad~~\<open>return_code: int,\<close> \\
|
|
633 |
\quad~~\<open>timeout: bool,\<close> \\
|
|
634 |
\quad~~\<open>timing: timing}\<close> \\
|
|
635 |
\end{tabular}
|
|
636 |
\<close>
|
|
637 |
|
|
638 |
text \<open>
|
|
639 |
The \<^verbatim>\<open>session_build\<close> command prepares given a session image for interactive
|
|
640 |
use of theories. This is a limited version of command-line tool @{tool
|
|
641 |
build} (\secref{sec:tool-build}), with specific options to request a formal
|
|
642 |
context of an interactive session: it also resembles options of @{tool
|
|
643 |
jedit} @{cite "isabelle-jedit"}.
|
|
644 |
|
|
645 |
The build process is asynchronous, with notifications that inform about the
|
|
646 |
progress of loaded theories. Some further human-readable messages may be
|
|
647 |
output as well.
|
|
648 |
|
|
649 |
Coordination of independent build processes is at the discretion of the
|
|
650 |
client: as for like @{tool build} there are no built-in measures against
|
|
651 |
conflicting builds with overlapping hierarchies of session images.
|
|
652 |
\<close>
|
|
653 |
|
|
654 |
|
|
655 |
subsubsection \<open>Arguments\<close>
|
|
656 |
|
|
657 |
text \<open>
|
|
658 |
The field \<open>session\<close> is mandatory. It specifies the target session name:
|
|
659 |
either directly (default) or indirectly (if \<open>required_session\<close> is
|
|
660 |
\<^verbatim>\<open>true\<close>).
|
|
661 |
|
|
662 |
\<^medskip>
|
|
663 |
The environment of Isabelle system options is determined from \<open>preferences\<close>
|
|
664 |
that are augmented by \<open>options\<close>, which is a list individual updates of the
|
|
665 |
form the \<open>name\<close>\<^verbatim>\<open>=\<close>\<open>value\<close> or \<open>name\<close> (the latter abbreviates
|
|
666 |
\<open>name\<close>\<^verbatim>\<open>=true\<close>); see also command-line option \<^verbatim>\<open>-o\<close> for @{tool build}. The
|
|
667 |
preferences are loaded from the file
|
|
668 |
\<^path>\<open>$ISABELLE_HOME_USER/etc/preferences\<close> by default, but the client may
|
|
669 |
provide alternative contents for it (as text, not a file-name). This could
|
|
670 |
be relevant in situations where client and server run in different
|
|
671 |
operating-system contexts.
|
|
672 |
|
|
673 |
\<^medskip>
|
|
674 |
The \<open>dirs\<close> field specifies additional directories for session ROOT files
|
|
675 |
(\secref{sec:session-root}). This augments the name space of available
|
|
676 |
sessions; see also option \<^verbatim>\<open>-d\<close> in @{tool build} or @{tool jedit}.
|
|
677 |
|
|
678 |
\<^medskip>
|
|
679 |
The \<open>ancestor_session\<close> field specifies an alternative image as starting
|
|
680 |
point for the target image. The default is to use the parent session
|
|
681 |
according to the ROOT entry; see also option \<^verbatim>\<open>-A\<close> in @{tool jedit}. This
|
|
682 |
can lead to a more light-weight build process, by skipping intermediate
|
|
683 |
session images of the hierarchy that are not used later on.
|
|
684 |
|
|
685 |
\<^medskip>
|
|
686 |
The \<open>all_known\<close> field set to \<^verbatim>\<open>true\<close> includes all existing sessions from
|
|
687 |
reachable ROOT entries in the name space of theories with a proper
|
|
688 |
session-qualified name (instead of referring to the file-system location).
|
|
689 |
This could be relevant for the \<^verbatim>\<open>use_theories\<close> command
|
|
690 |
(\secref{sec:command-use-theories}) to refer to arbitrary theories from
|
|
691 |
other sessions. Note that considerable time is required to explore all
|
|
692 |
accessible session directories and theory dependencies.
|
|
693 |
|
|
694 |
\<^medskip>
|
|
695 |
The \<open>focus_session\<close> field set to \<^verbatim>\<open>true\<close> to focuses on the target session:
|
|
696 |
the accessible name space of theories is restricted to sessions that are
|
|
697 |
connected to it.
|
|
698 |
|
|
699 |
\<^medskip>
|
|
700 |
The \<open>required_session\<close> field set to \<^verbatim>\<open>true\<close> indicates that the target image
|
|
701 |
should not be the \<open>session\<close>, but its parent (or ancestor according to
|
|
702 |
\<open>ancestor_session\<close>). Thus it prepares a session context where theories from
|
|
703 |
the \<open>session\<close> itself can be loaded.
|
|
704 |
|
|
705 |
\<^medskip>
|
|
706 |
The \<open>system_mode\<close> field may be set to \<^verbatim>\<open>true\<close> to store session images and
|
|
707 |
log files in @{path "$ISABELLE_HOME/heaps"} instead of the default location
|
|
708 |
@{setting ISABELLE_OUTPUT} (which is normally in @{setting
|
|
709 |
ISABELLE_HOME_USER}, i.e.\ the user's home directory). See also option \<^verbatim>\<open>-s\<close>
|
|
710 |
in @{tool build} and @{tool jedit}.
|
|
711 |
|
|
712 |
\<^medskip>
|
|
713 |
The \<open>verbose\<close> field may be set to \<^verbatim>\<open>true\<close> for extra verbosity. The effect is
|
|
714 |
similar to option \<^verbatim>\<open>-v\<close> in @{tool build}.
|
|
715 |
\<close>
|
|
716 |
|
|
717 |
|
|
718 |
subsubsection \<open>Intermediate output\<close>
|
|
719 |
|
|
720 |
text \<open>
|
|
721 |
The asynchronous notifications of command \<^verbatim>\<open>session_build\<close> mainly serve as
|
|
722 |
progress indicator: the output resembles that of the session build window of
|
|
723 |
Isabelle/jEdit after startup @{cite "isabelle-jedit"}.
|
|
724 |
|
|
725 |
For the client it is usually sufficient to print the messages in plain text,
|
|
726 |
but note that \<open>theory_progress\<close> also reveals the internal \<open>theory\<close> and
|
|
727 |
\<open>session\<close> names.
|
|
728 |
\<close>
|
|
729 |
|
|
730 |
|
|
731 |
subsubsection \<open>Results\<close>
|
|
732 |
|
|
733 |
text \<open>
|
|
734 |
The overall \<open>session_build_results\<close> contain both a summary and and entry
|
|
735 |
\<open>session_build_result\<close> for each session in the build hierarchy, leading up
|
|
736 |
to the specified target session. The result is always provided,
|
|
737 |
independently of overall success (\<^verbatim>\<open>FINISHED\<close> task) or failure (\<^verbatim>\<open>FAILED\<close>
|
|
738 |
task).
|
|
739 |
|
|
740 |
The \<open>ok\<close> field tells abstractly, whether all required session builds came
|
|
741 |
out as \<open>ok\<close>, i.e.\ \<open>return_code\<close>. A non-zero \<open>return_code\<close> indicates an
|
|
742 |
error according to usual POSIX conventions for process exit.
|
|
743 |
|
|
744 |
For individual \<open>session_build_result\<close> entries, there are additional fields:
|
|
745 |
\<open>timeout\<close> to tell if the build process was aborted after running too long,
|
|
746 |
and \<open>timing\<close> for the overall process timing in the usual Isabelle format
|
|
747 |
with elapsed, CPU, gc time.
|
|
748 |
\<close>
|
|
749 |
|
|
750 |
|
|
751 |
subsubsection \<open>Examples\<close>
|
|
752 |
|
|
753 |
text \<open>
|
|
754 |
Build of a session image from the Isabelle distribution:
|
|
755 |
@{verbatim [display] \<open>session_build {"session": "HOL-Word"}\<close>}
|
|
756 |
|
|
757 |
Build a session image from the Archive of Formal Proofs:
|
|
758 |
@{verbatim [display] \<open>session_build {"session": "Coinductive", "dirs": ["$AFP_BASE/thys"]}\<close>}
|
|
759 |
|
|
760 |
Build of a session image of \<^verbatim>\<open>HOL-Number_Theory\<close> directly on top of \<^verbatim>\<open>HOL\<close>:
|
|
761 |
@{verbatim [display] \<open>session_build {"session": "HOL-Number_Theory", "ancestor_session": "HOL"}\<close>}
|
|
762 |
\<close>
|
|
763 |
|
|
764 |
|
|
765 |
subsection \<open>Command \<^verbatim>\<open>session_start\<close> \label{sec:command-session-start}\<close>
|
|
766 |
|
|
767 |
text \<open>
|
|
768 |
\begin{tabular}{lll}
|
|
769 |
argument: & \<open>session_build_args \<oplus> {print_mode?: [string]}\<close> \\
|
|
770 |
immediate result: & \<^verbatim>\<open>OK\<close> \<open>task\<close> \\
|
|
771 |
notifications: & \<^verbatim>\<open>NOTE\<close> \<open>task \<oplus> (theory_progress | message)\<close> \\
|
|
772 |
regular result: & \<^verbatim>\<open>FINISHED\<close> \<open>task \<oplus> session_start_result\<close> \\
|
|
773 |
error result: & \<^verbatim>\<open>FAILED\<close> \<open>task \<oplus> error_message\<close> \\[2ex]
|
|
774 |
\end{tabular}
|
|
775 |
|
|
776 |
\begin{tabular}{l}
|
|
777 |
\<^bold>\<open>type\<close> \<open>session_start_result = {session: string, session_id: uuid}\<close>
|
|
778 |
\end{tabular}
|
|
779 |
|
|
780 |
\<^medskip>
|
|
781 |
The \<^verbatim>\<open>session_start\<close> command starts a new Isabelle/PIDE session with
|
|
782 |
underlying Isabelle/ML process, based on a session image that it produces on
|
|
783 |
demand in the same manner as \<^verbatim>\<open>session_build\<close>. Thus it accepts all
|
|
784 |
\<open>session_build_args\<close> and produces similar notifications, but the detailed
|
|
785 |
\<open>session_build_results\<close> are omitted.
|
|
786 |
|
|
787 |
The session build and startup process is asynchronous: when the task is
|
|
788 |
finished, the session remains active for commands such as \<^verbatim>\<open>use_theories\<close>
|
|
789 |
(\secref{sec:command-use-theories}), until a \<^verbatim>\<open>session_stop\<close> or \<^verbatim>\<open>shutdown\<close>
|
|
790 |
command is sent to the server.
|
|
791 |
|
|
792 |
Sessions are independent of client connections: it is possible to start a
|
|
793 |
session and later apply \<^verbatim>\<open>use_theories\<close> on different connections, as long as
|
|
794 |
the internal session identifier is known.
|
|
795 |
\<close>
|
|
796 |
|
|
797 |
|
|
798 |
subsubsection \<open>Arguments\<close>
|
|
799 |
|
|
800 |
text \<open>
|
|
801 |
Most of the arguments are the same as for \<^verbatim>\<open>session_build\<close>
|
|
802 |
(\secref{sec:command-session-build}).
|
|
803 |
|
|
804 |
\<^medskip>
|
|
805 |
The \<open>print_mode\<close> field adds identifiers of print modes to be made active for
|
|
806 |
this session. For example, \<^verbatim>\<open>"print_mode": ["ASCII"]\<close> prefers ASCII
|
|
807 |
replacement syntax over mathematical Isabelle symbols. See also option \<^verbatim>\<open>-m\<close>
|
|
808 |
in @{tool process} (\secref{sec:tool-process}).
|
|
809 |
\<close>
|
|
810 |
|
|
811 |
|
|
812 |
subsubsection \<open>Results\<close>
|
|
813 |
|
|
814 |
text \<open>
|
|
815 |
The \<open>session\<close> field provides the active session name for clarity.
|
|
816 |
|
|
817 |
\<^medskip>
|
|
818 |
The \<open>session_id\<close> field provides the internal identification of the session
|
|
819 |
object within the sever process. It can remain active as long as the server
|
|
820 |
is running, independently of the current client connection.
|
|
821 |
\<close>
|
|
822 |
|
|
823 |
|
|
824 |
subsection \<open>Examples\<close>
|
|
825 |
|
|
826 |
text \<open>
|
|
827 |
Start a default Isabelle/HOL session:
|
|
828 |
@{verbatim [display] \<open>session_start {"session": "HOL"}\<close>}
|
|
829 |
\<close>
|
|
830 |
|
|
831 |
|
|
832 |
subsection \<open>Command \<^verbatim>\<open>session_stop\<close>\<close>
|
|
833 |
|
|
834 |
text \<open>
|
|
835 |
\begin{tabular}{ll}
|
|
836 |
argument: & \<open>{session_id?: uuid}\<close> \\
|
|
837 |
immediate result: & \<^verbatim>\<open>OK\<close> \<open>task\<close> \\
|
|
838 |
regular result: & \<^verbatim>\<open>FINISHED\<close> \<open>task \<oplus> session_stop_result\<close> \\
|
|
839 |
error result: & \<^verbatim>\<open>FAILED\<close> \<open>task \<oplus> error_message \<oplus> session_stop_result\<close> \\[2ex]
|
|
840 |
\end{tabular}
|
|
841 |
|
|
842 |
\begin{tabular}{l}
|
|
843 |
\<^bold>\<open>type\<close> \<open>session_stop_result = {ok: bool, return_code: int}\<close>
|
|
844 |
\end{tabular}
|
|
845 |
|
|
846 |
\<^medskip>
|
|
847 |
The \<^verbatim>\<open>session_stop\<close> command forces a shutdown of the identified
|
|
848 |
Isabelle/PIDE session. This asynchronous tasks usually finishes quickly.
|
|
849 |
Failure only happens unusual situations, according to the return code of the
|
|
850 |
underlying Isabelle/ML process.
|
|
851 |
\<close>
|
|
852 |
|
|
853 |
|
|
854 |
subsubsection \<open>Arguments\<close>
|
|
855 |
|
|
856 |
text \<open>
|
|
857 |
The \<open>session_id\<close> field is the UUID originally created by the server for the
|
|
858 |
intended session.
|
|
859 |
\<close>
|
|
860 |
|
|
861 |
|
|
862 |
subsubsection \<open>Results\<close>
|
|
863 |
|
|
864 |
text \<open>
|
|
865 |
The \<open>ok\<close> field tells abstractly, whether the Isabelle/ML process terminated
|
|
866 |
properly. The \<open>return_code\<close> expresses this information according to usual
|
|
867 |
POSIX conventions for process exit.
|
|
868 |
\<close>
|
|
869 |
|
|
870 |
|
|
871 |
subsection \<open>Command \<^verbatim>\<open>use_theories\<close> \label{sec:command-use-theories}\<close>
|
|
872 |
|
|
873 |
text \<open>
|
|
874 |
\begin{tabular}{ll}
|
|
875 |
argument: & \<open>use_theories_arguments\<close> \\
|
|
876 |
regular result: & \<^verbatim>\<open>OK\<close> \<open>use_theories_results\<close> \\
|
|
877 |
\end{tabular}
|
|
878 |
|
|
879 |
\begin{tabular}{ll}
|
|
880 |
\<^bold>\<open>type\<close> \<open>theory_name = string | {name: string, pos: position}\<close> \\
|
|
881 |
\end{tabular}
|
|
882 |
|
|
883 |
\begin{tabular}{ll}
|
|
884 |
\<^bold>\<open>type\<close> \<open>use_theories_arguments =\<close> \\
|
|
885 |
\quad\<open>{session_id: uuid,\<close> \\
|
|
886 |
\quad~~\<open>theories: [theory_name],\<close> \\
|
|
887 |
\quad~~\<open>qualifier?: string,\<close> \\
|
|
888 |
\quad~~\<open>master_dir?: string,\<close> \\
|
|
889 |
\quad~~\<open>pretty_margin?: double\<close> & \<^bold>\<open>default:\<close> \<^verbatim>\<open>76\<close> \\
|
|
890 |
\quad~~\<open>unicode_symbols?: bool}\<close> \\[2ex]
|
|
891 |
|
|
892 |
\<^bold>\<open>type\<close> \<open>node_status =\<close> \\
|
|
893 |
\quad\<open>{ok: bool,\<close> \\
|
|
894 |
\quad~~\<open>total: int,\<close> \\
|
|
895 |
\quad~~\<open>unprocessed: int,\<close> \\
|
|
896 |
\quad~~\<open>running: int,\<close> \\
|
|
897 |
\quad~~\<open>warned: int,\<close> \\
|
|
898 |
\quad~~\<open>failed: int,\<close> \\
|
|
899 |
\quad~~\<open>finished: int,\<close> \\
|
|
900 |
\quad~~\<open>consolidated: bool}\<close> \\[2ex]
|
|
901 |
|
|
902 |
\<^bold>\<open>type\<close> \<open>node_result =\<close> \\
|
|
903 |
\quad\<open>{node_name: string,\<close> \\
|
|
904 |
\quad~~\<open>theory: string,\<close> \\
|
|
905 |
\quad~~\<open>status: node_status,\<close> \\
|
|
906 |
\quad~~\<open>messages: [message]}\<close> \\[2ex]
|
|
907 |
|
|
908 |
\<^bold>\<open>type\<close> \<open>use_theories_results =\<close> \\
|
|
909 |
\quad\<open>{ok: bool,\<close> \\
|
|
910 |
\quad~~\<open>errors: [message],\<close> \\
|
|
911 |
\quad~~\<open>nodes: [node_result]}\<close> \\[2ex]
|
|
912 |
\end{tabular}
|
|
913 |
|
|
914 |
\<^medskip>
|
|
915 |
|
|
916 |
The \<^verbatim>\<open>use_theories\<close> command updates the identified session by adding the
|
|
917 |
current version of given theory files to it: theory dependencies are
|
|
918 |
resolved implicitly. The command succeeds eventually, when all theories have
|
|
919 |
been \<^emph>\<open>consolidated\<close> in the sense that the outermost command structure has
|
|
920 |
finished (or failed) and the final \<^theory_text>\<open>end\<close> command of each theory has been
|
|
921 |
checked.
|
|
922 |
\<close>
|
|
923 |
|
|
924 |
|
|
925 |
subsubsection \<open>Arguments\<close>
|
|
926 |
|
|
927 |
text \<open>
|
|
928 |
The \<open>session_id\<close> is the identifier provided by the server, when the session
|
|
929 |
was created (possibly on a different client connection).
|
|
930 |
|
|
931 |
\<^medskip>
|
|
932 |
The \<open>theories\<close> field specifies theory names as in \<^theory_text>\<open>theory imports\<close> or in
|
|
933 |
session ROOT \<^verbatim>\<open>theories\<close>: an explicit source position for these theory name
|
|
934 |
specifications may be given as well, which is occasionally useful for
|
|
935 |
precise error locations.
|
|
936 |
|
|
937 |
\<^medskip>
|
|
938 |
The \<open>qualifier\<close> field provides an alternative session qualifier for theories
|
|
939 |
that are not formally recognized as a member of a particular session. The
|
|
940 |
default is \<^verbatim>\<open>Draft\<close> as in Isabelle/jEdit. There is rarely a need to change
|
|
941 |
that, as theory nodes are already uniquely identified by their physical
|
|
942 |
file-system location.
|
|
943 |
|
|
944 |
\<^medskip>
|
|
945 |
The \<open>master_dir\<close> field explicit specifies the formal master directory of the
|
|
946 |
imported theory. Normally this is determined implicitly from the parent
|
|
947 |
directory of the physical theory file location.
|
|
948 |
|
|
949 |
\<^medskip>
|
|
950 |
The \<open>pretty_margin\<close> field specifies the line width for pretty-printing. The
|
|
951 |
default is for classic console output. Formatting happens at the end of
|
|
952 |
\<^verbatim>\<open>use_theories\<close>, when all prover messages produced are exported to the
|
|
953 |
client.
|
|
954 |
|
|
955 |
\<^medskip>
|
|
956 |
The \<open>unicode_symbols\<close> field set to \<^verbatim>\<open>true\<close> means that message output is
|
|
957 |
rendered for direct output on a Unicode capable channel, ideally with the
|
|
958 |
Isabelle fonts as in Isabelle/jEdit (or Isabelle HTML output). The default
|
|
959 |
is to keep the symbolic representation of Isabelle text, e.g.\ \<^verbatim>\<open>\<forall>\<close> instead
|
|
960 |
of its rendering as \<open>\<forall>\<close>. This means the client needs to perform its own
|
|
961 |
rendering to present it to the end-user.
|
|
962 |
\<close>
|
|
963 |
|
|
964 |
subsubsection \<open>Results\<close>
|
|
965 |
|
|
966 |
text \<open>
|
|
967 |
The \<open>ok\<close> field indicates overall success of processing the specified
|
|
968 |
theories with all their dependencies.
|
|
969 |
|
|
970 |
When \<open>ok\<close> is \<^verbatim>\<open>false\<close>, the \<open>errors\<close> field lists all errors cumulatively,
|
|
971 |
including position information for the theory nodes where the error happened
|
|
972 |
(this includes imported theories).
|
|
973 |
|
|
974 |
\<^medskip>
|
|
975 |
The \<open>nodes\<close> field provides more detailed information about each imported
|
|
976 |
theory node. Here the individual fields are as follows:
|
|
977 |
|
|
978 |
\<^item> \<open>node_name\<close>: the physical name for the theory node, based on its
|
|
979 |
file-system location;\<^footnote>\<open>Clients may recognize the originally provided
|
|
980 |
file-names after careful normalization in the file-system of the server.\<close>
|
|
981 |
|
|
982 |
\<^item> \<open>theory\<close>: the logical theory name, e.g.\ \<^verbatim>\<open>HOL-Library.AList\<close> or
|
|
983 |
\<^verbatim>\<open>Draft.Test\<close>;
|
|
984 |
|
|
985 |
\<^item> \<open>status\<close>: the overall node status, e.g.\ see the visualization in the
|
|
986 |
\<open>Theories\<close> panel of Isabelle/jEdit @{cite "isabelle-jedit"};
|
|
987 |
|
|
988 |
\<^item> \<open>messages\<close>: the main bulk of prover messages produced in this theory note
|
|
989 |
(\<^verbatim>\<open>writeln\<close>, \<^verbatim>\<open>warning\<close>, \<^verbatim>\<open>error\<close>, etc.).
|
|
990 |
\<close>
|
|
991 |
|
|
992 |
|
|
993 |
subsubsection \<open>Examples\<close>
|
|
994 |
|
|
995 |
text \<open>
|
|
996 |
Process some example theory from the Isabelle distribution, within the
|
|
997 |
context of an already started session for Isabelle/HOL (see also
|
|
998 |
\secref{sec:command-session-start}):
|
|
999 |
@{verbatim [display] \<open>use_theories {"session_id": ..., "theories": ["~~/src/HOL/Isar_Examples/Drinker"]}\<close>}
|
|
1000 |
|
|
1001 |
\<^medskip>
|
|
1002 |
Process some example theories that import other theories via
|
|
1003 |
session-qualified theory names:
|
|
1004 |
|
|
1005 |
@{verbatim [display] \<open>session_start {"session": "HOL", "all_known": true}
|
|
1006 |
use_theories {"session_id": ..., "theories": ["~~/src/HOL/Unix/Unix"]}
|
|
1007 |
session_stop {"session_id": ...}\<close>}
|
|
1008 |
|
|
1009 |
The option \<open>all_known\<close> has been used here to the full name space of
|
|
1010 |
session-qualified theory names accessible in this session. This is also the
|
|
1011 |
default in Isabelle/jEdit, although it requires significant startup time.
|
|
1012 |
|
|
1013 |
\<^medskip>
|
|
1014 |
Process some example theories in the context of their (single) parent
|
|
1015 |
session:
|
|
1016 |
|
|
1017 |
@{verbatim [display] \<open>session_start {"session": "HOL-Library"}
|
|
1018 |
use_theories {"session_id": ..., "theories": ["~~/src/HOL/Unix/Unix"]}
|
|
1019 |
session_stop {"session_id": ...}\<close>}
|
67904
|
1020 |
\<close>
|
|
1021 |
|
|
1022 |
end
|