| author | wenzelm | 
| Sun, 15 Sep 2019 13:37:53 +0200 | |
| changeset 70698 | 93aa546ffbac | 
| parent 70665 | 94442fce40a5 | 
| child 70774 | 64751a7abfa6 | 
| permissions | -rw-r--r-- | 
| 56210 | 1  | 
/* Title: Pure/PIDE/session.scala  | 
| 36676 | 2  | 
Author: Makarius  | 
| 57923 | 3  | 
Options: :folding=explicit:  | 
| 36676 | 4  | 
|
| 56210 | 5  | 
PIDE editor 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  | 
|
| 
46771
 
06a9b24c4a36
explicit syslog_limit reduces danger of low-level message flooding;
 
wenzelm 
parents: 
46739 
diff
changeset
 | 
11  | 
import scala.collection.immutable.Queue  | 
| 
70664
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
12  | 
import scala.collection.mutable  | 
| 
69640
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
13  | 
import scala.annotation.tailrec  | 
| 
34777
 
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
 
wenzelm 
parents:  
diff
changeset
 | 
14  | 
|
| 
34815
 
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
 
wenzelm 
parents: 
34813 
diff
changeset
 | 
15  | 
|
| 34791 | 16  | 
object Session  | 
17  | 
{
 | 
|
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
18  | 
/* outlets */  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
19  | 
|
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
20  | 
object Consumer  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
21  | 
  {
 | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
22  | 
def apply[A](name: String)(consume: A => Unit): Consumer[A] =  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
23  | 
new Consumer[A](name, consume)  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
24  | 
}  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
25  | 
final class Consumer[-A] private(val name: String, val consume: A => Unit)  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
26  | 
|
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
27  | 
class Outlet[A](dispatcher: Consumer_Thread[() => Unit])  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
28  | 
  {
 | 
| 61590 | 29  | 
private val consumers = Synchronized[List[Consumer[A]]](Nil)  | 
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
30  | 
|
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
31  | 
    def += (c: Consumer[A]) { consumers.change(Library.update(c)) }
 | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
32  | 
    def -= (c: Consumer[A]) { consumers.change(Library.remove(c)) }
 | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
33  | 
|
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
34  | 
def post(a: A)  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
35  | 
    {
 | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
36  | 
      for (c <- consumers.value.iterator) {
 | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
37  | 
dispatcher.send(() =>  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
38  | 
          try { c.consume(a) }
 | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
39  | 
          catch {
 | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
40  | 
case exn: Throwable =>  | 
| 
56782
 
433cf57550fa
more systematic Isabelle output, like in classic Isabelle/ML (without markup);
 
wenzelm 
parents: 
56775 
diff
changeset
 | 
41  | 
              Output.error_message("Consumer failed: " + quote(c.name) + "\n" + Exn.message(exn))
 | 
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
42  | 
})  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
43  | 
}  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
44  | 
}  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
45  | 
}  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
46  | 
|
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
47  | 
|
| 56315 | 48  | 
/* change */  | 
49  | 
||
50  | 
sealed case class Change(  | 
|
51  | 
previous: Document.Version,  | 
|
| 
59077
 
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
 
wenzelm 
parents: 
58928 
diff
changeset
 | 
52  | 
syntax_changed: List[Document.Node.Name],  | 
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
53  | 
deps_changed: Boolean,  | 
| 56315 | 54  | 
doc_edits: List[Document.Edit_Command],  | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
55  | 
consolidate: List[Document.Node.Name],  | 
| 
70625
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
56  | 
share_common_data: Boolean,  | 
| 56315 | 57  | 
version: Document.Version)  | 
58  | 
||
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
59  | 
case object Change_Flush  | 
| 
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
60  | 
|
| 56315 | 61  | 
|
| 
34813
 
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
 
wenzelm 
parents: 
34810 
diff
changeset
 | 
62  | 
/* events */  | 
| 
 
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
 
wenzelm 
parents: 
34810 
diff
changeset
 | 
63  | 
|
| 43716 | 64  | 
  //{{{
 | 
| 
50697
 
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
 
wenzelm 
parents: 
50566 
diff
changeset
 | 
65  | 
case class Statistics(props: Properties.T)  | 
| 50117 | 66  | 
case class Global_Options(options: Options)  | 
| 44805 | 67  | 
case object Caret_Focus  | 
| 
70625
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
68  | 
case class Raw_Edits(  | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
69  | 
doc_blobs: Document.Blobs, edits: List[Document.Edit_Text], share_common_data: Boolean)  | 
| 52531 | 70  | 
case class Dialog_Result(id: Document_ID.Generic, serial: Long, result: String)  | 
| 59364 | 71  | 
case class Build_Theories(id: String, master_dir: Path, theories: List[(Options, List[Path])])  | 
| 
47027
 
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
 
wenzelm 
parents: 
46944 
diff
changeset
 | 
72  | 
case class Commands_Changed(  | 
| 
 
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
 
wenzelm 
parents: 
46944 
diff
changeset
 | 
73  | 
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
 | 
74  | 
|
| 
 
44181423183a
explicit Session.Phase indication with associated event bus;
 
wenzelm 
parents: 
39629 
diff
changeset
 | 
75  | 
sealed abstract class Phase  | 
| 65206 | 76  | 
  {
 | 
77  | 
def print: String =  | 
|
78  | 
      this match {
 | 
|
| 65317 | 79  | 
case Terminated(result) => if (result.ok) "finished" else "failed"  | 
| 65206 | 80  | 
case _ => Word.lowercase(this.toString)  | 
81  | 
}  | 
|
82  | 
}  | 
|
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
83  | 
case object Inactive extends Phase // stable  | 
| 39701 | 84  | 
case object Startup extends Phase // transient  | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
85  | 
case object Ready extends Phase // metastable  | 
| 39701 | 86  | 
case object Shutdown extends Phase // transient  | 
| 65317 | 87  | 
case class Terminated(result: Process_Result) extends Phase // stable  | 
| 43716 | 88  | 
//}}}  | 
| 
52111
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
89  | 
|
| 
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
90  | 
|
| 
56775
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
91  | 
/* syslog */  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
92  | 
|
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
93  | 
private[Session] class Syslog(limit: Int)  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
94  | 
  {
 | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
95  | 
private var queue = Queue.empty[XML.Elem]  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
96  | 
private var length = 0  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
97  | 
|
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
98  | 
    def += (msg: XML.Elem): Unit = synchronized {
 | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
99  | 
queue = queue.enqueue(msg)  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
100  | 
length += 1  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
101  | 
if (length > limit) queue = queue.dequeue._2  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
102  | 
}  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
103  | 
|
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
104  | 
    def content: String = synchronized {
 | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
105  | 
cat_lines(queue.iterator.map(XML.content)) +  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
106  | 
(if (length > limit) "\n(A total of " + length + " messages...)" else "")  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
107  | 
}  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
108  | 
}  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
109  | 
|
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
110  | 
|
| 
52111
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
111  | 
/* protocol handlers */  | 
| 
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
112  | 
|
| 
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
113  | 
abstract class Protocol_Handler  | 
| 
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
114  | 
  {
 | 
| 65219 | 115  | 
    def init(session: Session): Unit = {}
 | 
116  | 
    def exit(): Unit = {}
 | 
|
117  | 
val functions: List[(String, Prover.Protocol_Output => Boolean)]  | 
|
| 
52111
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
118  | 
}  | 
| 34791 | 119  | 
}  | 
120  | 
||
| 
34777
 
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
 
