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