author | wenzelm |
Wed, 12 Sep 2018 20:58:06 +0200 | |
changeset 68981 | 30daac7848b9 |
parent 68962 | 50676b0ab970 |
child 68986 | 22f02724e7d1 |
permissions | -rw-r--r-- |
67054 | 1 |
/* Title: Pure/Thy/thy_resources.scala |
2 |
Author: Makarius |
|
3 |
||
67892 | 4 |
PIDE resources for theory files: load/unload theories via PIDE document updates. |
67054 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
67925 | 10 |
import java.io.{File => JFile} |
11 |
||
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
12 |
import scala.annotation.tailrec |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
13 |
|
67925 | 14 |
|
67054 | 15 |
object Thy_Resources |
16 |
{ |
|
67061
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
17 |
/* PIDE session */ |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
18 |
|
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
19 |
def start_session( |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
20 |
options: Options, |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
21 |
session_name: String, |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
22 |
session_dirs: List[Path] = Nil, |
67948 | 23 |
include_sessions: List[String] = Nil, |
67062
ee0823ce2828
optional session_base, e.g. from existing Sessions.Deps in build.scala;
wenzelm
parents:
67061
diff
changeset
|
24 |
session_base: Option[Sessions.Base] = None, |
67869 | 25 |
print_mode: List[String] = Nil, |
26 |
progress: Progress = No_Progress, |
|
67061
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
27 |
log: Logger = No_Logger): Session = |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
28 |
{ |
67062
ee0823ce2828
optional session_base, e.g. from existing Sessions.Deps in build.scala;
wenzelm
parents:
67061
diff
changeset
|
29 |
val base = |
ee0823ce2828
optional session_base, e.g. from existing Sessions.Deps in build.scala;
wenzelm
parents:
67061
diff
changeset
|
30 |
session_base getOrElse |
67948 | 31 |
Sessions.base_info(options, session_name, include_sessions = include_sessions, |
32 |
progress = progress, dirs = session_dirs).check_base |
|
67062
ee0823ce2828
optional session_base, e.g. from existing Sessions.Deps in build.scala;
wenzelm
parents:
67061
diff
changeset
|
33 |
val resources = new Thy_Resources(base, log = log) |
67945 | 34 |
val session = new Session(session_name, options, resources) |
67061
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
35 |
|
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
36 |
val session_error = Future.promise[String] |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
37 |
var session_phase: Session.Consumer[Session.Phase] = null |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
38 |
session_phase = |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
39 |
Session.Consumer(getClass.getName) { |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
40 |
case Session.Ready => |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
41 |
session.phase_changed -= session_phase |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
42 |
session_error.fulfill("") |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
43 |
case Session.Terminated(result) if !result.ok => |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
44 |
session.phase_changed -= session_phase |
67869 | 45 |
session_error.fulfill("Session start failed: return code " + result.rc) |
67061
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
46 |
case _ => |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
47 |
} |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
48 |
session.phase_changed += session_phase |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
49 |
|
67877 | 50 |
progress.echo("Starting " + session_name + " ...") |
67061
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
51 |
Isabelle_Process.start(session, options, |
67869 | 52 |
logic = session_name, dirs = session_dirs, modes = print_mode) |
67061
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
53 |
|
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
54 |
session_error.join match { |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
55 |
case "" => session |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
56 |
case msg => session.stop(); error(msg) |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
57 |
} |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
58 |
} |
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
59 |
|
68916 | 60 |
private def stable_snapshot( |
61 |
state: Document.State, version: Document.Version, name: Document.Node.Name): Document.Snapshot = |
|
62 |
{ |
|
63 |
val snapshot = state.snapshot(name) |
|
64 |
assert(version.id == snapshot.version.id) |
|
65 |
snapshot |
|
66 |
} |
|
67 |
||
68365 | 68 |
class Theories_Result private[Thy_Resources]( |
67883 | 69 |
val state: Document.State, |
67889 | 70 |
val version: Document.Version, |
68925 | 71 |
val nodes: List[(Document.Node.Name, Document_Status.Node_Status)], |
72 |
val nodes_committed: List[(Document.Node.Name, Document_Status.Node_Status)]) |
|
67879 | 73 |
{ |
68925 | 74 |
def snapshot(name: Document.Node.Name): Document.Snapshot = |
75 |
stable_snapshot(state, version, name) |
|
76 |
||
77 |
def ok: Boolean = |
|
78 |
(nodes.iterator ++ nodes_committed.iterator).forall({ case (_, st) => st.ok }) |
|
67879 | 79 |
} |
80 |
||
68943 | 81 |
val default_check_delay = Time.seconds(0.5) |
82 |
val default_nodes_status_delay = Time.seconds(-1.0) |
|
68981 | 83 |
val default_commit_cleanup_delay = Time.seconds(60.0) |
68947 | 84 |
val default_watchdog_timeout = Time.seconds(600.0) |
68694
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
85 |
|
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
86 |
|
67063 | 87 |
class Session private[Thy_Resources]( |
67945 | 88 |
session_name: String, |
67064
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
89 |
session_options: Options, |
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
90 |
override val resources: Thy_Resources) extends isabelle.Session(session_options, resources) |
67063 | 91 |
{ |
92 |
session => |
|
93 |
||
68922 | 94 |
|
95 |
/* temporary directory */ |
|
96 |
||
67925 | 97 |
val tmp_dir: JFile = Isabelle_System.tmp_dir("server_session") |
67946 | 98 |
val tmp_dir_name: String = File.path(tmp_dir).implode |
67925 | 99 |
|
68923 | 100 |
def master_directory(master_dir: String): String = |
101 |
proper_string(master_dir) getOrElse tmp_dir_name |
|
102 |
||
67945 | 103 |
override def toString: String = session_name |
104 |
||
67925 | 105 |
override def stop(): Process_Result = |
106 |
{ |
|
107 |
try { super.stop() } |
|
108 |
finally { Isabelle_System.rm_tree(tmp_dir) } |
|
109 |
} |
|
110 |
||
67936 | 111 |
|
112 |
/* theories */ |
|
113 |
||
68914 | 114 |
private sealed case class Use_Theories_State( |
115 |
last_update: Time = Time.now(), |
|
116 |
nodes_status: Document_Status.Nodes_Status = Document_Status.Nodes_Status.empty, |
|
68925 | 117 |
already_committed: Map[Document.Node.Name, Document_Status.Node_Status] = Map.empty, |
68916 | 118 |
result: Promise[Theories_Result] = Future.promise[Theories_Result]) |
68914 | 119 |
{ |
120 |
def update(new_nodes_status: Document_Status.Nodes_Status): Use_Theories_State = |
|
121 |
copy(last_update = Time.now(), nodes_status = new_nodes_status) |
|
122 |
||
123 |
def watchdog(watchdog_timeout: Time): Boolean = |
|
124 |
watchdog_timeout > Time.zero && Time.now() - last_update > watchdog_timeout |
|
125 |
||
68916 | 126 |
def cancel_result { result.cancel } |
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
127 |
def finished_result: Boolean = result.is_finished |
68916 | 128 |
def await_result { result.join_result } |
129 |
def join_result: Theories_Result = result.join |
|
130 |
def check_result( |
|
131 |
state: Document.State, |
|
132 |
version: Document.Version, |
|
68925 | 133 |
dep_theories: List[Document.Node.Name], |
68916 | 134 |
beyond_limit: Boolean, |
135 |
watchdog_timeout: Time, |
|
136 |
commit: Option[(Document.Snapshot, Document_Status.Node_Status) => Unit]) |
|
137 |
: Use_Theories_State = |
|
138 |
{ |
|
139 |
val st1 = |
|
140 |
if (commit.isDefined) { |
|
68949
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
141 |
val already_committed1 = |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
142 |
(already_committed /: dep_theories)({ case (committed, name) => |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
143 |
def parents_committed: Boolean = |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
144 |
version.nodes(name).header.imports.forall({ case (parent, _) => |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
145 |
Sessions.is_pure(parent.theory) || committed.isDefinedAt(parent) |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
146 |
}) |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
147 |
if (!committed.isDefinedAt(name) && parents_committed && |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
148 |
state.node_consolidated(version, name)) |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
149 |
{ |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
150 |
val snapshot = stable_snapshot(state, version, name) |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
151 |
val status = Document_Status.Node_Status.make(state, version, name) |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
152 |
commit.get.apply(snapshot, status) |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
153 |
committed + (name -> status) |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
154 |
} |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
155 |
else committed |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
156 |
}) |
e848328cb2c1
ensure foundational order of commits, taking Pure as implicit starting point;
wenzelm
parents:
68947
diff
changeset
|
157 |
copy(already_committed = already_committed1) |
68916 | 158 |
} |
159 |
else this |
|
160 |
||
161 |
if (beyond_limit || watchdog(watchdog_timeout) || |
|
68925 | 162 |
dep_theories.forall(name => |
163 |
already_committed.isDefinedAt(name) || |
|
68916 | 164 |
state.node_consolidated(version, name) || |
165 |
nodes_status.quasi_consolidated(name))) |
|
166 |
{ |
|
167 |
val nodes = |
|
68925 | 168 |
for (name <- dep_theories) |
68916 | 169 |
yield { (name -> Document_Status.Node_Status.make(state, version, name)) } |
68925 | 170 |
val nodes_committed = |
171 |
for { |
|
172 |
name <- dep_theories |
|
173 |
status <- already_committed.get(name) |
|
174 |
} yield (name -> status) |
|
175 |
||
176 |
try { result.fulfill(new Theories_Result(state, version, nodes, nodes_committed)) } |
|
68916 | 177 |
catch { case _: IllegalStateException => } |
178 |
} |
|
179 |
||
180 |
st1 |
|
181 |
} |
|
68914 | 182 |
} |
183 |
||
67064
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
184 |
def use_theories( |
67940
b4e80f062fbf
clarified signature -- eliminated somewhat pointless positions;
wenzelm
parents:
67939
diff
changeset
|
185 |
theories: List[String], |
67064
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
186 |
qualifier: String = Sessions.DRAFT, |
67881 | 187 |
master_dir: String = "", |
68943 | 188 |
check_delay: Time = default_check_delay, |
68694
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
189 |
check_limit: Int = 0, |
68947 | 190 |
watchdog_timeout: Time = default_watchdog_timeout, |
68943 | 191 |
nodes_status_delay: Time = default_nodes_status_delay, |
67885 | 192 |
id: UUID = UUID(), |
68916 | 193 |
// commit: must not block, must not fail |
194 |
commit: Option[(Document.Snapshot, Document_Status.Node_Status) => Unit] = None, |
|
68981 | 195 |
commit_cleanup_delay: Time = default_commit_cleanup_delay, |
67881 | 196 |
progress: Progress = No_Progress): Theories_Result = |
67064
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
197 |
{ |
67887
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
198 |
val dep_theories = |
68894
1dbdad1b57a5
more robust: load_theories after consumer is installed;
wenzelm
parents:
68888
diff
changeset
|
199 |
{ |
1dbdad1b57a5
more robust: load_theories after consumer is installed;
wenzelm
parents:
68888
diff
changeset
|
200 |
val import_names = |
68923 | 201 |
theories.map(thy => |
202 |
resources.import_name(qualifier, master_directory(master_dir), thy) -> Position.none) |
|
68894
1dbdad1b57a5
more robust: load_theories after consumer is installed;
wenzelm
parents:
68888
diff
changeset
|
203 |
resources.dependencies(import_names, progress = progress).check_errors.theories |
1dbdad1b57a5
more robust: load_theories after consumer is installed;
wenzelm
parents:
68888
diff
changeset
|
204 |
} |
67064
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
205 |
|
68914 | 206 |
val use_theories_state = Synchronized(Use_Theories_State()) |
67064
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
207 |
|
68916 | 208 |
def check_result(beyond_limit: Boolean = false) |
67064
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
209 |
{ |
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
210 |
val state = session.current_state() |
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
211 |
state.stable_tip_version match { |
68694
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
212 |
case Some(version) => |
68916 | 213 |
use_theories_state.change( |
214 |
_.check_result(state, version, dep_theories, beyond_limit, watchdog_timeout, commit)) |
|
68694
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
215 |
case None => |
67064
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
216 |
} |
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
217 |
} |
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
218 |
|
67894
fee080c4045f
more robust check_state loop, even without session activity (e.g. idempotent use_theories);
wenzelm
parents:
67893
diff
changeset
|
219 |
val check_progress = |
68694
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
220 |
{ |
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
221 |
var check_count = 0 |
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
222 |
Event_Timer.request(Time.now(), repeat = Some(check_delay)) |
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
223 |
{ |
68916 | 224 |
if (progress.stopped) use_theories_state.value.cancel_result |
68694
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
225 |
else { |
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
226 |
check_count += 1 |
68916 | 227 |
check_result(check_limit > 0 && check_count > check_limit) |
68694
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
228 |
} |
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
229 |
} |
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
230 |
} |
67894
fee080c4045f
more robust check_state loop, even without session activity (e.g. idempotent use_theories);
wenzelm
parents:
67893
diff
changeset
|
231 |
|
68906 | 232 |
val consumer = |
233 |
{ |
|
234 |
val delay_nodes_status = |
|
235 |
Standard_Thread.delay_first(nodes_status_delay max Time.zero) { |
|
68914 | 236 |
progress.nodes_status(use_theories_state.value.nodes_status) |
68906 | 237 |
} |
68770
add44e2b8cb0
optional notification of nodes_status (via progress);
wenzelm
parents:
68758
diff
changeset
|
238 |
|
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
239 |
val delay_commit_clean = |
68981 | 240 |
Standard_Thread.delay_first(commit_cleanup_delay max Time.zero) { |
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
241 |
val clean = use_theories_state.value.already_committed.keySet |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
242 |
resources.clean_theories(session, id, clean) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
243 |
} |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
244 |
|
68952 | 245 |
val dep_theories_set = dep_theories.toSet |
246 |
||
67064
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
247 |
Session.Consumer[Session.Commands_Changed](getClass.getName) { |
68330 | 248 |
case changed => |
68770
add44e2b8cb0
optional notification of nodes_status (via progress);
wenzelm
parents:
68758
diff
changeset
|
249 |
if (changed.nodes.exists(dep_theories_set)) { |
add44e2b8cb0
optional notification of nodes_status (via progress);
wenzelm
parents:
68758
diff
changeset
|
250 |
val snapshot = session.snapshot() |
add44e2b8cb0
optional notification of nodes_status (via progress);
wenzelm
parents:
68758
diff
changeset
|
251 |
val state = snapshot.state |
add44e2b8cb0
optional notification of nodes_status (via progress);
wenzelm
parents:
68758
diff
changeset
|
252 |
val version = snapshot.version |
add44e2b8cb0
optional notification of nodes_status (via progress);
wenzelm
parents:
68758
diff
changeset
|
253 |
|
68957 | 254 |
val theory_progress = |
68914 | 255 |
use_theories_state.change_result(st => |
68903 | 256 |
{ |
68883
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68771
diff
changeset
|
257 |
val domain = |
68914 | 258 |
if (st.nodes_status.is_empty) dep_theories_set |
68883
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68771
diff
changeset
|
259 |
else changed.nodes.iterator.filter(dep_theories_set).toSet |
68899 | 260 |
|
68903 | 261 |
val (nodes_status_changed, nodes_status1) = |
68914 | 262 |
st.nodes_status.update(resources.session_base, state, version, |
68903 | 263 |
domain = Some(domain), trim = changed.assignment) |
68899 | 264 |
|
68903 | 265 |
if (nodes_status_delay >= Time.zero && nodes_status_changed) { |
68883
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68771
diff
changeset
|
266 |
delay_nodes_status.invoke |
68899 | 267 |
} |
68883
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68771
diff
changeset
|
268 |
|
68957 | 269 |
val theory_progress = |
68905 | 270 |
(for { |
68904 | 271 |
(name, node_status) <- nodes_status1.present.iterator |
68959 | 272 |
if changed.nodes.contains(name) && !st.already_committed.isDefinedAt(name) |
68962 | 273 |
p1 = node_status.percentage |
274 |
if p1 > 0 && Some(p1) != st.nodes_status.get(name).map(_.percentage) |
|
275 |
} yield Progress.Theory(name.theory, percentage = Some(p1))).toList |
|
68903 | 276 |
|
68957 | 277 |
(theory_progress, st.update(nodes_status1)) |
68903 | 278 |
}) |
68330 | 279 |
|
68957 | 280 |
theory_progress.foreach(progress.theory(_)) |
68903 | 281 |
|
68916 | 282 |
check_result() |
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
283 |
|
68981 | 284 |
if (commit.isDefined && commit_cleanup_delay > Time.zero) { |
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
285 |
if (use_theories_state.value.finished_result) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
286 |
delay_commit_clean.revoke |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
287 |
else delay_commit_clean.invoke |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
288 |
} |
68330 | 289 |
} |
67064
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
290 |
} |
68906 | 291 |
} |
67064
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
292 |
|
67892 | 293 |
try { |
294 |
session.commands_changed += consumer |
|
68894
1dbdad1b57a5
more robust: load_theories after consumer is installed;
wenzelm
parents:
68888
diff
changeset
|
295 |
resources.load_theories(session, id, dep_theories, progress) |
68916 | 296 |
use_theories_state.value.await_result |
67894
fee080c4045f
more robust check_state loop, even without session activity (e.g. idempotent use_theories);
wenzelm
parents:
67893
diff
changeset
|
297 |
check_progress.cancel |
67892 | 298 |
} |
299 |
finally { |
|
68907 | 300 |
session.commands_changed -= consumer |
67892 | 301 |
resources.unload_theories(session, id, dep_theories) |
302 |
} |
|
67884
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
303 |
|
68916 | 304 |
use_theories_state.value.join_result |
67064
fb487246ef4f
synchronous use_theories, based on consolidated_state;
wenzelm
parents:
67063
diff
changeset
|
305 |
} |
67936 | 306 |
|
67939 | 307 |
def purge_theories( |
68915 | 308 |
theories: List[String], |
309 |
qualifier: String = Sessions.DRAFT, |
|
310 |
master_dir: String = "", |
|
311 |
all: Boolean = false): (List[Document.Node.Name], List[Document.Node.Name]) = |
|
312 |
{ |
|
68923 | 313 |
val nodes = |
314 |
if (all) None |
|
315 |
else Some(theories.map(resources.import_name(qualifier, master_directory(master_dir), _))) |
|
68915 | 316 |
resources.purge_theories(session, nodes) |
317 |
} |
|
67063 | 318 |
} |
319 |
||
67061
2efa25302f34
synchronous session start (similar to isabelle.vscode.Server);
wenzelm
parents:
67059
diff
changeset
|
320 |
|
67054 | 321 |
/* internal state */ |
322 |
||
68922 | 323 |
final class Theory private[Thy_Resources]( |
324 |
val node_name: Document.Node.Name, |
|
325 |
val node_header: Document.Node.Header, |
|
326 |
val text: String, |
|
327 |
val node_required: Boolean) |
|
328 |
{ |
|
329 |
override def toString: String = node_name.toString |
|
330 |
||
331 |
def node_perspective: Document.Node.Perspective_Text = |
|
332 |
Document.Node.Perspective(node_required, Text.Perspective.empty, Document.Node.Overlays.empty) |
|
333 |
||
334 |
def make_edits(text_edits: List[Text.Edit]): List[Document.Edit_Text] = |
|
335 |
List(node_name -> Document.Node.Deps(node_header), |
|
336 |
node_name -> Document.Node.Edits(text_edits), |
|
337 |
node_name -> node_perspective) |
|
338 |
||
339 |
def node_edits(old: Option[Theory]): List[Document.Edit_Text] = |
|
340 |
{ |
|
341 |
val (text_edits, old_required) = |
|
342 |
if (old.isEmpty) (Text.Edit.inserts(0, text), false) |
|
343 |
else (Text.Edit.replace(0, old.get.text, text), old.get.node_required) |
|
344 |
||
345 |
if (text_edits.isEmpty && node_required == old_required) Nil |
|
346 |
else make_edits(text_edits) |
|
347 |
} |
|
348 |
||
349 |
def purge_edits: List[Document.Edit_Text] = |
|
350 |
make_edits(Text.Edit.removes(0, text)) |
|
351 |
||
352 |
def required(required: Boolean): Theory = |
|
353 |
if (required == node_required) this |
|
354 |
else new Theory(node_name, node_header, text, required) |
|
355 |
} |
|
356 |
||
67884
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
357 |
sealed case class State( |
67887
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
358 |
required: Multi_Map[Document.Node.Name, UUID] = Multi_Map.empty, |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
359 |
theories: Map[Document.Node.Name, Theory] = Map.empty) |
67884
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
360 |
{ |
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
361 |
lazy val theory_graph: Graph[Document.Node.Name, Unit] = |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
362 |
{ |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
363 |
val entries = |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
364 |
for ((name, theory) <- theories.toList) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
365 |
yield ((name, ()), theory.node_header.imports.map(_._1).filter(theories.isDefinedAt(_))) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
366 |
Graph.make(entries, symmetric = true)(Document.Node.Name.Ordering) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
367 |
} |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
368 |
|
67887
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
369 |
def is_required(name: Document.Node.Name): Boolean = required.isDefinedAt(name) |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
370 |
|
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
371 |
def insert_required(id: UUID, names: List[Document.Node.Name]): State = |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
372 |
copy(required = (required /: names)(_.insert(_, id))) |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
373 |
|
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
374 |
def remove_required(id: UUID, names: List[Document.Node.Name]): State = |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
375 |
copy(required = (required /: names)(_.remove(_, id))) |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
376 |
|
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
377 |
def update_theories(update: List[(Document.Node.Name, Theory)]): State = |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
378 |
copy(theories = |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
379 |
(theories /: update)({ case (thys, (name, thy)) => |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
380 |
thys.get(name) match { |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
381 |
case Some(thy1) if thy1 == thy => thys |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
382 |
case _ => thys + (name -> thy) |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
383 |
} |
a4d5342898b1
unload_theories: actually observe required state;
wenzelm
parents:
67885
diff
changeset
|
384 |
})) |
67936 | 385 |
|
386 |
def remove_theories(remove: List[Document.Node.Name]): State = |
|
387 |
{ |
|
388 |
require(remove.forall(name => !is_required(name))) |
|
389 |
copy(theories = theories -- remove) |
|
390 |
} |
|
391 |
||
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
392 |
def unload_theories(session: Session, id: UUID, dep_theories: List[Document.Node.Name]): State = |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
393 |
{ |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
394 |
val st1 = remove_required(id, dep_theories) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
395 |
val theory_edits = |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
396 |
for { |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
397 |
node_name <- dep_theories |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
398 |
theory <- st1.theories.get(node_name) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
399 |
} |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
400 |
yield { |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
401 |
val theory1 = theory.required(st1.is_required(node_name)) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
402 |
val edits = theory1.node_edits(Some(theory)) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
403 |
(edits, (node_name, theory1)) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
404 |
} |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
405 |
session.update(Document.Blobs.empty, theory_edits.flatMap(_._1)) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
406 |
st1.update_theories(theory_edits.map(_._2)) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
407 |
} |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
408 |
|
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
409 |
def purge_theories(session: Session, nodes: List[Document.Node.Name]) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
410 |
: ((List[Document.Node.Name], List[Document.Node.Name]), State) = |
67936 | 411 |
{ |
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
412 |
val all_nodes = theory_graph.topological_order |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
413 |
val purge = nodes.filterNot(is_required(_)).toSet |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
414 |
|
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
415 |
val retain = theory_graph.all_preds(all_nodes.filterNot(purge)).toSet |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
416 |
val (retained, purged) = all_nodes.partition(retain) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
417 |
|
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
418 |
val purge_edits = purged.flatMap(name => theories(name).purge_edits) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
419 |
session.update(Document.Blobs.empty, purge_edits) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
420 |
|
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
421 |
((purged, retained), remove_theories(purged)) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
422 |
} |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
423 |
|
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
424 |
def frontier_theories(clean: Set[Document.Node.Name]): Set[Document.Node.Name] = |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
425 |
{ |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
426 |
@tailrec def frontier(base: List[Document.Node.Name], front: Set[Document.Node.Name]) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
427 |
: Set[Document.Node.Name] = |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
428 |
{ |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
429 |
val add = base.filter(b => theory_graph.imm_succs(b).forall(front)) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
430 |
if (add.isEmpty) front |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
431 |
else { |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
432 |
val pre_add = add.map(theory_graph.imm_preds) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
433 |
val base1 = (pre_add.head /: pre_add.tail)(_ ++ _).toList.filter(clean) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
434 |
frontier(base1, front ++ add) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
435 |
} |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
436 |
} |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
437 |
frontier(theory_graph.maximals.filter(clean), Set.empty) |
67936 | 438 |
} |
67884
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
439 |
} |
67054 | 440 |
} |
441 |
||
67056 | 442 |
class Thy_Resources(session_base: Sessions.Base, log: Logger = No_Logger) |
67054 | 443 |
extends Resources(session_base, log = log) |
444 |
{ |
|
67056 | 445 |
resources => |
446 |
||
67054 | 447 |
private val state = Synchronized(Thy_Resources.State()) |
67056 | 448 |
|
449 |
def load_theories( |
|
450 |
session: Session, |
|
67885 | 451 |
id: UUID, |
68894
1dbdad1b57a5
more robust: load_theories after consumer is installed;
wenzelm
parents:
68888
diff
changeset
|
452 |
dep_theories: List[Document.Node.Name], |
1dbdad1b57a5
more robust: load_theories after consumer is installed;
wenzelm
parents:
68888
diff
changeset
|
453 |
progress: Progress) |
67056 | 454 |
{ |
67888 | 455 |
val loaded_theories = |
456 |
for (node_name <- dep_theories) |
|
457 |
yield { |
|
458 |
val path = node_name.path |
|
459 |
if (!node_name.is_theory) error("Not a theory file: " + path) |
|
460 |
||
461 |
progress.expose_interrupt() |
|
462 |
val text = File.read(path) |
|
463 |
val node_header = resources.check_thy_reader(node_name, Scan.char_reader(text)) |
|
464 |
new Thy_Resources.Theory(node_name, node_header, text, true) |
|
465 |
} |
|
67056 | 466 |
|
68958 | 467 |
val loaded = loaded_theories.length |
468 |
if (loaded > 1) progress.echo("Loading " + loaded + " theories ...") |
|
469 |
||
67893 | 470 |
state.change(st => |
471 |
{ |
|
472 |
val st1 = st.insert_required(id, dep_theories) |
|
473 |
val theory_edits = |
|
474 |
for (theory <- loaded_theories) |
|
475 |
yield { |
|
476 |
val node_name = theory.node_name |
|
477 |
val theory1 = theory.required(st1.is_required(node_name)) |
|
478 |
val edits = theory1.node_edits(st1.theories.get(node_name)) |
|
479 |
(edits, (node_name, theory1)) |
|
480 |
} |
|
481 |
session.update(Document.Blobs.empty, theory_edits.flatMap(_._1)) |
|
482 |
st1.update_theories(theory_edits.map(_._2)) |
|
483 |
}) |
|
67056 | 484 |
} |
67884
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
485 |
|
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
486 |
def unload_theories( |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
487 |
session: Thy_Resources.Session, id: UUID, dep_theories: List[Document.Node.Name]) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
488 |
{ |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
489 |
state.change(_.unload_theories(session, id, dep_theories)) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
490 |
} |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
491 |
|
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
492 |
def clean_theories(session: Thy_Resources.Session, id: UUID, clean: Set[Document.Node.Name]) |
67884
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
493 |
{ |
67893 | 494 |
state.change(st => |
495 |
{ |
|
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
496 |
val frontier = st.frontier_theories(clean).toList |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
497 |
if (frontier.isEmpty) st |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
498 |
else { |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
499 |
val st1 = st.unload_theories(session, id, frontier) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
500 |
val (_, st2) = st1.purge_theories(session, frontier) |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
501 |
st2 |
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
502 |
} |
67893 | 503 |
}) |
67884
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
504 |
} |
67936 | 505 |
|
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
506 |
def purge_theories(session: Thy_Resources.Session, nodes: Option[List[Document.Node.Name]]) |
68915 | 507 |
: (List[Document.Node.Name], List[Document.Node.Name]) = |
67936 | 508 |
{ |
68936
90c08c7bab9c
continuously clean frontier of already committed theories: much less resource requirements;
wenzelm
parents:
68935
diff
changeset
|
509 |
state.change_result(st => st.purge_theories(session, nodes getOrElse st.theory_graph.keys)) |
67936 | 510 |
} |
67054 | 511 |
} |