author | wenzelm |
Fri, 19 Jan 2018 14:55:46 +0100 | |
changeset 67471 | bddfa23a4ea9 |
parent 67219 | 81e9804b2014 |
child 67493 | c4e9e0c50487 |
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] => |
65300 | 17 |
(Options.set_default (Options.decode (YXML.parse_body options_yxml)); |
18 |
Isabelle_Process.init_options_interactive ())); |
|
52585 | 19 |
|
20 |
val _ = |
|
67219 | 21 |
Isabelle_Process.protocol_command "Prover.init_session_base" |
67471 | 22 |
(fn [sessions_yxml, doc_names_yxml, global_theories_yxml, loaded_theories_yxml, |
23 |
known_theories_yxml] => |
|
65470 | 24 |
let |
25 |
val decode_table = YXML.parse_body #> let open XML.Decode in list (pair string string) end; |
|
66712 | 26 |
val decode_list = YXML.parse_body #> let open XML.Decode in list string end; |
65470 | 27 |
in |
65478
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65470
diff
changeset
|
28 |
Resources.init_session_base |
67219 | 29 |
{sessions = decode_list sessions_yxml, |
67471 | 30 |
doc_names = decode_list doc_names_yxml, |
67219 | 31 |
global_theories = decode_table global_theories_yxml, |
66712 | 32 |
loaded_theories = decode_list loaded_theories_yxml, |
65470 | 33 |
known_theories = decode_table known_theories_yxml} |
34 |
end); |
|
35 |
||
36 |
val _ = |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
37 |
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
|
38 |
(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
|
39 |
|
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
40 |
val _ = |
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
41 |
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
|
42 |
(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
|
43 |
let |
59685
c043306d2598
clarified markup for embedded files, early before execution;
wenzelm
parents:
59671
diff
changeset
|
44 |
val (blobs, blobs_index) = |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
45 |
YXML.parse_body blobs_yxml |> |
59714
ae322325adbb
tuned protocol -- resolve command positions in ML;
wenzelm
parents:
59685
diff
changeset
|
46 |
let |
ae322325adbb
tuned protocol -- resolve command positions in ML;
wenzelm
parents:
59685
diff
changeset
|
47 |
val message = |
ae322325adbb
tuned protocol -- resolve command positions in ML;
wenzelm
parents:
59685
diff
changeset
|
48 |
YXML.string_of_body o Protocol_Message.command_positions id; |
ae322325adbb
tuned protocol -- resolve command positions in ML;
wenzelm
parents:
59685
diff
changeset
|
49 |
open XML.Decode; |
ae322325adbb
tuned protocol -- resolve command positions in ML;
wenzelm
parents:
59685
diff
changeset
|
50 |
in |
59685
c043306d2598
clarified markup for embedded files, early before execution;
wenzelm
parents:
59671
diff
changeset
|
51 |
pair |
c043306d2598
clarified markup for embedded files, early before execution;
wenzelm
parents:
59671
diff
changeset
|
52 |
(list (variant |
c043306d2598
clarified markup for embedded files, early before execution;
wenzelm
parents:
59671
diff
changeset
|
53 |
[fn ([], a) => Exn.Res (pair string (option string) a), |
59714
ae322325adbb
tuned protocol -- resolve command positions in ML;
wenzelm
parents:
59685
diff
changeset
|
54 |
fn ([], a) => Exn.Exn (ERROR (message a))])) |
59685
c043306d2598
clarified markup for embedded files, early before execution;
wenzelm
parents:
59671
diff
changeset
|
55 |
int |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
56 |
end; |
59085
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58928
diff
changeset
|
57 |
val toks = |
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58928
diff
changeset
|
58 |
(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
|
59 |
in |
59685
c043306d2598
clarified markup for embedded files, early before execution;
wenzelm
parents:
59671
diff
changeset
|
60 |
Document.change_state |
c043306d2598
clarified markup for embedded files, early before execution;
wenzelm
parents:
59671
diff
changeset
|
61 |
(Document.define_command (Document_ID.parse id) name blobs blobs_index toks) |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
53192
diff
changeset
|
62 |
end); |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
63 |
|
38418
9a7af64d71bb
more explicit / functional ML version of document model;
wenzelm
parents:
38417
diff
changeset
|
64 |
val _ = |
66379
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
wenzelm
parents:
66370
diff
changeset
|
65 |
Isabelle_Process.protocol_command "Document.consolidate_execution" |
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
wenzelm
parents:
66370
diff
changeset
|
66 |
(fn [] => Document.consolidate_execution (Document.state ())); |
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
wenzelm
parents:
66370
diff
changeset
|
67 |
|
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
wenzelm
parents:
66370
diff
changeset
|
68 |
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
|
69 |
Isabelle_Process.protocol_command "Document.discontinue_execution" |
52606 | 70 |
(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
|
71 |
|
b8aeab386414
less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents:
46938
diff
changeset
|
72 |
val _ = |
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
73 |
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
|
74 |
(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
|
75 |
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
76 |
val _ = |
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
77 |
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
|
78 |
(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
|
79 |
(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
|
80 |
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
|
81 |
val _ = Execution.discontinue (); |
47404
e6e5750f1311
simplified Future.cancel/cancel_group (again) -- running threads only;
wenzelm
parents:
47388
diff
changeset
|
82 |
|
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
|
83 |
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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
(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
|
90 |
[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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
(pair (list (pair string |
63429 | 96 |
(pair (pair string (list string)) (list string)))) |
59671
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
wenzelm
parents:
59463
diff
changeset
|
97 |
(list YXML.string_of_body)))) a; |
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
|
98 |
val imports' = map (rpair Position.none) imports; |
59934
b65c4370f831
more position information and PIDE markup for command keywords;
wenzelm
parents:
59715
diff
changeset
|
99 |
val keywords' = map (fn (x, y) => ((x, Position.none), y)) keywords; |
b65c4370f831
more position information and PIDE markup for command keywords;
wenzelm
parents:
59715
diff
changeset
|
100 |
val header = Thy_Header.make (name, Position.none) imports' keywords'; |
59715
4f0d0e4ad68d
avoid duplicate header errors, more precise positions;
wenzelm
parents:
59714
diff
changeset
|
101 |
in Document.Deps {master = master, header = header, errors = errors} end, |
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
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
end; |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
106 |
|
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
|
107 |
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
|
108 |
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
|
109 |
(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
|
110 |
{name = "Document.update/remove", group = NONE, |
66370 | 111 |
deps = Execution.snapshot removed, |
60610
f52b4b0c10c4
improved scheduling for urgent tasks, using farm of replacement threads (may lead to factor 2 overloading, but CPUs are usually hyperthreaded);
wenzelm
parents:
60074
diff
changeset
|
112 |
pri = Task_Queue.urgent_pri + 2, interrupts = false} |
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
|
113 |
(fn () => (Execution.purge removed; List.app Isabelle_Process.reset_tracing removed)); |
52601 | 114 |
|
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
|
115 |
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
|
116 |
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
|
117 |
[(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
|
118 |
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
|
119 |
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
|
120 |
|> 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
|
121 |
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
|
122 |
|
43748 | 123 |
val _ = |
46119
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
wenzelm
parents:
45709
diff
changeset
|
124 |
Isabelle_Process.protocol_command "Document.remove_versions" |
44673 | 125 |
(fn [versions_yxml] => Document.change_state (fn state => |
126 |
let |
|
127 |
val versions = |
|
128 |
YXML.parse_body versions_yxml |> |
|
129 |
let open XML.Decode in list int end; |
|
44676 | 130 |
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
|
131 |
val _ = Output.protocol_message Markup.removed_versions [versions_yxml]; |
44676 | 132 |
in state1 end)); |
44673 | 133 |
|
134 |
val _ = |
|
50498 | 135 |
Isabelle_Process.protocol_command "Document.dialog_result" |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
136 |
(fn [serial, result] => |
63806 | 137 |
Active.dialog_result (Value.parse_int serial) result |
62505 | 138 |
handle exn => if Exn.is_interrupt exn then () (*sic!*) else Exn.reraise exn); |
50498 | 139 |
|
56616
abc2da18d08d
added protocol command "use_theories", with core functionality of batch build;
wenzelm
parents:
56458
diff
changeset
|
140 |
val _ = |
62467 | 141 |
Isabelle_Process.protocol_command "ML_Heap.share_common_data" |
142 |
(fn [] => ML_Heap.share_common_data ()); |
|
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
|
143 |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
144 |
end; |
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
145 |