src/Pure/Tools/simplifier_trace.scala
author wenzelm
Fri, 25 Apr 2014 13:29:56 +0200
changeset 56718 096139bcfadd
parent 56717 d96b10ec397c
child 56782 433cf57550fa
permissions -rw-r--r--
replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54730
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     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: 54730
diff changeset
     2
    Author:     Lars Hupel
54730
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     3
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     4
Interactive Simplifier trace.
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     5
*/
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     6
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     7
package isabelle
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     8
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff 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: 54730
diff 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: 54730
diff 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: 54730
diff changeset
    12
54730
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
    13
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
    14
object Simplifier_Trace
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
    15
{
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff 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: 54730
diff changeset
    17
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    18
  val TEXT = "text"
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    19
  val Text = new Properties.String(TEXT)
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    20
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    21
  val PARENT = "parent"
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    22
  val Parent = new Properties.Long(PARENT)
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    23
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    24
  val SUCCESS = "success"
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    25
  val Success = new Properties.Boolean(SUCCESS)
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    26
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    27
  val MEMORY = "memory"
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    28
  val Memory = new Properties.Boolean(MEMORY)
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    29
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    30
  object Item
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    31
  {
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    32
    case class Data(
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    33
      serial: Long, markup: String, text: String,
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    34
      parent: Long, props: Properties.T, content: XML.Body)
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    35
    {
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    36
      def memory: Boolean = Memory.unapply(props) getOrElse true
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    37
    }
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    38
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    39
    def unapply(tree: XML.Tree): Option[(String, Data)] =
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    40
      tree match {
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    41
        case XML.Elem(Markup(Markup.RESULT, Markup.Serial(serial)),
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    42
          List(XML.Elem(Markup(markup, props), content)))
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    43
        if markup.startsWith("simp_trace_") =>  // FIXME proper comparison of string constants
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    44
          (props, props) match {
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    45
            case (Text(text), Parent(parent)) =>
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    46
              Some((markup, Data(serial, markup, text, parent, props, content)))
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    47
            case _ => None
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    48
          }
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    49
        case _ => None
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    50
      }
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff 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: 54730
diff changeset
    52
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    53
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff 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: 54730
diff changeset
    55
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff 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: 54730
diff changeset
    57
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff 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: 54730
diff changeset
    59
  {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff 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: 54730
diff changeset
    61
    {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff 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: 54730
diff 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: 54730
diff 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: 54730
diff 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: 54730
diff 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: 54730
diff changeset
    67
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    68
      val default = skip
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    69
      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: 54730
diff changeset
    70
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    71
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    72
    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: 54730
diff changeset
    73
    {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    74
      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: 54730
diff changeset
    75
      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: 54730
diff changeset
    76
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    77
      val default = exit
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    78
      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: 54730
diff changeset
    79
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    80
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    81
55555
9c16317c91d1 prefer concrete list append;
wenzelm
parents: 55553
diff changeset
    82
  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: 54730
diff changeset
    83
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    84
  object Active
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    85
  {
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    86
    def unapply(tree: XML.Tree): Option[(Long, Answer)] =
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    87
      tree match {
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    88
        case XML.Elem(Markup(Markup.SIMP_TRACE, props), _) =>
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    89
          (props, props) match {
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    90
            case (Markup.Serial(serial), Markup.Name(name)) =>
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    91
              all_answers.find(_.name == name).map((serial, _))
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    92
            case _ => None
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    93
          }
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    94
        case _ => None
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    95
      }
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    96
  }
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    97
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    98
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    99
  /* GUI interaction */
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   100
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   101
  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: 54730
diff changeset
   102
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   103
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   104
  /* 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: 54730
diff changeset
   105
56717
d96b10ec397c tuned whitespace;
wenzelm
parents: 56715
diff changeset
   106
  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: 56717
diff changeset
   107
    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: 56717
diff changeset
   108
  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: 54730
diff changeset
   109
  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: 54730
diff changeset
   110
  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: 54730
diff changeset
   111
  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: 54730
diff changeset
   112
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
   113
  case class Question(data: Item.Data, answers: List[Answer], default_answer: Answer)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   114
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   115
  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: 54730
diff changeset
   116
    last_serial: Long = 0L,
56717
d96b10ec397c tuned whitespace;
wenzelm
parents: 56715
diff changeset
   117
    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: 54730
diff changeset
   118
  {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   119
    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: 54730
diff changeset
   120
      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: 54730
diff changeset
   121
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   122
    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: 54730
diff changeset
   123
      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: 54730
diff changeset
   124
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   125
    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: 54730
diff changeset
   126
      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: 54730
diff changeset
   127
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   128
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
   129
  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: 54730
diff changeset
   130
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   131
  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: 54730
diff changeset
   132
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   133
  object Index
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   134
  {
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
   135
    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: 54730
diff changeset
   136
      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: 54730
diff changeset
   137
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   138
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   139
  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: 56717
diff changeset
   140
  {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   141
    val slot = Future.promise[Context]
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   142
    manager.send(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: 56717
diff changeset
   143
    slot.join
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff 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: 54730
diff changeset
   145
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   146
  def generate_trace(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: 56717
diff changeset
   147
  {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   148
    val slot = Future.promise[Trace]
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   149
    manager.send(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: 56717
diff changeset
   150
    slot.join
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   151
  }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   152
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   153
  def clear_memory() =
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   154
    manager.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: 54730
diff changeset
   155
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   156
  def send_reply(session: Session, serial: Long, answer: Answer) =
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   157
    manager.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: 54730
diff changeset
   158
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   159
  private lazy val manager: Consumer_Thread[Any] =
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   160
  {
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   161
    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: 54730
diff changeset
   162
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   163
    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: 54730
diff changeset
   164
    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: 54730
diff changeset
   165
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   166
    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: 54730
diff changeset
   167
      contexts collectFirst {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   168
        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: 54730
diff changeset
   169
          (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: 54730
diff changeset
   170
      }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   171
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   172
    def do_cancel(serial: Long, id: Document_ID.Command)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   173
    {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   174
      // 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: 54730
diff changeset
   175
      // 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: 54730
diff changeset
   176
      // 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: 54730
diff changeset
   177
      // 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: 54730
diff changeset
   178
      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: 54730
diff changeset
   179
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   180
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   181
    def do_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: 54730
diff changeset
   182
    {
56717
d96b10ec397c tuned whitespace;
wenzelm
parents: 56715
diff changeset
   183
      session.protocol_command(
d96b10ec397c tuned whitespace;
wenzelm
parents: 56715
diff changeset
   184
        "Simplifier_Trace.reply", Properties.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: 54730
diff changeset
   185
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   186
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   187
    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: 56717
diff changeset
   188
      consume = (arg: Any) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   189
      {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   190
        arg match {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   191
          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: 56717
diff changeset
   192
            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: 56717
diff changeset
   193
            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: 54730
diff changeset
   194
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   195
            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: 56717
diff changeset
   196
            {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   197
              result match {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   198
                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: 56717
diff changeset
   199
                  memory_children +=
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   200
                    (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: 54730
diff changeset
   201
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   202
                  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: 54730
diff changeset
   203
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   204
                    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: 56717
diff changeset
   205
                      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: 56717
diff changeset
   206
                      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: 56717
diff changeset
   207
                        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: 56717
diff changeset
   208
                          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: 56717
diff changeset
   209
                        case _ =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   210
                          new_context += Question(data, Answer.step.all, Answer.step.default)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   211
                      }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   212
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   213
                    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: 56717
diff changeset
   214
                      data.props match {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   215
                        case Success(false) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   216
                          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: 56717
diff changeset
   217
                            case Some(Item(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: 56717
diff changeset
   218
                              new_context +=
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   219
                                Question(data, Answer.hint_fail.all, Answer.hint_fail.default)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   220
                            case _ =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   221
                              // unknown, better send a default reply
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   222
                              do_reply(session, data.serial, Answer.hint_fail.default)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   223
                          }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   224
                        case _ =>
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   225
                      }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   226
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   227
                    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: 56717
diff changeset
   228
                      // 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: 56717
diff changeset
   229
                      // 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: 56717
diff changeset
   230
                      // 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: 56717
diff changeset
   231
                      // 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: 54730
diff changeset
   232
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   233
                      @tailrec
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   234
                      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: 56717
diff changeset
   235
                        queue match {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   236
                          case s +: rest =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   237
                            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: 56717
diff changeset
   238
                              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: 56717
diff changeset
   239
                            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: 56717
diff changeset
   240
                            memory_children -= s
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   241
                            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: 56717
diff changeset
   242
                          case _ =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   243
                        }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   244
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   245
                      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: 56717
diff changeset
   246
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   247
                    case _ =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   248
                  }
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   249
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   250
                case _ =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   251
              }
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   252
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   253
              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: 54730
diff changeset
   254
            }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   255
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   256
            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: 56717
diff changeset
   257
            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: 56717
diff changeset
   258
            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: 54730
diff changeset
   259
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   260
          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: 56717
diff changeset
   261
            // 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: 56717
diff changeset
   262
            // 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: 56717
diff changeset
   263
            // 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: 54730
diff changeset
   264
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   265
            val items =
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   266
              (for { (_, Item(_, data)) <- results.iterator }
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   267
                yield 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: 54730
diff changeset
   268
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   269
            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: 54730
diff changeset
   270
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   271
          case Cancel(serial) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   272
            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: 56717
diff changeset
   273
              case Some((id, _)) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   274
                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: 56717
diff changeset
   275
              case None =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   276
            }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   277
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   278
          case Clear_Memory =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   279
            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: 56717
diff changeset
   280
            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: 54730
diff changeset
   281
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   282
          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: 56717
diff changeset
   283
            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: 56717
diff changeset
   284
              case Some((id, Question(data, _, _))) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   285
                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: 56717
diff changeset
   286
                {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   287
                  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: 56717
diff changeset
   288
                  memory += (index -> answer)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   289
                }
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   290
                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: 56717
diff changeset
   291
              case None =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   292
                System.err.println("send_reply: unknown serial " + serial)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff 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: 54730
diff changeset
   294
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   295
            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: 56717
diff changeset
   296
            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: 56717
diff changeset
   297
        }
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   298
        true
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   299
      },
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   300
      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: 56717
diff changeset
   301
    )
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   302
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   303
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   304
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   305
  /* protocol handler */
54730
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
   306
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
   307
  class Handler extends Session.Protocol_Handler
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
   308
  {
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   309
    assert(manager.is_active)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   310
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
   311
    private def cancel(prover: Prover, 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: 54730
diff changeset
   312
      msg.properties match {
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
   313
        case Markup.Simp_Trace_Cancel(serial) =>
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   314
          manager.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: 54730
diff changeset
   315
          true
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   316
        case _ =>
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   317
          false
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   318
      }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   319
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
   320
    override def stop(prover: Prover) =
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   321
    {
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   322
      manager.send(Clear_Memory)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   323
      manager.shutdown()
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   324
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   325
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
   326
    val functions = Map(Markup.SIMP_TRACE_CANCEL -> cancel _)
54730
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
   327
  }
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
   328
}