| author | blanchet |
| Thu, 13 Mar 2014 16:21:09 +0100 | |
| changeset 56112 | 040424c3800d |
| parent 55801 | 28b59620f0d0 |
| child 56208 | 06cc31dff138 |
| permissions | -rw-r--r-- |
| 36676 | 1 |
/* Title: Pure/System/session.scala |
2 |
Author: Makarius |
|
| 38221 | 3 |
Options: :folding=explicit:collapseFolds=1: |
| 36676 | 4 |
|
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
5 |
Main Isabelle/Scala session, potentially with running prover process. |
| 36676 | 6 |
*/ |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
7 |
|
|
34871
e596a0b71f3c
incorporate "proofdocument" part into main Isabelle/Pure.jar -- except for html_panel.scala, which depends on external library (Lobo/Cobra browser);
wenzelm
parents:
34859
diff
changeset
|
8 |
package isabelle |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
9 |
|
|
44733
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
10 |
|
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
11 |
import java.util.{Timer, TimerTask}
|
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
12 |
|
|
44733
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
13 |
import scala.collection.mutable |
|
46771
06a9b24c4a36
explicit syslog_limit reduces danger of low-level message flooding;
wenzelm
parents:
46739
diff
changeset
|
14 |
import scala.collection.immutable.Queue |
|
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
15 |
import scala.actors.TIMEOUT |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
16 |
import scala.actors.Actor._ |
|
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
17 |
|
|
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
18 |
|
| 34791 | 19 |
object Session |
20 |
{
|
|
|
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
21 |
/* events */ |
|
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
22 |
|
| 43716 | 23 |
//{{{
|
|
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50566
diff
changeset
|
24 |
case class Statistics(props: Properties.T) |
| 50117 | 25 |
case class Global_Options(options: Options) |
| 44805 | 26 |
case object Caret_Focus |
|
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
27 |
case class Raw_Edits(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text]) |
| 52531 | 28 |
case class Dialog_Result(id: Document_ID.Generic, serial: Long, result: String) |
|
47027
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
29 |
case class Commands_Changed( |
|
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
30 |
assignment: Boolean, nodes: Set[Document.Node.Name], commands: Set[Command]) |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
31 |
|
|
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
32 |
sealed abstract class Phase |
|
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
33 |
case object Inactive extends Phase |
| 39701 | 34 |
case object Startup extends Phase // transient |
35 |
case object Failed extends Phase |
|
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
36 |
case object Ready extends Phase |
| 39701 | 37 |
case object Shutdown extends Phase // transient |
| 43716 | 38 |
//}}} |
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
39 |
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
40 |
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
41 |
/* protocol handlers */ |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
42 |
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
43 |
type Prover = Isabelle_Process with Protocol |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
44 |
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
45 |
abstract class Protocol_Handler |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
46 |
{
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
47 |
def stop(prover: Prover): Unit = {}
|
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
48 |
val functions: Map[String, (Prover, Isabelle_Process.Protocol_Output) => Boolean] |
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
49 |
} |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
50 |
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
51 |
class Protocol_Handlers( |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
52 |
handlers: Map[String, Session.Protocol_Handler] = Map.empty, |
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
53 |
functions: Map[String, Isabelle_Process.Protocol_Output => Boolean] = Map.empty) |
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
54 |
{
|
|
53054
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
55 |
def get(name: String): Option[Protocol_Handler] = handlers.get(name) |
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
56 |
|
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
57 |
def add(prover: Prover, name: String): Protocol_Handlers = |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
58 |
{
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
59 |
val (handlers1, functions1) = |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
60 |
handlers.get(name) match {
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
61 |
case Some(old_handler) => |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
62 |
System.err.println("Redefining protocol handler: " + name)
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
63 |
old_handler.stop(prover) |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
64 |
(handlers - name, functions -- old_handler.functions.keys) |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
65 |
case None => (handlers, functions) |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
66 |
} |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
67 |
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
68 |
val (handlers2, functions2) = |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
69 |
try {
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
70 |
val new_handler = Class.forName(name).newInstance.asInstanceOf[Protocol_Handler] |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
71 |
val new_functions = |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
72 |
for ((a, f) <- new_handler.functions.toList) yield |
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
73 |
(a, (msg: Isabelle_Process.Protocol_Output) => f(prover, msg)) |
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
74 |
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
75 |
val dups = for ((a, _) <- new_functions if functions1.isDefinedAt(a)) yield a |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
76 |
if (!dups.isEmpty) error("Duplicate protocol functions: " + commas_quote(dups))
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
77 |
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
78 |
(handlers1 + (name -> new_handler), functions1 ++ new_functions) |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
79 |
} |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
80 |
catch {
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
81 |
case exn: Throwable => |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
82 |
System.err.println("Failed to initialize protocol handler: " +
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
83 |
name + "\n" + Exn.message(exn)) |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
84 |
(handlers1, functions1) |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
85 |
} |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
86 |
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
87 |
new Protocol_Handlers(handlers2, functions2) |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
88 |
} |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
89 |
|
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
90 |
def invoke(msg: Isabelle_Process.Protocol_Output): Boolean = |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
91 |
msg.properties match {
|
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
92 |
case Markup.Function(a) if functions.isDefinedAt(a) => |
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
93 |
try { functions(a)(msg) }
|
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
94 |
catch {
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
95 |
case exn: Throwable => |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
96 |
System.err.println("Failed invocation of protocol function: " +
|
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
97 |
quote(a) + "\n" + Exn.message(exn)) |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
98 |
false |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
99 |
} |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
100 |
case _ => false |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
101 |
} |
| 52113 | 102 |
|
103 |
def stop(prover: Prover): Protocol_Handlers = |
|
104 |
{
|
|
105 |
for ((_, handler) <- handlers) handler.stop(prover) |
|
106 |
new Protocol_Handlers() |
|
107 |
} |
|
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
108 |
} |
| 34791 | 109 |
} |
110 |
||
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
111 |
|
|
48870
4accee106f0f
clarified initialization of Thy_Load, Thy_Info, Session;
wenzelm
parents:
48794
diff
changeset
|
112 |
class Session(val thy_load: Thy_Load) |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
113 |
{
|
| 47653 | 114 |
/* global flags */ |
115 |
||
116 |
@volatile var timing: Boolean = false |
|
117 |
@volatile var verbose: Boolean = false |
|
118 |
||
119 |
||
| 49288 | 120 |
/* tuning parameters */ |
121 |
||
122 |
def output_delay: Time = Time.seconds(0.1) // prover output (markup, common messages) |
|
|
52800
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents:
52766
diff
changeset
|
123 |
def message_delay: Time = Time.seconds(0.1) // prover input/output messages |
|
49293
afcccb9bfa3b
prefer tuning parameters as public methods (again) -- to allow overriding in applications;
wenzelm
parents:
49288
diff
changeset
|
124 |
def prune_delay: Time = Time.seconds(60.0) // prune history -- delete old versions |
|
afcccb9bfa3b
prefer tuning parameters as public methods (again) -- to allow overriding in applications;
wenzelm
parents:
49288
diff
changeset
|
125 |
def prune_size: Int = 0 // size of retained history |
|
afcccb9bfa3b
prefer tuning parameters as public methods (again) -- to allow overriding in applications;
wenzelm
parents:
49288
diff
changeset
|
126 |
def syslog_limit: Int = 100 |
|
49524
68796a77c42b
Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
wenzelm
parents:
49523
diff
changeset
|
127 |
def reparse_limit: Int = 0 |
| 37849 | 128 |
|
129 |
||
| 34809 | 130 |
/* pervasive event buses */ |
131 |
||
|
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
50363
diff
changeset
|
132 |
val statistics = new Event_Bus[Session.Statistics] |
| 50117 | 133 |
val global_options = new Event_Bus[Session.Global_Options] |
| 44805 | 134 |
val caret_focus = new Event_Bus[Session.Caret_Focus.type] |
|
49196
1d63ceb0d177
postpone update of text overview panel after incoming session edits, to improve reactivity of editing massive theories like src/HOL/Multivariate_Analysis;
wenzelm
parents:
48999
diff
changeset
|
135 |
val raw_edits = new Event_Bus[Session.Raw_Edits] |
| 43716 | 136 |
val commands_changed = new Event_Bus[Session.Commands_Changed] |
137 |
val phase_changed = new Event_Bus[Session.Phase] |
|
|
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
138 |
val syslog_messages = new Event_Bus[Isabelle_Process.Output] |
|
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
139 |
val raw_output_messages = new Event_Bus[Isabelle_Process.Output] |
| 46774 | 140 |
val all_messages = new Event_Bus[Isabelle_Process.Message] // potential bottle-neck |
|
55316
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
55134
diff
changeset
|
141 |
val trace_events = new Event_Bus[Simplifier_Trace.Event.type] |
| 34809 | 142 |
|
143 |
||
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
144 |
/** buffered command changes (delay_first discipline) **/ |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
145 |
|
| 43716 | 146 |
//{{{
|
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
147 |
private case object Stop |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
148 |
|
|
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
149 |
private val (_, commands_changed_buffer) = |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
150 |
Simple_Thread.actor("commands_changed_buffer", daemon = true)
|
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
151 |
{
|
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
152 |
var finished = false |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
153 |
while (!finished) {
|
|
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
154 |
receive {
|
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
155 |
case Stop => finished = true; reply(()) |
|
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
156 |
case changed: Session.Commands_Changed => commands_changed.event(changed) |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
157 |
case bad => System.err.println("commands_changed_buffer: ignoring bad message " + bad)
|
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
158 |
} |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
159 |
} |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
160 |
} |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
161 |
//}}} |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
162 |
|
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
163 |
|
|
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
164 |
/** pipelined change parsing **/ |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
165 |
|
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
166 |
//{{{
|
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
167 |
private case class Text_Edits( |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
168 |
previous: Future[Document.Version], |
|
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
169 |
doc_blobs: Document.Blobs, |
|
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
170 |
text_edits: List[Document.Edit_Text], |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
171 |
version_result: Promise[Document.Version]) |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
172 |
|
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
173 |
private val (_, change_parser) = Simple_Thread.actor("change_parser", daemon = true)
|
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
174 |
{
|
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
175 |
var finished = false |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
176 |
while (!finished) {
|
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
177 |
receive {
|
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
178 |
case Stop => finished = true; reply(()) |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
179 |
|
|
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
180 |
case Text_Edits(previous, doc_blobs, text_edits, version_result) => |
|
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
181 |
val prev = previous.get_finished |
|
55134
1b67b17cdad5
propagate update of outer syntax keywords: global propertiesChanged, buffer TokenMarker.markTokens, text area repainting;
wenzelm
parents:
54559
diff
changeset
|
182 |
val (syntax_changed, doc_edits, version) = |
|
50566
b43c4f660320
tuned signature: use thy_load to adapt to prover/editor specific view on sources;
wenzelm
parents:
50501
diff
changeset
|
183 |
Timing.timeit("Thy_Load.text_edits", timing) {
|
|
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
184 |
thy_load.text_edits(reparse_limit, prev, doc_blobs, text_edits) |
| 47653 | 185 |
} |
|
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
186 |
version_result.fulfill(version) |
|
55134
1b67b17cdad5
propagate update of outer syntax keywords: global propertiesChanged, buffer TokenMarker.markTokens, text area repainting;
wenzelm
parents:
54559
diff
changeset
|
187 |
sender ! Change(doc_blobs, syntax_changed, doc_edits, prev, version) |
|
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
188 |
|
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
189 |
case bad => System.err.println("change_parser: ignoring bad message " + bad)
|
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
190 |
} |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
191 |
} |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
192 |
} |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
193 |
//}}} |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
194 |
|
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
195 |
|
| 47653 | 196 |
|
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
197 |
/** main protocol actor **/ |
| 34809 | 198 |
|
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
199 |
/* global state */ |
| 43644 | 200 |
|
|
46771
06a9b24c4a36
explicit syslog_limit reduces danger of low-level message flooding;
wenzelm
parents:
46739
diff
changeset
|
201 |
private val syslog = Volatile(Queue.empty[XML.Elem]) |
|
49416
1053a564dd25
some actual rich text markup via XML.content_markup;
wenzelm
parents:
49293
diff
changeset
|
202 |
def current_syslog(): String = cat_lines(syslog().iterator.map(XML.content)) |
|
39626
a5d0bcfb95a3
manage persistent syslog via Session, not Isabelle_Process;
wenzelm
parents:
39625
diff
changeset
|
203 |
|
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
204 |
@volatile private var _phase: Session.Phase = Session.Inactive |
| 39633 | 205 |
private def phase_=(new_phase: Session.Phase) |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
206 |
{
|
|
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
207 |
_phase = new_phase |
| 39701 | 208 |
phase_changed.event(new_phase) |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
209 |
} |
| 43716 | 210 |
def phase = _phase |
| 43553 | 211 |
def is_ready: Boolean = phase == Session.Ready |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
212 |
|
| 45248 | 213 |
private val global_state = Volatile(Document.State.init) |
| 43719 | 214 |
def current_state(): Document.State = global_state() |
|
46944
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
215 |
|
|
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
216 |
def recent_syntax(): Outer_Syntax = |
|
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
217 |
{
|
|
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
218 |
val version = current_state().recent_finished.version.get_finished |
|
48870
4accee106f0f
clarified initialization of Thy_Load, Thy_Info, Session;
wenzelm
parents:
48794
diff
changeset
|
219 |
if (version.is_init) thy_load.base_syntax |
|
46944
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
220 |
else version.syntax |
|
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
221 |
} |
|
34816
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34815
diff
changeset
|
222 |
|
| 44960 | 223 |
def snapshot(name: Document.Node.Name = Document.Node.Name.empty, |
224 |
pending_edits: List[Text.Edit] = Nil): Document.Snapshot = |
|
| 43719 | 225 |
global_state().snapshot(name, pending_edits) |
| 43716 | 226 |
|
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
227 |
|
|
53054
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
228 |
/* protocol handlers */ |
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
229 |
|
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
230 |
@volatile private var _protocol_handlers = new Session.Protocol_Handlers() |
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
231 |
|
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
232 |
def protocol_handler(name: String): Option[Session.Protocol_Handler] = |
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
233 |
_protocol_handlers.get(name) |
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
234 |
|
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
235 |
|
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
236 |
/* theory files */ |
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
237 |
|
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48422
diff
changeset
|
238 |
def header_edit(name: Document.Node.Name, header: Document.Node.Header): Document.Edit_Text = |
|
44442
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
239 |
{
|
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48422
diff
changeset
|
240 |
val header1 = |
|
48870
4accee106f0f
clarified initialization of Thy_Load, Thy_Info, Session;
wenzelm
parents:
48794
diff
changeset
|
241 |
if (thy_load.loaded_theories(name.theory)) |
| 54559 | 242 |
header.error("Cannot update finished theory " + quote(name.theory))
|
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48422
diff
changeset
|
243 |
else header |
|
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48422
diff
changeset
|
244 |
(name, Document.Node.Deps(header1)) |
|
44442
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
245 |
} |
|
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
246 |
|
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
247 |
|
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
248 |
/* actor messages */ |
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
249 |
|
|
48870
4accee106f0f
clarified initialization of Thy_Load, Thy_Info, Session;
wenzelm
parents:
48794
diff
changeset
|
250 |
private case class Start(args: List[String]) |
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52800
diff
changeset
|
251 |
private case class Cancel_Exec(exec_id: Document_ID.Exec) |
| 47629 | 252 |
private case class Change( |
|
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
253 |
doc_blobs: Document.Blobs, |
|
55134
1b67b17cdad5
propagate update of outer syntax keywords: global propertiesChanged, buffer TokenMarker.markTokens, text area repainting;
wenzelm
parents:
54559
diff
changeset
|
254 |
syntax_changed: Boolean, |
| 43722 | 255 |
doc_edits: List[Document.Edit_Command], |
256 |
previous: Document.Version, |
|
257 |
version: Document.Version) |
|
|
53054
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
258 |
private case class Protocol_Command(name: String, args: List[String]) |
|
44733
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
259 |
private case class Messages(msgs: List[Isabelle_Process.Message]) |
|
52084
573e80625c78
more explicit Session.update_options as source of Global_Options event;
wenzelm
parents:
51818
diff
changeset
|
260 |
private case class Update_Options(options: Options) |
| 41534 | 261 |
|
| 39572 | 262 |
private val (_, session_actor) = Simple_Thread.actor("session_actor", daemon = true)
|
|
38639
f642faca303e
main session actor as independent thread, to avoid starvation via regular worker pool;
wenzelm
parents:
38569
diff
changeset
|
263 |
{
|
| 43648 | 264 |
val this_actor = self |
| 34809 | 265 |
|
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
266 |
var prune_next = System.currentTimeMillis() + prune_delay.ms |
| 49470 | 267 |
|
| 34809 | 268 |
|
|
44733
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
269 |
/* buffered prover messages */ |
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
270 |
|
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
271 |
object receiver |
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
272 |
{
|
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
273 |
private var buffer = new mutable.ListBuffer[Isabelle_Process.Message] |
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
274 |
|
|
52800
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents:
52766
diff
changeset
|
275 |
private def flush(): Unit = synchronized {
|
|
44733
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
276 |
if (!buffer.isEmpty) {
|
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
277 |
val msgs = buffer.toList |
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
278 |
this_actor ! Messages(msgs) |
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
279 |
buffer = new mutable.ListBuffer[Isabelle_Process.Message] |
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
280 |
} |
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
281 |
} |
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
282 |
def invoke(msg: Isabelle_Process.Message): Unit = synchronized {
|
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
283 |
msg match {
|
|
52800
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents:
52766
diff
changeset
|
284 |
case _: Isabelle_Process.Input => |
|
1baa5d19ac44
less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents:
52766
diff
changeset
|
285 |
buffer += msg |
|
54443
9714b5474f39
more distinctive Isabelle_Process.Output vs. Isabelle_Process.Protocol_Output;
wenzelm
parents:
54442
diff
changeset
|
286 |
case output: Isabelle_Process.Protocol_Output if output.properties == Markup.Flush => |
|
9714b5474f39
more distinctive Isabelle_Process.Output vs. Isabelle_Process.Protocol_Output;
wenzelm
parents:
54442
diff
changeset
|
287 |
flush() |
|
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
288 |
case output: Isabelle_Process.Output => |
|
54443
9714b5474f39
more distinctive Isabelle_Process.Output vs. Isabelle_Process.Protocol_Output;
wenzelm
parents:
54442
diff
changeset
|
289 |
buffer += msg |
|
9714b5474f39
more distinctive Isabelle_Process.Output vs. Isabelle_Process.Protocol_Output;
wenzelm
parents:
54442
diff
changeset
|
290 |
if (output.is_syslog) |
|
9714b5474f39
more distinctive Isabelle_Process.Output vs. Isabelle_Process.Protocol_Output;
wenzelm
parents:
54442
diff
changeset
|
291 |
syslog >> (queue => |
|
9714b5474f39
more distinctive Isabelle_Process.Output vs. Isabelle_Process.Protocol_Output;
wenzelm
parents:
54442
diff
changeset
|
292 |
{
|
|
9714b5474f39
more distinctive Isabelle_Process.Output vs. Isabelle_Process.Protocol_Output;
wenzelm
parents:
54442
diff
changeset
|
293 |
val queue1 = queue.enqueue(output.message) |
|
9714b5474f39
more distinctive Isabelle_Process.Output vs. Isabelle_Process.Protocol_Output;
wenzelm
parents:
54442
diff
changeset
|
294 |
if (queue1.length > syslog_limit) queue1.dequeue._2 else queue1 |
|
9714b5474f39
more distinctive Isabelle_Process.Output vs. Isabelle_Process.Protocol_Output;
wenzelm
parents:
54442
diff
changeset
|
295 |
}) |
|
44733
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
296 |
} |
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
297 |
} |
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
298 |
|
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
299 |
private val timer = new Timer("session_actor.receiver", true)
|
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
300 |
timer.schedule(new TimerTask { def run = flush }, message_delay.ms, message_delay.ms)
|
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
301 |
|
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
302 |
def cancel() { timer.cancel() }
|
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
303 |
} |
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
304 |
|
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
305 |
var prover: Option[Session.Prover] = None |
|
44733
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
306 |
|
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
307 |
|
|
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
308 |
/* delayed command changes */ |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
309 |
|
| 46570 | 310 |
object delay_commands_changed |
|
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
311 |
{
|
|
47027
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
312 |
private var changed_assignment: Boolean = false |
|
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
313 |
private var changed_nodes: Set[Document.Node.Name] = Set.empty |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
314 |
private var changed_commands: Set[Command] = Set.empty |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
315 |
|
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
316 |
private var flush_time: Option[Long] = None |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
317 |
|
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
318 |
def flush_timeout: Long = |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
319 |
flush_time match {
|
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
320 |
case None => 5000L |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
321 |
case Some(time) => (time - System.currentTimeMillis()) max 0 |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
322 |
} |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
323 |
|
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
324 |
def flush() |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
325 |
{
|
|
47027
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
326 |
if (changed_assignment || !changed_nodes.isEmpty || !changed_commands.isEmpty) |
|
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
327 |
commands_changed_buffer ! |
|
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
328 |
Session.Commands_Changed(changed_assignment, changed_nodes, changed_commands) |
|
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
329 |
changed_assignment = false |
|
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
330 |
changed_nodes = Set.empty |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
331 |
changed_commands = Set.empty |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
332 |
flush_time = None |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
333 |
} |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
334 |
|
|
47027
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
335 |
def invoke(assign: Boolean, commands: List[Command]) |
|
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
336 |
{
|
|
47027
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
337 |
changed_assignment |= assign |
|
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
338 |
for (command <- commands) {
|
|
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
339 |
changed_nodes += command.node_name |
|
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
340 |
changed_commands += command |
|
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
46944
diff
changeset
|
341 |
} |
|
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
342 |
val now = System.currentTimeMillis() |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
343 |
flush_time match {
|
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
344 |
case None => flush_time = Some(now + output_delay.ms) |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
345 |
case Some(time) => if (now >= time) flush() |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
346 |
} |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
347 |
} |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
348 |
} |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
349 |
|
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
350 |
|
|
52649
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
351 |
/* raw edits */ |
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
352 |
|
|
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
353 |
def handle_raw_edits(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text]) |
|
52649
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
354 |
//{{{
|
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
355 |
{
|
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
356 |
prover.get.discontinue_execution() |
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
357 |
|
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
358 |
val previous = global_state().history.tip.version |
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
359 |
val version = Future.promise[Document.Version] |
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
360 |
val change = global_state >>> (_.continue_history(previous, edits, version)) |
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
361 |
|
|
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
362 |
raw_edits.event(Session.Raw_Edits(doc_blobs, edits)) |
|
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
363 |
change_parser ! Text_Edits(previous, doc_blobs, edits, version) |
|
52649
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
364 |
} |
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
365 |
//}}} |
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
366 |
|
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
367 |
|
| 43716 | 368 |
/* resulting changes */ |
| 34809 | 369 |
|
| 47629 | 370 |
def handle_change(change: Change) |
| 38221 | 371 |
//{{{
|
| 34809 | 372 |
{
|
|
55134
1b67b17cdad5
propagate update of outer syntax keywords: global propertiesChanged, buffer TokenMarker.markTokens, text area repainting;
wenzelm
parents:
54559
diff
changeset
|
373 |
val Change(doc_blobs, syntax_changed, doc_edits, previous, version) = change |
|
38366
fea82d1add74
simplified/clarified Change: transition prev --edits--> result, based on futures;
wenzelm
parents:
38365
diff
changeset
|
374 |
|
| 44383 | 375 |
def id_command(command: Command) |
| 43720 | 376 |
{
|
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
377 |
for {
|
|
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
378 |
digest <- command.blobs_digests |
|
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
379 |
if !global_state().defined_blob(digest) |
|
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
380 |
} {
|
| 55801 | 381 |
doc_blobs.get(digest) match {
|
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
382 |
case Some(blob) => |
|
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
383 |
global_state >> (_.define_blob(digest)) |
|
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
384 |
prover.get.define_blob(blob) |
| 55783 | 385 |
case None => |
386 |
System.err.println("Missing blob for SHA1 digest " + digest)
|
|
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
387 |
} |
|
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
388 |
} |
|
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
389 |
|
| 44582 | 390 |
if (!global_state().defined_command(command.id)) {
|
| 46687 | 391 |
global_state >> (_.define_command(command)) |
|
44644
317e4962dd0f
clarified define_command: store name as structural information;
wenzelm
parents:
44616
diff
changeset
|
392 |
prover.get.define_command(command) |
| 43720 | 393 |
} |
394 |
} |
|
| 44383 | 395 |
doc_edits foreach {
|
396 |
case (_, edit) => |
|
397 |
edit foreach { case (c1, c2) => c1 foreach id_command; c2 foreach id_command }
|
|
398 |
} |
|
| 43722 | 399 |
|
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
400 |
val assignment = global_state().the_assignment(previous).check_finished |
| 46687 | 401 |
global_state >> (_.define_version(version, assignment)) |
| 44481 | 402 |
prover.get.update(previous.id, version.id, doc_edits) |
|
55134
1b67b17cdad5
propagate update of outer syntax keywords: global propertiesChanged, buffer TokenMarker.markTokens, text area repainting;
wenzelm
parents:
54559
diff
changeset
|
403 |
|
|
1b67b17cdad5
propagate update of outer syntax keywords: global propertiesChanged, buffer TokenMarker.markTokens, text area repainting;
wenzelm
parents:
54559
diff
changeset
|
404 |
if (syntax_changed) thy_load.syntax_changed() |
| 34809 | 405 |
} |
| 38221 | 406 |
//}}} |
| 34809 | 407 |
|
408 |
||
|
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
409 |
/* prover output */ |
| 34809 | 410 |
|
|
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
411 |
def handle_output(output: Isabelle_Process.Output) |
| 38221 | 412 |
//{{{
|
| 34809 | 413 |
{
|
|
51662
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
414 |
def bad_output() |
| 43716 | 415 |
{
|
416 |
if (verbose) |
|
|
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
417 |
System.err.println("Ignoring prover output: " + output.message.toString)
|
| 43716 | 418 |
} |
419 |
||
| 52531 | 420 |
def accumulate(state_id: Document_ID.Generic, message: XML.Elem) |
|
51662
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
421 |
{
|
|
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
422 |
try {
|
|
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
423 |
val st = global_state >>> (_.accumulate(state_id, message)) |
|
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
424 |
delay_commands_changed.invoke(false, List(st.command)) |
|
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
425 |
} |
|
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
426 |
catch {
|
|
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
427 |
case _: Document.State.Fail => bad_output() |
|
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
428 |
} |
|
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
429 |
} |
|
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
430 |
|
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
431 |
output match {
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
432 |
case msg: Isabelle_Process.Protocol_Output => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
433 |
val handled = _protocol_handlers.invoke(msg) |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
434 |
if (!handled) {
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
435 |
msg.properties match {
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
436 |
case Markup.Protocol_Handler(name) => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
437 |
_protocol_handlers = _protocol_handlers.add(prover.get, name) |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
438 |
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
439 |
case Protocol.Command_Timing(state_id, timing) => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
440 |
val message = XML.elem(Markup.STATUS, List(XML.Elem(Markup.Timing(timing), Nil))) |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
441 |
accumulate(state_id, prover.get.xml_cache.elem(message)) |
| 46122 | 442 |
|
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
443 |
case Markup.Assign_Update => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
444 |
msg.text match {
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
445 |
case Protocol.Assign_Update(id, update) => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
446 |
try {
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
447 |
val cmds = global_state >>> (_.assign(id, update)) |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
448 |
delay_commands_changed.invoke(true, cmds) |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
449 |
} |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
450 |
catch { case _: Document.State.Fail => bad_output() }
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
451 |
case _ => bad_output() |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
452 |
} |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
453 |
// FIXME separate timeout event/message!? |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
454 |
if (prover.isDefined && System.currentTimeMillis() > prune_next) {
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
455 |
val old_versions = global_state >>> (_.prune_history(prune_size)) |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
456 |
if (!old_versions.isEmpty) prover.get.remove_versions(old_versions) |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
457 |
prune_next = System.currentTimeMillis() + prune_delay.ms |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
458 |
} |
| 46122 | 459 |
|
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
460 |
case Markup.Removed_Versions => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
461 |
msg.text match {
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
462 |
case Protocol.Removed(removed) => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
463 |
try {
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
464 |
global_state >> (_.removed_versions(removed)) |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
465 |
} |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
466 |
catch { case _: Document.State.Fail => bad_output() }
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
467 |
case _ => bad_output() |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
468 |
} |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
469 |
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
470 |
case Markup.ML_Statistics(props) => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
471 |
statistics.event(Session.Statistics(props)) |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
472 |
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
473 |
case Markup.Task_Statistics(props) => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
474 |
// FIXME |
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
475 |
|
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
476 |
case _ => bad_output() |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
477 |
} |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
478 |
} |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
479 |
case _ => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
480 |
output.properties match {
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
481 |
case Position.Id(state_id) => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
482 |
accumulate(state_id, output.message) |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
483 |
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
484 |
case _ if output.is_init => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
485 |
phase = Session.Ready |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
486 |
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
487 |
case Markup.Return_Code(rc) if output.is_exit => |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
488 |
if (rc == 0) phase = Session.Inactive |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
489 |
else phase = Session.Failed |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
490 |
|
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
491 |
case _ => raw_output_messages.event(output) |
|
44661
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents:
44644
diff
changeset
|
492 |
} |
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
493 |
} |
| 34809 | 494 |
} |
| 38221 | 495 |
//}}} |
| 34809 | 496 |
|
|
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
497 |
|
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
498 |
/* main loop */ |
| 34809 | 499 |
|
| 43716 | 500 |
//{{{
|
|
38639
f642faca303e
main session actor as independent thread, to avoid starvation via regular worker pool;
wenzelm
parents:
38569
diff
changeset
|
501 |
var finished = false |
|
f642faca303e
main session actor as independent thread, to avoid starvation via regular worker pool;
wenzelm
parents:
38569
diff
changeset
|
502 |
while (!finished) {
|
| 46570 | 503 |
receiveWithin(delay_commands_changed.flush_timeout) {
|
504 |
case TIMEOUT => delay_commands_changed.flush() |
|
|
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
505 |
|
|
48870
4accee106f0f
clarified initialization of Thy_Load, Thy_Info, Session;
wenzelm
parents:
48794
diff
changeset
|
506 |
case Start(args) if prover.isEmpty => |
| 39701 | 507 |
if (phase == Session.Inactive || phase == Session.Failed) {
|
508 |
phase = Session.Startup |
|
|
48020
a4f9957878ab
clarified prover startup: no timeout, read stderr more carefully;
wenzelm
parents:
48016
diff
changeset
|
509 |
prover = Some(new Isabelle_Process(receiver.invoke _, args) with Protocol) |
| 39701 | 510 |
} |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
511 |
|
| 39701 | 512 |
case Stop => |
513 |
if (phase == Session.Ready) {
|
|
|
53054
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
514 |
_protocol_handlers = _protocol_handlers.stop(prover.get) |
| 46687 | 515 |
global_state >> (_ => Document.State.init) // FIXME event bus!? |
| 39701 | 516 |
phase = Session.Shutdown |
| 43649 | 517 |
prover.get.terminate |
| 43717 | 518 |
prover = None |
| 39701 | 519 |
phase = Session.Inactive |
520 |
} |
|
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
521 |
finished = true |
|
44733
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
522 |
receiver.cancel() |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
523 |
reply(()) |
|
38850
5c3e5c548f12
session_actor: ignore spurious TIMEOUT (again) -- probably stemming from earlier use of receiveWithin;
wenzelm
parents:
38849
diff
changeset
|
524 |
|
|
52084
573e80625c78
more explicit Session.update_options as source of Global_Options event;
wenzelm
parents:
51818
diff
changeset
|
525 |
case Update_Options(options) if prover.isDefined => |
|
52649
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
526 |
if (is_ready) {
|
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
527 |
prover.get.options(options) |
| 55783 | 528 |
handle_raw_edits(Document.Blobs.empty, Nil) |
|
52649
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
529 |
} |
|
52084
573e80625c78
more explicit Session.update_options as source of Global_Options event;
wenzelm
parents:
51818
diff
changeset
|
530 |
global_options.event(Session.Global_Options(options)) |
|
573e80625c78
more explicit Session.update_options as source of Global_Options event;
wenzelm
parents:
51818
diff
changeset
|
531 |
reply(()) |
| 50117 | 532 |
|
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52800
diff
changeset
|
533 |
case Cancel_Exec(exec_id) if prover.isDefined => |
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52800
diff
changeset
|
534 |
prover.get.cancel_exec(exec_id) |
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52800
diff
changeset
|
535 |
|
|
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
536 |
case Session.Raw_Edits(doc_blobs, edits) if prover.isDefined => |
|
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
537 |
handle_raw_edits(doc_blobs, edits) |
| 43718 | 538 |
reply(()) |
539 |
||
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50499
diff
changeset
|
540 |
case Session.Dialog_Result(id, serial, result) if prover.isDefined => |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50499
diff
changeset
|
541 |
prover.get.dialog_result(serial, result) |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
542 |
handle_output(new Isabelle_Process.Output(Protocol.Dialog_Result(id, serial, result))) |
| 50498 | 543 |
|
|
53054
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
544 |
case Protocol_Command(name, args) if prover.isDefined => |
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
545 |
prover.get.protocol_command(name, args:_*) |
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
546 |
|
|
44733
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
547 |
case Messages(msgs) => |
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
548 |
msgs foreach {
|
|
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
549 |
case input: Isabelle_Process.Input => |
| 46774 | 550 |
all_messages.event(input) |
|
43721
fad8634cee62
echo prover input via raw_messages, for improved protocol tracing;
wenzelm
parents:
43720
diff
changeset
|
551 |
|
|
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
552 |
case output: Isabelle_Process.Output => |
| 48999 | 553 |
if (output.is_stdout || output.is_stderr) raw_output_messages.event(output) |
554 |
else handle_output(output) |
|
|
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
555 |
if (output.is_syslog) syslog_messages.event(output) |
| 46774 | 556 |
all_messages.event(output) |
|
44733
329320fc88df
buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents:
44732
diff
changeset
|
557 |
} |
| 43716 | 558 |
|
| 47629 | 559 |
case change: Change |
|
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
560 |
if prover.isDefined && global_state().is_assigned(change.previous) => |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
561 |
handle_change(change) |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
562 |
|
| 47629 | 563 |
case bad if !bad.isInstanceOf[Change] => |
|
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
564 |
System.err.println("session_actor: ignoring bad message " + bad)
|
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
565 |
} |
|
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
566 |
} |
| 43716 | 567 |
//}}} |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
568 |
} |
|
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
569 |
|
| 34809 | 570 |
|
| 43716 | 571 |
/* actions */ |
| 34809 | 572 |
|
|
48870
4accee106f0f
clarified initialization of Thy_Load, Thy_Info, Session;
wenzelm
parents:
48794
diff
changeset
|
573 |
def start(args: List[String]) |
| 50117 | 574 |
{
|
575 |
session_actor ! Start(args) |
|
576 |
} |
|
| 45076 | 577 |
|
| 50117 | 578 |
def stop() |
579 |
{
|
|
580 |
commands_changed_buffer !? Stop |
|
581 |
change_parser !? Stop |
|
582 |
session_actor !? Stop |
|
583 |
} |
|
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
584 |
|
|
53054
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
585 |
def protocol_command(name: String, args: String*) |
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
586 |
{ session_actor ! Protocol_Command(name, args.toList) }
|
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
587 |
|
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52800
diff
changeset
|
588 |
def cancel_exec(exec_id: Document_ID.Exec) { session_actor ! Cancel_Exec(exec_id) }
|
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52800
diff
changeset
|
589 |
|
|
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
590 |
def update(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text]) |
|
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
591 |
{ if (!edits.isEmpty) session_actor !? Session.Raw_Edits(doc_blobs, edits) }
|
| 50498 | 592 |
|
|
52084
573e80625c78
more explicit Session.update_options as source of Global_Options event;
wenzelm
parents:
51818
diff
changeset
|
593 |
def update_options(options: Options) |
|
573e80625c78
more explicit Session.update_options as source of Global_Options event;
wenzelm
parents:
51818
diff
changeset
|
594 |
{ session_actor !? Update_Options(options) }
|
|
573e80625c78
more explicit Session.update_options as source of Global_Options event;
wenzelm
parents:
51818
diff
changeset
|
595 |
|
| 52531 | 596 |
def dialog_result(id: Document_ID.Generic, serial: Long, result: String) |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50499
diff
changeset
|
597 |
{ session_actor ! Session.Dialog_Result(id, serial, result) }
|
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
598 |
} |