| author | wenzelm | 
| Sat, 09 Apr 2022 15:28:55 +0200 | |
| changeset 75436 | 40630fec3b5d | 
| parent 75393 | 87ebf5a50283 | 
| child 75440 | 39011d0d2128 | 
| 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  | 
|
| 75393 | 16  | 
object Session {
 | 
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
17  | 
/* outlets */  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
18  | 
|
| 75393 | 19  | 
  object Consumer {
 | 
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
20  | 
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
 | 
21  | 
new Consumer[A](name, consume)  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
22  | 
}  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
23  | 
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
 | 
24  | 
|
| 75393 | 25  | 
  class Outlet[A](dispatcher: Consumer_Thread[() => Unit]) {
 | 
| 61590 | 26  | 
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
 | 
27  | 
|
| 73340 | 28  | 
def += (c: Consumer[A]): Unit = consumers.change(Library.update(c))  | 
29  | 
def -= (c: Consumer[A]): Unit = consumers.change(Library.remove(c))  | 
|
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
30  | 
|
| 75393 | 31  | 
    def post(a: A): Unit = {
 | 
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
32  | 
      for (c <- consumers.value.iterator) {
 | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
33  | 
dispatcher.send(() =>  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
34  | 
          try { c.consume(a) }
 | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
35  | 
          catch {
 | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
36  | 
case exn: Throwable =>  | 
| 
56782
 
433cf57550fa
more systematic Isabelle output, like in classic Isabelle/ML (without markup);
 
wenzelm 
parents: 
56775 
diff
changeset
 | 
37  | 
              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
 | 
38  | 
})  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
39  | 
}  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
40  | 
}  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
41  | 
}  | 
| 
 
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  | 
|
| 56315 | 44  | 
/* change */  | 
45  | 
||
46  | 
sealed case class Change(  | 
|
47  | 
previous: Document.Version,  | 
|
| 
59077
 
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
 
wenzelm 
parents: 
58928 
diff
changeset
 | 
48  | 
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
 | 
49  | 
deps_changed: Boolean,  | 
| 56315 | 50  | 
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
 | 
51  | 
consolidate: List[Document.Node.Name],  | 
| 56315 | 52  | 
version: Document.Version)  | 
53  | 
||
| 
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
 | 
54  | 
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
 | 
55  | 
|
| 56315 | 56  | 
|
| 
34813
 
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
 
wenzelm 
parents: 
34810 
diff
changeset
 | 
57  | 
/* events */  | 
| 
 
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
 
wenzelm 
parents: 
34810 
diff
changeset
 | 
58  | 
|
| 43716 | 59  | 
  //{{{
 | 
| 71652 | 60  | 
case class Command_Timing(props: Properties.T)  | 
61  | 
case class Theory_Timing(props: Properties.T)  | 
|
62  | 
case class Runtime_Statistics(props: Properties.T)  | 
|
63  | 
case class Task_Statistics(props: Properties.T)  | 
|
| 50117 | 64  | 
case class Global_Options(options: Options)  | 
| 44805 | 65  | 
case object Caret_Focus  | 
| 
70796
 
2739631ac368
discontinued pointless dump_checkpoint and share_common_data -- superseded by base logic image in Isabelle/MMT;
 
wenzelm 
parents: 
70778 
diff
changeset
 | 
66  | 
case class Raw_Edits(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text])  | 
| 52531 | 67  | 
case class Dialog_Result(id: Document_ID.Generic, serial: Long, result: String)  | 
| 59364 | 68  | 
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
 | 
