author | wenzelm |
Wed, 28 Jan 2015 22:19:22 +0100 | |
changeset 59463 | b91dc7ab3464 |
parent 59370 | b13ff987c559 |
child 59671 | 9715eb8e9408 |
permissions | -rw-r--r-- |
45709
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents:
45672
diff
changeset
|
1 |
(* Title: Pure/PIDE/protocol.ML |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
3 |
|
45709
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents:
45672
diff
changeset
|
4 |
Protocol message formats for interactive proof documents. |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
5 |
*) |
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
6 |
|
45709
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents:
45672
diff
changeset
|
7 |
structure Protocol: sig end = |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
8 |
struct |
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
9 |
|
38418
9a7af64d71bb
more explicit / functional ML version of document model;
wenzelm
parents:
38417
diff
changeset
|
10 |
val _ = |
56387 | 11 |
Isabelle_Process.protocol_command "Prover.echo" |
52786 | 12 |
(fn args => List.app writeln args); |
13 |
||
14 |
val _ = |
|
56387 | 15 |
Isabelle_Process.protocol_command "Prover.options" |
52786 | 16 |
(fn [options_yxml] => |
17 |
let val options = Options.decode (YXML.parse_body options_yxml) in |
|
18 |
Options.set_default options; |
|
19 |
Future.ML_statistics := true; |
|
20 |
Multithreading.trace := Options.int options "threads_trace"; |
|
54717 | 21 |
Multithreading.max_threads_update (Options.int options "threads"); |
52786 | 22 |
Goal.parallel_proofs := (if Options.int options "parallel_proofs" > 0 then 3 else 0) |
23 |
end); |
|
52585 | 24 |
|
25 |
val _ = |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
26 |
Isabelle_Process.protocol_command "Document.define_blob" |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
27 |
(fn [digest, content] => Document.change_state (Document.define_blob digest content)); |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
28 |
|
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
29 |
val _ = |
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
30 |
Isabelle_Process.protocol_command "Document.define_command" |
59085
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58928
diff
changeset
|
31 |
(fn id :: name :: blobs_yxml :: toks_yxml :: sources => |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
32 |
let |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
33 |
val blobs = |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
34 |
YXML.parse_body blobs_yxml |> |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
35 |
let open XML.Decode in |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
36 |
list (variant |
56458
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56447
diff
changeset
|
37 |
[fn ([], a) => Exn.Res (pair string (option string) a), |
54526 | 38 |
fn ([], a) => Exn.Exn (ERROR (string a))]) |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
39 |
end; |
59085
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58928
diff
changeset
|
40 |
val toks = |
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58928
diff
changeset
|
41 |
(YXML.parse_body toks_yxml |> let open XML.Decode in list (pair int int) end) ~~ sources; |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
42 |
in |
59085
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58928
diff
changeset
|
43 |
Document.change_state (Document.define_command (Document_ID.parse id) name blobs toks) |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
44 |
end); |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
45 |
|
38418
9a7af64d71bb
more explicit / functional ML version of document model;
wenzelm
parents:
38417
diff
changeset
|
46 |
val _ = |
47343
b8aeab386414
less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents:
46938
diff
changeset
|
47 |
Isabelle_Process.protocol_command "Document.discontinue_execution" |
52606 | 48 |
(fn [] => Execution.discontinue ()); |
47343
b8aeab386414
less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents:
46938
diff
changeset
|
49 |
|
b8aeab386414
less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents:
46938
diff
changeset
|
50 |
val _ = |
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
51 |
Isabelle_Process.protocol_command "Document.cancel_exec" |
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
52 |
(fn [exec_id] => Execution.cancel (Document_ID.parse exec_id)); |
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
53 |
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
54 |
val _ = |
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
55 |
Isabelle_Process.protocol_command "Document.update" |
59370
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
56 |
(Future.task_context "Document.update" (Future.new_group NONE) |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
57 |
(fn [old_id_string, new_id_string, edits_yxml] => Document.change_state (fn state => |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
58 |
let |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
59 |
val _ = Execution.discontinue (); |
47404
e6e5750f1311
simplified Future.cancel/cancel_group (again) -- running threads only;
wenzelm
parents:
47388
diff
changeset
|
60 |
|
59370
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
61 |
val old_id = Document_ID.parse old_id_string; |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
62 |
val new_id = Document_ID.parse new_id_string; |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
63 |
val edits = |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
64 |
YXML.parse_body edits_yxml |> |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
65 |
let open XML.Decode in |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
66 |
list (pair string |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
67 |
(variant |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
68 |
[fn ([], a) => Document.Edits (list (pair (option int) (option int)) a), |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
69 |
fn ([], a) => |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
70 |
let |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
71 |
val (master, (name, (imports, (keywords, errors)))) = |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
72 |
pair string (pair string (pair (list string) |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
73 |
(pair (list (pair string |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
74 |
(option (pair (pair string (list string)) (list string))))) |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
75 |
(list string)))) a; |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
76 |
val imports' = map (rpair Position.none) imports; |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
77 |
val header = Thy_Header.make (name, Position.none) imports' keywords; |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
78 |
in Document.Deps (master, header, errors) end, |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
79 |
fn (a :: b, c) => |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
80 |
Document.Perspective (bool_atom a, map int_atom b, |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
81 |
list (pair int (pair string (list string))) c)])) |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
82 |
end; |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
83 |
|
59370
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
84 |
val (removed, assign_update, state') = Document.update old_id new_id edits state; |
59463
b91dc7ab3464
more robust protocol command: purge removed execs asynchronously, to remain reactive despite problems to cancel "Command.run_process" in a situation of overrunning non-terminating tasks (see also 59f1591a11cb);
wenzelm
parents:
59370
diff
changeset
|
85 |
val _ = |
b91dc7ab3464
more robust protocol command: purge removed execs asynchronously, to remain reactive despite problems to cancel "Command.run_process" in a situation of overrunning non-terminating tasks (see also 59f1591a11cb);
wenzelm
parents:
59370
diff
changeset
|
86 |
(singleton o Future.forks) |
b91dc7ab3464
more robust protocol command: purge removed execs asynchronously, to remain reactive despite problems to cancel "Command.run_process" in a situation of overrunning non-terminating tasks (see also 59f1591a11cb);
wenzelm
parents:
59370
diff
changeset
|
87 |
{name = "Document.update/remove", group = NONE, |
b91dc7ab3464
more robust protocol command: purge removed execs asynchronously, to remain reactive despite problems to cancel "Command.run_process" in a situation of overrunning non-terminating tasks (see also 59f1591a11cb);
wenzelm
parents:
59370
diff
changeset
|
88 |
deps = maps Future.group_snapshot (maps Execution.peek removed), |
b91dc7ab3464
more robust protocol command: purge removed execs asynchronously, to remain reactive despite problems to cancel "Command.run_process" in a situation of overrunning non-terminating tasks (see also 59f1591a11cb);
wenzelm
parents:
59370
diff
changeset
|
89 |
pri = 1, interrupts = false} |
b91dc7ab3464
more robust protocol command: purge removed execs asynchronously, to remain reactive despite problems to cancel "Command.run_process" in a situation of overrunning non-terminating tasks (see also 59f1591a11cb);
wenzelm
parents:
59370
diff
changeset
|
90 |
(fn () => (Execution.purge removed; List.app Isabelle_Process.reset_tracing removed)); |
52601 | 91 |
|
59370
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
92 |
val _ = |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
93 |
Output.protocol_message Markup.assign_update |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
94 |
[(new_id, assign_update) |> |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
95 |
let open XML.Encode |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
96 |
in pair int (list (pair int (list int))) end |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
97 |
|> YXML.string_of_body]; |
b13ff987c559
refrain from default task_context for all protocol commands, e.g. relevant for "build_theories" to admit Session.shutdown;
wenzelm
parents:
59366
diff
changeset
|
98 |
in Document.start_execution state' end))); |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
99 |
|
43748 | 100 |
val _ = |
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
101 |
Isabelle_Process.protocol_command "Document.remove_versions" |
44673 | 102 |
(fn [versions_yxml] => Document.change_state (fn state => |
103 |
let |
|
104 |
val versions = |
|
105 |
YXML.parse_body versions_yxml |> |
|
106 |
let open XML.Decode in list int end; |
|
44676 | 107 |
val state1 = Document.remove_versions versions state; |
56333
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents:
54717
diff
changeset
|
108 |
val _ = Output.protocol_message Markup.removed_versions [versions_yxml]; |
44676 | 109 |
in state1 end)); |
44673 | 110 |
|
111 |
val _ = |
|
50498 | 112 |
Isabelle_Process.protocol_command "Document.dialog_result" |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
113 |
(fn [serial, result] => |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
114 |
Active.dialog_result (Markup.parse_int serial) result |
52775
e0169f13bd37
keep memo_exec execution running, which is important to cancel goal forks eventually;
wenzelm
parents:
52774
diff
changeset
|
115 |
handle exn => if Exn.is_interrupt exn then () (*sic!*) else reraise exn); |
50498 | 116 |
|
56616
abc2da18d08d
added protocol command "use_theories", with core functionality of batch build;
wenzelm
parents:
56458
diff
changeset
|
117 |
val _ = |
57868
0b954ac94827
protocol command for heap management, e.g. in Isabelle/jEdit/Scala console: PIDE.session.protocol_command("ML_System.share_common_data");
wenzelm
parents:
56616
diff
changeset
|
118 |
Isabelle_Process.protocol_command "ML_System.share_common_data" |
0b954ac94827
protocol command for heap management, e.g. in Isabelle/jEdit/Scala console: PIDE.session.protocol_command("ML_System.share_common_data");
wenzelm
parents:
56616
diff
changeset
|
119 |
(fn [] => ML_System.share_common_data ()); |
0b954ac94827
protocol command for heap management, e.g. in Isabelle/jEdit/Scala console: PIDE.session.protocol_command("ML_System.share_common_data");
wenzelm
parents:
56616
diff
changeset
|
120 |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
121 |
end; |
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
122 |