| author | wenzelm | 
| Fri, 23 Dec 2022 22:51:47 +0100 | |
| changeset 76767 | 540cd80c5af2 | 
| parent 75440 | 39011d0d2128 | 
| child 78592 | fdfe9b91d96e | 
| permissions | -rw-r--r-- | 
| 54730 | 1 | /* Title: Pure/Tools/simplifier_trace.scala | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 2 | Author: Lars Hupel | 
| 54730 | 3 | |
| 4 | Interactive Simplifier trace. | |
| 5 | */ | |
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 9 | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 10 | import scala.annotation.tailrec | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 11 | import scala.collection.immutable.SortedMap | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 12 | |
| 54730 | 13 | |
| 75393 | 14 | object Simplifier_Trace {
 | 
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 15 | /* trace items from the prover */ | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 16 | |
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 17 | val TEXT = "text" | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 18 | val Text = new Properties.String(TEXT) | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 19 | |
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 20 | val PARENT = "parent" | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 21 | val Parent = new Properties.Long(PARENT) | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 22 | |
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 23 | val SUCCESS = "success" | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 24 | val Success = new Properties.Boolean(SUCCESS) | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 25 | |
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 26 | val MEMORY = "memory" | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 27 | val Memory = new Properties.Boolean(MEMORY) | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 28 | |
| 75393 | 29 |   object Item {
 | 
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 30 | case class Data( | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 31 | serial: Long, markup: String, text: String, | 
| 75393 | 32 | parent: Long, props: Properties.T, content: XML.Body | 
| 33 |     ) {
 | |
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 34 | def memory: Boolean = Memory.unapply(props) getOrElse true | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 35 | } | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 36 | |
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 37 | def unapply(tree: XML.Tree): Option[(String, Data)] = | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 38 |       tree match {
 | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 39 | case XML.Elem(Markup(Markup.RESULT, Markup.Serial(serial)), | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 40 | List(XML.Elem(Markup(markup, props), content))) | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 41 |         if markup.startsWith("simp_trace_") =>  // FIXME proper comparison of string constants
 | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 42 |           (props, props) match {
 | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 43 | case (Text(text), Parent(parent)) => | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 44 | Some((markup, Data(serial, markup, text, parent, props, content))) | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 45 | case _ => None | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 46 | } | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 47 | case _ => None | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 48 | } | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 49 | } | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 50 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 51 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 52 | /* replies to the prover */ | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 53 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 54 | case class Answer private[Simplifier_Trace](val name: String, val string: String) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 55 | |
| 75393 | 56 |   object Answer {
 | 
| 57 |     object step {
 | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 58 |       val skip = Answer("skip", "Skip")
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 59 |       val continue = Answer("continue", "Continue")
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 60 |       val continue_trace = Answer("continue_trace", "Continue (with full trace)")
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 61 |       val continue_passive = Answer("continue_passive", "Continue (without asking)")
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 62 |       val continue_disable = Answer("continue_disable", "Continue (without any trace)")
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 63 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 64 | val all = List(continue, continue_trace, continue_passive, continue_disable, skip) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 65 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 66 | |
| 75393 | 67 |     object hint_fail {
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 68 |       val exit = Answer("exit", "Exit")
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 69 |       val redo = Answer("redo", "Redo")
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 70 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 71 | val all = List(redo, exit) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 72 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 73 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 74 | |
| 55555 | 75 | val all_answers: List[Answer] = Answer.step.all ::: Answer.hint_fail.all | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 76 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 77 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 78 | /* GUI interaction */ | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 79 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 80 | case object Event | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 81 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 82 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 83 | /* manager thread */ | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 84 | |
| 56717 | 85 | private case class Handle_Results( | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 86 | session: Session, id: Document_ID.Command, results: Command.Results, slot: Promise[Context]) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 87 | private case class Generate_Trace(results: Command.Results, slot: Promise[Trace]) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 88 | private case class Cancel(serial: Long) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 89 | private object Clear_Memory | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 90 | case class Reply(session: Session, serial: Long, answer: Answer) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 91 | |
| 57593 
2f7d91242b99
proper Swing buttons instead of active areas within text (by Lars Hupel);
 wenzelm parents: 
56782diff
changeset | 92 | case class Question(data: Item.Data, answers: List[Answer]) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 93 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 94 | case class Context( | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 95 | last_serial: Long = 0L, | 
| 75393 | 96 | questions: SortedMap[Long, Question] = SortedMap.empty | 
| 97 |   ) {
 | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 98 | def +(q: Question): Context = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 99 | copy(questions = questions + ((q.data.serial, q))) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 100 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 101 | def -(s: Long): Context = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 102 | copy(questions = questions - s) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 103 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 104 | def with_serial(s: Long): Context = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 105 | copy(last_serial = Math.max(last_serial, s)) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 106 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 107 | |
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 108 | case class Trace(entries: List[Item.Data]) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 109 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 110 | case class Index(text: String, content: XML.Body) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 111 | |
| 75393 | 112 |   object Index {
 | 
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 113 | def of_data(data: Item.Data): Index = | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 114 | Index(data.text, data.content) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 115 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 116 | |
| 75393 | 117 | def handle_results( | 
| 118 | session: Session, | |
| 119 | id: Document_ID.Command, | |
| 120 | results: Command.Results | |
| 121 |   ): Context = {
 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 122 | val slot = Future.promise[Context] | 
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 123 | the_manager(session).send(Handle_Results(session, id, results, slot)) | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 124 | slot.join | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 125 | } | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 126 | |
| 75393 | 127 |   def generate_trace(session: Session, results: Command.Results): Trace = {
 | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 128 | val slot = Future.promise[Trace] | 
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 129 | the_manager(session).send(Generate_Trace(results, slot)) | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 130 | slot.join | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 131 | } | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 132 | |
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 133 | def clear_memory(session: Session): Unit = | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 134 | the_manager(session).send(Clear_Memory) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 135 | |
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 136 | def send_reply(session: Session, serial: Long, answer: Answer): Unit = | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 137 | the_manager(session).send(Reply(session, serial, answer)) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 138 | |
| 75393 | 139 |   def make_manager: Consumer_Thread[Any] = {
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 140 | var contexts = Map.empty[Document_ID.Command, Context] | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 141 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 142 | var memory_children = Map.empty[Long, Set[Long]] | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 143 | var memory = Map.empty[Index, Answer] | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 144 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 145 | def find_question(serial: Long): Option[(Document_ID.Command, Question)] = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 146 |       contexts collectFirst {
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 147 | case (id, context) if context.questions contains serial => | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 148 | (id, context.questions(serial)) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 149 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 150 | |
| 75393 | 151 |     def do_cancel(serial: Long, id: Document_ID.Command): Unit = {
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 152 | // To save memory, we could try to remove empty contexts at this point. | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 153 | // However, if a new serial gets attached to the same command_id after we deleted | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 154 | // its context, its last_serial counter will start at 0 again, and we'll think the | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 155 | // old serials are actually new | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 156 | contexts += (id -> (contexts(id) - serial)) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 157 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 158 | |
| 75393 | 159 |     def do_reply(session: Session, serial: Long, answer: Answer): Unit = {
 | 
| 56717 | 160 | session.protocol_command( | 
| 63805 | 161 | "Simplifier_Trace.reply", Value.Long(serial), answer.name) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 162 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 163 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 164 |     Consumer_Thread.fork[Any]("Simplifier_Trace.manager", daemon = true)(
 | 
| 75394 | 165 |       consume = { (arg: Any) =>
 | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 166 |         arg match {
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 167 | case Handle_Results(session, id, results, slot) => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 168 | var new_context = contexts.getOrElse(id, Context()) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 169 | var new_serial = new_context.last_serial | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 170 | |
| 75393 | 171 |             for ((serial, result) <- results.iterator if serial > new_context.last_serial) {
 | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 172 |               result match {
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 173 | case Item(markup, data) => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 174 | memory_children += | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 175 | (data.parent -> (memory_children.getOrElse(data.parent, Set.empty) + serial)) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 176 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 177 |                   markup match {
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 178 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 179 | case Markup.SIMP_TRACE_STEP => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 180 | val index = Index.of_data(data) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 181 |                       memory.get(index) match {
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 182 | case Some(answer) if data.memory => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 183 | do_reply(session, serial, answer) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 184 | case _ => | 
| 57593 
2f7d91242b99
proper Swing buttons instead of active areas within text (by Lars Hupel);
 wenzelm parents: 
56782diff
changeset | 185 | new_context += Question(data, Answer.step.all) | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 186 | } | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 187 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 188 | case Markup.SIMP_TRACE_HINT => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 189 |                       data.props match {
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 190 | case Success(false) => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 191 |                           results.get(data.parent) match {
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 192 | case Some(Item(Markup.SIMP_TRACE_STEP, _)) => | 
| 57593 
2f7d91242b99
proper Swing buttons instead of active areas within text (by Lars Hupel);
 wenzelm parents: 
56782diff
changeset | 193 | new_context += Question(data, Answer.hint_fail.all) | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 194 | case _ => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 195 | // unknown, better send a default reply | 
| 57593 
2f7d91242b99
proper Swing buttons instead of active areas within text (by Lars Hupel);
 wenzelm parents: 
56782diff
changeset | 196 | do_reply(session, data.serial, Answer.hint_fail.exit) | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 197 | } | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 198 | case _ => | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 199 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 200 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 201 | case Markup.SIMP_TRACE_IGNORE => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 202 | // At this point, we know that the parent of this 'IGNORE' entry is a 'STEP' | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 203 | // entry, and that that 'STEP' entry is about to be replayed. Hence, we need | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 204 | // to selectively purge the replies which have been memorized, going down from | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 205 | // the parent to all leaves. | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 206 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 207 | @tailrec | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 208 | def purge(queue: Vector[Long]): Unit = | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 209 |                         queue match {
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 210 | case s +: rest => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 211 | for (Item(Markup.SIMP_TRACE_STEP, data) <- results.get(s)) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 212 | memory -= Index.of_data(data) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 213 | val children = memory_children.getOrElse(s, Set.empty) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 214 | memory_children -= s | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 215 | purge(rest ++ children.toVector) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 216 | case _ => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 217 | } | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 218 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 219 | purge(Vector(data.parent)) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 220 | |
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 221 | case _ => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 222 | } | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 223 | |
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 224 | case _ => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 225 | } | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 226 | |
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 227 | new_serial = serial | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 228 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 229 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 230 | new_context = new_context.with_serial(new_serial) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 231 | contexts += (id -> new_context) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 232 | slot.fulfill(new_context) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 233 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 234 | case Generate_Trace(results, slot) => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 235 | // Since there are potentially lots of trace messages, we do not cache them here again. | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 236 | // Instead, everytime the trace is being requested, we re-assemble it based on the | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 237 | // current results. | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 238 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 239 | val items = | 
| 57593 
2f7d91242b99
proper Swing buttons instead of active areas within text (by Lars Hupel);
 wenzelm parents: 
56782diff
changeset | 240 |               results.iterator.collect { case (_, Item(_, data)) => data }.toList
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 241 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 242 | slot.fulfill(Trace(items)) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 243 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 244 | case Cancel(serial) => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 245 |             find_question(serial) match {
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 246 | case Some((id, _)) => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 247 | do_cancel(serial, id) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 248 | case None => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 249 | } | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 250 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 251 | case Clear_Memory => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 252 | memory_children = Map.empty | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 253 | memory = Map.empty | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 254 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 255 | case Reply(session, serial, answer) => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 256 |             find_question(serial) match {
 | 
| 57593 
2f7d91242b99
proper Swing buttons instead of active areas within text (by Lars Hupel);
 wenzelm parents: 
56782diff
changeset | 257 | case Some((id, Question(data, _))) => | 
| 75393 | 258 |                 if (data.markup == Markup.SIMP_TRACE_STEP && data.memory) {
 | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 259 | val index = Index.of_data(data) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 260 | memory += (index -> answer) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 261 | } | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 262 | do_cancel(serial, id) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 263 | case None => | 
| 56782 
433cf57550fa
more systematic Isabelle output, like in classic Isabelle/ML (without markup);
 wenzelm parents: 
56718diff
changeset | 264 |                 Output.warning("send_reply: unknown serial " + serial)
 | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 265 | } | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 266 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 267 | do_reply(session, serial, answer) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 268 | session.trace_events.post(Event) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 269 | } | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 270 | true | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 271 | }, | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 272 | finish = () => contexts = Map.empty | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 273 | ) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 274 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 275 | |
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 276 | private val managers = Synchronized(Map.empty[Session, Consumer_Thread[Any]]) | 
| 66461 
0b55fbc51f76
reinit the manager thread, e.g. after restart of the Isabelle/jEdit plugin;
 wenzelm parents: 
65220diff
changeset | 277 | |
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 278 | def the_manager(session: Session): Consumer_Thread[Any] = | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 279 |     managers.value.get(session) match {
 | 
| 74253 | 280 | case Some(thread) if thread.is_active() => thread | 
| 66461 
0b55fbc51f76
reinit the manager thread, e.g. after restart of the Isabelle/jEdit plugin;
 wenzelm parents: 
65220diff
changeset | 281 |       case _ => error("Bad Simplifier_Trace.manager thread")
 | 
| 
0b55fbc51f76
reinit the manager thread, e.g. after restart of the Isabelle/jEdit plugin;
 wenzelm parents: 
65220diff
changeset | 282 | } | 
| 
0b55fbc51f76
reinit the manager thread, e.g. after restart of the Isabelle/jEdit plugin;
 wenzelm parents: 
65220diff
changeset | 283 | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 284 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 285 | /* protocol handler */ | 
| 54730 | 286 | |
| 75393 | 287 |   class Handler extends Session.Protocol_Handler {
 | 
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 288 | private var the_session: Session = null | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 289 | |
| 75393 | 290 |     override def init(session: Session): Unit = {
 | 
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 291 |       try { the_manager(session) }
 | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 292 |       catch { case ERROR(_) => managers.change(map => map + (session -> make_manager)) }
 | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 293 | the_session = session | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 294 | } | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 295 | |
| 75393 | 296 |     override def exit(): Unit = {
 | 
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 297 | val session = the_session | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 298 |       if (session != null) {
 | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 299 | val manager = the_manager(session) | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 300 | manager.send(Clear_Memory) | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 301 | manager.shutdown() | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 302 | managers.change(map => map - session) | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 303 | the_session = null | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 304 | } | 
| 65220 | 305 | } | 
| 306 | ||
| 65219 | 307 | private def cancel(msg: Prover.Protocol_Output): Boolean = | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 308 |       msg.properties match {
 | 
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 309 | case Markup.Simp_Trace_Cancel(serial) => | 
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 310 | the_manager(the_session).send(Cancel(serial)) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 311 | true | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 312 | case _ => | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 313 | false | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 314 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 315 | |
| 75440 | 316 | override val functions: Session.Protocol_Functions = | 
| 317 | List(Markup.SIMP_TRACE_CANCEL -> cancel) | |
| 54730 | 318 | } | 
| 319 | } |