author | wenzelm |
Mon, 22 Sep 2025 17:20:06 +0200 | |
changeset 83215 | 0526a640f44f |
parent 83210 | 9cc5d77d505c |
child 83219 | f143ff394324 |
permissions | -rw-r--r-- |
68758 | 1 |
/* Title: Pure/PIDE/document_status.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Document status based on markup information. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
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 | 13 |
object Document_Status { |
83161 | 14 |
/* theory status: via 'theory' or 'end' commands */ |
15 |
||
16 |
object Theory_Status extends Enumeration { |
|
17 |
val NONE, INITIALIZED, FINALIZED, CONSOLIDATING, CONSOLIDATED = Value |
|
18 |
||
19 |
def initialized(t: Value): Boolean = t >= INITIALIZED |
|
20 |
def finalized(t: Value): Boolean = t >= FINALIZED |
|
21 |
def consolidating(t: Value): Boolean = t >= CONSOLIDATING |
|
22 |
def consolidated(t: Value): Boolean = t >= CONSOLIDATED |
|
23 |
||
24 |
def merge(t1: Value, t2: Value): Value = if (t1 >= t2) t1 else t2 |
|
25 |
} |
|
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 | 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 |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
38 |
object Command_Timings { |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
39 |
type Entry = (Symbol.Offset, Timing) |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
40 |
val empty: Command_Timings = |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
41 |
new Command_Timings(SortedMap.empty, Timing.zero) |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
42 |
def make(args: IterableOnce[Entry]): Command_Timings = |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
43 |
args.iterator.foldLeft(empty)(_ + _) |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
44 |
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
|
45 |
args.iterator.foldLeft(empty)(_ ++ _) |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
46 |
} |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
47 |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
48 |
final class Command_Timings private( |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
49 |
private val rep: SortedMap[Symbol.Offset, Timing], |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
50 |
val sum: Timing |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
51 |
) { |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
52 |
def is_empty: Boolean = rep.isEmpty |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
53 |
def count: Int = rep.size |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
54 |
def apply(offset: Symbol.Offset): Timing = rep.getOrElse(offset, Timing.zero) |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
55 |
def iterator: Iterator[(Symbol.Offset, Timing)] = rep.iterator |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
56 |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
57 |
def + (entry: Command_Timings.Entry): Command_Timings = { |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
58 |
val (offset, timing) = entry |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
59 |
val rep1 = rep + (offset -> (apply(offset) + timing)) |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
60 |
val sum1 = sum + timing |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
61 |
new Command_Timings(rep1, sum1) |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
62 |
} |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
63 |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
64 |
def ++ (other: Command_Timings): Command_Timings = |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
65 |
if (rep.isEmpty) other |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
66 |
else other.rep.foldLeft(this)(_ + _) |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
67 |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
68 |
override def hashCode: Int = rep.hashCode |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
69 |
override def equals(that: Any): Boolean = |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
70 |
that match { |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
71 |
case other: Command_Timings => rep == other.rep |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
72 |
case _ => false |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
73 |
} |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
74 |
override def toString: String = rep.mkString("Command_Timings(", ", ", ")") |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
75 |
} |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
76 |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
77 |
|
68758 | 78 |
/* command status */ |
79 |
||
75393 | 80 |
object Command_Status { |
68758 | 81 |
val proper_elements: Markup.Elements = |
82 |
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
|
83 |
Markup.FINISHED, Markup.FAILED, Markup.CANCELED) |
68758 | 84 |
|
85 |
val liberal_elements: Markup.Elements = |
|
86 |
proper_elements + Markup.WARNING + Markup.LEGACY + Markup.ERROR |
|
87 |
||
83157 | 88 |
def make( |
83185 | 89 |
markups: List[Markup] = Nil, |
83157 | 90 |
warned: Boolean = false, |
91 |
failed: Boolean = false |
|
92 |
): Command_Status = { |
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
93 |
var theory_status = Theory_Status.NONE |
68758 | 94 |
var touched = false |
95 |
var accepted = false |
|
83157 | 96 |
var warned1 = warned |
97 |
var failed1 = failed |
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
98 |
var canceled = false |
68758 | 99 |
var forks = 0 |
100 |
var runs = 0 |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
101 |
var timings = Command_Timings.empty |
83155 | 102 |
for (markup <- markups) { |
68758 | 103 |
markup.name match { |
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
104 |
case Markup.INITIALIZED => |
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
105 |
theory_status = Theory_Status.merge(theory_status, Theory_Status.INITIALIZED) |
83160
bc86832bd2fd
clarified Theory_Status.FINALIZED: it belongs to this linear row, too;
wenzelm
parents:
83158
diff
changeset
|
106 |
case Markup.FINALIZED => |
bc86832bd2fd
clarified Theory_Status.FINALIZED: it belongs to this linear row, too;
wenzelm
parents:
83158
diff
changeset
|
107 |
theory_status = Theory_Status.merge(theory_status, Theory_Status.FINALIZED) |
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
108 |
case Markup.CONSOLIDATING => |
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
109 |
theory_status = Theory_Status.merge(theory_status, Theory_Status.CONSOLIDATING) |
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
110 |
case Markup.CONSOLIDATED => |
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
111 |
theory_status = Theory_Status.merge(theory_status, Theory_Status.CONSOLIDATED) |
68758 | 112 |
case Markup.ACCEPTED => accepted = true |
113 |
case Markup.FORKED => touched = true; forks += 1 |
|
114 |
case Markup.JOINED => forks -= 1 |
|
115 |
case Markup.RUNNING => touched = true; runs += 1 |
|
116 |
case Markup.FINISHED => runs -= 1 |
|
83157 | 117 |
case Markup.WARNING | Markup.LEGACY => warned1 = true |
118 |
case Markup.FAILED | Markup.ERROR => failed1 = true |
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
119 |
case Markup.CANCELED => canceled = true |
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
120 |
case Markup.TIMING => |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
121 |
val props = markup.properties |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
122 |
val offset = Position.Offset.get(props) |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
123 |
val timing = Markup.Timing_Properties.get(props) |
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
124 |
timings += (offset -> timing) |
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
125 |
case _ => |
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
126 |
} |
68758 | 127 |
} |
83155 | 128 |
new Command_Status( |
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
129 |
theory_status = theory_status, |
68887 | 130 |
touched = touched, |
131 |
accepted = accepted, |
|
83157 | 132 |
warned = warned1, |
133 |
failed = failed1, |
|
68887 | 134 |
canceled = canceled, |
135 |
forks = forks, |
|
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
136 |
runs = runs, |
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
137 |
timings = timings) |
68758 | 138 |
} |
139 |
||
83183
6e03fb945baf
more scalable Command.State.document_status: prefer incremental update;
wenzelm
parents:
83181
diff
changeset
|
140 |
val empty: Command_Status = make() |
68758 | 141 |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
142 |
def merge(args: IterableOnce[Command_Status]): Command_Status = |
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
143 |
args.iterator.foldLeft(empty)(_ + _) |
68758 | 144 |
} |
145 |
||
83155 | 146 |
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
|
147 |
val theory_status: Theory_Status.Value, |
68758 | 148 |
private val touched: Boolean, |
149 |
private val accepted: Boolean, |
|
150 |
private val warned: Boolean, |
|
151 |
private val failed: Boolean, |
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
152 |
private val canceled: Boolean, |
83155 | 153 |
val forks: Int, |
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
154 |
val runs: Int, |
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
155 |
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
|
156 |
) extends Theory_Status { |
83155 | 157 |
override def toString: String = |
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
158 |
if (is_empty) "Command_Status.empty" |
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
159 |
else if (failed) "Command_Status(failed)" |
83155 | 160 |
else if (warned) "Command_Status(warned)" |
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
161 |
else "Command_Status(...)" |
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
162 |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
163 |
def is_empty: Boolean = |
83161 | 164 |
!Theory_Status.initialized(theory_status) && |
83160
bc86832bd2fd
clarified Theory_Status.FINALIZED: it belongs to this linear row, too;
wenzelm
parents:
83158
diff
changeset
|
165 |
!touched && !accepted && !warned && !failed && !canceled && |
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
166 |
forks == 0 && runs == 0 && timings.is_empty |
83155 | 167 |
|
68758 | 168 |
def + (that: Command_Status): Command_Status = |
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
169 |
if (is_empty) that |
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
170 |
else if (that.is_empty) this |
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
171 |
else { |
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
172 |
new Command_Status( |
83161 | 173 |
theory_status = Theory_Status.merge(theory_status, that.theory_status), |
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
174 |
touched = touched || that.touched, |
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
175 |
accepted = accepted || that.accepted, |
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
176 |
warned = warned || that.warned, |
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
177 |
failed = failed || that.failed, |
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
178 |
canceled = canceled || that.canceled, |
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
179 |
forks = forks + that.forks, |
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
180 |
runs = runs + that.runs, |
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
181 |
timings = timings ++ that.timings) |
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
182 |
} |
68758 | 183 |
|
83185 | 184 |
def update( |
185 |
markups: List[Markup] = Nil, |
|
186 |
warned: Boolean = false, |
|
187 |
failed: Boolean = false |
|
188 |
): Command_Status = { |
|
189 |
if (markups.isEmpty) { |
|
190 |
val warned1 = this.warned || warned |
|
191 |
val failed1 = this.failed || failed |
|
192 |
if (this.warned == warned1 && this.failed == failed1) this |
|
193 |
else { |
|
194 |
new Command_Status( |
|
195 |
theory_status = theory_status, |
|
196 |
touched = touched, |
|
197 |
accepted = accepted, |
|
198 |
warned = warned1, |
|
199 |
failed = failed1, |
|
200 |
canceled = canceled, |
|
201 |
forks = forks, |
|
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
202 |
runs = runs, |
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
203 |
timings = timings) |
83185 | 204 |
} |
83184 | 205 |
} |
83185 | 206 |
else this + Command_Status.make(markups = markups, warned = warned, failed = failed) |
83184 | 207 |
} |
208 |
||
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
209 |
def maybe_consolidated: Boolean = touched && forks == 0 && runs == 0 |
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
210 |
|
68758 | 211 |
def is_unprocessed: Boolean = accepted && !failed && (!touched || (forks != 0 && runs == 0)) |
212 |
def is_running: Boolean = runs != 0 |
|
213 |
def is_warned: Boolean = warned |
|
214 |
def is_failed: Boolean = failed |
|
215 |
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
|
216 |
def is_canceled: Boolean = canceled |
68881 | 217 |
def is_terminated: Boolean = canceled || touched && forks == 0 && runs == 0 |
68758 | 218 |
} |
219 |
||
220 |
||
221 |
/* node status */ |
|
222 |
||
75393 | 223 |
object Node_Status { |
83167 | 224 |
val empty: Node_Status = Node_Status() |
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
225 |
|
68758 | 226 |
def make( |
227 |
state: Document.State, |
|
228 |
version: Document.Version, |
|
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
229 |
name: Document.Node.Name, |
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
230 |
threshold: Time = Time.max |
76714 | 231 |
): Node_Status = { |
68758 | 232 |
var unprocessed = 0 |
233 |
var running = 0 |
|
234 |
var warned = 0 |
|
235 |
var failed = 0 |
|
236 |
var finished = 0 |
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
237 |
var canceled = false |
68892 | 238 |
var terminated = true |
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
239 |
var total_time = Time.zero |
83189 | 240 |
var max_time = Time.zero |
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
241 |
var command_timings = Map.empty[Command, Time] |
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
|
242 |
var theory_status = Document_Status.Theory_Status.NONE |
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
243 |
|
83178
952c1ca9b842
clarified signature: more uniform Node_Status.make vs. Overall_Timing.make;
wenzelm
parents:
83176
diff
changeset
|
244 |
for (command <- version.nodes(name).commands.iterator) { |
83164 | 245 |
val status = state.command_status(version, command) |
68758 | 246 |
|
247 |
if (status.is_running) running += 1 |
|
248 |
else if (status.is_failed) failed += 1 |
|
249 |
else if (status.is_warned) warned += 1 |
|
250 |
else if (status.is_finished) finished += 1 |
|
251 |
else unprocessed += 1 |
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
252 |
|
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
253 |
if (status.is_canceled) canceled = true |
68892 | 254 |
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
|
255 |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
256 |
val t = status.timings.sum.elapsed |
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
257 |
total_time += t |
83189 | 258 |
if (t > max_time) max_time = t |
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
259 |
if (t.is_notable(threshold)) command_timings += (command -> t) |
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
260 |
|
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
|
261 |
theory_status = Theory_Status.merge(theory_status, status.theory_status) |
68758 | 262 |
} |
263 |
||
68887 | 264 |
Node_Status( |
83163 | 265 |
suppressed = version.nodes.suppressed(name), |
68887 | 266 |
unprocessed = unprocessed, |
267 |
running = running, |
|
268 |
warned = warned, |
|
269 |
failed = failed, |
|
270 |
finished = finished, |
|
271 |
canceled = canceled, |
|
272 |
terminated = terminated, |
|
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
273 |
total_time = total_time, |
83189 | 274 |
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
|
275 |
threshold = threshold, |
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
276 |
command_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
|
277 |
theory_status = theory_status) |
68758 | 278 |
} |
279 |
} |
|
280 |
||
281 |
sealed case class Node_Status( |
|
83167 | 282 |
suppressed: Boolean = false, |
283 |
unprocessed: Int = 0, |
|
284 |
running: Int = 0, |
|
285 |
warned: Int = 0, |
|
286 |
failed: Int = 0, |
|
287 |
finished: Int = 0, |
|
288 |
canceled: Boolean = false, |
|
289 |
terminated: Boolean = false, |
|
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
290 |
total_time: Time = Time.zero, |
83189 | 291 |
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
|
292 |
threshold: Time = Time.zero, |
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
293 |
command_timings: Map[Command, Time] = Map.empty, |
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
294 |
theory_status: Theory_Status.Value = Theory_Status.NONE, |
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
|
295 |
) extends Theory_Status { |
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
296 |
def is_empty: Boolean = this == Node_Status.empty |
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
297 |
|
68758 | 298 |
def ok: Boolean = failed == 0 |
299 |
def total: Int = unprocessed + running + warned + failed + finished |
|
300 |
||
83163 | 301 |
def quasi_consolidated: Boolean = !suppressed && !finalized && terminated |
68897 | 302 |
|
68898 | 303 |
def percentage: Int = |
304 |
if (consolidated) 100 |
|
305 |
else if (total == 0) 0 |
|
306 |
else (((total - unprocessed).toDouble / total) * 100).toInt min 99 |
|
307 |
||
68758 | 308 |
def json: JSON.Object.T = |
309 |
JSON.Object("ok" -> ok, "total" -> total, "unprocessed" -> unprocessed, |
|
310 |
"running" -> running, "warned" -> warned, "failed" -> failed, "finished" -> finished, |
|
68898 | 311 |
"canceled" -> canceled, "consolidated" -> consolidated, |
312 |
"percentage" -> percentage) |
|
68758 | 313 |
} |
314 |
||
315 |
||
68759 | 316 |
/* nodes status */ |
317 |
||
83169 | 318 |
enum Overall_Status { case ok, failed, pending } |
68759 | 319 |
|
75393 | 320 |
object Nodes_Status { |
83205
99ce7933db6d
clarified signature: explicit domain for Nodes_Status operations;
wenzelm
parents:
83195
diff
changeset
|
321 |
val empty: Nodes_Status = new Nodes_Status(Map.empty) |
68759 | 322 |
} |
323 |
||
83205
99ce7933db6d
clarified signature: explicit domain for Nodes_Status operations;
wenzelm
parents:
83195
diff
changeset
|
324 |
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
|
325 |
def is_empty: Boolean = rep.isEmpty |
83187
2b9457f5ffef
more robust: total "apply", with subtle change of semantics;
wenzelm
parents:
83186
diff
changeset
|
326 |
def apply(name: Document.Node.Name): Node_Status = rep.getOrElse(name, Node_Status.empty) |
68759 | 327 |
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
|
328 |
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
|
329 |
|
68884
9b97d0b20d95
clarified quasi_consolidated state: ensure that exports are present for ok nodes;
wenzelm
parents:
68883
diff
changeset
|
330 |
def quasi_consolidated(name: Document.Node.Name): Boolean = |
83170 | 331 |
get(name) match { |
68897 | 332 |
case Some(st) => st.quasi_consolidated |
68883
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
333 |
case None => false |
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
334 |
} |
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
335 |
|
83169 | 336 |
def overall_status(name: Document.Node.Name): Overall_Status = |
83170 | 337 |
get(name) match { |
68759 | 338 |
case Some(st) if st.consolidated => |
83169 | 339 |
if (st.ok) Overall_Status.ok else Overall_Status.failed |
340 |
case _ => Overall_Status.pending |
|
68759 | 341 |
} |
342 |
||
83208 | 343 |
def update_node( |
344 |
state: Document.State, |
|
345 |
version: Document.Version, |
|
346 |
name: Document.Node.Name, |
|
347 |
threshold: Time = Time.max |
|
348 |
): Nodes_Status = { |
|
83215
0526a640f44f
avoid shortcuts based on potentially expensive equality test;
wenzelm
parents:
83210
diff
changeset
|
349 |
val node_status = Document_Status.Node_Status.make(state, version, name, threshold = threshold) |
0526a640f44f
avoid shortcuts based on potentially expensive equality test;
wenzelm
parents:
83210
diff
changeset
|
350 |
new Nodes_Status(rep + (name -> node_status)) |
83208 | 351 |
} |
352 |
||
353 |
def update_nodes( |
|
69255
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
wenzelm
parents:
68904
diff
changeset
|
354 |
resources: Resources, |
68763 | 355 |
state: Document.State, |
356 |
version: Document.Version, |
|
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
357 |
threshold: Time = Time.max, |
68769 | 358 |
domain: Option[Set[Document.Node.Name]] = None, |
75393 | 359 |
trim: Boolean = false |
83206 | 360 |
): Nodes_Status = { |
83208 | 361 |
val domain1 = version.nodes.domain |
362 |
val that = |
|
363 |
domain.getOrElse(domain1).iterator.foldLeft(this)( |
|
364 |
{ case (a, name) => |
|
365 |
if (Resources.hidden_node(name) || resources.loaded_theory(name)) a |
|
366 |
else a.update_node(state, version, name, threshold = threshold) }) |
|
367 |
if (trim) new Nodes_Status(that.rep -- that.rep.keysIterator.filterNot(domain1)) |
|
368 |
else that |
|
68763 | 369 |
} |
68761 | 370 |
|
68759 | 371 |
override def hashCode: Int = rep.hashCode |
372 |
override def equals(that: Any): Boolean = |
|
373 |
that match { |
|
374 |
case other: Nodes_Status => rep == other.rep |
|
375 |
case _ => false |
|
376 |
} |
|
68765 | 377 |
|
75393 | 378 |
override def toString: String = { |
68765 | 379 |
var ok = 0 |
380 |
var failed = 0 |
|
381 |
var pending = 0 |
|
68873 | 382 |
var canceled = 0 |
68765 | 383 |
for (name <- rep.keysIterator) { |
83169 | 384 |
overall_status(name) match { |
385 |
case Overall_Status.ok => ok += 1 |
|
386 |
case Overall_Status.failed => failed += 1 |
|
387 |
case Overall_Status.pending => pending += 1 |
|
68765 | 388 |
} |
68873 | 389 |
if (apply(name).canceled) canceled += 1 |
68765 | 390 |
} |
68873 | 391 |
"Nodes_Status(ok = " + ok + ", failed = " + failed + ", pending = " + pending + |
392 |
", canceled = " + canceled + ")" |
|
68765 | 393 |
} |
68759 | 394 |
} |
68758 | 395 |
} |