69  | 
case class Commands_Changed(  | 
| 
 
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
 
wenzelm 
parents: 
46944 
diff
changeset
 | 
70  | 
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
 | 
71  | 
|
| 75393 | 72  | 
  sealed abstract class Phase {
 | 
| 65206 | 73  | 
def print: String =  | 
74  | 
      this match {
 | 
|
| 65317 | 75  | 
case Terminated(result) => if (result.ok) "finished" else "failed"  | 
| 65206 | 76  | 
case _ => Word.lowercase(this.toString)  | 
77  | 
}  | 
|
78  | 
}  | 
|
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
79  | 
case object Inactive extends Phase // stable  | 
| 39701 | 80  | 
case object Startup extends Phase // transient  | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
81  | 
case object Ready extends Phase // metastable  | 
| 39701 | 82  | 
case object Shutdown extends Phase // transient  | 
| 65317 | 83  | 
case class Terminated(result: Process_Result) extends Phase // stable  | 
| 43716 | 84  | 
//}}}  | 
| 
52111
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
85  | 
|
| 
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
86  | 
|
| 
56775
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
87  | 
/* syslog */  | 
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
88  | 
|
| 75393 | 89  | 
  private[Session] class Syslog(limit: Int) {
 | 
| 
56775
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
90  | 
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
 | 
91  | 
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
 | 
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  | 
    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
 | 
94  | 
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
 | 
95  | 
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
 | 
96  | 
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
 | 
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  | 
|
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
99  | 
    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
 | 
100  | 
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
 | 
101  | 
(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
 | 
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  | 
|
| 
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
105  | 
|
| 
52111
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
106  | 
/* protocol handlers */  | 
| 
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
107  | 
|
| 71970 | 108  | 
type Protocol_Function = Prover.Protocol_Output => Boolean  | 
109  | 
||
| 75393 | 110  | 
  abstract class Protocol_Handler extends Isabelle_System.Service {
 | 
| 65219 | 111  | 
    def init(session: Session): Unit = {}
 | 
112  | 
    def exit(): Unit = {}
 | 
|
| 72212 | 113  | 
def functions: List[(String, Protocol_Function)] = Nil  | 
| 72216 | 114  | 
def prover_options(options: Options): Options = options  | 
| 
52111
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
115  | 
}  | 
| 34791 | 116  | 
}  | 
117  | 
||
| 
34777
 
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
 
wenzelm 
parents:  
diff
changeset
 | 
118  | 
|
| 75393 | 119  | 
class Session(_session_options: => Options, val resources: Resources) extends Document.Session {
 | 
| 65214 | 120  | 
session =>  | 
121  | 
||
| 
74731
 
161e84e6b40a
just one cache, via HTML_Context, via Sessions.Store or Session;
 
wenzelm 
parents: 
74685 
diff
changeset
 | 
122  | 
val cache: Term.Cache = Term.Cache.make()  | 
| 65218 | 123  | 
|
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72721 
diff
changeset
 | 
124  | 
def build_blobs_info(name: Document.Node.Name): Command.Blobs_Info =  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72721 
diff
changeset
 | 
125  | 
Command.Blobs_Info.none  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72721 
diff
changeset
 | 
126  | 
|
| 65214 | 127  | 
|
| 47653 | 128  | 
/* global flags */  | 
129  | 
||
130  | 
@volatile var timing: Boolean = false  | 
|
131  | 
@volatile var verbose: Boolean = false  | 
|
132  | 
||
133  | 
||
| 
65264
 
7e6ecd04b5fe
dynamic session_options for tuning parameters and initial prover options;
 
wenzelm 
parents: 
65223 
diff
changeset
 | 
134  | 
/* dynamic session options */  | 
| 49288 | 135  | 
|
| 69492 | 136  | 
def session_options: Options = _session_options  | 
137  | 
||
| 
65264
 
7e6ecd04b5fe
dynamic session_options for tuning parameters and initial prover options;
 
wenzelm 
parents: 
65223 
diff
changeset
 | 
138  | 
  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
 | 
139  | 
  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
 | 
140  | 
  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
 | 
141  | 
  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
 | 
142  | 
  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
 | 
143  | 
  def reparse_limit: Int = session_options.int("editor_reparse_limit")
 | 
| 37849 | 144  | 
|
145  | 
||
| 66094 | 146  | 
/* dispatcher */  | 
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
147  | 
|
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
148  | 
private val dispatcher =  | 
| 
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
149  | 
    Consumer_Thread.fork[() => Unit]("Session.dispatcher", daemon = true) { case e => e(); true }
 | 
| 34809 | 150  | 
|
| 75393 | 151  | 
  def assert_dispatcher[A](body: => A): A = {
 | 
| 74254 | 152  | 
assert(dispatcher.check_thread())  | 
| 66094 | 153  | 
body  | 
154  | 
}  | 
|
155  | 
||
| 75393 | 156  | 
  def require_dispatcher[A](body: => A): A = {
 | 
| 74254 | 157  | 
require(dispatcher.check_thread(), "not on dispatcher thread")  | 
| 66094 | 158  | 
body  | 
159  | 
}  | 
|
160  | 
||
| 75393 | 161  | 
  def send_dispatcher(body: => Unit): Unit = {
 | 
| 74254 | 162  | 
if (dispatcher.check_thread()) body  | 
| 66094 | 163  | 
else dispatcher.send(() => body)  | 
164  | 
}  | 
|
165  | 
||
| 75393 | 166  | 
  def send_wait_dispatcher(body: => Unit): Unit = {
 | 
| 74254 | 167  | 
if (dispatcher.check_thread()) body  | 
| 66094 | 168  | 
else dispatcher.send_wait(() => body)  | 
169  | 
}  | 
|
170  | 
||
171  | 
||
172  | 
/* outlets */  | 
|
173  | 
||
| 
72721
 
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
 
wenzelm 
parents: 
72692 
diff
changeset
 | 
174  | 
val finished_theories = new Session.Outlet[Document.Snapshot](dispatcher)  | 
| 71652 | 175  | 
val command_timings = new Session.Outlet[Session.Command_Timing](dispatcher)  | 
176  | 
val theory_timings = new Session.Outlet[Session.Theory_Timing](dispatcher)  | 
|
177  | 
val runtime_statistics = new Session.Outlet[Session.Runtime_Statistics](dispatcher)  | 
|
178  | 
val task_statistics = new Session.Outlet[Session.Task_Statistics](dispatcher)  | 
|
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
179  | 
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
 | 
180  | 
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
 | 
181  | 
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
 | 
182  | 
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
 | 
183  | 
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
 | 
184  | 
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
 | 
185  | 
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
 | 
186  | 
val trace_events = new Session.Outlet[Simplifier_Trace.Event.type](dispatcher)  | 
| 60900 | 187  | 
val debugger_updates = new Session.Outlet[Debugger.Update.type](dispatcher)  | 
| 34809 | 188  | 
|
| 60749 | 189  | 
val all_messages = new Session.Outlet[Prover.Message](dispatcher) // potential bottle-neck!  | 
| 34809 | 190  | 
|
| 
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
 | 
191  | 
|
| 56799 | 192  | 
/** 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
 | 
193  | 
|
| 56799 | 194  | 
/* 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
 | 
195  | 
|
| 
62556
 
c115e69f457f
more abstract Session.start, without prover command-line;
 
wenzelm 
parents: 
62545 
diff
changeset
 | 
196  | 
private case class Start(start_prover: Prover.Receiver => Prover)  | 
| 56799 | 197  | 
private case object Stop  | 
| 
70775
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
198  | 
private case class Get_State(promise: Promise[Document.State])  | 
| 56799 | 199  | 
private case class Cancel_Exec(exec_id: Document_ID.Exec)  | 
| 73565 | 200  | 
private case class Protocol_Command_Raw(name: String, args: List[Bytes])  | 
201  | 
private case class Protocol_Command_Args(name: String, args: List[String])  | 
|
| 56799 | 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  | 
|
| 75393 | 209  | 
  private def post_phase(new_phase: Session.Phase): Session.Phase = {
 | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
210  | 
phase_changed.post(new_phase)  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
211  | 
new_phase  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
212  | 
}  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
213  | 
private val _phase = Synchronized[Session.Phase](Session.Inactive)  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
214  | 
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
 | 
215  | 
|
| 71601 | 216  | 
def phase: Session.Phase = _phase.value  | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
217  | 
def is_ready: Boolean = phase == Session.Ready  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
218  | 
|
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
219  | 
|
| 
70775
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
220  | 
/* syslog */  | 
| 43644 | 221  | 
|
| 
56775
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
222  | 
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
 | 
223  | 
def syslog_content(): String = syslog.content  | 
| 
39626
 
a5d0bcfb95a3
manage persistent syslog via Session, not Isabelle_Process;
 
wenzelm 
parents: 
39625 
diff
changeset
 | 
224  | 
|
| 
43651
 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 
wenzelm 
parents: 
43649 
diff
changeset
 | 
225  | 
|
| 56799 | 226  | 
/* pipelined change parsing */  | 
227  | 
||
228  | 
private case class Text_Edits(  | 
|
229  | 
previous: Future[Document.Version],  | 
|
230  | 
doc_blobs: Document.Blobs,  | 
|
231  | 
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
 | 
232  | 
consolidate: List[Document.Node.Name],  | 
| 56799 | 233  | 
version_result: Promise[Document.Version])  | 
| 
43651
 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 
wenzelm 
parents: 
43649 
diff
changeset
 | 
234  | 
|
| 75393 | 235  | 
  private val change_parser = Consumer_Thread.fork[Text_Edits]("change_parser", daemon = true) {
 | 
| 
70796
 
2739631ac368
discontinued pointless dump_checkpoint and share_common_data -- superseded by base logic image in Isabelle/MMT;
 
wenzelm 
parents: 
70778 
diff
changeset
 | 
236  | 
case Text_Edits(previous, doc_blobs, text_edits, consolidate, version_result) =>  | 
| 56799 | 237  | 
val prev = previous.get_finished  | 
238  | 
val change =  | 
|
239  | 
        Timing.timeit("parse_change", timing) {
 | 
|
| 
70796
 
2739631ac368
discontinued pointless dump_checkpoint and share_common_data -- superseded by base logic image in Isabelle/MMT;
 
wenzelm 
parents: 
70778 
diff
changeset
 | 
240  | 
resources.parse_change(reparse_limit, prev, doc_blobs, text_edits, consolidate)  | 
| 56799 | 241  | 
}  | 
242  | 
version_result.fulfill(change.version)  | 
|
243  | 
manager.send(change)  | 
|
244  | 
true  | 
|
245  | 
}  | 
|
| 41534 | 246  | 
|
| 
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
 | 
247  | 
|
| 
56719
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
248  | 
/* buffered changes */  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
249  | 
|
| 75393 | 250  | 
  private object change_buffer {
 | 
| 
56719
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
251  | 
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
 | 
252  | 
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
 | 
253  | 
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
 | 
254  | 
|
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
255  | 
    def flush(): Unit = synchronized {
 | 
| 59319 | 256  | 
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
 | 
257  | 
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
 | 
258  | 
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
 | 
259  | 
assignment = false  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
260  | 
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
 | 
261  | 
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
 | 
262  | 
}  | 
| 71704 | 263  | 
    private val delay_flush = 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
 | 
264  | 
|
| 
70284
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
265  | 
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
 | 
266  | 
      synchronized {
 | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
267  | 
assignment |= assign  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
268  | 
        for (node <- edited_nodes) {
 | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
269  | 
nodes += node  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
270  | 
}  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
271  | 
        for (command <- cmds) {
 | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
272  | 
nodes += command.node_name  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
273  | 
command.blobs_names.foreach(nodes += _)  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
274  | 
commands += command  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
275  | 
}  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
276  | 
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
 | 
277  | 
}  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
278  | 
|
| 75393 | 279  | 
    def shutdown(): Unit = {
 | 
| 
56771
 
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
 
wenzelm 
parents: 
56735 
diff
changeset
 | 
280  | 
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
 | 
281  | 
flush()  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
282  | 
}  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
283  | 
}  | 
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
284  | 
|
| 
 
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
 
wenzelm 
parents: 
56715 
diff
changeset
 | 
285  | 
|
| 
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
 | 
286  | 
/* 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
 | 
287  | 
|
| 75393 | 288  | 
  private object postponed_changes {
 | 
| 
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
 | 
289  | 
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
 | 
290  | 
|
| 
 
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
 | 
291  | 
    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
 | 
292  | 
|
| 
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
 | 
293  | 
    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
 | 
294  | 
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
 | 
295  | 
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
 | 
296  | 
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
 | 
297  | 
}  | 
| 
 
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
 | 
298  | 
}  | 
| 
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
 | 
299  | 
|
| 
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
 | 
300  | 
|
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
301  | 
/* node consolidation */  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
302  | 
|
| 75393 | 303  | 
  private object consolidation {
 | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
304  | 
private val delay =  | 
| 71704 | 305  | 
      Delay.first(consolidate_delay) { manager.send(Consolidate_Execution) }
 | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
306  | 
|
| 
68807
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
307  | 
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
 | 
308  | 
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
 | 
309  | 
|
| 75393 | 310  | 
    def exit(): Unit = {
 | 
| 
68807
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
311  | 
delay.revoke()  | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
312  | 
state.change(_ => None)  | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
313  | 
}  | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
314  | 
|
| 75393 | 315  | 
    def update(new_nodes: Set[Document.Node.Name] = Set.empty): Unit = {
 | 
| 
68807
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
316  | 
val active =  | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
317  | 
state.change_result(st =>  | 
| 
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
318  | 
(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
 | 
319  | 
if (active) delay.invoke()  | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
320  | 
}  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
321  | 
|
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
322  | 
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
 | 
323  | 
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
 | 
324  | 
}  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
325  | 
|
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
326  | 
|
| 
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
 | 
327  | 
/* 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
 | 
328  | 
|
| 75393 | 329  | 
  private object prover {
 | 
| 61590 | 330  | 
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
 | 
331  | 
|
| 
 
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
 | 
332  | 
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
 | 
333  | 
def get: Prover = variable.value.get  | 
| 73340 | 334  | 
def set(p: Prover): Unit = variable.change(_ => Some(p))  | 
335  | 
def reset: Unit = variable.change(_ => None)  | 
|
336  | 
    def await_reset(): Unit = variable.guarded_access({ case None => Some((), None) case _ => 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
 | 
337  | 
}  | 
| 
 
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
 | 
338  | 
|
| 
 
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
 | 
339  | 
|
| 72216 | 340  | 
/* file formats and protocol handlers */  | 
| 
69488
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
341  | 
|
| 72216 | 342  | 
private lazy val file_formats: File_Format.Session =  | 
| 71733 | 343  | 
File_Format.registry.start_session(session)  | 
| 
69488
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
344  | 
|
| 65215 | 345  | 
private val protocol_handlers = Protocol_Handlers.init(session)  | 
| 
59366
 
e94df7f6b608
clarified build_theories: proper protocol handler;
 
wenzelm 
parents: 
59364 
diff
changeset
 | 
346  | 
|
| 72215 | 347  | 
def get_protocol_handler[C <: Session.Protocol_Handler](c: Class[C]): Option[C] =  | 
348  | 
    protocol_handlers.get(c.getName) match {
 | 
|
349  | 
case Some(h) if Library.is_subclass(h.getClass, c) => Some(h.asInstanceOf[C])  | 
|
350  | 
case _ => None  | 
|
351  | 
}  | 
|
| 
59366
 
e94df7f6b608
clarified build_theories: proper protocol handler;
 
wenzelm 
parents: 
59364 
diff
changeset
 | 
352  | 
|
| 65315 | 353  | 
def init_protocol_handler(handler: Session.Protocol_Handler): Unit =  | 
354  | 
protocol_handlers.init(handler)  | 
|
| 65214 | 355  | 
|
| 72216 | 356  | 
def prover_options(options: Options): Options =  | 
357  | 
protocol_handlers.prover_options(file_formats.prover_options(options))  | 
|
358  | 
||
| 
59366
 
e94df7f6b608
clarified build_theories: proper protocol handler;
 
wenzelm 
parents: 
59364 
diff
changeset
 | 
359  | 
|
| 
65222
 
fb8253564483
more robust debugger initialization, e.g. required for GUI components before actual session startup;
 
wenzelm 
parents: 
65221 
diff
changeset
 | 
360  | 
/* debugger */  | 
| 
 
fb8253564483
more robust debugger initialization, e.g. required for GUI components before actual session startup;
 
wenzelm 
parents: 
65221 
diff
changeset
 | 
361  | 
|
| 
 
fb8253564483
more robust debugger initialization, e.g. required for GUI components before actual session startup;
 
wenzelm 
parents: 
65221 
diff
changeset
 | 
362  | 
private val debugger_handler = new Debugger.Handler(this)  | 
| 65315 | 363  | 
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
 | 
364  | 
|
| 
 
fb8253564483
more robust debugger initialization, e.g. required for GUI components before actual session startup;
 
wenzelm 
parents: 
65221 
diff
changeset
 | 
365  | 
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
 | 
366  | 
|
| 
 
fb8253564483
more robust debugger initialization, e.g. required for GUI components before actual session startup;
 
wenzelm 
parents: 
65221 
diff
changeset
 | 
367  | 
|
| 
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
 | 
368  | 
/* 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
 | 
369  | 
|
| 
62115
 
57895801cb57
prune old versions more often, to reduce overall heap requirements;
 
wenzelm 
parents: 
62050 
diff
changeset
 | 
370  | 
private val delay_prune =  | 
| 71704 | 371  | 
    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
 | 
372  | 
|
| 75393 | 373  | 
  private val manager: Consumer_Thread[Any] = {
 | 
| 
70775
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
374  | 
/* global state */  | 
| 
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
375  | 
val global_state = Synchronized(Document.State.init)  | 
| 
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
376  | 
|
| 
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
377  | 
|
| 
52649
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
378  | 
/* raw edits */  | 
| 
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
379  | 
|
| 
68336
 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 
wenzelm 
parents: 
68293 
diff
changeset
 | 
380  | 
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
 | 
381  | 
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
 | 
382  | 
edits: List[Document.Edit_Text] = Nil,  | 
| 75393 | 383  | 
      consolidate: List[Document.Node.Name] = Nil): Unit = {
 | 
| 
52649
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
384  | 
    //{{{
 | 
| 
73120
 
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
 
wenzelm 
parents: 
73031 
diff
changeset
 | 
385  | 
require(prover.defined, "prover process not defined (handle_raw_edits)")  | 
| 56712 | 386  | 
|
| 
70778
 
f326596f5752
consolidate less aggressively: avoid live-lock when PIDE round-trip takes too long (e.g. in complex theory hierarchies);
 
wenzelm 
parents: 
70776 
diff
changeset
 | 
387  | 
if (edits.nonEmpty) prover.get.discontinue_execution()  | 
| 
52649
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
388  | 
|
| 56687 | 389  | 
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
 | 
390  | 
val version = Future.promise[Document.Version]  | 
| 56711 | 391  | 
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
 | 
392  | 
|
| 
70796
 
2739631ac368
discontinued pointless dump_checkpoint and share_common_data -- superseded by base logic image in Isabelle/MMT;
 
wenzelm 
parents: 
70778 
diff
changeset
 | 
393  | 
raw_edits.post(Session.Raw_Edits(doc_blobs, edits))  | 
| 
 
2739631ac368
discontinued pointless dump_checkpoint and share_common_data -- superseded by base logic image in Isabelle/MMT;
 
wenzelm 
parents: 
70778 
diff
changeset
 | 
394  | 
change_parser.send(Text_Edits(previous, doc_blobs, edits, consolidate, version))  | 
| 75393 | 395  | 
//}}}  | 
| 
52649
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
396  | 
}  | 
| 
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
397  | 
|
| 
 
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
 
wenzelm 
parents: 
52563 
diff
changeset
 | 
398  | 
|
| 43716 | 399  | 
/* resulting changes */  | 
| 34809 | 400  | 
|
| 75393 | 401  | 
    def handle_change(change: Session.Change): Unit = {
 | 
| 38221 | 402  | 
    //{{{
 | 
| 
73120
 
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
 
wenzelm 
parents: 
73031 
diff
changeset
 | 
403  | 
require(prover.defined, "prover process not defined (handle_change)")  | 
| 56712 | 404  | 
|
| 
70664
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
405  | 
// define commands  | 
| 43720 | 406  | 
      {
 | 
| 
70664
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
407  | 
val id_commands = new mutable.ListBuffer[Command]  | 
| 75393 | 408  | 
        def id_command(command: Command): Unit = {
 | 
| 
70664
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
409  | 
          for {
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
410  | 
(name, digest) <- command.blobs_defined  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
411  | 
if !global_state.value.defined_blob(digest)  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
412  | 
          } {
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
413  | 
            change.version.nodes(name).get_blob match {
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
414  | 
case Some(blob) =>  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
415  | 
global_state.change(_.define_blob(digest))  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
416  | 
prover.get.define_blob(digest, blob.bytes)  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
417  | 
case None =>  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
418  | 
                Output.error_message("Missing blob " + quote(name.toString))
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
419  | 
}  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
420  | 
}  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
421  | 
|
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
422  | 
          if (!global_state.value.defined_command(command.id)) {
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
423  | 
global_state.change(_.define_command(command))  | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
424  | 
id_commands += command  | 
| 
54519
 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 
wenzelm 
parents: 
54443 
diff
changeset
 | 
425  | 
}  | 
| 
 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 
wenzelm 
parents: 
54443 
diff
changeset
 | 
426  | 
}  | 
| 
70664
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
427  | 
        for { (_, edit) <- change.doc_edits } {
 | 
| 
 
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
 
wenzelm 
parents: 
70661 
diff
changeset
 | 
428  | 
          edit.foreach({ case (c1, c2) => c1.foreach(id_command); c2.foreach(id_command) })
 | 
| 43720 | 429  | 
}  | 
| 72946 | 430  | 
        if (id_commands.nonEmpty) {
 | 
431  | 
prover.get.define_commands_bulk(resources, id_commands.toList)  | 
|
432  | 
}  | 
|
| 44383 | 433  | 
}  | 
| 43722 | 434  | 
|
| 56687 | 435  | 
val assignment = global_state.value.the_assignment(change.previous).check_finished  | 
436  | 
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
 | 
437  | 
|
| 
68336
 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 
wenzelm 
parents: 
68293 
diff
changeset
 | 
438  | 
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
 | 
439  | 
resources.commit(change)  | 
| 75393 | 440  | 
//}}}  | 
| 34809 | 441  | 
}  | 
442  | 
||
443  | 
||
| 
46772
 
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
 
wenzelm 
parents: 
46771 
diff
changeset
 | 
444  | 
/* prover output */  | 
| 34809 | 445  | 
|
| 75393 | 446  | 
    def handle_output(output: Prover.Output): Unit = {
 | 
| 38221 | 447  | 
    //{{{
 | 
| 75393 | 448  | 
      def bad_output(): Unit = {
 | 
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
449  | 
if (verbose)  | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
450  | 
          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
 | 
451  | 
}  | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
452  | 
|
| 75393 | 453  | 
      def change_command(f: Document.State => (Command.State, Document.State)): Unit = {
 | 
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
454  | 
        try {
 | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
455  | 
val st = global_state.change_result(f)  | 
| 
72692
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72217 
diff
changeset
 | 
456  | 
          if (!st.command.span.is_theory) {
 | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72217 
diff
changeset
 | 
457  | 
change_buffer.invoke(false, Nil, List(st.command))  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72217 
diff
changeset
 | 
458  | 
}  | 
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
459  | 
}  | 
| 
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
460  | 
        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
 | 
461  | 
}  | 
| 
51662
 
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
 
wenzelm 
parents: 
51083 
diff
changeset
 | 
462  | 
|
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
463  | 
      output match {
 | 
| 56385 | 464  | 
case msg: Prover.Protocol_Output =>  | 
| 65214 | 465  | 
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
 | 
466  | 
          if (!handled) {
 | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
467  | 
            msg.properties match {
 | 
| 71673 | 468  | 
case Protocol.Command_Timing(props, state_id, timing) if prover.defined =>  | 
469  | 
command_timings.post(Session.Command_Timing(props))  | 
|
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
470  | 
val message = XML.elem(Markup.STATUS, List(XML.Elem(Markup.Timing(timing), Nil)))  | 
| 
73031
 
f93f0597f4fb
clarified signature: absorb XZ.Cache into XML.Cache;
 
wenzelm 
parents: 
73024 
diff
changeset
 | 
471  | 
change_command(_.accumulate(state_id, cache.elem(message), cache))  | 
| 46122 | 472  | 
|
| 71673 | 473  | 
case Markup.Theory_Timing(props) =>  | 
474  | 
theory_timings.post(Session.Theory_Timing(props))  | 
|
| 
66873
 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 
wenzelm 
parents: 
66720 
diff
changeset
 | 
475  | 
|
| 71671 | 476  | 
case Markup.Task_Statistics(props) =>  | 
477  | 
task_statistics.post(Session.Task_Statistics(props))  | 
|
478  | 
||
| 71624 | 479  | 
case Protocol.Export(args)  | 
| 68101 | 480  | 
if args.id.isDefined && Value.Long.unapply(args.id.get).isDefined =>  | 
| 
71968
 
ec0ef3ebe75e
removed pointless pide_exports: unused during "build_session" process (reverting 6a64205b491a);
 
wenzelm 
parents: 
71960 
diff
changeset
 | 
481  | 
val id = Value.Long.unapply(args.id.get).get  | 
| 74685 | 482  | 
                val entry = Export.make_entry("", args, msg.chunk, cache)
 | 
483  | 
change_command(_.add_export(id, (args.serial, entry)))  | 
|
| 68088 | 484  | 
|
| 
72692
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72217 
diff
changeset
 | 
485  | 
case Protocol.Loading_Theory(node_name, id) =>  | 
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72721 
diff
changeset
 | 
486  | 
val blobs_info = build_blobs_info(node_name)  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72721 
diff
changeset
 | 
487  | 
                try { global_state.change(_.begin_theory(node_name, id, msg.text, blobs_info)) }
 | 
| 
72692
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72217 
diff
changeset
 | 
488  | 
                catch { case _: Document.State.Fail => bad_output() }
 | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72217 
diff
changeset
 | 
489  | 
|
| 71673 | 490  | 
case List(Markup.Commands_Accepted.PROPERTY) =>  | 
| 
70665
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
491  | 
                msg.text match {
 | 
| 
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
492  | 
case Protocol.Commands_Accepted(ids) =>  | 
| 
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
493  | 
ids.foreach(id =>  | 
| 
73031
 
f93f0597f4fb
clarified signature: absorb XZ.Cache into XML.Cache;
 
wenzelm 
parents: 
73024 
diff
changeset
 | 
494  | 
change_command(_.accumulate(id, Protocol.Commands_Accepted.message, cache)))  | 
| 
70665
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
495  | 
case _ => bad_output()  | 
| 
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
496  | 
}  | 
| 
 
94442fce40a5
prefer commands_accepted: fewer protocol messages;
 
wenzelm 
parents: 
70664 
diff
changeset
 | 
497  | 
|
| 71673 | 498  | 
case List(Markup.Assign_Update.PROPERTY) =>  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
499  | 
                msg.text match {
 | 
| 
70284
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
500  | 
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
 | 
501  | 
                    try {
 | 
| 
70284
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
502  | 
val (edited_nodes, cmds) =  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69640 
diff
changeset
 | 
503  | 
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
 | 
504  | 
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
 | 
505  | 
manager.send(Session.Change_Flush)  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
506  | 
}  | 
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
507  | 
                    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
 | 
508  | 
case _ => bad_output()  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
509  | 
}  | 
| 
56771
 
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
 
wenzelm 
parents: 
56735 
diff
changeset
 | 
510  | 
delay_prune.invoke()  | 
| 46122 | 511  | 
|
| 71673 | 512  | 
case List(Markup.Removed_Versions.PROPERTY) =>  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
513  | 
                msg.text match {
 | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
514  | 
case Protocol.Removed(removed) =>  | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
515  | 
                    try {
 | 
| 56687 | 516  | 
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
 | 
517  | 
manager.send(Session.Change_Flush)  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
518  | 
}  | 
| 
68103
 
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
 
wenzelm 
parents: 
68101 
diff
changeset
 | 
519  | 
                    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
 | 
520  | 
case _ => bad_output()  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
521  | 
}  | 
| 
 
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  | 
case _ => bad_output()  | 
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
524  | 
}  | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
525  | 
}  | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
526  | 
case _ =>  | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
527  | 
          output.properties match {
 | 
| 
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
528  | 
case Position.Id(state_id) =>  | 
| 
73031
 
f93f0597f4fb
clarified signature: absorb XZ.Cache into XML.Cache;
 
wenzelm 
parents: 
73024 
diff
changeset
 | 
529  | 
change_command(_.accumulate(state_id, output.message, cache))  | 
| 56210 | 530  | 
|
| 
54442
 
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
 
wenzelm 
parents: 
53054 
diff
changeset
 | 
531  | 
case _ if output.is_init =>  | 
| 72217 | 532  | 
val init_ok =  | 
533  | 
                try {
 | 
|
534  | 
Isabelle_System.make_services(classOf[Session.Protocol_Handler])  | 
|
535  | 
.foreach(init_protocol_handler)  | 
|
536  | 
true  | 
|
537  | 
}  | 
|
538  | 
                catch {
 | 
|
539  | 
case exn: Throwable =>  | 
|
540  | 
                    prover.get.protocol_command("Prover.stop", "1", Exn.message(exn))
 | 
|
541  | 
false  | 
|
542  | 
}  | 
|
| 
72156
 
065dcd80293e
provide protocol handlers via isabelle_system_service;
 
wenzelm 
parents: 
72116 
diff
changeset
 | 
543  | 
|
| 72217 | 544  | 
              if (init_ok) {
 | 
545  | 
prover.get.options(prover_options(session_options))  | 
|
546  | 
prover.get.init_session(resources)  | 
|
| 72216 | 547  | 
|
| 72217 | 548  | 
phase = Session.Ready  | 
549  | 
debugger.ready()  | 
|
550  | 
}  | 
|
| 56210 | 551  | 
|
| 65317 | 552  | 
case Markup.Process_Result(result) if output.is_exit =>  | 
| 
72115
 
c998827f1df9
more thorough protocol_handlers.exit, like file_formats.stop_session;
 
wenzelm 
parents: 
71970 
diff
changeset
 | 
553  | 
if (prover.defined) protocol_handlers.exit()  | 
| 
72861
 
3f5e6da08687
clarified protocol: support "isabelle log" on failed theories as well;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
554  | 
              for (id <- global_state.value.theories.keys) {
 | 
| 
 
3f5e6da08687
clarified protocol: support "isabelle log" on failed theories as well;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
555  | 
val snapshot = global_state.change_result(_.end_theory(id))  | 
| 
 
3f5e6da08687
clarified protocol: support "isabelle log" on failed theories as well;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
556  | 
finished_theories.post(snapshot)  | 
| 
 
3f5e6da08687
clarified protocol: support "isabelle log" on failed theories as well;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
557  | 
}  | 
| 
69488
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
558  | 
file_formats.stop_session  | 
| 65317 | 559  | 
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
 | 
560  | 
prover.reset  | 
| 56210 | 561  | 
|
| 
61376
 
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
 
wenzelm 
parents: 
60934 
diff
changeset
 | 
562  | 
case _ =>  | 
| 
 
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
 
wenzelm 
parents: 
60934 
diff
changeset
 | 
563  | 
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
 | 
564  | 
}  | 
| 
52111
 
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
 
wenzelm 
parents: 
52084 
diff
changeset
 | 
565  | 
}  | 
| 75393 | 566  | 
//}}}  | 
| 34809 | 567  | 
}  | 
568  | 
||
| 
34820
 
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
 
wenzelm 
parents: 
34819 
diff
changeset
 | 
569  | 
|
| 
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
 | 
570  | 
/* 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
 | 
571  | 
|
| 75393 | 572  | 
    Consumer_Thread.fork[Any]("Session.manager", daemon = true) {
 | 
| 56709 | 573  | 
case arg: Any =>  | 
574  | 
        //{{{
 | 
|
575  | 
        arg match {
 | 
|
| 
56733
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
576  | 
case output: Prover.Output =>  | 
| 
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
577  | 
            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
 | 
578  | 
syslog += output.message  | 
| 
56733
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
579  | 
syslog_messages.post(output)  | 
| 
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
580  | 
}  | 
| 
56775
 
59f70b89e5fd
improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
 
wenzelm 
parents: 
56772 
diff
changeset
 | 
581  | 
|
| 
71606
 
b3b0d87edd20
clarified order: update syslog before handling exit;
 
wenzelm 
parents: 
71601 
diff
changeset
 | 
582  | 
if (output.is_stdout || output.is_stderr)  | 
| 
 
b3b0d87edd20
clarified order: update syslog before handling exit;
 
wenzelm 
parents: 
71601 
diff
changeset
 | 
583  | 
raw_output_messages.post(output)  | 
| 
 
b3b0d87edd20
clarified order: update syslog before handling exit;
 
wenzelm 
parents: 
71601 
diff
changeset
 | 
584  | 
else handle_output(output)  | 
| 
 
b3b0d87edd20
clarified order: update syslog before handling exit;
 
wenzelm 
parents: 
71601 
diff
changeset
 | 
585  | 
|
| 
56733
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
586  | 
all_messages.post(output)  | 
| 
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
587  | 
|
| 
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
588  | 
case input: Prover.Input =>  | 
| 
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
589  | 
all_messages.post(input)  | 
| 
 
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
 
wenzelm 
parents: 
56719 
diff
changeset
 | 
590  | 
|
| 
62556
 
c115e69f457f
more abstract Session.start, without prover command-line;
 
wenzelm 
parents: 
62545 
diff
changeset
 | 
591  | 
case Start(start_prover) if !prover.defined =>  | 
| 
65207
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
592  | 
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
 | 
593  | 
|
| 56709 | 594  | 
case Stop =>  | 
| 
68807
 
e28978310a2a
more robust exit: avoid later Consolidate_Execution with handle_raw_edits (cf. 2fd3a6d6ba2e);
 
wenzelm 
parents: 
68382 
diff
changeset
 | 
595  | 
consolidation.exit()  | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
596  | 
delay_prune.revoke()  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
597  | 
            if (prover.defined) {
 | 
| 56772 | 598  | 
global_state.change(_ => Document.State.init)  | 
| 73367 | 599  | 
prover.get.terminate()  | 
| 56709 | 600  | 
}  | 
| 
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
 | 
601  | 
|
| 
70775
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
602  | 
case Get_State(promise) =>  | 
| 
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
603  | 
promise.fulfill(global_state.value)  | 
| 
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
604  | 
|
| 
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
 | 
605  | 
case Consolidate_Execution =>  | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
606  | 
            if (prover.defined) {
 | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
607  | 
val state = global_state.value  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
608  | 
              state.stable_tip_version match {
 | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
609  | 
case None => consolidation.update()  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
610  | 
case Some(version) =>  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
611  | 
val consolidate =  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
612  | 
consolidation.flush().iterator.filter(name =>  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
613  | 
!resources.session_base.loaded_theory(name) &&  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
614  | 
!state.node_consolidated(version, name) &&  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
615  | 
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
 | 
616  | 
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
 | 
617  | 
}  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68336 
diff
changeset
 | 
618  | 
}  | 
| 
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
 | 
619  | 
|
| 
56771
 
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
 
wenzelm 
parents: 
56735 
diff
changeset
 | 
620  | 
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
 | 
621  | 
            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
 | 
622  | 
val old_versions = global_state.change_result(_.remove_versions(prune_size))  | 
| 59319 | 623  | 
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
 | 
624  | 
}  | 
| 
 
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
 
wenzelm 
parents: 
56735 
diff
changeset
 | 
625  | 
|
| 56709 | 626  | 
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
 | 
627  | 
            if (prover.defined && is_ready) {
 | 
| 72216 | 628  | 
prover.get.options(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
 | 
629  | 
handle_raw_edits()  | 
| 56709 | 630  | 
}  | 
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
631  | 
global_options.post(Session.Global_Options(options))  | 
| 34809 | 632  | 
|
| 
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
 | 
633  | 
case Cancel_Exec(exec_id) if prover.defined =>  | 
| 56709 | 634  | 
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
 | 
635  | 
|
| 
70796
 
2739631ac368
discontinued pointless dump_checkpoint and share_common_data -- superseded by base logic image in Isabelle/MMT;
 
wenzelm 
parents: 
70778 
diff
changeset
 | 
636  | 
case Session.Raw_Edits(doc_blobs, edits) if prover.defined =>  | 
| 
 
2739631ac368
discontinued pointless dump_checkpoint and share_common_data -- superseded by base logic image in Isabelle/MMT;
 
wenzelm 
parents: 
70778 
diff
changeset
 | 
637  | 
handle_raw_edits(doc_blobs = doc_blobs, edits = edits)  | 
| 56709 | 638  | 
|
| 
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
 | 
639  | 
case Session.Dialog_Result(id, serial, result) if prover.defined =>  | 
| 56709 | 640  | 
prover.get.dialog_result(serial, result)  | 
641  | 
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
 | 
642  | 
|
| 73565 | 643  | 
case Protocol_Command_Raw(name, args) if prover.defined =>  | 
644  | 
prover.get.protocol_command_raw(name, args)  | 
|
645  | 
||
646  | 
case Protocol_Command_Args(name, args) if prover.defined =>  | 
|
| 70661 | 647  | 
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
 | 
648  | 
|
| 
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
 | 
649  | 
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
 | 
650  | 
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
 | 
651  | 
if (!state.removing_versions && state.is_assigned(change.previous))  | 
| 56709 | 652  | 
handle_change(change)  | 
653  | 
else postponed_changes.store(change)  | 
|
| 
57651
 
10df45dd14da
less warnings -- ignore potential prover startup/shutdown races;
 
wenzelm 
parents: 
56864 
diff
changeset
 | 
654  | 
|
| 
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
 | 
655  | 
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
 | 
656  | 
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
 | 
657  | 
if (!state.removing_versions)  | 
| 71601 | 658  | 
postponed_changes.flush(state).foreach(handle_change)  | 
| 
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
 | 
659  | 
|
| 
57651
 
10df45dd14da
less warnings -- ignore potential prover startup/shutdown races;
 
wenzelm 
parents: 
56864 
diff
changeset
 | 
660  | 
case bad =>  | 
| 
 
10df45dd14da
less warnings -- ignore potential prover startup/shutdown races;
 
wenzelm 
parents: 
56864 
diff
changeset
 | 
661  | 
            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
 | 
662  | 
}  | 
| 56709 | 663  | 
true  | 
664  | 
//}}}  | 
|
665  | 
}  | 
|
| 
34777
 
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
 
wenzelm 
parents:  
diff
changeset
 | 
666  | 
}  | 
| 
 
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
 
wenzelm 
parents:  
diff
changeset
 | 
667  | 
|
| 34809 | 668  | 
|
| 56799 | 669  | 
/* main operations */  | 
670  | 
||
| 75393 | 671  | 
  def get_state(): Document.State = {
 | 
| 74253 | 672  | 
    if (manager.is_active()) {
 | 
| 70776 | 673  | 
val promise = Future.promise[Document.State]  | 
674  | 
manager.send_wait(Get_State(promise))  | 
|
675  | 
promise.join  | 
|
676  | 
}  | 
|
677  | 
else Document.State.init  | 
|
| 
70775
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
678  | 
}  | 
| 
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
679  | 
|
| 56799 | 680  | 
def snapshot(name: Document.Node.Name = Document.Node.Name.empty,  | 
681  | 
pending_edits: List[Text.Edit] = Nil): Document.Snapshot =  | 
|
| 
70775
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
682  | 
get_state().snapshot(name, pending_edits)  | 
| 
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
683  | 
|
| 
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
684  | 
def recent_syntax(name: Document.Node.Name): Outer_Syntax =  | 
| 
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
685  | 
get_state().recent_finished.version.get_finished.nodes(name).syntax getOrElse  | 
| 
 
97d3485028b6
more sequential access to Session.manager.global_state: avoid minor divergence of tip version;
 
wenzelm 
parents: 
70774 
diff
changeset
 | 
686  | 
resources.session_base.overall_syntax  | 
| 34809 | 687  | 
|
| 75393 | 688  | 
  @tailrec final def await_stable_snapshot(): Document.Snapshot = {
 | 
| 
69640
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
689  | 
val snapshot = this.snapshot()  | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
690  | 
    if (snapshot.is_outdated) {
 | 
| 
73702
 
7202e12cb324
tuned signature --- following hints by IntelliJ IDEA;
 
wenzelm 
parents: 
73565 
diff
changeset
 | 
691  | 
output_delay.sleep()  | 
| 
69640
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
692  | 
await_stable_snapshot()  | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
693  | 
}  | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
694  | 
else snapshot  | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
695  | 
}  | 
| 
 
af09cc4792dc
more robust: no assumptions about GUI thread or document model;
 
wenzelm 
parents: 
69492 
diff
changeset
 | 
696  | 
|
| 75393 | 697  | 
  def start(start_prover: Prover.Receiver => Prover): Unit = {
 | 
| 
69488
 
b05c0bb47f6d
support for File_Format.Session, e.g. server process accessible via prover options;
 
wenzelm 
parents: 
68807 
diff
changeset
 | 
698  | 
file_formats  | 
| 
65207
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
699  | 
_phase.change(  | 
| 
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
700  | 
      {
 | 
| 
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
701  | 
case Session.Inactive =>  | 
| 
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
702  | 
manager.send(Start(start_prover))  | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
703  | 
post_phase(Session.Startup)  | 
| 
65207
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
704  | 
        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
 | 
705  | 
})  | 
| 
 
004bc5968c2a
more strict Session.start: no restart from terminated session;
 
wenzelm 
parents: 
65206 
diff
changeset
 | 
706  | 
}  | 
| 45076 | 707  | 
|
| 75393 | 708  | 
  def stop(): Process_Result = {
 | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
709  | 
val was_ready =  | 
| 
71667
 
4d2de35214c5
proper treatment of protocol exceptions and prover termination: avoid session.stop while saving image;
 
wenzelm 
parents: 
71655 
diff
changeset
 | 
710  | 
_phase.guarded_access(  | 
| 
 
4d2de35214c5
proper treatment of protocol exceptions and prover termination: avoid session.stop while saving image;
 
wenzelm 
parents: 
71655 
diff
changeset
 | 
711  | 
        {
 | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
712  | 
case Session.Startup | Session.Shutdown => None  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
713  | 
case Session.Terminated(_) => Some((false, phase))  | 
| 65317 | 714  | 
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
 | 
715  | 
case Session.Ready => Some((true, post_phase(Session.Shutdown)))  | 
| 
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
716  | 
})  | 
| 65311 | 717  | 
if (was_ready) manager.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
 | 
718  | 
prover.await_reset()  | 
| 
65208
 
91c528cd376a
more robust Session.stop: idempotent, avoid conflict with startup;
 
wenzelm 
parents: 
65207 
diff
changeset
 | 
719  | 
|
| 56704 | 720  | 
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
 | 
721  | 
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
 | 
722  | 
manager.shutdown()  | 
| 
56715
 
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
 
wenzelm 
parents: 
56713 
diff
changeset
 | 
723  | 
dispatcher.shutdown()  | 
| 65209 | 724  | 
|
725  | 
    phase match {
 | 
|
| 65317 | 726  | 
case Session.Terminated(result) => result  | 
| 65209 | 727  | 
      case phase => error("Bad session phase after shutdown: " + quote(phase.print))
 | 
728  | 
}  | 
|
| 50117 | 729  | 
}  | 
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38722 
diff
changeset
 | 
730  | 
|
| 73565 | 731  | 
def protocol_command_raw(name: String, args: List[Bytes]): Unit =  | 
732  | 
manager.send(Protocol_Command_Raw(name, args))  | 
|
733  | 
||
734  | 
def protocol_command_args(name: String, args: List[String]): Unit =  | 
|
735  | 
manager.send(Protocol_Command_Args(name, args))  | 
|
736  | 
||
| 73340 | 737  | 
def protocol_command(name: String, args: String*): Unit =  | 
| 73565 | 738  | 
protocol_command_args(name, args.toList)  | 
| 
53054
 
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
 
wenzelm 
parents: 
52931 
diff
changeset
 | 
739  | 
|
| 73340 | 740  | 
def cancel_exec(exec_id: Document_ID.Exec): Unit =  | 
741  | 
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
 | 
742  | 
|
| 73340 | 743  | 
def update(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text]): Unit =  | 
| 
70796
 
2739631ac368
discontinued pointless dump_checkpoint and share_common_data -- superseded by base logic image in Isabelle/MMT;
 
wenzelm 
parents: 
70778 
diff
changeset
 | 
744  | 
if (edits.nonEmpty) manager.send_wait(Session.Raw_Edits(doc_blobs, edits))  | 
| 73340 | 745  | 
|
746  | 
def update_options(options: Options): Unit =  | 
|
747  | 
manager.send_wait(Update_Options(options))  | 
|
| 50498 | 748  | 
|
| 73340 | 749  | 
def dialog_result(id: Document_ID.Generic, serial: Long, result: String): Unit =  | 
750  | 
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
 | 
751  | 
}  |