| author | wenzelm | 
| Sat, 17 Aug 2019 19:04:03 +0200 | |
| changeset 70570 | d94456876f2d | 
| parent 70284 | 3e17c3a5fd39 | 
| child 70663 | 4a358f8c7cb7 | 
| permissions | -rw-r--r-- | 
| 45709 
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
 wenzelm parents: 
45672diff
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: 
45672diff
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: 
45672diff
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: 
38417diff
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; | 
| 67493 
c4e9e0c50487
treat sessions as entities with defining position;
 wenzelm parents: 
67471diff
changeset | 27 | val decode_sessions = | 
| 
c4e9e0c50487
treat sessions as entities with defining position;
 wenzelm parents: 
67471diff
changeset | 28 | YXML.parse_body #> let open XML.Decode in list (pair string properties) end; | 
| 65470 | 29 | 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: 
65470diff
changeset | 30 | Resources.init_session_base | 
| 67493 
c4e9e0c50487
treat sessions as entities with defining position;
 wenzelm parents: 
67471diff
changeset | 31 |           {sessions = decode_sessions sessions_yxml,
 | 
| 
c4e9e0c50487
treat sessions as entities with defining position;
 wenzelm parents: 
67471diff
changeset | 32 | docs = decode_list doc_names_yxml, | 
| 67219 | 33 | global_theories = decode_table global_theories_yxml, | 
| 66712 | 34 | loaded_theories = decode_list loaded_theories_yxml, | 
| 65470 | 35 | known_theories = decode_table known_theories_yxml} | 
| 36 | end); | |
| 37 | ||
| 38 | val _ = | |
| 54519 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
53192diff
changeset | 39 | Isabelle_Process.protocol_command "Document.define_blob" | 
| 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
53192diff
changeset | 40 | (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: 
53192diff
changeset | 41 | |
| 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
53192diff
changeset | 42 | val _ = | 
| 46119 
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
 wenzelm parents: 
45709diff
changeset | 43 | Isabelle_Process.protocol_command "Document.define_command" | 
| 59085 
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
 wenzelm parents: 
58928diff
changeset | 44 | (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: 
53192diff
changeset | 45 | let | 
| 59685 
c043306d2598
clarified markup for embedded files, early before execution;
 wenzelm parents: 
59671diff
changeset | 46 | val (blobs, blobs_index) = | 
| 54519 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
53192diff
changeset | 47 | YXML.parse_body blobs_yxml |> | 
| 59714 
ae322325adbb
tuned protocol -- resolve command positions in ML;
 wenzelm parents: 
59685diff
changeset | 48 | let | 
| 
ae322325adbb
tuned protocol -- resolve command positions in ML;
 wenzelm parents: 
59685diff
changeset | 49 | val message = | 
| 
ae322325adbb
tuned protocol -- resolve command positions in ML;
 wenzelm parents: 
59685diff
changeset | 50 | YXML.string_of_body o Protocol_Message.command_positions id; | 
| 
ae322325adbb
tuned protocol -- resolve command positions in ML;
 wenzelm parents: 
59685diff
changeset | 51 | open XML.Decode; | 
| 
ae322325adbb
tuned protocol -- resolve command positions in ML;
 wenzelm parents: 
59685diff
changeset | 52 | in | 
| 59685 
c043306d2598
clarified markup for embedded files, early before execution;
 wenzelm parents: 
59671diff
changeset | 53 | pair | 
| 
c043306d2598
clarified markup for embedded files, early before execution;
 wenzelm parents: 
59671diff
changeset | 54 | (list (variant | 
| 
c043306d2598
clarified markup for embedded files, early before execution;
 wenzelm parents: 
59671diff
changeset | 55 | [fn ([], a) => Exn.Res (pair string (option string) a), | 
| 59714 
ae322325adbb
tuned protocol -- resolve command positions in ML;
 wenzelm parents: 
59685diff
changeset | 56 | fn ([], a) => Exn.Exn (ERROR (message a))])) | 
| 59685 
c043306d2598
clarified markup for embedded files, early before execution;
 wenzelm parents: 
59671diff
changeset | 57 | int | 
| 54519 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
53192diff
changeset | 58 | end; | 
| 59085 
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
 wenzelm parents: 
58928diff
changeset | 59 | val toks = | 
| 
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
 wenzelm parents: 
58928diff
changeset | 60 | (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: 
53192diff
changeset | 61 | in | 
| 59685 
c043306d2598
clarified markup for embedded files, early before execution;
 wenzelm parents: 
59671diff
changeset | 62 | Document.change_state | 
| 
c043306d2598
clarified markup for embedded files, early before execution;
 wenzelm parents: 
59671diff
changeset | 63 | (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: 
53192diff
changeset | 64 | end); | 
| 38412 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 65 | |
| 38418 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 66 | val _ = | 
| 47343 
b8aeab386414
less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
 wenzelm parents: 
46938diff
changeset | 67 | Isabelle_Process.protocol_command "Document.discontinue_execution" | 
| 52606 | 68 | (fn [] => Execution.discontinue ()); | 
| 47343 
b8aeab386414
less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
 wenzelm parents: 
46938diff
changeset | 69 | |
| 
b8aeab386414
less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
 wenzelm parents: 
46938diff
changeset | 70 | val _ = | 
| 52931 
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
 wenzelm parents: 
52862diff
changeset | 71 | Isabelle_Process.protocol_command "Document.cancel_exec" | 
| 
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
 wenzelm parents: 
52862diff
changeset | 72 | (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: 
52862diff
changeset | 73 | |
| 
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
 wenzelm parents: 
52862diff
changeset | 74 | val _ = | 
| 46119 
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
 wenzelm parents: 
45709diff
changeset | 75 | 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: 
59366diff
changeset | 76 | (Future.task_context "Document.update" (Future.new_group NONE) | 
| 69849 | 77 | (fn old_id_string :: new_id_string :: consolidate_yxml :: edits_yxml => | 
| 68336 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 78 | Document.change_state (fn state => | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 79 | let | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 80 | val old_id = Document_ID.parse old_id_string; | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 81 | val new_id = Document_ID.parse new_id_string; | 
| 69849 | 82 | val consolidate = | 
| 83 | YXML.parse_body consolidate_yxml |> | |
| 84 | let open XML.Decode in list string end; | |
| 68336 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 85 | val edits = | 
| 69849 | 86 | edits_yxml |> map (YXML.parse_body #> | 
| 68336 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 87 | let open XML.Decode in | 
| 69849 | 88 | pair string | 
| 68336 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 89 | (variant | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 90 | [fn ([], a) => Document.Edits (list (pair (option int) (option int)) a), | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 91 | fn ([], a) => | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 92 | let | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 93 | val (master, (name, (imports, (keywords, errors)))) = | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 94 | pair string (pair string (pair (list string) | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 95 | (pair (list (pair string | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 96 | (pair (pair string (list string)) (list string)))) | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 97 | (list YXML.string_of_body)))) a; | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 98 | val imports' = map (rpair Position.none) imports; | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 99 | val keywords' = map (fn (x, y) => ((x, Position.none), y)) keywords; | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 100 | val header = Thy_Header.make (name, Position.none) imports' keywords'; | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 101 |                         in Document.Deps {master = master, header = header, errors = errors} end,
 | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 102 | fn (a :: b, c) => | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 103 | Document.Perspective (bool_atom a, map int_atom b, | 
| 69849 | 104 | list (pair int (pair string (list string))) c)]) | 
| 105 | end); | |
| 47404 
e6e5750f1311
simplified Future.cancel/cancel_group (again) -- running threads only;
 wenzelm parents: 
47388diff
changeset | 106 | |
| 68336 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 107 | val _ = Execution.discontinue (); | 
| 38412 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 108 | |
| 70284 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 wenzelm parents: 
69849diff
changeset | 109 | val (edited, removed, assign_update, state') = | 
| 68336 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 110 | Document.update old_id new_id edits consolidate state; | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 111 | val _ = | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 112 | (singleton o Future.forks) | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 113 |                {name = "Document.update/remove", group = NONE,
 | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 114 | deps = Execution.snapshot removed, | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 115 | pri = Task_Queue.urgent_pri + 2, interrupts = false} | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 116 | (fn () => (Execution.purge removed; List.app Isabelle_Process.reset_tracing removed)); | 
| 52601 | 117 | |
| 68336 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 118 | val _ = | 
| 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 119 | Output.protocol_message Markup.assign_update | 
| 70284 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 wenzelm parents: 
69849diff
changeset | 120 | ((new_id, edited, assign_update) |> | 
| 69846 | 121 | let | 
| 122 | open XML.Encode; | |
| 123 | fun encode_upd (a, bs) = | |
| 124 | string (space_implode "," (map Value.print_int (a :: bs))); | |
| 70284 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 wenzelm parents: 
69849diff
changeset | 125 | in triple int (list string) (list encode_upd) end | 
| 69845 | 126 | |> YXML.chunks_of_body); | 
| 68336 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
67493diff
changeset | 127 | 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 | 128 | |
| 43748 | 129 | val _ = | 
| 46119 
0d7172a7672c
tuned signature -- emphasize special nature of protocol commands;
 wenzelm parents: 
45709diff
changeset | 130 | Isabelle_Process.protocol_command "Document.remove_versions" | 
| 44673 | 131 | (fn [versions_yxml] => Document.change_state (fn state => | 
| 132 | let | |
| 133 | val versions = | |
| 134 | YXML.parse_body versions_yxml |> | |
| 135 | let open XML.Decode in list int end; | |
| 44676 | 136 | 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: 
54717diff
changeset | 137 | val _ = Output.protocol_message Markup.removed_versions [versions_yxml]; | 
| 44676 | 138 | in state1 end)); | 
| 44673 | 139 | |
| 140 | val _ = | |
| 50498 | 141 | Isabelle_Process.protocol_command "Document.dialog_result" | 
| 50500 
c94bba7906d2
identify dialogs via official serial and maintain as result message;
 wenzelm parents: 
50498diff
changeset | 142 | (fn [serial, result] => | 
| 63806 | 143 | Active.dialog_result (Value.parse_int serial) result | 
| 62505 | 144 | handle exn => if Exn.is_interrupt exn then () (*sic!*) else Exn.reraise exn); | 
| 50498 | 145 | |
| 56616 
abc2da18d08d
added protocol command "use_theories", with core functionality of batch build;
 wenzelm parents: 
56458diff
changeset | 146 | val _ = | 
| 62467 | 147 | Isabelle_Process.protocol_command "ML_Heap.share_common_data" | 
| 148 | (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: 
56616diff
changeset | 149 | |
| 38412 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 150 | end; | 
| 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 151 |