| author | Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> | 
| Thu, 04 Nov 2021 16:50:03 +0100 | |
| changeset 74691 | 634e2323b6cf | 
| parent 74253 | 45dc9de1bd33 | 
| child 75393 | 87ebf5a50283 | 
| 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 | |
| 14 | object Simplifier_Trace | |
| 15 | {
 | |
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 16 | /* 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 | 17 | |
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 18 | val TEXT = "text" | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 19 | val Text = new Properties.String(TEXT) | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 20 | |
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 21 | val PARENT = "parent" | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 22 | val Parent = new Properties.Long(PARENT) | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 23 | |
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 24 | val SUCCESS = "success" | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 25 | val Success = new Properties.Boolean(SUCCESS) | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 26 | |
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 27 | val MEMORY = "memory" | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 28 | val Memory = new Properties.Boolean(MEMORY) | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 29 | |
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 30 | object Item | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 31 |   {
 | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 32 | case class Data( | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 33 | serial: Long, markup: String, text: String, | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 34 | parent: Long, props: Properties.T, content: XML.Body) | 
| 
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 | def memory: Boolean = Memory.unapply(props) getOrElse true | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 37 | } | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 38 | |
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 39 | def unapply(tree: XML.Tree): Option[(String, Data)] = | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 40 |       tree match {
 | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 41 | case XML.Elem(Markup(Markup.RESULT, Markup.Serial(serial)), | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 42 | List(XML.Elem(Markup(markup, props), content))) | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 43 |         if markup.startsWith("simp_trace_") =>  // FIXME proper comparison of string constants
 | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 44 |           (props, props) match {
 | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 45 | case (Text(text), Parent(parent)) => | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 46 | Some((markup, Data(serial, markup, text, parent, props, content))) | 
| 
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 | case _ => None | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 50 | } | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 51 | } | 
| 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 | 52 | |
| 
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 | /* 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 | 55 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 56 | 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 | 57 | |
| 
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 | object 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 | 59 |   {
 | 
| 
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 | object step | 
| 
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 |     {
 | 
| 
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 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 | 63 |       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 | 64 |       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 | 65 |       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 | 66 |       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 | 67 | |
| 
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 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 | 69 | } | 
| 
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 | object hint_fail | 
| 
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 |       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 | 74 |       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 | 75 | |
| 
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 | 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 | 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 | } | 
| 
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 | |
| 55555 | 80 | 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 | 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 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 83 | /* 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 | 84 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 85 | 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 | 86 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 87 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 88 | /* 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 | 89 | |
| 56717 | 90 | 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 | 91 | 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 | 92 | 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 | 93 | 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 | 94 | 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 | 95 | 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 | 96 | |
| 57593 
2f7d91242b99
proper Swing buttons instead of active areas within text (by Lars Hupel);
 wenzelm parents: 
56782diff
changeset | 97 | 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 | 98 | |
| 
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 | 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 | 100 | last_serial: Long = 0L, | 
| 56717 | 101 | questions: SortedMap[Long, Question] = SortedMap.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 | 102 |   {
 | 
| 
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 | 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 | 104 | 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 | 105 | |
| 
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 | 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 | 107 | 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 | 108 | |
| 
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 | 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 | 110 | 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 | 111 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 112 | |
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 113 | 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 | 114 | |
| 
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 | 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 | 116 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 117 | object Index | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 118 |   {
 | 
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 119 | 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 | 120 | 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 | 121 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 122 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 123 | def handle_results(session: Session, id: Document_ID.Command, results: Command.Results): 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 | 124 |   {
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 125 | val slot = Future.promise[Context] | 
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 126 | 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 | 127 | 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 | 128 | } | 
| 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 | 129 | |
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 130 | 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 | 131 |   {
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 132 | val slot = Future.promise[Trace] | 
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 133 | 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 | 134 | 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 | 135 | } | 
| 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 | 136 | |
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 137 | def clear_memory(session: Session): Unit = | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 138 | 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 | 139 | |
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 140 | def send_reply(session: Session, serial: Long, answer: Answer): Unit = | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 141 | 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 | 142 | |
| 66461 
0b55fbc51f76
reinit the manager thread, e.g. after restart of the Isabelle/jEdit plugin;
 wenzelm parents: 
65220diff
changeset | 143 | def make_manager: Consumer_Thread[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 | 144 |   {
 | 
| 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 | 145 | 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 | 146 | |
| 
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 | 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 | 148 | 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 | 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 | 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 | 151 |       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 | 152 | 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 | 153 | (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 | 154 | } | 
| 
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 | |
| 73340 | 156 | 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 | 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 | // 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 | 159 | // 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 | 160 | // 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 | 161 | // 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 | 162 | 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 | 163 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 164 | |
| 73340 | 165 | def do_reply(session: Session, serial: Long, answer: Answer): 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 | 166 |     {
 | 
| 56717 | 167 | session.protocol_command( | 
| 63805 | 168 | "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 | 169 | } | 
| 
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 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 171 |     Consumer_Thread.fork[Any]("Simplifier_Trace.manager", daemon = true)(
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 172 | consume = (arg: Any) => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 173 |       {
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 174 |         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 | 175 | 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 | 176 | 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 | 177 | 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 | 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 | for ((serial, result) <- results.iterator if serial > new_context.last_serial) | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 180 |             {
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 181 |               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 | 182 | 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 | 183 | 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 | 184 | (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 | 185 | |
| 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 |                   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 | 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_STEP => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 189 | 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 | 190 |                       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 | 191 | 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 | 192 | 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 | 193 | case _ => | 
| 57593 
2f7d91242b99
proper Swing buttons instead of active areas within text (by Lars Hupel);
 wenzelm parents: 
56782diff
changeset | 194 | 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 | 195 | } | 
| 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 | 196 | |
| 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 | 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 | 198 |                       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 | 199 | 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 | 200 |                           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 | 201 | 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 | 202 | 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 | 203 | case _ => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 204 | // unknown, better send a default reply | 
| 57593 
2f7d91242b99
proper Swing buttons instead of active areas within text (by Lars Hupel);
 wenzelm parents: 
56782diff
changeset | 205 | 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 | 206 | } | 
| 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 | 207 | 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 | 208 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 209 | |
| 56718 
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 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 | 211 | // 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 | 212 | // 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 | 213 | // 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 | 214 | // 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 | 215 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 216 | @tailrec | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 217 | 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 | 218 |                         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 | 219 | 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 | 220 | 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 | 221 | 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 | 222 | 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 | 223 | 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 | 224 | 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 | 225 | case _ => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 226 | } | 
| 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 | 227 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 228 | 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 | 229 | |
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 230 | case _ => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 231 | } | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 232 | |
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 233 | case _ => | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 234 | } | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 235 | |
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 236 | 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 | 237 | } | 
| 
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 | 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 | 240 | 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 | 241 | 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 | 242 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 243 | 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 | 244 | // 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 | 245 | // 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 | 246 | // 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 | 247 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 248 | val items = | 
| 57593 
2f7d91242b99
proper Swing buttons instead of active areas within text (by Lars Hupel);
 wenzelm parents: 
56782diff
changeset | 249 |               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 | 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 | 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 | 252 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 253 | 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 | 254 |             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 | 255 | 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 | 256 | 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 | 257 | 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 | 258 | } | 
| 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 | 259 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 260 | 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 | 261 | 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 | 262 | 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 | 263 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 264 | 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 | 265 |             find_question(serial) match {
 | 
| 57593 
2f7d91242b99
proper Swing buttons instead of active areas within text (by Lars Hupel);
 wenzelm parents: 
56782diff
changeset | 266 | case Some((id, Question(data, _))) => | 
| 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 | if (data.markup == Markup.SIMP_TRACE_STEP && 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 | 268 |                 {
 | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 269 | 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 | 270 | 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 | 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 | 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 | 273 | case None => | 
| 56782 
433cf57550fa
more systematic Isabelle output, like in classic Isabelle/ML (without markup);
 wenzelm parents: 
56718diff
changeset | 274 |                 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 | 275 | } | 
| 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 | 276 | |
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 277 | 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 | 278 | 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 | 279 | } | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 280 | true | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 281 | }, | 
| 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 282 | 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 | 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 | |
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 286 | 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 | 287 | |
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 288 | def the_manager(session: Session): Consumer_Thread[Any] = | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 289 |     managers.value.get(session) match {
 | 
| 74253 | 290 | 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 | 291 |       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 | 292 | } | 
| 
0b55fbc51f76
reinit the manager thread, e.g. after restart of the Isabelle/jEdit plugin;
 wenzelm parents: 
65220diff
changeset | 293 | |
| 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 | 294 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 295 | /* protocol handler */ | 
| 54730 | 296 | |
| 297 | class Handler extends Session.Protocol_Handler | |
| 298 |   {
 | |
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 299 | private var the_session: Session = null | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 300 | |
| 73340 | 301 | override def init(session: Session): Unit = | 
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 302 |     {
 | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 303 |       try { the_manager(session) }
 | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 304 |       catch { case ERROR(_) => managers.change(map => map + (session -> make_manager)) }
 | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 305 | the_session = session | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 306 | } | 
| 56718 
096139bcfadd
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
 wenzelm parents: 
56717diff
changeset | 307 | |
| 73340 | 308 | override def exit(): Unit = | 
| 65220 | 309 |     {
 | 
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 310 | val session = the_session | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 311 |       if (session != null) {
 | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 312 | val manager = the_manager(session) | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 313 | manager.send(Clear_Memory) | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 314 | manager.shutdown() | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 315 | managers.change(map => map - session) | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 316 | the_session = null | 
| 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 317 | } | 
| 65220 | 318 | } | 
| 319 | ||
| 65219 | 320 | 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 | 321 |       msg.properties match {
 | 
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55390diff
changeset | 322 | case Markup.Simp_Trace_Cancel(serial) => | 
| 71650 
95ab607398bd
support multiple sessions, notably for "isabelle build -P -j2";
 wenzelm parents: 
71610diff
changeset | 323 | 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 | 324 | 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 | 325 | 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 | 326 | 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 | 327 | } | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54730diff
changeset | 328 | |
| 72212 | 329 | override val functions = List(Markup.SIMP_TRACE_CANCEL -> cancel) | 
| 54730 | 330 | } | 
| 331 | } |