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