wenzelm 
parents:  
diff
changeset
 | 
121  | 
|
| 69492 | 122  | 
class Session(_session_options: => Options, val resources: Resources) extends Document.Session  | 
| 
34777
 
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
 
wenzelm 
parents:  
diff
changeset
 | 
123  | 
{
 | 
| 65214 | 124  | 
session =>  | 
125  | 
||
| 68169 | 126  | 
val xml_cache: XML.Cache = XML.make_cache()  | 
| 68168 | 127  | 
val xz_cache: XZ.Cache = XZ.make_cache()  | 
| 65218 | 128  | 
|
| 65214 | 129  | 
|
| 47653 | 130  | 
/* global flags */  | 
131  | 
||
132  | 
@volatile var timing: Boolean = false  | 
|
133  | 
@volatile var verbose: Boolean = false  | 
|
134  | 
||
135  | 
||
| 
65264
 
7e6ecd04b5fe
dynamic session_options for tuning parameters and initial prover options;
 
wenzelm 
parents: 
65223 
diff
changeset
 | 
136  | 
/* dynamic session options */  | 
| 49288 | 137  | 
|
| 69492 | 138  | 
def session_options: Options = _session_options  | 
139  | 
||
| 
65264
 
7e6ecd04b5fe
dynamic session_options for tuning parameters and initial prover options;
 
wenzelm 
parents: 
65223 
diff
changeset
 | 
140  | 
  def output_delay: Time = session_options.seconds("editor_output_delay")
 | 
| 
66379
 
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
 
wenzelm 
parents: 
66094 
diff
changeset
 | 
141  | 
  def consolidate_delay: Time = session_options.seconds("editor_consolidate_delay")
 | 
| 
65264
 
7e6ecd04b5fe
dynamic session_options for tuning parameters and initial prover options;
 
wenzelm 
parents: 
65223 
diff
changeset
 | 
142  | 
  def prune_delay: Time = session_options.seconds("editor_prune_delay")
 | 
| 
 
7e6ecd04b5fe
dynamic session_options for tuning parameters and initial prover options;
 
wenzelm 
parents: 
65223 
diff
changeset
 | 
143  | 
  def prune_size: Int = session_options.int("editor_prune_size")
 | 
| 
 
7e6ecd04b5fe
dynamic session_options for tuning parameters and initial prover options;
 
wenzelm 
parents: 
65223 
diff
changeset
 | 
144  | 
  def syslog_limit: Int = session_options.int("editor_syslog_limit")
 | 
| 
 
7e6ecd04b5fe
dynamic session_options for tuning parameters and initial prover options;
 
wenzelm 
parents: 
65223 
diff
changeset
 | 
145  | 
  def reparse_limit: Int = session_options.int("editor_reparse_limit")
 | 
| 37849 | 146  | 
|
147  | 
||
| 66094 | 148  | 
/* dispatcher */  | 
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
149  | 
|
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
150  | 
private val dispatcher =  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
151  | 
    Consumer_Thread.fork[() => Unit]("Session.dispatcher", daemon = true) { case e => e(); true }
 | 
| 34809 | 152  | 
|
| 66094 | 153  | 
def assert_dispatcher[A](body: => A): A =  | 
154  | 
  {
 | 
|
155  | 
assert(dispatcher.check_thread)  | 
|
156  | 
body  | 
|
157  | 
}  | 
|
158  | 
||
159  | 
def require_dispatcher[A](body: => A): A =  | 
|
160  | 
  {
 | 
|
161  | 
require(dispatcher.check_thread)  | 
|
162  | 
body  | 
|
163  | 
}  | 
|
164  | 
||
165  | 
def send_dispatcher(body: => Unit): Unit =  | 
|
166  | 
  {
 | 
|
167  | 
if (dispatcher.check_thread) body  | 
|
168  | 
else dispatcher.send(() => body)  | 
|
169  | 
}  | 
|
170  | 
||
171  | 
def send_wait_dispatcher(body: => Unit): Unit =  | 
|
172  | 
  {
 | 
|
173  | 
if (dispatcher.check_thread) body  | 
|
174  | 
else dispatcher.send_wait(() => body)  | 
|
175  | 
}  | 
|
176  | 
||
177  | 
||
178  | 
/* outlets */  | 
|
179  | 
||
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
180  | 
val statistics = new Session.Outlet[Session.Statistics](dispatcher)  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
181  | 
val global_options = new Session.Outlet[Session.Global_Options](dispatcher)  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
182  | 
val caret_focus = new Session.Outlet[Session.Caret_Focus.type](dispatcher)  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
183  | 
val raw_edits = new Session.Outlet[Session.Raw_Edits](dispatcher)  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
184  | 
val commands_changed = new Session.Outlet[Session.Commands_Changed](dispatcher)  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
185  | 
val phase_changed = new Session.Outlet[Session.Phase](dispatcher)  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
186  | 
val syslog_messages = new Session.Outlet[Prover.Output](dispatcher)  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
187  | 
val raw_output_messages = new Session.Outlet[Prover.Output](dispatcher)  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
188  | 
val trace_events = new Session.Outlet[Simplifier_Trace.Event.type](dispatcher)  | 
| 60900 | 189  | 
val debugger_updates = new Session.Outlet[Debugger.Update.type](dispatcher)  | 
| 34809 | 190  | 
|
| 60749 | 191  | 
val all_messages = new Session.Outlet[Prover.Message](dispatcher) // potential bottle-neck!  | 
| 34809 | 192  | 
|
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
193  | 
|
| 56799 | 194  | 
/** main protocol manager **/  | 
| 
45635
 
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
 
wenzelm 
parents: 
45633 
diff
changeset
 | 
195  | 
|
| 56799 | 196  | 
/* internal messages */  | 
| 
45635
 
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
 
wenzelm 
parents: 
45633 
diff
changeset
 | 
197  | 
|
| 
62556
 
c115e69f457f
more abstract Session.start, without prover command-line;
 
wenzelm 
parents: 
62545 
diff
changeset
 | 
198  | 
private case class Start(start_prover: Prover.Receiver => Prover)  | 
| 56799 | 199  | 
private case object Stop  | 
200  | 
private case class Cancel_Exec(exec_id: Document_ID.Exec)  | 
|
201  | 
private case class Protocol_Command(name: String, args: List[String])  | 
|
202  | 
private case class Update_Options(options: Options)  | 
|
| 
66379
 
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
 
wenzelm 
parents: 
66094 
diff
changeset
 | 
203  | 
private case object Consolidate_Execution  | 
| 56799 | 204  | 
private case object Prune_History  | 
| 
45635
 
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
 
wenzelm 
parents: 
45633 
diff
changeset
 | 
205  | 
|
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38722 
diff
changeset
 | 
206  | 
|
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
207  | 
/* phase */  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
208  | 
|
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
209  | 
private def post_phase(new_phase: Session.Phase): Session.Phase =  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
210  | 
  {
 | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
211  | 
phase_changed.post(new_phase)  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
212  | 
new_phase  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
213  | 
}  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
214  | 
private val _phase = Synchronized[Session.Phase](Session.Inactive)  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
215  | 
private def phase_=(new_phase: Session.Phase): Unit = _phase.change(_ => post_phase(new_phase))  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
216  | 
|
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
217  | 
def phase = _phase.value  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
218  | 
def is_ready: Boolean = phase == Session.Ready  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
219  | 
|
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
220  | 
|
| 
43651
 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 
wenzelm 
parents: 
43649 
diff
changeset
 | 
221  | 
/* global state */  | 
| 43644 | 222  | 
|
| 
56775
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
223  | 
private val syslog = new Session.Syslog(syslog_limit)  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
224  | 
def syslog_content(): String = syslog.content  | 
| 
39626
 
a5d0bcfb95a3
manage persistent syslog via Session, not Isabelle_Process;
 
wenzelm 
parents: 
39625 
diff
changeset
 | 
225  | 
|
| 56690 | 226  | 
private val global_state = Synchronized(Document.State.init)  | 
| 56687 | 227  | 
def current_state(): Document.State = global_state.value  | 
| 
46944
 
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
228  | 
|
| 
63584
 
68751fe1c036
tuned signature -- prover-independence is presently theoretical;
 
wenzelm 
parents: 
62556 
diff
changeset
 | 
229  | 
def recent_syntax(name: Document.Node.Name): Outer_Syntax =  | 
| 60934 | 230  | 
global_state.value.recent_finished.version.get_finished.nodes(name).syntax getOrElse  | 
| 66720 | 231  | 
resources.session_base.overall_syntax  | 
| 
34816
 
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
 
wenzelm 
parents: 
34815 
diff
changeset
 | 
232  | 
|
| 
43651
 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 
wenzelm 
parents: 
43649 
diff
changeset
 | 
233  | 
|
| 56799 | 234  | 
/* pipelined change parsing */  | 
235  | 
||
236  | 
private case class Text_Edits(  | 
|
237  | 
previous: Future[Document.Version],  | 
|
238  | 
doc_blobs: Document.Blobs,  | 
|
239  | 
text_edits: List[Document.Edit_Text],  | 
|
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
240  | 
consolidate: List[Document.Node.Name],  | 
| 
70625
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
241  | 
share_common_data: Boolean,  | 
| 56799 | 242  | 
version_result: Promise[Document.Version])  | 
| 
43651
 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 
wenzelm 
parents: 
43649 
diff
changeset
 | 
243  | 
|
| 56799 | 244  | 
  private val change_parser = Consumer_Thread.fork[Text_Edits]("change_parser", daemon = true)
 | 
245  | 
  {
 | 
|
| 
70625
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
246  | 
case Text_Edits(previous, doc_blobs, text_edits, consolidate, share_common_data, version_result) =>  | 
| 56799 | 247  | 
val prev = previous.get_finished  | 
248  | 
val change =  | 
|
249  | 
        Timing.timeit("parse_change", timing) {
 | 
|
| 
70625
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
250  | 
resources.parse_change(  | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
251  | 
reparse_limit, prev, doc_blobs, text_edits, consolidate, share_common_data)  | 
| 56799 | 252  | 
}  | 
253  | 
version_result.fulfill(change.version)  | 
|
254  | 
manager.send(change)  | 
|
255  | 
true  | 
|
256  | 
}  | 
|
| 41534 | 257  | 
|
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
258  | 
|
| 
56719
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
259  | 
/* buffered changes */  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
260  | 
|
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
261  | 
private object change_buffer  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
262  | 
  {
 | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
263  | 
private var assignment: Boolean = false  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
264  | 
private var nodes: Set[Document.Node.Name] = Set.empty  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
265  | 
private var commands: Set[Command] = Set.empty  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
266  | 
|
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
267  | 
    def flush(): Unit = synchronized {
 | 
| 59319 | 268  | 
if (assignment || nodes.nonEmpty || commands.nonEmpty)  | 
| 
56719
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
269  | 
commands_changed.post(Session.Commands_Changed(assignment, nodes, commands))  | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
270  | 
if (nodes.nonEmpty) consolidation.update(nodes)  | 
| 
56719
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
271  | 
assignment = false  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
272  | 
nodes = Set.empty  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
273  | 
commands = Set.empty  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
274  | 
}  | 
| 61556 | 275  | 
    private val delay_flush = Standard_Thread.delay_first(output_delay) { flush() }
 | 
| 
56719
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
276  | 
|
| 
70284
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
277  | 
def invoke(assign: Boolean, edited_nodes: List[Document.Node.Name], cmds: List[Command]): Unit =  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
278  | 
      synchronized {
 | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
279  | 
assignment |= assign  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
280  | 
        for (node <- edited_nodes) {
 | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
281  | 
nodes += node  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
282  | 
}  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
283  | 
        for (command <- cmds) {
 | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
284  | 
nodes += command.node_name  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
285  | 
command.blobs_names.foreach(nodes += _)  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
286  | 
commands += command  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
287  | 
}  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
288  | 
delay_flush.invoke()  | 
| 
56719
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
289  | 
}  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
290  | 
|
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
291  | 
def shutdown()  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
292  | 
    {
 | 
| 
56771
 
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
 
wenzelm 
parents: 
56735 
diff
changeset
 | 
293  | 
delay_flush.revoke()  | 
| 
56719
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
294  | 
flush()  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
295  | 
}  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
296  | 
}  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
297  | 
|
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
298  | 
|
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
299  | 
/* postponed changes */  | 
| 
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
 | 
300  | 
|
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
301  | 
private object postponed_changes  | 
| 
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
302  | 
  {
 | 
| 
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
303  | 
private var postponed: List[Session.Change] = Nil  | 
| 
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
304  | 
|
| 
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
305  | 
    def store(change: Session.Change): Unit = synchronized { postponed ::= change }
 | 
| 
56705
 
937826d702d5
simplified commands_changed_buffer (in contrast to a8331fb5c959): rely on better performance of Consumer_Thread/Mailbox and more direct Timer (like session_actor.receiver);
 
wenzelm 
parents: 
56704 
diff
changeset
 | 
306  | 
|
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
307  | 
    def flush(state: Document.State): List[Session.Change] = synchronized {
 | 
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
308  | 
val (assigned, unassigned) = postponed.partition(change => state.is_assigned(change.previous))  | 
| 
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
309  | 
postponed = unassigned  | 
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
310  | 
assigned.reverse  | 
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
311  | 
}  | 
| 
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
312  | 
}  | 
| 
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
 | 
313  | 
|
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
314  | 
|
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
315  | 
/* node consolidation */  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
316  | 
|
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
317  | 
private object consolidation  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
318  | 
  {
 | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
319  | 
private val delay =  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
320  | 
      Standard_Thread.delay_first(consolidate_delay) { manager.send(Consolidate_Execution) }
 | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
321  | 
|
| 
68807
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
322  | 
private val init_state: Option[Set[Document.Node.Name]] = Some(Set.empty)  | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
323  | 
private val state = Synchronized(init_state)  | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
324  | 
|
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
325  | 
def exit()  | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
326  | 
    {
 | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
327  | 
delay.revoke()  | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
328  | 
state.change(_ => None)  | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
329  | 
}  | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
330  | 
|
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
331  | 
def update(new_nodes: Set[Document.Node.Name] = Set.empty)  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
332  | 
    {
 | 
| 
68807
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
333  | 
val active =  | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
334  | 
state.change_result(st =>  | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
335  | 
(st.isDefined, st.map(nodes => if (nodes.isEmpty) new_nodes else nodes ++ new_nodes)))  | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
336  | 
if (active) delay.invoke()  | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
337  | 
}  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
338  | 
|
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
339  | 
def flush(): Set[Document.Node.Name] =  | 
| 
68807
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
340  | 
state.change_result(st => if (st.isDefined) (st.get, init_state) else (Set.empty, None))  | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
341  | 
}  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
342  | 
|
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
343  | 
|
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
344  | 
/* prover process */  | 
| 
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
345  | 
|
| 
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
346  | 
private object prover  | 
| 
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
347  | 
  {
 | 
| 61590 | 348  | 
private val variable = Synchronized[Option[Prover]](None)  | 
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
349  | 
|
| 
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
350  | 
def defined: Boolean = variable.value.isDefined  | 
| 
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
351  | 
def get: Prover = variable.value.get  | 
| 
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
352  | 
    def set(p: Prover) { variable.change(_ => Some(p)) }
 | 
| 
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
353  | 
    def reset { variable.change(_ => None) }
 | 
| 
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
354  | 
    def await_reset() { variable.guarded_access({ case None => Some((), None) case _ => None }) }
 | 
| 
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
355  | 
}  | 
| 
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
356  | 
|
| 
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
357  | 
|
| 
69488
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
358  | 
/* file formats */  | 
| 
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
359  | 
|
| 
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
360  | 
lazy val file_formats: File_Format.Session =  | 
| 
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
361  | 
resources.file_formats.start_session(session)  | 
| 
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
362  | 
|
| 
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
363  | 
|
| 
59366
 
e94df7f6b608
clarified build_theories: proper protocol handler;
 
wenzelm 
parents: 
59364 
diff
changeset
 | 
364  | 
/* protocol handlers */  | 
| 
 
e94df7f6b608
clarified build_theories: proper protocol handler;
 
wenzelm 
parents: 
59364 
diff
changeset
 | 
365  | 
|
| 65215 | 366  | 
private val protocol_handlers = Protocol_Handlers.init(session)  | 
| 
59366
 
e94df7f6b608
clarified build_theories: proper protocol handler;
 
wenzelm 
parents: 
59364 
diff
changeset
 | 
367  | 
|
| 
 
e94df7f6b608
clarified build_theories: proper protocol handler;
 
wenzelm 
parents: 
59364 
diff
changeset
 | 
368  | 
def get_protocol_handler(name: String): Option[Session.Protocol_Handler] =  | 
| 65214 | 369  | 
protocol_handlers.get(name)  | 
| 
59366
 
e94df7f6b608
clarified build_theories: proper protocol handler;
 
wenzelm 
parents: 
59364 
diff
changeset
 | 
370  | 
|
| 65315 | 371  | 
def init_protocol_handler(handler: Session.Protocol_Handler): Unit =  | 
372  | 
protocol_handlers.init(handler)  | 
|
| 65214 | 373  | 
|
| 65315 | 374  | 
def init_protocol_handler(name: String): Unit =  | 
375  | 
protocol_handlers.init(name)  | 
|
| 
59366
 
e94df7f6b608
clarified build_theories: proper protocol handler;
 
wenzelm 
parents: 
59364 
diff
changeset
 | 
376  | 
|
| 
 
e94df7f6b608
clarified build_theories: proper protocol handler;
 
wenzelm 
parents: 
59364 
diff
changeset
 | 
377  | 
|
| 
65222
 
fb8253564483
more robust debugger initialization, e.g. required for GUI components before actual session startup;
 
wenzelm 
parents: 
65221 
diff
changeset
 | 
378  | 
/* debugger */  | 
| 
 
fb8253564483
more robust debugger initialization, e.g. required for GUI components before actual session startup;
 
wenzelm 
parents: 
65221 
diff
changeset
 | 
379  | 
|
| 
 
fb8253564483
more robust debugger initialization, e.g. required for GUI components before actual session startup;
 
wenzelm 
parents: 
65221 
diff
changeset
 | 
380  | 
private val debugger_handler = new Debugger.Handler(this)  | 
| 65315 | 381  | 
init_protocol_handler(debugger_handler)  | 
| 
65222
 
fb8253564483
more robust debugger initialization, e.g. required for GUI components before actual session startup;
 
wenzelm 
parents: 
65221 
diff
changeset
 | 
382  | 
|
| 
 
fb8253564483
more robust debugger initialization, e.g. required for GUI components before actual session startup;
 
wenzelm 
parents: 
65221 
diff
changeset
 | 
383  | 
def debugger: Debugger = debugger_handler.debugger  | 
| 
 
fb8253564483
more robust debugger initialization, e.g. required for GUI components before actual session startup;
 
wenzelm 
parents: 
65221 
diff
changeset
 | 
384  | 
|
| 
 
fb8253564483
more robust debugger initialization, e.g. required for GUI components before actual session startup;
 
wenzelm 
parents: 
65221 
diff
changeset
 | 
385  | 
|
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
386  | 
/* manager thread */  | 
| 
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
 | 
387  | 
|
| 
62115
 
57895801cb57
prune old versions more often, to reduce overall heap requirements;
 
wenzelm 
parents: 
62050 
diff
changeset
 | 
388  | 
private val delay_prune =  | 
| 
 
57895801cb57
prune old versions more often, to reduce overall heap requirements;
 
wenzelm 
parents: 
62050 
diff
changeset
 | 
389  | 
    Standard_Thread.delay_first(prune_delay) { manager.send(Prune_History) }
 | 
| 
56771
 
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
 
wenzelm 
parents: 
56735 
diff
changeset
 | 
390  | 
|
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
391  | 
private val manager: Consumer_Thread[Any] =  | 
| 
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
392  | 
  {
 | 
| 
52649
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
393  | 
/* raw edits */  | 
| 
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
394  | 
|
| 
68336
 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 
wenzelm 
parents: 
68293 
diff
changeset
 | 
395  | 
def handle_raw_edits(  | 
| 
 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 
wenzelm 
parents: 
68293 
diff
changeset
 | 
396  | 
doc_blobs: Document.Blobs = Document.Blobs.empty,  | 
| 
 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 
wenzelm 
parents: 
68293 
diff
changeset
 | 
397  | 
edits: List[Document.Edit_Text] = Nil,  | 
| 
70625
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
398  | 
consolidate: List[Document.Node.Name] = Nil,  | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
399  | 
share_common_data: Boolean = false)  | 
| 
52649
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
400  | 
    //{{{
 | 
| 
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
401  | 
    {
 | 
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
402  | 
require(prover.defined)  | 
| 56712 | 403  | 
|
| 
52649
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
404  | 
prover.get.discontinue_execution()  | 
| 
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
405  | 
|
| 56687 | 406  | 
val previous = global_state.value.history.tip.version  | 
| 
52649
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
407  | 
val version = Future.promise[Document.Version]  | 
| 56711 | 408  | 
global_state.change(_.continue_history(previous, edits, version))  | 
| 
52649
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
409  | 
|
| 
70625
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
410  | 
raw_edits.post(Session.Raw_Edits(doc_blobs, edits, share_common_data))  | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
411  | 
change_parser.send(  | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
412  | 
Text_Edits(previous, doc_blobs, edits, consolidate, share_common_data, version))  | 
| 
52649
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
413  | 
}  | 
| 
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
414  | 
//}}}  | 
| 
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
415  | 
|
| 
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
416  | 
|
| 43716 | 417  | 
/* resulting changes */  | 
| 34809 | 418  | 
|
| 56315 | 419  | 
def handle_change(change: Session.Change)  | 
| 38221 | 420  | 
    //{{{
 | 
| 34809 | 421  | 
    {
 | 
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
422  | 
require(prover.defined)  | 
| 56712 | 423  | 
|
| 
70664
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
424  | 
// define commands  | 
| 43720 | 425  | 
      {
 | 
| 
70664
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
426  | 
val id_commands = new mutable.ListBuffer[Command]  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
427  | 
def id_command(command: Command)  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
428  | 
        {
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
429  | 
          for {
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
430  | 
(name, digest) <- command.blobs_defined  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
431  | 
if !global_state.value.defined_blob(digest)  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
432  | 
          } {
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
433  | 
            change.version.nodes(name).get_blob match {
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
434  | 
case Some(blob) =>  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
435  | 
global_state.change(_.define_blob(digest))  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
436  | 
prover.get.define_blob(digest, blob.bytes)  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
437  | 
case None =>  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
438  | 
                Output.error_message("Missing blob " + quote(name.toString))
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
439  | 
}  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
440  | 
}  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
441  | 
|
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
442  | 
          if (!global_state.value.defined_command(command.id)) {
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
443  | 
global_state.change(_.define_command(command))  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
444  | 
id_commands += command  | 
| 
54519
 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 
wenzelm 
parents: 
54443 
diff
changeset
 | 
445  | 
}  | 
| 
 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 
wenzelm 
parents: 
54443 
diff
changeset
 | 
446  | 
}  | 
| 
70664
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
447  | 
        for { (_, edit) <- change.doc_edits } {
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
448  | 
          edit.foreach({ case (c1, c2) => c1.foreach(id_command); c2.foreach(id_command) })
 | 
| 43720 | 449  | 
}  | 
| 
70664
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
450  | 
if (id_commands.nonEmpty) prover.get.define_commands_bulk(id_commands.toList)  | 
| 44383 | 451  | 
}  | 
| 43722 | 452  | 
|
| 56687 | 453  | 
val assignment = global_state.value.the_assignment(change.previous).check_finished  | 
454  | 
global_state.change(_.define_version(change.version, assignment))  | 
|
| 
70625
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
455  | 
|
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
456  | 
      if (change.share_common_data) {
 | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
457  | 
        prover.get.protocol_command("ML_Heap.share_common_data")
 | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
458  | 
}  | 
| 
68336
 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 
wenzelm 
parents: 
68293 
diff
changeset
 | 
459  | 
prover.get.update(change.previous.id, change.version.id, change.doc_edits, change.consolidate)  | 
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
460  | 
resources.commit(change)  | 
| 34809 | 461  | 
}  | 
| 38221 | 462  | 
//}}}  | 
| 34809 | 463  | 
|
464  | 
||
| 
46772
 
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
 
wenzelm 
parents: 
46771 
diff
changeset
 | 
465  | 
/* prover output */  | 
| 34809 | 466  | 
|
| 56385 | 467  | 
def handle_output(output: Prover.Output)  | 
| 38221 | 468  | 
    //{{{
 | 
| 34809 | 469  | 
    {
 | 
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
470  | 
def bad_output()  | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
471  | 
      {
 | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
472  | 
if (verbose)  | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
473  | 
          Output.warning("Ignoring bad prover output: " + output.message.toString)
 | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
474  | 
}  | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
475  | 
|
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
476  | 
def change_command(f: Document.State => (Command.State, Document.State))  | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
477  | 
      {
 | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
478  | 
        try {
 | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
479  | 
val st = global_state.change_result(f)  | 
| 
70284
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
480  | 
change_buffer.invoke(false, Nil, List(st.command))  | 
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
481  | 
}  | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
482  | 
        catch { case _: Document.State.Fail => bad_output() }
 | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
483  | 
}  | 
| 
51662
 
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
 
wenzelm 
parents: 
51083 
diff
changeset
 | 
484  | 
|
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
485  | 
      output match {
 | 
| 56385 | 486  | 
case msg: Prover.Protocol_Output =>  | 
| 65214 | 487  | 
val handled = protocol_handlers.invoke(msg)  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
488  | 
          if (!handled) {
 | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
489  | 
            msg.properties match {
 | 
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
490  | 
case Markup.Protocol_Handler(name) if prover.defined =>  | 
| 65315 | 491  | 
init_protocol_handler(name)  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
492  | 
|
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
493  | 
case Protocol.Command_Timing(state_id, timing) if prover.defined =>  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
494  | 
val message = XML.elem(Markup.STATUS, List(XML.Elem(Markup.Timing(timing), Nil)))  | 
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
495  | 
change_command(_.accumulate(state_id, xml_cache.elem(message), xml_cache))  | 
| 46122 | 496  | 
|
| 
66873
 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 
wenzelm 
parents: 
66720 
diff
changeset
 | 
497  | 
case Protocol.Theory_Timing(_, _) =>  | 
| 
 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 
wenzelm 
parents: 
66720 
diff
changeset
 | 
498  | 
// FIXME  | 
| 
 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 
wenzelm 
parents: 
66720 
diff
changeset
 | 
499  | 
|
| 68101 | 500  | 
case Markup.Export(args)  | 
501  | 
if args.id.isDefined && Value.Long.unapply(args.id.get).isDefined =>  | 
|
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
502  | 
val id = Value.Long.unapply(args.id.get).get  | 
| 68168 | 503  | 
                val export = Export.make_entry("", args, msg.bytes, cache = xz_cache)
 | 
504  | 
change_command(_.add_export(id, (args.serial, export)))  | 
|
| 68088 | 505  | 
|
| 
70665
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
506  | 
case Markup.Commands_Accepted =>  | 
| 
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
507  | 
                msg.text match {
 | 
| 
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
508  | 
case Protocol.Commands_Accepted(ids) =>  | 
| 
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
509  | 
ids.foreach(id =>  | 
| 
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
510  | 
change_command(_.accumulate(id, Protocol.Commands_Accepted.message, xml_cache)))  | 
| 
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
511  | 
case _ => bad_output()  | 
| 
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
512  | 
}  | 
| 
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
513  | 
|
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
514  | 
case Markup.Assign_Update =>  | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
515  | 
                msg.text match {
 | 
| 
70284
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
516  | 
case Protocol.Assign_Update(id, edited, update) =>  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
517  | 
                    try {
 | 
| 
70284
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
518  | 
val (edited_nodes, cmds) =  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
519  | 
global_state.change_result(_.assign(id, edited, update))  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
520  | 
change_buffer.invoke(true, edited_nodes, cmds)  | 
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
521  | 
manager.send(Session.Change_Flush)  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
522  | 
}  | 
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
523  | 
                    catch { case _: Document.State.Fail => bad_output() }
 | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
524  | 
case _ => bad_output()  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
525  | 
}  | 
| 
56771
 
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
 
wenzelm 
parents: 
56735 
diff
changeset
 | 
526  | 
delay_prune.invoke()  | 
| 46122 | 527  | 
|
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
528  | 
case Markup.Removed_Versions =>  | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
529  | 
                msg.text match {
 | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
530  | 
case Protocol.Removed(removed) =>  | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
531  | 
                    try {
 | 
| 56687 | 532  | 
global_state.change(_.removed_versions(removed))  | 
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
533  | 
manager.send(Session.Change_Flush)  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
534  | 
}  | 
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
535  | 
                    catch { case _: Document.State.Fail => bad_output() }
 | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
536  | 
case _ => bad_output()  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
537  | 
}  | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
538  | 
|
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
539  | 
case Markup.ML_Statistics(props) =>  | 
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
540  | 
statistics.post(Session.Statistics(props))  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
541  | 
|
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
542  | 
case Markup.Task_Statistics(props) =>  | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
543  | 
// FIXME  | 
| 
52111
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
544  | 
|
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
545  | 
case _ => bad_output()  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
546  | 
}  | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
547  | 
}  | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
548  | 
case _ =>  | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
549  | 
          output.properties match {
 | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
550  | 
case Position.Id(state_id) =>  | 
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
551  | 
change_command(_.accumulate(state_id, output.message, xml_cache))  | 
| 56210 | 552  | 
|
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
553  | 
case _ if output.is_init =>  | 
| 
69488
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
554  | 
prover.get.options(file_formats.prover_options(session_options))  | 
| 65470 | 555  | 
prover.get.session_base(resources)  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
556  | 
phase = Session.Ready  | 
| 
65223
 
844c067bc3d4
more robust startup, despite remaining race condition of debugger.is_active vs. session.is_ready;
 
wenzelm 
parents: 
65222 
diff
changeset
 | 
557  | 
debugger.ready()  | 
| 56210 | 558  | 
|
| 65317 | 559  | 
case Markup.Process_Result(result) if output.is_exit =>  | 
| 
69488
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
560  | 
file_formats.stop_session  | 
| 65317 | 561  | 
phase = Session.Terminated(result)  | 
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
562  | 
prover.reset  | 
| 56210 | 563  | 
|
| 
61376
 
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
 
wenzelm 
parents: 
60934 
diff
changeset
 | 
564  | 
case _ =>  | 
| 
 
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
 
wenzelm 
parents: 
60934 
diff
changeset
 | 
565  | 
raw_output_messages.post(output)  | 
| 
44661
 
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
 
wenzelm 
parents: 
44644 
diff
changeset
 | 
566  | 
}  | 
| 
52111
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
567  | 
}  | 
| 34809 | 568  | 
}  | 
| 38221 | 569  | 
//}}}  | 
| 34809 | 570  | 
|
| 
34820
 
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
 
wenzelm 
parents: 
34819 
diff
changeset
 | 
571  | 
|
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
572  | 
/* main thread */  | 
| 
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
573  | 
|
| 
56710
 
8f102c18eab7
more uniform warning/error handling, potentially with propagation to send_wait caller;
 
wenzelm 
parents: 
56709 
diff
changeset
 | 
574  | 
    Consumer_Thread.fork[Any]("Session.manager", daemon = true)
 | 
| 56709 | 575  | 
    {
 | 
576  | 
case arg: Any =>  | 
|
577  | 
        //{{{
 | 
|
578  | 
        arg match {
 | 
|
| 
56733
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
579  | 
case output: Prover.Output =>  | 
| 
56775
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
580  | 
if (output.is_stdout || output.is_stderr)  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
581  | 
raw_output_messages.post(output)  | 
| 
56733
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
582  | 
else handle_output(output)  | 
| 
56775
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
583  | 
|
| 
56733
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
584  | 
            if (output.is_syslog) {
 | 
| 
56775
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
585  | 
syslog += output.message  | 
| 
56733
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
586  | 
syslog_messages.post(output)  | 
| 
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
587  | 
}  | 
| 
56775
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
588  | 
|
| 
56733
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
589  | 
all_messages.post(output)  | 
| 
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
590  | 
|
| 
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
591  | 
case input: Prover.Input =>  | 
| 
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
592  | 
all_messages.post(input)  | 
| 
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
593  | 
|
| 
62556
 
c115e69f457f
more abstract Session.start, without prover command-line;
 
wenzelm 
parents: 
62545 
diff
changeset
 | 
594  | 
case Start(start_prover) if !prover.defined =>  | 
| 
65207
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
595  | 
prover.set(start_prover(manager.send(_)))  | 
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
596  | 
|
| 56709 | 597  | 
case Stop =>  | 
| 
68807
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
598  | 
consolidation.exit()  | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
599  | 
delay_prune.revoke()  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
600  | 
            if (prover.defined) {
 | 
| 65219 | 601  | 
protocol_handlers.exit()  | 
| 56772 | 602  | 
global_state.change(_ => Document.State.init)  | 
| 56709 | 603  | 
prover.get.terminate  | 
604  | 
}  | 
|
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
605  | 
|
| 
66379
 
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
 
wenzelm 
parents: 
66094 
diff
changeset
 | 
606  | 
case Consolidate_Execution =>  | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
607  | 
            if (prover.defined) {
 | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
608  | 
val state = global_state.value  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
609  | 
              state.stable_tip_version match {
 | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
610  | 
case None => consolidation.update()  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
611  | 
case Some(version) =>  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
612  | 
val consolidate =  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
613  | 
consolidation.flush().iterator.filter(name =>  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
614  | 
!resources.session_base.loaded_theory(name) &&  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
615  | 
!state.node_consolidated(version, name) &&  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
616  | 
state.node_maybe_consolidated(version, name)).toList  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
617  | 
if (consolidate.nonEmpty) handle_raw_edits(consolidate = consolidate)  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
618  | 
}  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
619  | 
}  | 
| 
66379
 
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
 
wenzelm 
parents: 
66094 
diff
changeset
 | 
620  | 
|
| 
56771
 
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
 
wenzelm 
parents: 
56735 
diff
changeset
 | 
621  | 
case Prune_History =>  | 
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
622  | 
            if (prover.defined) {
 | 
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
623  | 
val old_versions = global_state.change_result(_.remove_versions(prune_size))  | 
| 59319 | 624  | 
if (old_versions.nonEmpty) prover.get.remove_versions(old_versions)  | 
| 
56771
 
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
 
wenzelm 
parents: 
56735 
diff
changeset
 | 
625  | 
}  | 
| 
 
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
 
wenzelm 
parents: 
56735 
diff
changeset
 | 
626  | 
|
| 56709 | 627  | 
case Update_Options(options) =>  | 
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
628  | 
            if (prover.defined && is_ready) {
 | 
| 
69488
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
629  | 
prover.get.options(file_formats.prover_options(options))  | 
| 
68336
 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 
wenzelm 
parents: 
68293 
diff
changeset
 | 
630  | 
handle_raw_edits()  | 
| 56709 | 631  | 
}  | 
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
632  | 
global_options.post(Session.Global_Options(options))  | 
| 34809 | 633  | 
|
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
634  | 
case Cancel_Exec(exec_id) if prover.defined =>  | 
| 56709 | 635  | 
prover.get.cancel_exec(exec_id)  | 
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
636  | 
|
| 
70625
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
637  | 
case Session.Raw_Edits(doc_blobs, edits, share_common_data) if prover.defined =>  | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
638  | 
handle_raw_edits(doc_blobs = doc_blobs, edits = edits,  | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
639  | 
share_common_data = share_common_data)  | 
| 56709 | 640  | 
|
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
641  | 
case Session.Dialog_Result(id, serial, result) if prover.defined =>  | 
| 56709 | 642  | 
prover.get.dialog_result(serial, result)  | 
643  | 
handle_output(new Prover.Output(Protocol.Dialog_Result(id, serial, result)))  | 
|
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
644  | 
|
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
645  | 
case Protocol_Command(name, args) if prover.defined =>  | 
| 70661 | 646  | 
prover.get.protocol_command_args(name, args)  | 
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
647  | 
|
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
648  | 
case change: Session.Change if prover.defined =>  | 
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
649  | 
val state = global_state.value  | 
| 
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
650  | 
if (!state.removing_versions && state.is_assigned(change.previous))  | 
| 56709 | 651  | 
handle_change(change)  | 
652  | 
else postponed_changes.store(change)  | 
|
| 
57651
 
10df45dd14da
less warnings -- ignore potential prover startup/shutdown races;
 
wenzelm 
parents: 
56864 
diff
changeset
 | 
653  | 
|
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
654  | 
case Session.Change_Flush if prover.defined =>  | 
| 
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
655  | 
val state = global_state.value  | 
| 
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
656  | 
if (!state.removing_versions)  | 
| 
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
657  | 
postponed_changes.flush(state).foreach(handle_change(_))  | 
| 
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57867 
diff
changeset
 | 
658  | 
|
| 
57651
 
10df45dd14da
less warnings -- ignore potential prover startup/shutdown races;
 
wenzelm 
parents: 
56864 
diff
changeset
 | 
659  | 
case bad =>  | 
| 
 
10df45dd14da
less warnings -- ignore potential prover startup/shutdown races;
 
wenzelm 
parents: 
56864 
diff
changeset
 | 
660  | 
            if (verbose) Output.warning("Ignoring bad message: " + bad.toString)
 | 
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
661  | 
}  | 
| 56709 | 662  | 
true  | 
663  | 
//}}}  | 
|
664  | 
}  | 
|
| 
34777
 
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
 
wenzelm 
parents:  
diff
changeset
 | 
665  | 
}  | 
| 
 
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
 
wenzelm 
parents:  
diff
changeset
 | 
666  | 
|
| 34809 | 667  | 
|
| 56799 | 668  | 
/* main operations */  | 
669  | 
||
670  | 
def snapshot(name: Document.Node.Name = Document.Node.Name.empty,  | 
|
671  | 
pending_edits: List[Text.Edit] = Nil): Document.Snapshot =  | 
|
672  | 
global_state.value.snapshot(name, pending_edits)  | 
|
| 34809 | 673  | 
|
| 
69640
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
674  | 
@tailrec final def await_stable_snapshot(): Document.Snapshot =  | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
675  | 
  {
 | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
676  | 
val snapshot = this.snapshot()  | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
677  | 
    if (snapshot.is_outdated) {
 | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
678  | 
Thread.sleep(output_delay.ms)  | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
679  | 
await_stable_snapshot()  | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
680  | 
}  | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
681  | 
else snapshot  | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
682  | 
}  | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
683  | 
|
| 
62556
 
c115e69f457f
more abstract Session.start, without prover command-line;
 
wenzelm 
parents: 
62545 
diff
changeset
 | 
684  | 
def start(start_prover: Prover.Receiver => Prover)  | 
| 
65207
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
685  | 
  {
 | 
| 
69488
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
686  | 
file_formats  | 
| 
65207
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
687  | 
_phase.change(  | 
| 
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
688  | 
      {
 | 
| 
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
689  | 
case Session.Inactive =>  | 
| 
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
690  | 
manager.send(Start(start_prover))  | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
691  | 
post_phase(Session.Startup)  | 
| 
65207
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
692  | 
        case phase => error("Cannot start prover in phase " + quote(phase.print))
 | 
| 
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
693  | 
})  | 
| 
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
694  | 
}  | 
| 45076 | 695  | 
|
| 65311 | 696  | 
def send_stop()  | 
| 50117 | 697  | 
  {
 | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
698  | 
val was_ready =  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
699  | 
_phase.guarded_access(phase =>  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
700  | 
        phase match {
 | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
701  | 
case Session.Startup | Session.Shutdown => None  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
702  | 
case Session.Terminated(_) => Some((false, phase))  | 
| 65317 | 703  | 
case Session.Inactive => Some((false, post_phase(Session.Terminated(Process_Result(0)))))  | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
704  | 
case Session.Ready => Some((true, post_phase(Session.Shutdown)))  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
705  | 
})  | 
| 65311 | 706  | 
if (was_ready) manager.send(Stop)  | 
707  | 
}  | 
|
708  | 
||
| 65317 | 709  | 
def stop(): Process_Result =  | 
| 65311 | 710  | 
  {
 | 
711  | 
send_stop()  | 
|
| 
56793
 
d5ab6a8799ce
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
 
wenzelm 
parents: 
56782 
diff
changeset
 | 
712  | 
prover.await_reset()  | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
713  | 
|
| 56704 | 714  | 
change_parser.shutdown()  | 
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
715  | 
change_buffer.shutdown()  | 
| 
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
716  | 
manager.shutdown()  | 
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
717  | 
dispatcher.shutdown()  | 
| 65209 | 718  | 
|
719  | 
    phase match {
 | 
|
| 65317 | 720  | 
case Session.Terminated(result) => result  | 
| 65209 | 721  | 
      case phase => error("Bad session phase after shutdown: " + quote(phase.print))
 | 
722  | 
}  | 
|
| 50117 | 723  | 
}  | 
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38722 
diff
changeset
 | 
724  | 
|
| 
53054
 
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
 
wenzelm 
parents: 
52931 
diff
changeset
 | 
725  | 
def protocol_command(name: String, args: String*)  | 
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
726  | 
  { manager.send(Protocol_Command(name, args.toList)) }
 | 
| 
53054
 
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
 
wenzelm 
parents: 
52931 
diff
changeset
 | 
727  | 
|
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
728  | 
def cancel_exec(exec_id: Document_ID.Exec)  | 
| 
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
729  | 
  { manager.send(Cancel_Exec(exec_id)) }
 | 
| 
52931
 
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
 
wenzelm 
parents: 
52800 
diff
changeset
 | 
730  | 
|
| 
70625
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
731  | 
def update(  | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
732  | 
doc_blobs: Document.Blobs,  | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
733  | 
edits: List[Document.Edit_Text],  | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
734  | 
share_common_data: Boolean = false)  | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
735  | 
  {
 | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
736  | 
if (edits.nonEmpty) manager.send_wait(Session.Raw_Edits(doc_blobs, edits, share_common_data))  | 
| 
 
1ae987cc052f
support for share_common_data after define_command and before actual update: this affects string particles of command tokens;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
737  | 
}  | 
| 50498 | 738  | 
|
| 
52084
 
573e80625c78
more explicit Session.update_options as source of Global_Options event;
 
wenzelm 
parents: 
51818 
diff
changeset
 | 
739  | 
def update_options(options: Options)  | 
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
740  | 
  { manager.send_wait(Update_Options(options)) }
 | 
| 
52084
 
573e80625c78
more explicit Session.update_options as source of Global_Options event;
 
wenzelm 
parents: 
51818 
diff
changeset
 | 
741  | 
|
| 52531 | 742  | 
def dialog_result(id: Document_ID.Generic, serial: Long, result: String)  | 
| 
56706
 
f2f53f7046f4
converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
 
wenzelm 
parents: 
56705 
diff
changeset
 | 
743  | 
  { manager.send(Session.Dialog_Result(id, serial, result)) }
 | 
| 
34777
 
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
 
wenzelm 
parents:  
diff
changeset
 | 
744  | 
}  |