src/Pure/PIDE/document_status.scala
author wenzelm
Tue, 04 Nov 2025 22:09:26 +0100
changeset 83507 989304e45ad7
parent 83505 ef6863b14ca2
permissions -rw-r--r--
progress for long-running commands;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/PIDE/document_status.scala
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
     3
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
     4
Document status based on markup information.
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
     5
*/
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
     6
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
     7
package isabelle
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
     8
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
     9
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    10
import scala.collection.immutable.SortedMap
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    11
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    12
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74756
diff changeset
    13
object Document_Status {
83161
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    14
  /* theory status: via 'theory' or 'end' commands */
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    15
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    16
  object Theory_Status extends Enumeration {
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    17
    val NONE, INITIALIZED, FINALIZED, CONSOLIDATING, CONSOLIDATED = Value
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    18
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    19
    def initialized(t: Value): Boolean = t >= INITIALIZED
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    20
    def finalized(t: Value): Boolean = t >= FINALIZED
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    21
    def consolidating(t: Value): Boolean = t >= CONSOLIDATING
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    22
    def consolidated(t: Value): Boolean = t >= CONSOLIDATED
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    23
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    24
    def merge(t1: Value, t2: Value): Value = if (t1 >= t2) t1 else t2
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    25
  }
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    26
83165
9f3f723938fc more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents: 83164
diff changeset
    27
  trait Theory_Status {
9f3f723938fc more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents: 83164
diff changeset
    28
    def theory_status: Theory_Status.Value
9f3f723938fc more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents: 83164
diff changeset
    29
    def initialized: Boolean = Theory_Status.initialized(theory_status)
9f3f723938fc more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents: 83164
diff changeset
    30
    def finalized: Boolean = Theory_Status.finalized(theory_status)
9f3f723938fc more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents: 83164
diff changeset
    31
    def consolidating: Boolean = Theory_Status.consolidating(theory_status)
9f3f723938fc more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents: 83164
diff changeset
    32
    def consolidated: Boolean = Theory_Status.consolidated(theory_status)
9f3f723938fc more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents: 83164
diff changeset
    33
  }
9f3f723938fc more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents: 83164
diff changeset
    34
83161
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
    35
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    36
  /* command timings: for pro-forma command with actual commands at offset */
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    37
83505
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
    38
  sealed case class Command_Running(name: String, line: Int, start: Date) {
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
    39
    def time(now: Date): Time = now - start
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
    40
  }
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
    41
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    42
  object Command_Timings {
83505
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
    43
    type Entry_Running = (Symbol.Offset, Command_Running)
83289
2cd87a6da20b clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents: 83266
diff changeset
    44
    type Entry = (Symbol.Offset, Time)
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    45
    val empty: Command_Timings =
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    46
      new Command_Timings(SortedMap.empty, SortedMap.empty, Time.zero)
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    47
    def merge(args: IterableOnce[Command_Timings]): Command_Timings =
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    48
      args.iterator.foldLeft(empty)(_ ++ _)
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    49
  }
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    50
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    51
  final class Command_Timings private(
83505
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
    52
    private val running: SortedMap[Symbol.Offset, Command_Running],  // start time (in Scala)
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    53
    private val finished: SortedMap[Symbol.Offset, Time],  // elapsed time (in ML)
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    54
    private val sum_finished: Time
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    55
  ) {
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    56
    def is_empty: Boolean = running.isEmpty && finished.isEmpty
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    57
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    58
    def has_running: Boolean = running.nonEmpty
83507
989304e45ad7 progress for long-running commands;
wenzelm
parents: 83505
diff changeset
    59
    def long_running(now: Date, threshold: Time): List[Command_Running] =
989304e45ad7 progress for long-running commands;
wenzelm
parents: 83505
diff changeset
    60
      List.from(for (run <- running.valuesIterator if run.time(now) >= threshold) yield run)
83505
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
    61
    def add_running(entry: Command_Timings.Entry_Running): Command_Timings =
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    62
      new Command_Timings(running + entry, finished, sum_finished)
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    63
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    64
    def count_finished: Int = finished.size
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    65
    def get_finished(offset: Symbol.Offset): Time = finished.getOrElse(offset, Time.zero)
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    66
    def add_finished(entry: Command_Timings.Entry): Command_Timings = {
83289
2cd87a6da20b clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents: 83266
diff changeset
    67
      val (offset, t) = entry
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    68
      val running1 = running - offset
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    69
      val finished1 = finished + (offset -> (get_finished(offset) + t))
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    70
      val sum_finished1 = sum_finished + t
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    71
      new Command_Timings(running1, finished1, sum_finished1)
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    72
    }
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    73
83503
7b1b7ac616c0 more robust representation of start time as Date;
wenzelm
parents: 83298
diff changeset
    74
    def sum(now: Date): Time =
83505
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
    75
      running.valuesIterator.foldLeft(sum_finished)({ case (t, run) => t + run.time(now) })
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    76
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    77
    def ++ (other: Command_Timings): Command_Timings =
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    78
      if (is_empty) other
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    79
      else other.running.foldLeft(other.finished.foldLeft(this)(_ add_finished _))(_ add_running _)
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    80
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    81
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    82
    override def hashCode: Int = (running, finished).hashCode
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    83
    override def equals(that: Any): Boolean =
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    84
      that match {
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    85
        case other: Command_Timings => running == other.running && finished == other.finished
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    86
        case _ => false
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    87
      }
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    88
    override def toString: String =
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    89
      running.mkString("Command_Timings(running = (", ", ", "), ") +
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
    90
      finished.mkString("finished = (", ", ", "))")
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    91
  }
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    92
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
    93
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
    94
  /* command status */
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
    95
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74756
diff changeset
    96
  object Command_Status {
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
    97
    val proper_elements: Markup.Elements =
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
    98
      Markup.Elements(Markup.ACCEPTED, Markup.FORKED, Markup.JOINED, Markup.RUNNING,
68871
f5c76072db55 more explicit status for "canceled" command within theory node;
wenzelm
parents: 68770
diff changeset
    99
        Markup.FINISHED, Markup.FAILED, Markup.CANCELED)
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   100
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   101
    val liberal_elements: Markup.Elements =
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   102
      proper_elements + Markup.WARNING + Markup.LEGACY + Markup.ERROR
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   103
83247
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   104
    val empty: Command_Status =
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   105
      new Command_Status(
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   106
        theory_status = Theory_Status.NONE,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   107
        touched = false,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   108
        accepted = false,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   109
        warned = false,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   110
        failed = false,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   111
        canceled = false,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   112
        forks = 0,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   113
        runs = 0,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   114
        timings = Command_Timings.empty)
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   115
83157
dc54c60492c3 minor performance tuning;
wenzelm
parents: 83156
diff changeset
   116
    def make(
83503
7b1b7ac616c0 more robust representation of start time as Date;
wenzelm
parents: 83298
diff changeset
   117
      now: Date,
83185
47edc6384e7a tuned signature: more explicit operations;
wenzelm
parents: 83184
diff changeset
   118
      markups: List[Markup] = Nil,
83157
dc54c60492c3 minor performance tuning;
wenzelm
parents: 83156
diff changeset
   119
      warned: Boolean = false,
dc54c60492c3 minor performance tuning;
wenzelm
parents: 83156
diff changeset
   120
      failed: Boolean = false
dc54c60492c3 minor performance tuning;
wenzelm
parents: 83156
diff changeset
   121
    ): Command_Status = {
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
   122
      empty.update(now, markups = markups, warned = warned, failed = failed)
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   123
    }
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   124
83156
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   125
    def merge(args: IterableOnce[Command_Status]): Command_Status =
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   126
      args.iterator.foldLeft(empty)(_ + _)
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   127
  }
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   128
83155
92063df67f2b clarified signature;
wenzelm
parents: 83154
diff changeset
   129
  final class Command_Status private(
83165
9f3f723938fc more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents: 83164
diff changeset
   130
    val theory_status: Theory_Status.Value,
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   131
    private val touched: Boolean,
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   132
    private val accepted: Boolean,
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   133
    private val warned: Boolean,
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   134
    private val failed: Boolean,
68871
f5c76072db55 more explicit status for "canceled" command within theory node;
wenzelm
parents: 68770
diff changeset
   135
    private val canceled: Boolean,
83155
92063df67f2b clarified signature;
wenzelm
parents: 83154
diff changeset
   136
    val forks: Int,
83186
887f1eac24d1 more scalable timing, as part of incremental document_status;
wenzelm
parents: 83185
diff changeset
   137
    val runs: Int,
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
   138
    val timings: Command_Timings
83165
9f3f723938fc more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents: 83164
diff changeset
   139
  ) extends Theory_Status {
83155
92063df67f2b clarified signature;
wenzelm
parents: 83154
diff changeset
   140
    override def toString: String =
83156
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   141
      if (is_empty) "Command_Status.empty"
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   142
      else if (failed) "Command_Status(failed)"
83155
92063df67f2b clarified signature;
wenzelm
parents: 83154
diff changeset
   143
      else if (warned) "Command_Status(warned)"
83156
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   144
      else "Command_Status(...)"
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   145
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   146
    def is_empty: Boolean =
83161
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
   147
      !Theory_Status.initialized(theory_status) &&
83160
bc86832bd2fd clarified Theory_Status.FINALIZED: it belongs to this linear row, too;
wenzelm
parents: 83158
diff changeset
   148
      !touched && !accepted && !warned && !failed && !canceled &&
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
   149
      forks == 0 && runs == 0 && timings.is_empty
83155
92063df67f2b clarified signature;
wenzelm
parents: 83154
diff changeset
   150
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   151
    def + (that: Command_Status): Command_Status =
83156
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   152
      if (is_empty) that
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   153
      else if (that.is_empty) this
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   154
      else {
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   155
        new Command_Status(
83161
87ceb18f23f3 clarified modules;
wenzelm
parents: 83160
diff changeset
   156
          theory_status = Theory_Status.merge(theory_status, that.theory_status),
83156
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   157
          touched = touched || that.touched,
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   158
          accepted = accepted || that.accepted,
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   159
          warned = warned || that.warned,
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   160
          failed = failed || that.failed,
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   161
          canceled = canceled || that.canceled,
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   162
          forks = forks + that.forks,
83186
887f1eac24d1 more scalable timing, as part of incremental document_status;
wenzelm
parents: 83185
diff changeset
   163
          runs = runs + that.runs,
83210
9cc5d77d505c more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents: 83208
diff changeset
   164
          timings = timings ++ that.timings)
83156
6bc5835bc794 clarified signature, following e.g. Command.Markups;
wenzelm
parents: 83155
diff changeset
   165
      }
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   166
83185
47edc6384e7a tuned signature: more explicit operations;
wenzelm
parents: 83184
diff changeset
   167
    def update(
83503
7b1b7ac616c0 more robust representation of start time as Date;
wenzelm
parents: 83298
diff changeset
   168
      now: Date,
83185
47edc6384e7a tuned signature: more explicit operations;
wenzelm
parents: 83184
diff changeset
   169
      markups: List[Markup] = Nil,
47edc6384e7a tuned signature: more explicit operations;
wenzelm
parents: 83184
diff changeset
   170
      warned: Boolean = false,
47edc6384e7a tuned signature: more explicit operations;
wenzelm
parents: 83184
diff changeset
   171
      failed: Boolean = false
47edc6384e7a tuned signature: more explicit operations;
wenzelm
parents: 83184
diff changeset
   172
    ): Command_Status = {
83247
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   173
      var theory_status1 = theory_status
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   174
      var touched1 = touched
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   175
      var accepted1 = accepted
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   176
      var warned1 = this.warned || warned
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   177
      var failed1 = this.failed || failed
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   178
      var canceled1 = canceled
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   179
      var forks1 = forks
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   180
      var runs1 = runs
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   181
      var timings1 = timings
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   182
      for (markup <- markups) {
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   183
        markup.name match {
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   184
          case Markup.INITIALIZED =>
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   185
            theory_status1 = Theory_Status.merge(theory_status1, Theory_Status.INITIALIZED)
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   186
          case Markup.FINALIZED =>
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   187
            theory_status1 = Theory_Status.merge(theory_status1, Theory_Status.FINALIZED)
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   188
          case Markup.CONSOLIDATING =>
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   189
            theory_status1 = Theory_Status.merge(theory_status1, Theory_Status.CONSOLIDATING)
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   190
          case Markup.CONSOLIDATED =>
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   191
            theory_status1 = Theory_Status.merge(theory_status1, Theory_Status.CONSOLIDATED)
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   192
          case Markup.ACCEPTED => accepted1 = true
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   193
          case Markup.FORKED => touched1 = true; forks1 += 1
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   194
          case Markup.JOINED => forks1 -= 1
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   195
          case Markup.RUNNING => touched1 = true; runs1 += 1
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   196
          case Markup.FINISHED => runs1 -= 1
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   197
          case Markup.WARNING | Markup.LEGACY => warned1 = true
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   198
          case Markup.FAILED | Markup.ERROR => failed1 = true
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   199
          case Markup.CANCELED => canceled1 = true
83294
8d30612cff2d clarified markup: re-use protocol function name;
wenzelm
parents: 83289
diff changeset
   200
          case Markup.Command_Timing.name =>
83247
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   201
            val props = markup.properties
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   202
            val offset = Position.Offset.get(props)
83505
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
   203
            val is_running = props.contains(Markup.command_running)
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
   204
            timings1 =
83505
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
   205
              if (is_running) {
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
   206
                val name = Markup.Name.get(props)
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
   207
                val line = Position.Line.get(props)
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
   208
                timings1.add_running(offset -> Command_Running(name, line, now))
ef6863b14ca2 more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents: 83503
diff changeset
   209
              }
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
   210
              else timings1.add_finished(offset -> Time.seconds(Markup.Elapsed.get(props)))
83247
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   211
          case _ =>
83185
47edc6384e7a tuned signature: more explicit operations;
wenzelm
parents: 83184
diff changeset
   212
        }
83184
9e05d3acd2b4 tuned signature: more explicit operations;
wenzelm
parents: 83183
diff changeset
   213
      }
83247
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   214
      if (this.theory_status == theory_status1 &&
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   215
          this.touched == touched1 &&
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   216
          this.accepted == accepted1 &&
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   217
          this.warned == warned1 &&
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   218
          this.failed == failed1 &&
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   219
          this.canceled == canceled1 &&
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   220
          this.forks == forks1 &&
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   221
          this.runs == runs1 &&
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   222
          this.timings.eq(timings1)) this
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   223
      else {
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   224
        new Command_Status(
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   225
          theory_status = theory_status1,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   226
          touched = touched1,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   227
          accepted = accepted1,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   228
          warned = warned1,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   229
          failed = failed1,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   230
          canceled = canceled1,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   231
          forks = forks1,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   232
          runs = runs1,
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   233
          timings = timings1)
fbba662ca976 minor performance tuning;
wenzelm
parents: 83246
diff changeset
   234
      }
83184
9e05d3acd2b4 tuned signature: more explicit operations;
wenzelm
parents: 83183
diff changeset
   235
    }
9e05d3acd2b4 tuned signature: more explicit operations;
wenzelm
parents: 83183
diff changeset
   236
83158
7e94f31b6d6c clarified signature: more explicit type Theory_Status;
wenzelm
parents: 83157
diff changeset
   237
    def maybe_consolidated: Boolean = touched && forks == 0 && runs == 0
7e94f31b6d6c clarified signature: more explicit type Theory_Status;
wenzelm
parents: 83157
diff changeset
   238
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   239
    def is_unprocessed: Boolean = accepted && !failed && (!touched || (forks != 0 && runs == 0))
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   240
    def is_running: Boolean = runs != 0
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   241
    def is_warned: Boolean = warned
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   242
    def is_failed: Boolean = failed
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   243
    def is_finished: Boolean = !failed && touched && forks == 0 && runs == 0
68871
f5c76072db55 more explicit status for "canceled" command within theory node;
wenzelm
parents: 68770
diff changeset
   244
    def is_canceled: Boolean = canceled
68881
d975449b266e more detailed node_status;
wenzelm
parents: 68873
diff changeset
   245
    def is_terminated: Boolean = canceled || touched && forks == 0 && runs == 0
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   246
  }
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   247
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   248
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   249
  /* node status */
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   250
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74756
diff changeset
   251
  object Node_Status {
83167
84b092fd0f7a clarified signature;
wenzelm
parents: 83165
diff changeset
   252
    val empty: Node_Status = Node_Status()
76716
a7602257a825 clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents: 76714
diff changeset
   253
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   254
    def make(
83503
7b1b7ac616c0 more robust representation of start time as Date;
wenzelm
parents: 83298
diff changeset
   255
      now: Date,
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   256
      state: Document.State,
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   257
      version: Document.Version,
83188
481c3e1cb957 incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents: 83187
diff changeset
   258
      name: Document.Node.Name,
481c3e1cb957 incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents: 83187
diff changeset
   259
      threshold: Time = Time.max
76714
95a926d483c5 tuned whitespace;
wenzelm
parents: 75393
diff changeset
   260
    ): Node_Status = {
83229
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   261
      val node = version.nodes(name)
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   262
83220
a6c91d4df0c6 tuned signature;
wenzelm
parents: 83219
diff changeset
   263
      var theory_status = Document_Status.Theory_Status.NONE
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   264
      var unprocessed = 0
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   265
      var running = 0
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   266
      var warned = 0
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   267
      var failed = 0
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   268
      var finished = 0
68871
f5c76072db55 more explicit status for "canceled" command within theory node;
wenzelm
parents: 68770
diff changeset
   269
      var canceled = false
68892
dce6cbd3cafc proper polarity of terminated status;
wenzelm
parents: 68889
diff changeset
   270
      var terminated = true
83289
2cd87a6da20b clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents: 83266
diff changeset
   271
      var cumulated_time = Time.zero
83189
5e2076fb2eff more informative Node_Status;
wenzelm
parents: 83188
diff changeset
   272
      var max_time = Time.zero
83219
f143ff394324 clarified signature;
wenzelm
parents: 83215
diff changeset
   273
      var command_timings = Map.empty[Command, Command_Timings]
83188
481c3e1cb957 incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents: 83187
diff changeset
   274
83229
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   275
      for (command <- node.commands.iterator) {
83164
851f3f9440ef tuned signature;
wenzelm
parents: 83163
diff changeset
   276
        val status = state.command_status(version, command)
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   277
83220
a6c91d4df0c6 tuned signature;
wenzelm
parents: 83219
diff changeset
   278
        theory_status = Theory_Status.merge(theory_status, status.theory_status)
a6c91d4df0c6 tuned signature;
wenzelm
parents: 83219
diff changeset
   279
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   280
        if (status.is_running) running += 1
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   281
        else if (status.is_failed) failed += 1
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   282
        else if (status.is_warned) warned += 1
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   283
        else if (status.is_finished) finished += 1
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   284
        else unprocessed += 1
68871
f5c76072db55 more explicit status for "canceled" command within theory node;
wenzelm
parents: 68770
diff changeset
   285
f5c76072db55 more explicit status for "canceled" command within theory node;
wenzelm
parents: 68770
diff changeset
   286
        if (status.is_canceled) canceled = true
68892
dce6cbd3cafc proper polarity of terminated status;
wenzelm
parents: 68889
diff changeset
   287
        if (!status.is_terminated) terminated = false
83165
9f3f723938fc more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents: 83164
diff changeset
   288
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
   289
        val t = status.timings.sum(now)
83289
2cd87a6da20b clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents: 83266
diff changeset
   290
        cumulated_time += t
83189
5e2076fb2eff more informative Node_Status;
wenzelm
parents: 83188
diff changeset
   291
        if (t > max_time) max_time = t
83219
f143ff394324 clarified signature;
wenzelm
parents: 83215
diff changeset
   292
        if (t.is_notable(threshold)) command_timings += (command -> status.timings)
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   293
      }
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   294
83229
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   295
      def percent(a: Int, b: Int): Int =
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   296
        if (b == 0) 0 else ((a.toDouble / b) * 100).toInt
83228
b06ce93632ec clarified signature: prefer static percentage;
wenzelm
parents: 83224
diff changeset
   297
83229
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   298
      val percentage: Int = {
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   299
        node.get_theory match {
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   300
          case None =>
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   301
            if (Theory_Status.consolidated(theory_status)) 100
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   302
            else {
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   303
              val total = unprocessed + running + warned + failed + finished
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   304
              percent(total - unprocessed, total).min(99)
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   305
            }
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   306
          case Some(command) =>
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   307
            val total = command.span.theory_commands
83297
00bb83e60336 clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents: 83296
diff changeset
   308
            val processed = state.command_status(version, command).timings.count_finished
83229
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   309
            percent(processed, total)
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   310
        }
ad2b6030cb9c build_progress with percentage;
wenzelm
parents: 83228
diff changeset
   311
      }
83228
b06ce93632ec clarified signature: prefer static percentage;
wenzelm
parents: 83224
diff changeset
   312
68887
b07735ce02b3 tuned -- more robust against changes;
wenzelm
parents: 68885
diff changeset
   313
      Node_Status(
83220
a6c91d4df0c6 tuned signature;
wenzelm
parents: 83219
diff changeset
   314
        theory_status = theory_status,
83163
64c9d94478b8 clarified signature;
wenzelm
parents: 83161
diff changeset
   315
        suppressed = version.nodes.suppressed(name),
68887
b07735ce02b3 tuned -- more robust against changes;
wenzelm
parents: 68885
diff changeset
   316
        unprocessed = unprocessed,
b07735ce02b3 tuned -- more robust against changes;
wenzelm
parents: 68885
diff changeset
   317
        running = running,
b07735ce02b3 tuned -- more robust against changes;
wenzelm
parents: 68885
diff changeset
   318
        warned = warned,
b07735ce02b3 tuned -- more robust against changes;
wenzelm
parents: 68885
diff changeset
   319
        failed = failed,
b07735ce02b3 tuned -- more robust against changes;
wenzelm
parents: 68885
diff changeset
   320
        finished = finished,
b07735ce02b3 tuned -- more robust against changes;
wenzelm
parents: 68885
diff changeset
   321
        canceled = canceled,
b07735ce02b3 tuned -- more robust against changes;
wenzelm
parents: 68885
diff changeset
   322
        terminated = terminated,
83289
2cd87a6da20b clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents: 83266
diff changeset
   323
        cumulated_time = cumulated_time,
83189
5e2076fb2eff more informative Node_Status;
wenzelm
parents: 83188
diff changeset
   324
        max_time = max_time,
83188
481c3e1cb957 incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents: 83187
diff changeset
   325
        threshold = threshold,
83228
b06ce93632ec clarified signature: prefer static percentage;
wenzelm
parents: 83224
diff changeset
   326
        command_timings = command_timings,
b06ce93632ec clarified signature: prefer static percentage;
wenzelm
parents: 83224
diff changeset
   327
        percentage)
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   328
    }
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   329
  }
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   330
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   331
  sealed case class Node_Status(
83220
a6c91d4df0c6 tuned signature;
wenzelm
parents: 83219
diff changeset
   332
    theory_status: Theory_Status.Value = Theory_Status.NONE,
83167
84b092fd0f7a clarified signature;
wenzelm
parents: 83165
diff changeset
   333
    suppressed: Boolean = false,
84b092fd0f7a clarified signature;
wenzelm
parents: 83165
diff changeset
   334
    unprocessed: Int = 0,
84b092fd0f7a clarified signature;
wenzelm
parents: 83165
diff changeset
   335
    running: Int = 0,
84b092fd0f7a clarified signature;
wenzelm
parents: 83165
diff changeset
   336
    warned: Int = 0,
84b092fd0f7a clarified signature;
wenzelm
parents: 83165
diff changeset
   337
    failed: Int = 0,
84b092fd0f7a clarified signature;
wenzelm
parents: 83165
diff changeset
   338
    finished: Int = 0,
84b092fd0f7a clarified signature;
wenzelm
parents: 83165
diff changeset
   339
    canceled: Boolean = false,
84b092fd0f7a clarified signature;
wenzelm
parents: 83165
diff changeset
   340
    terminated: Boolean = false,
83289
2cd87a6da20b clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents: 83266
diff changeset
   341
    cumulated_time: Time = Time.zero,
83189
5e2076fb2eff more informative Node_Status;
wenzelm
parents: 83188
diff changeset
   342
    max_time: Time = Time.zero,
83188
481c3e1cb957 incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents: 83187
diff changeset
   343
    threshold: Time = Time.zero,
83228
b06ce93632ec clarified signature: prefer static percentage;
wenzelm
parents: 83224
diff changeset
   344
    command_timings: Map[Command, Command_Timings] = Map.empty,
b06ce93632ec clarified signature: prefer static percentage;
wenzelm
parents: 83224
diff changeset
   345
    percentage: Int = 0
83165
9f3f723938fc more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents: 83164
diff changeset
   346
  ) extends Theory_Status {
76716
a7602257a825 clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents: 76714
diff changeset
   347
    def is_empty: Boolean = this == Node_Status.empty
a7602257a825 clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents: 76714
diff changeset
   348
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   349
    def ok: Boolean = failed == 0
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   350
    def total: Int = unprocessed + running + warned + failed + finished
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   351
83163
64c9d94478b8 clarified signature;
wenzelm
parents: 83161
diff changeset
   352
    def quasi_consolidated: Boolean = !suppressed && !finalized && terminated
68897
bdc38f0fd68c tuned signature;
wenzelm
parents: 68892
diff changeset
   353
83298
d2ffec6f4b89 clarified status_theories: show only running or updated theories;
wenzelm
parents: 83297
diff changeset
   354
    def progress: Boolean = running > 0 || command_timings.valuesIterator.exists(_.has_running)
d2ffec6f4b89 clarified status_theories: show only running or updated theories;
wenzelm
parents: 83297
diff changeset
   355
83266
2f75f2495e3e more detailed Console_Progress via Progress.Status;
wenzelm
parents: 83247
diff changeset
   356
    def started: Boolean = percentage == 0
2f75f2495e3e more detailed Console_Progress via Progress.Status;
wenzelm
parents: 83247
diff changeset
   357
    def completed: Boolean = percentage == 100
2f75f2495e3e more detailed Console_Progress via Progress.Status;
wenzelm
parents: 83247
diff changeset
   358
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   359
    def json: JSON.Object.T =
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   360
      JSON.Object("ok" -> ok, "total" -> total, "unprocessed" -> unprocessed,
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   361
        "running" -> running, "warned" -> warned, "failed" -> failed, "finished" -> finished,
68898
241d08beaf5c more informative node_status;
wenzelm
parents: 68897
diff changeset
   362
        "canceled" -> canceled, "consolidated" -> consolidated,
241d08beaf5c more informative node_status;
wenzelm
parents: 68897
diff changeset
   363
        "percentage" -> percentage)
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   364
  }
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   365
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   366
68759
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   367
  /* nodes status */
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   368
83169
f009f8ac4de1 clarified signature;
wenzelm
parents: 83167
diff changeset
   369
  enum Overall_Status { case ok, failed, pending }
68759
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   370
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74756
diff changeset
   371
  object Nodes_Status {
83205
99ce7933db6d clarified signature: explicit domain for Nodes_Status operations;
wenzelm
parents: 83195
diff changeset
   372
    val empty: Nodes_Status = new Nodes_Status(Map.empty)
68759
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   373
  }
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   374
83205
99ce7933db6d clarified signature: explicit domain for Nodes_Status operations;
wenzelm
parents: 83195
diff changeset
   375
  final class Nodes_Status private(private val rep: Map[Document.Node.Name, Node_Status]) {
68770
add44e2b8cb0 optional notification of nodes_status (via progress);
wenzelm
parents: 68769
diff changeset
   376
    def is_empty: Boolean = rep.isEmpty
83187
2b9457f5ffef more robust: total "apply", with subtle change of semantics;
wenzelm
parents: 83186
diff changeset
   377
    def apply(name: Document.Node.Name): Node_Status = rep.getOrElse(name, Node_Status.empty)
68759
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   378
    def get(name: Document.Node.Name): Option[Node_Status] = rep.get(name)
83188
481c3e1cb957 incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents: 83187
diff changeset
   379
    def iterator: Iterator[(Document.Node.Name, Node_Status)] = rep.iterator
481c3e1cb957 incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents: 83187
diff changeset
   380
68884
9b97d0b20d95 clarified quasi_consolidated state: ensure that exports are present for ok nodes;
wenzelm
parents: 68883
diff changeset
   381
    def quasi_consolidated(name: Document.Node.Name): Boolean =
83170
d7796493edb5 tuned signature;
wenzelm
parents: 83169
diff changeset
   382
      get(name) match {
68897
bdc38f0fd68c tuned signature;
wenzelm
parents: 68892
diff changeset
   383
        case Some(st) => st.quasi_consolidated
68883
3653b3ad729e clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents: 68881
diff changeset
   384
        case None => false
3653b3ad729e clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents: 68881
diff changeset
   385
      }
3653b3ad729e clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents: 68881
diff changeset
   386
83169
f009f8ac4de1 clarified signature;
wenzelm
parents: 83167
diff changeset
   387
    def overall_status(name: Document.Node.Name): Overall_Status =
83170
d7796493edb5 tuned signature;
wenzelm
parents: 83169
diff changeset
   388
      get(name) match {
68759
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   389
        case Some(st) if st.consolidated =>
83169
f009f8ac4de1 clarified signature;
wenzelm
parents: 83167
diff changeset
   390
          if (st.ok) Overall_Status.ok else Overall_Status.failed
f009f8ac4de1 clarified signature;
wenzelm
parents: 83167
diff changeset
   391
        case _ => Overall_Status.pending
68759
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   392
      }
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   393
83208
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   394
    def update_node(
83503
7b1b7ac616c0 more robust representation of start time as Date;
wenzelm
parents: 83298
diff changeset
   395
      now: Date,
83208
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   396
      state: Document.State,
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   397
      version: Document.Version,
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   398
      name: Document.Node.Name,
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   399
      threshold: Time = Time.max
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   400
    ): Nodes_Status = {
83503
7b1b7ac616c0 more robust representation of start time as Date;
wenzelm
parents: 83298
diff changeset
   401
      val node_status =
7b1b7ac616c0 more robust representation of start time as Date;
wenzelm
parents: 83298
diff changeset
   402
        Document_Status.Node_Status.make(now, state, version, name, threshold = threshold)
83215
0526a640f44f avoid shortcuts based on potentially expensive equality test;
wenzelm
parents: 83210
diff changeset
   403
      new Nodes_Status(rep + (name -> node_status))
83208
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   404
    }
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   405
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   406
    def update_nodes(
83503
7b1b7ac616c0 more robust representation of start time as Date;
wenzelm
parents: 83298
diff changeset
   407
      now: Date,
69255
800b1ce96fce more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
wenzelm
parents: 68904
diff changeset
   408
      resources: Resources,
68763
3c5857c6bc5b clarified signature;
wenzelm
parents: 68761
diff changeset
   409
      state: Document.State,
3c5857c6bc5b clarified signature;
wenzelm
parents: 68761
diff changeset
   410
      version: Document.Version,
83188
481c3e1cb957 incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents: 83187
diff changeset
   411
      threshold: Time = Time.max,
68769
59fcff4f8b73 tuned signature;
wenzelm
parents: 68766
diff changeset
   412
      domain: Option[Set[Document.Node.Name]] = None,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74756
diff changeset
   413
      trim: Boolean = false
83206
ca24ee152c80 clarified signature: prefer explicit operations;
wenzelm
parents: 83205
diff changeset
   414
    ): Nodes_Status = {
83208
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   415
      val domain1 = version.nodes.domain
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   416
      val that =
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   417
        domain.getOrElse(domain1).iterator.foldLeft(this)(
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   418
          { case (a, name) =>
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   419
              if (Resources.hidden_node(name) || resources.loaded_theory(name)) a
83503
7b1b7ac616c0 more robust representation of start time as Date;
wenzelm
parents: 83298
diff changeset
   420
              else a.update_node(now, state, version, name, threshold = threshold) })
83208
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   421
      if (trim) new Nodes_Status(that.rep -- that.rep.keysIterator.filterNot(domain1))
cde288fef097 clarified signature;
wenzelm
parents: 83206
diff changeset
   422
      else that
68763
3c5857c6bc5b clarified signature;
wenzelm
parents: 68761
diff changeset
   423
    }
68761
8bb51b3de39f trim nodes_status: avoid potential memory leak;
wenzelm
parents: 68760
diff changeset
   424
68759
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   425
    override def hashCode: Int = rep.hashCode
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   426
    override def equals(that: Any): Boolean =
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   427
      that match {
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   428
        case other: Nodes_Status => rep == other.rep
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   429
        case _ => false
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   430
      }
68765
be5f255a9943 tuned output;
wenzelm
parents: 68764
diff changeset
   431
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74756
diff changeset
   432
    override def toString: String = {
68765
be5f255a9943 tuned output;
wenzelm
parents: 68764
diff changeset
   433
      var ok = 0
be5f255a9943 tuned output;
wenzelm
parents: 68764
diff changeset
   434
      var failed = 0
be5f255a9943 tuned output;
wenzelm
parents: 68764
diff changeset
   435
      var pending = 0
68873
13a984eba612 clarified message;
wenzelm
parents: 68871
diff changeset
   436
      var canceled = 0
68765
be5f255a9943 tuned output;
wenzelm
parents: 68764
diff changeset
   437
      for (name <- rep.keysIterator) {
83169
f009f8ac4de1 clarified signature;
wenzelm
parents: 83167
diff changeset
   438
        overall_status(name) match {
f009f8ac4de1 clarified signature;
wenzelm
parents: 83167
diff changeset
   439
          case Overall_Status.ok => ok += 1
f009f8ac4de1 clarified signature;
wenzelm
parents: 83167
diff changeset
   440
          case Overall_Status.failed => failed += 1
f009f8ac4de1 clarified signature;
wenzelm
parents: 83167
diff changeset
   441
          case Overall_Status.pending => pending += 1
68765
be5f255a9943 tuned output;
wenzelm
parents: 68764
diff changeset
   442
        }
68873
13a984eba612 clarified message;
wenzelm
parents: 68871
diff changeset
   443
        if (apply(name).canceled) canceled += 1
68765
be5f255a9943 tuned output;
wenzelm
parents: 68764
diff changeset
   444
      }
68873
13a984eba612 clarified message;
wenzelm
parents: 68871
diff changeset
   445
      "Nodes_Status(ok = " + ok + ", failed = " + failed + ", pending = " + pending +
13a984eba612 clarified message;
wenzelm
parents: 68871
diff changeset
   446
        ", canceled = " + canceled + ")"
68765
be5f255a9943 tuned output;
wenzelm
parents: 68764
diff changeset
   447
    }
68759
4247e91fa21d clarified modules;
wenzelm
parents: 68758
diff changeset
   448
  }
68758
a110e7e24e55 clarified modules;
wenzelm
parents:
diff changeset
   449
}