author | wenzelm |
Sat, 03 Mar 2012 18:18:39 +0100 | |
changeset 46774 | 38f113b052b1 |
parent 46772 | be21f050eda4 |
child 46941 | c0f776b661fa |
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 |
|
43520
cec9b95fa35d
explicit import java.lang.System to prevent odd scope problems;
wenzelm
parents:
43443
diff
changeset
|
11 |
import java.lang.System |
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
|
12 |
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
|
13 |
|
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
|
14 |
import scala.collection.mutable |
46771
06a9b24c4a36
explicit syslog_limit reduces danger of low-level message flooding;
wenzelm
parents:
46739
diff
changeset
|
15 |
import scala.collection.immutable.Queue |
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
16 |
import scala.actors.TIMEOUT |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
17 |
import scala.actors.Actor._ |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
18 |
|
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
19 |
|
34791 | 20 |
object Session |
21 |
{ |
|
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
22 |
/* events */ |
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
23 |
|
43716 | 24 |
//{{{ |
34791 | 25 |
case object Global_Settings |
44805 | 26 |
case object Caret_Focus |
44615 | 27 |
case class Commands_Changed(nodes: Set[Document.Node.Name], commands: Set[Command]) |
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
28 |
|
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
29 |
sealed abstract class Phase |
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
30 |
case object Inactive extends Phase |
39701 | 31 |
case object Startup extends Phase // transient |
32 |
case object Failed extends Phase |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
33 |
case object Ready extends Phase |
39701 | 34 |
case object Shutdown extends Phase // transient |
43716 | 35 |
//}}} |
34791 | 36 |
} |
37 |
||
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
38 |
|
46739
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
wenzelm
parents:
46737
diff
changeset
|
39 |
class Session(thy_load: Thy_Load = new Thy_Load) |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
40 |
{ |
46771
06a9b24c4a36
explicit syslog_limit reduces danger of low-level message flooding;
wenzelm
parents:
46739
diff
changeset
|
41 |
/* tuning parameters */ // FIXME properties or settings (!?) |
37849 | 42 |
|
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
|
43 |
val message_delay = Time.seconds(0.01) // prover messages |
43716 | 44 |
val input_delay = Time.seconds(0.3) // user input (e.g. text edits, cursor movement) |
45 |
val output_delay = Time.seconds(0.1) // prover output (markup, common messages) |
|
46 |
val update_delay = Time.seconds(0.5) // GUI layout updates |
|
44573
51f8895b9ad9
some dialog for auto loading of required files (still inactive);
wenzelm
parents:
44484
diff
changeset
|
47 |
val load_delay = Time.seconds(0.5) // file load operations (new buffers etc.) |
44676 | 48 |
val prune_delay = Time.seconds(60.0) // prune history -- delete old versions |
49 |
val prune_size = 0 // size of retained history |
|
46771
06a9b24c4a36
explicit syslog_limit reduces danger of low-level message flooding;
wenzelm
parents:
46739
diff
changeset
|
50 |
val syslog_limit = 100 |
37849 | 51 |
|
52 |
||
34809 | 53 |
/* pervasive event buses */ |
54 |
||
55 |
val global_settings = new Event_Bus[Session.Global_Settings.type] |
|
44805 | 56 |
val caret_focus = new Event_Bus[Session.Caret_Focus.type] |
43716 | 57 |
val commands_changed = new Event_Bus[Session.Commands_Changed] |
58 |
val phase_changed = new Event_Bus[Session.Phase] |
|
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
59 |
val syslog_messages = new Event_Bus[Isabelle_Process.Output] |
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
60 |
val raw_output_messages = new Event_Bus[Isabelle_Process.Output] |
46774 | 61 |
val all_messages = new Event_Bus[Isabelle_Process.Message] // potential bottle-neck |
43716 | 62 |
|
34809 | 63 |
|
64 |
||
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
65 |
/** 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
|
66 |
|
43716 | 67 |
//{{{ |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
68 |
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
|
69 |
|
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
70 |
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
|
71 |
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
|
72 |
{ |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
73 |
var finished = false |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
74 |
while (!finished) { |
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
75 |
receive { |
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
80 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
81 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
82 |
//}}} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
83 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
84 |
|
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
85 |
/** 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
|
86 |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
87 |
//{{{ |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
88 |
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
|
89 |
syntax: Outer_Syntax, |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
90 |
name: Document.Node.Name, |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
91 |
previous: Future[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
|
92 |
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
|
93 |
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
|
94 |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
95 |
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
|
96 |
{ |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
97 |
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
|
98 |
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
|
99 |
receive { |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
100 |
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
|
101 |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
102 |
case Text_Edits(syntax, name, previous, text_edits, version_result) => |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
103 |
val prev = previous.get_finished |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
104 |
val (doc_edits, version) = Thy_Syntax.text_edits(syntax, prev, 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
|
105 |
version_result.fulfill(version) |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
106 |
sender ! Change_Node(name, doc_edits, prev, version) |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
107 |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
108 |
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
|
109 |
} |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
110 |
} |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
111 |
} |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
112 |
//}}} |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
113 |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
114 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
115 |
/** main protocol actor **/ |
34809 | 116 |
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
117 |
/* global state */ |
43644 | 118 |
|
43716 | 119 |
@volatile var verbose: Boolean = false |
120 |
||
46626 | 121 |
@volatile private var syntax = Outer_Syntax.init() |
38569 | 122 |
def current_syntax(): Outer_Syntax = syntax |
34809 | 123 |
|
46771
06a9b24c4a36
explicit syslog_limit reduces danger of low-level message flooding;
wenzelm
parents:
46739
diff
changeset
|
124 |
private val syslog = Volatile(Queue.empty[XML.Elem]) |
06a9b24c4a36
explicit syslog_limit reduces danger of low-level message flooding;
wenzelm
parents:
46739
diff
changeset
|
125 |
def current_syslog(): String = cat_lines(syslog().iterator.map(msg => XML.content(msg).mkString)) |
39626
a5d0bcfb95a3
manage persistent syslog via Session, not Isabelle_Process;
wenzelm
parents:
39625
diff
changeset
|
126 |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
127 |
@volatile private var _phase: Session.Phase = Session.Inactive |
39633 | 128 |
private def phase_=(new_phase: Session.Phase) |
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
129 |
{ |
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
130 |
_phase = new_phase |
39701 | 131 |
phase_changed.event(new_phase) |
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
132 |
} |
43716 | 133 |
def phase = _phase |
43553 | 134 |
def is_ready: Boolean = phase == Session.Ready |
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
135 |
|
45248 | 136 |
private val global_state = Volatile(Document.State.init) |
43719 | 137 |
def current_state(): Document.State = global_state() |
34816
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34815
diff
changeset
|
138 |
|
44960 | 139 |
def snapshot(name: Document.Node.Name = Document.Node.Name.empty, |
140 |
pending_edits: List[Text.Edit] = Nil): Document.Snapshot = |
|
43719 | 141 |
global_state().snapshot(name, pending_edits) |
43716 | 142 |
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
143 |
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
144 |
/* theory files */ |
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
145 |
|
44615 | 146 |
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
|
147 |
{ |
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
148 |
val header1: Document.Node_Header = |
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
149 |
header match { |
46737 | 150 |
case Exn.Res(_) if (thy_load.is_loaded(name.theory)) => |
151 |
Exn.Exn(ERROR("Attempt to update loaded theory " + quote(name.theory))) |
|
152 |
case _ => header |
|
44442
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
153 |
} |
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
154 |
(name, Document.Node.Header(header1)) |
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
155 |
} |
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
156 |
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
157 |
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
158 |
/* actor messages */ |
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
159 |
|
45158 | 160 |
private case class Start(timeout: Time, args: List[String]) |
44775
27930cf6f0f7
added "cancel" button based on cancel_execution, not interrupt (cf. 156be0e43336);
wenzelm
parents:
44734
diff
changeset
|
161 |
private case object Cancel_Execution |
44615 | 162 |
private case class Init_Node(name: Document.Node.Name, |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
163 |
header: Document.Node_Header, perspective: Text.Perspective, text: String) |
44615 | 164 |
private case class Edit_Node(name: Document.Node.Name, |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
165 |
header: Document.Node_Header, perspective: Text.Perspective, edits: List[Text.Edit]) |
43722 | 166 |
private case class Change_Node( |
44615 | 167 |
name: Document.Node.Name, |
43722 | 168 |
doc_edits: List[Document.Edit_Command], |
169 |
previous: Document.Version, |
|
170 |
version: Document.Version) |
|
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
|
171 |
private case class Messages(msgs: List[Isabelle_Process.Message]) |
41534 | 172 |
|
39572 | 173 |
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
|
174 |
{ |
43648 | 175 |
val this_actor = self |
34809 | 176 |
|
44676 | 177 |
var prune_next = System.currentTimeMillis() + prune_delay.ms |
178 |
||
34809 | 179 |
|
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
|
180 |
/* 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
|
181 |
|
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
|
182 |
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
|
183 |
{ |
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
|
184 |
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
|
185 |
|
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
|
186 |
def flush(): 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
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
} |
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
|
192 |
} |
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
|
193 |
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
|
194 |
buffer += msg |
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
|
195 |
msg match { |
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
196 |
case output: Isabelle_Process.Output => |
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
197 |
if (output.is_syslog) |
46771
06a9b24c4a36
explicit syslog_limit reduces danger of low-level message flooding;
wenzelm
parents:
46739
diff
changeset
|
198 |
syslog >> (queue => |
06a9b24c4a36
explicit syslog_limit reduces danger of low-level message flooding;
wenzelm
parents:
46739
diff
changeset
|
199 |
{ |
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
200 |
val queue1 = queue.enqueue(output.message) |
46771
06a9b24c4a36
explicit syslog_limit reduces danger of low-level message flooding;
wenzelm
parents:
46739
diff
changeset
|
201 |
if (queue1.length > syslog_limit) queue1.dequeue._2 else queue1 |
06a9b24c4a36
explicit syslog_limit reduces danger of low-level message flooding;
wenzelm
parents:
46739
diff
changeset
|
202 |
}) |
46774 | 203 |
if (output.is_protocol) flush() |
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
|
204 |
case _ => |
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
|
205 |
} |
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
|
206 |
} |
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
|
207 |
|
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
|
208 |
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
|
209 |
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
|
210 |
|
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
|
211 |
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
|
212 |
} |
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
|
213 |
|
45709
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents:
45672
diff
changeset
|
214 |
var prover: Option[Isabelle_Process with Protocol] = 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
|
215 |
|
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
|
216 |
|
44722
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
217 |
/* delayed command changes */ |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
218 |
|
46570 | 219 |
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
|
220 |
{ |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
221 |
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
|
222 |
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
|
223 |
private def changed: Boolean = !changed_nodes.isEmpty || !changed_commands.isEmpty |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
224 |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
225 |
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
|
226 |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
227 |
def flush_timeout: Long = |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
228 |
flush_time match { |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
229 |
case None => 5000L |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
230 |
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
|
231 |
} |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
232 |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
233 |
def flush() |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
234 |
{ |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
235 |
if (changed) |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
236 |
commands_changed_buffer ! Session.Commands_Changed(changed_nodes, changed_commands) |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
237 |
changed_nodes = Set.empty |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
238 |
changed_commands = Set.empty |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
239 |
flush_time = None |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
240 |
} |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
241 |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
242 |
def invoke(command: Command) |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
243 |
{ |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
244 |
changed_nodes += command.node_name |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
245 |
changed_commands += command |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
246 |
val now = System.currentTimeMillis() |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
247 |
flush_time match { |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
248 |
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
|
249 |
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
|
250 |
} |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
251 |
} |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
252 |
} |
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
253 |
|
a8331fb5c959
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm
parents:
44721
diff
changeset
|
254 |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
255 |
/* perspective */ |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
256 |
|
44615 | 257 |
def update_perspective(name: Document.Node.Name, text_perspective: Text.Perspective) |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
258 |
{ |
44475 | 259 |
val previous = global_state().tip_version |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
260 |
val (perspective, version) = Thy_Syntax.edit_perspective(previous, name, text_perspective) |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
261 |
|
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
262 |
val text_edits: List[Document.Edit_Text] = |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
263 |
List((name, Document.Node.Perspective(text_perspective))) |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
264 |
val change = |
46687 | 265 |
global_state >>> |
266 |
(_.continue_history(Future.value(previous), text_edits, Future.value(version))) |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
267 |
|
44477 | 268 |
val assignment = global_state().the_assignment(previous).check_finished |
46687 | 269 |
global_state >> (_.define_version(version, assignment)) |
270 |
global_state >>> (_.assign(version.id)) |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
271 |
|
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
272 |
prover.get.update_perspective(previous.id, version.id, name, perspective) |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
273 |
} |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
274 |
|
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
275 |
|
43716 | 276 |
/* incoming edits */ |
277 |
||
44615 | 278 |
def handle_edits(name: Document.Node.Name, |
44384 | 279 |
header: Document.Node_Header, edits: List[Document.Node.Edit[Text.Edit, Text.Perspective]]) |
43716 | 280 |
//{{{ |
281 |
{ |
|
282 |
val syntax = current_syntax() |
|
43719 | 283 |
val previous = global_state().history.tip.version |
44185 | 284 |
|
44612
990ac978854c
explicit cancel_execution before queueing new edits -- potential performance improvement for machines with few cores;
wenzelm
parents:
44608
diff
changeset
|
285 |
prover.get.cancel_execution() |
990ac978854c
explicit cancel_execution before queueing new edits -- potential performance improvement for machines with few cores;
wenzelm
parents:
44608
diff
changeset
|
286 |
|
44615 | 287 |
val text_edits = header_edit(name, header) :: edits.map(edit => (name, edit)) |
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
288 |
val version = Future.promise[Document.Version] |
46687 | 289 |
val change = global_state >>> (_.continue_history(previous, text_edits, version)) |
43716 | 290 |
|
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
291 |
change_parser ! Text_Edits(syntax, name, previous, text_edits, version) |
43716 | 292 |
} |
293 |
//}}} |
|
294 |
||
295 |
||
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
296 |
/* exec state assignment */ |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
297 |
|
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
298 |
def handle_assign(id: Document.Version_ID, assign: Document.Assign) |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
299 |
//{{{ |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
300 |
{ |
46687 | 301 |
val cmds = global_state >>> (_.assign(id, assign)) |
46570 | 302 |
for (cmd <- cmds) delay_commands_changed.invoke(cmd) |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
303 |
} |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
304 |
//}}} |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
305 |
|
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
306 |
|
44676 | 307 |
/* removed versions */ |
308 |
||
309 |
def handle_removed(removed: List[Document.Version_ID]) |
|
310 |
//{{{ |
|
311 |
{ |
|
46687 | 312 |
global_state >> (_.removed_versions(removed)) |
44676 | 313 |
} |
314 |
//}}} |
|
315 |
||
316 |
||
43716 | 317 |
/* resulting changes */ |
34809 | 318 |
|
43722 | 319 |
def handle_change(change: Change_Node) |
38221 | 320 |
//{{{ |
34809 | 321 |
{ |
43722 | 322 |
val previous = change.previous |
323 |
val version = change.version |
|
324 |
val name = change.name |
|
325 |
val doc_edits = change.doc_edits |
|
38366
fea82d1add74
simplified/clarified Change: transition prev --edits--> result, based on futures;
wenzelm
parents:
38365
diff
changeset
|
326 |
|
44383 | 327 |
def id_command(command: Command) |
43720 | 328 |
{ |
44582 | 329 |
if (!global_state().defined_command(command.id)) { |
46687 | 330 |
global_state >> (_.define_command(command)) |
44644
317e4962dd0f
clarified define_command: store name as structural information;
wenzelm
parents:
44616
diff
changeset
|
331 |
prover.get.define_command(command) |
43720 | 332 |
} |
333 |
} |
|
44383 | 334 |
doc_edits foreach { |
335 |
case (_, edit) => |
|
336 |
edit foreach { case (c1, c2) => c1 foreach id_command; c2 foreach id_command } |
|
337 |
} |
|
43722 | 338 |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
339 |
val assignment = global_state().the_assignment(previous).check_finished |
46687 | 340 |
global_state >> (_.define_version(version, assignment)) |
44481 | 341 |
prover.get.update(previous.id, version.id, doc_edits) |
34809 | 342 |
} |
38221 | 343 |
//}}} |
34809 | 344 |
|
345 |
||
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
346 |
/* prover output */ |
34809 | 347 |
|
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
348 |
def handle_output(output: Isabelle_Process.Output) |
38221 | 349 |
//{{{ |
34809 | 350 |
{ |
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
351 |
def bad_output(output: Isabelle_Process.Output) |
43716 | 352 |
{ |
353 |
if (verbose) |
|
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
354 |
System.err.println("Ignoring prover output: " + output.message.toString) |
43716 | 355 |
} |
356 |
||
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
357 |
output.properties match { |
46122 | 358 |
|
46774 | 359 |
case Position.Id(state_id) if !output.is_protocol => |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38366
diff
changeset
|
360 |
try { |
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
361 |
val st = global_state >>> (_.accumulate(state_id, output.message)) |
46570 | 362 |
delay_commands_changed.invoke(st.command) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38366
diff
changeset
|
363 |
} |
43748 | 364 |
catch { |
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
365 |
case _: Document.State.Fail => bad_output(output) |
43748 | 366 |
} |
46122 | 367 |
|
46774 | 368 |
case Isabelle_Markup.Assign_Execs if output.is_protocol => |
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
369 |
XML.content(output.body).mkString match { |
45709
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents:
45672
diff
changeset
|
370 |
case Protocol.Assign(id, assign) => |
44661
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents:
44644
diff
changeset
|
371 |
try { handle_assign(id, assign) } |
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
372 |
catch { case _: Document.State.Fail => bad_output(output) } |
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
373 |
case _ => bad_output(output) |
44661
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents:
44644
diff
changeset
|
374 |
} |
44676 | 375 |
// FIXME separate timeout event/message!? |
376 |
if (prover.isDefined && System.currentTimeMillis() > prune_next) { |
|
46687 | 377 |
val old_versions = global_state >>> (_.prune_history(prune_size)) |
44676 | 378 |
if (!old_versions.isEmpty) prover.get.remove_versions(old_versions) |
379 |
prune_next = System.currentTimeMillis() + prune_delay.ms |
|
380 |
} |
|
46122 | 381 |
|
46774 | 382 |
case Isabelle_Markup.Removed_Versions if output.is_protocol => |
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
383 |
XML.content(output.body).mkString match { |
45709
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents:
45672
diff
changeset
|
384 |
case Protocol.Removed(removed) => |
44676 | 385 |
try { handle_removed(removed) } |
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
386 |
catch { case _: Document.State.Fail => bad_output(output) } |
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
387 |
case _ => bad_output(output) |
44676 | 388 |
} |
46122 | 389 |
|
46774 | 390 |
case Isabelle_Markup.Invoke_Scala(name, id) if output.is_protocol => |
43748 | 391 |
Future.fork { |
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
392 |
val arg = XML.content(output.body).mkString |
43748 | 393 |
val (tag, res) = Invoke_Scala.method(name, arg) |
394 |
prover.get.invoke_scala(id, tag, res) |
|
395 |
} |
|
46122 | 396 |
|
46774 | 397 |
case Isabelle_Markup.Cancel_Scala(id) if output.is_protocol => |
46121 | 398 |
System.err.println("cancel_scala " + id) // FIXME actually cancel JVM task |
46122 | 399 |
|
46774 | 400 |
case Isabelle_Markup.Ready if output.is_protocol => |
46121 | 401 |
// FIXME move to ML side (!?) |
402 |
syntax += ("hence", Keyword.PRF_ASM_GOAL, "then have") |
|
403 |
syntax += ("thus", Keyword.PRF_ASM_GOAL, "then show") |
|
404 |
phase = Session.Ready |
|
46122 | 405 |
|
46774 | 406 |
case Isabelle_Markup.Loaded_Theory(name) if output.is_protocol => |
46122 | 407 |
thy_load.register_thy(name) |
408 |
||
46774 | 409 |
case Isabelle_Markup.Command_Decl(name, kind) if output.is_protocol => |
46123 | 410 |
syntax += (name, kind) |
411 |
||
46774 | 412 |
case Isabelle_Markup.Keyword_Decl(name) if output.is_protocol => |
46123 | 413 |
syntax += name |
414 |
||
38722
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38639
diff
changeset
|
415 |
case _ => |
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
416 |
if (output.is_exit && phase == Session.Startup) phase = Session.Failed |
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
417 |
else if (output.is_exit) phase = Session.Inactive |
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
418 |
else if (output.is_stdout) { } |
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
419 |
else bad_output(output) |
43748 | 420 |
} |
34809 | 421 |
} |
38221 | 422 |
//}}} |
34809 | 423 |
|
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
424 |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
425 |
/* main loop */ |
34809 | 426 |
|
43716 | 427 |
//{{{ |
38639
f642faca303e
main session actor as independent thread, to avoid starvation via regular worker pool;
wenzelm
parents:
38569
diff
changeset
|
428 |
var finished = false |
f642faca303e
main session actor as independent thread, to avoid starvation via regular worker pool;
wenzelm
parents:
38569
diff
changeset
|
429 |
while (!finished) { |
46570 | 430 |
receiveWithin(delay_commands_changed.flush_timeout) { |
431 |
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
|
432 |
|
45158 | 433 |
case Start(timeout, args) if prover.isEmpty => |
39701 | 434 |
if (phase == Session.Inactive || phase == Session.Failed) { |
435 |
phase = Session.Startup |
|
45709
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents:
45672
diff
changeset
|
436 |
prover = Some(new Isabelle_Process(timeout, receiver.invoke _, args) with Protocol) |
39701 | 437 |
} |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
438 |
|
39701 | 439 |
case Stop => |
440 |
if (phase == Session.Ready) { |
|
46687 | 441 |
global_state >> (_ => Document.State.init) // FIXME event bus!? |
39701 | 442 |
phase = Session.Shutdown |
43649 | 443 |
prover.get.terminate |
43717 | 444 |
prover = None |
39701 | 445 |
phase = Session.Inactive |
446 |
} |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
447 |
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
|
448 |
receiver.cancel() |
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
449 |
reply(()) |
38850
5c3e5c548f12
session_actor: ignore spurious TIMEOUT (again) -- probably stemming from earlier use of receiveWithin;
wenzelm
parents:
38849
diff
changeset
|
450 |
|
44775
27930cf6f0f7
added "cancel" button based on cancel_execution, not interrupt (cf. 156be0e43336);
wenzelm
parents:
44734
diff
changeset
|
451 |
case Cancel_Execution if prover.isDefined => |
27930cf6f0f7
added "cancel" button based on cancel_execution, not interrupt (cf. 156be0e43336);
wenzelm
parents:
44734
diff
changeset
|
452 |
prover.get.cancel_execution() |
43716 | 453 |
|
44615 | 454 |
case Init_Node(name, header, perspective, text) if prover.isDefined => |
43716 | 455 |
// FIXME compare with existing node |
44615 | 456 |
handle_edits(name, header, |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
457 |
List(Document.Node.Clear(), |
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
458 |
Document.Node.Edits(List(Text.Edit.insert(0, text))), |
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
459 |
Document.Node.Perspective(perspective))) |
43716 | 460 |
reply(()) |
461 |
||
44615 | 462 |
case Edit_Node(name, header, perspective, text_edits) if prover.isDefined => |
44484
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44481
diff
changeset
|
463 |
if (text_edits.isEmpty && global_state().tip_stable && |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44481
diff
changeset
|
464 |
perspective.range.stop <= global_state().last_exec_offset(name)) |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44481
diff
changeset
|
465 |
update_perspective(name, perspective) |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44481
diff
changeset
|
466 |
else |
44615 | 467 |
handle_edits(name, header, |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
468 |
List(Document.Node.Edits(text_edits), Document.Node.Perspective(perspective))) |
43718 | 469 |
reply(()) |
470 |
||
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
|
471 |
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
|
472 |
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
|
473 |
case input: Isabelle_Process.Input => |
46774 | 474 |
all_messages.event(input) |
43721
fad8634cee62
echo prover input via raw_messages, for improved protocol tracing;
wenzelm
parents:
43720
diff
changeset
|
475 |
|
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
476 |
case output: Isabelle_Process.Output => |
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
477 |
handle_output(output) |
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
478 |
if (output.is_syslog) syslog_messages.event(output) |
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
479 |
if (output.is_stdout || output.is_stderr) raw_output_messages.event(output) |
46774 | 480 |
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
|
481 |
} |
43716 | 482 |
|
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
483 |
case change: Change_Node |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
484 |
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
|
485 |
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
|
486 |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
487 |
case bad if !bad.isInstanceOf[Change_Node] => |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
488 |
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
|
489 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
490 |
} |
43716 | 491 |
//}}} |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
492 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
493 |
|
34809 | 494 |
|
43716 | 495 |
/* actions */ |
34809 | 496 |
|
45158 | 497 |
def start(timeout: Time, args: List[String]) |
498 |
{ session_actor ! Start(timeout, args) } |
|
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
499 |
|
45158 | 500 |
def start(args: List[String]) { start (Time.seconds(25), args) } |
45076 | 501 |
|
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
502 |
def stop() { commands_changed_buffer !? Stop; change_parser !? Stop; session_actor !? Stop } |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
503 |
|
44775
27930cf6f0f7
added "cancel" button based on cancel_execution, not interrupt (cf. 156be0e43336);
wenzelm
parents:
44734
diff
changeset
|
504 |
def cancel_execution() { session_actor ! Cancel_Execution } |
43648 | 505 |
|
44615 | 506 |
def init_node(name: Document.Node.Name, |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
507 |
header: Document.Node_Header, perspective: Text.Perspective, text: String) |
44615 | 508 |
{ session_actor !? Init_Node(name, header, perspective, text) } |
38221 | 509 |
|
44615 | 510 |
def edit_node(name: Document.Node.Name, |
511 |
header: Document.Node_Header, perspective: Text.Perspective, edits: List[Text.Edit]) |
|
512 |
{ session_actor !? Edit_Node(name, header, perspective, edits) } |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
513 |
} |