author | wenzelm |
Fri, 14 Jan 2011 13:58:07 +0100 | |
changeset 41548 | bd0bebf93fa6 |
parent 41536 | 47fef6afe756 |
child 41672 | 2f70b1ddd09f |
permissions | -rw-r--r-- |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
1 |
(* Title: Pure/Thy/thy_info.ML |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
2 |
Author: Markus Wenzel, TU Muenchen |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
3 |
|
37978
548f3f165d05
simplified Thy_Header.read -- include Source.of_string_limited here;
wenzelm
parents:
37977
diff
changeset
|
4 |
Global theory info database, with auto-loading according to theory and |
15801 | 5 |
file dependencies. |
3976 | 6 |
*) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
7 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
8 |
signature THY_INFO = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
9 |
sig |
37981
9a15982f41fe
theory loader: removed obsolete touch/outdate operations (require_thy no longer changes the database implicitly);
wenzelm
parents:
37980
diff
changeset
|
10 |
datatype action = Update | Remove |
7099 | 11 |
val add_hook: (action -> string -> unit) -> unit |
26614 | 12 |
val get_names: unit -> string list |
7288 | 13 |
val lookup_theory: string -> theory option |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
14 |
val get_theory: string -> theory |
24563 | 15 |
val is_finished: string -> bool |
26983 | 16 |
val master_directory: string -> Path.T |
24080
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
17 |
val loaded_files: string -> Path.T list |
29421
db532e37cda2
use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents:
29118
diff
changeset
|
18 |
val remove_thy: string -> unit |
db532e37cda2
use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents:
29118
diff
changeset
|
19 |
val kill_thy: string -> unit |
38146 | 20 |
val use_thys_wrt: Path.T -> string list -> unit |
24057
f42665561801
removed obsolete Output.ML_errors/toplevel_errors;
wenzelm
parents:
23982
diff
changeset
|
21 |
val use_thys: string list -> unit |
f42665561801
removed obsolete Output.ML_errors/toplevel_errors;
wenzelm
parents:
23982
diff
changeset
|
22 |
val use_thy: string -> unit |
41536
47fef6afe756
Toplevel.init_theory: maintain optional master directory, to allow bypassing global Thy_Load.master_path;
wenzelm
parents:
40741
diff
changeset
|
23 |
val toplevel_begin_theory: Path.T option -> string -> |
47fef6afe756
Toplevel.init_theory: maintain optional master directory, to allow bypassing global Thy_Load.master_path;
wenzelm
parents:
40741
diff
changeset
|
24 |
string list -> (Path.T * bool) list -> theory |
37954
a2e73df0b1e0
simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents:
37953
diff
changeset
|
25 |
val register_thy: theory -> unit |
24080
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
26 |
val finish: unit -> unit |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
27 |
end; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
28 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36953
diff
changeset
|
29 |
structure Thy_Info: THY_INFO = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
30 |
struct |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
31 |
|
7099 | 32 |
(** theory loader actions and hooks **) |
33 |
||
37981
9a15982f41fe
theory loader: removed obsolete touch/outdate operations (require_thy no longer changes the database implicitly);
wenzelm
parents:
37980
diff
changeset
|
34 |
datatype action = Update | Remove; |
7099 | 35 |
|
36 |
local |
|
32738 | 37 |
val hooks = Unsynchronized.ref ([]: (action -> string -> unit) list); |
7099 | 38 |
in |
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
39 |
fun add_hook f = NAMED_CRITICAL "Thy_Info" (fn () => Unsynchronized.change hooks (cons f)); |
15570 | 40 |
fun perform action name = List.app (fn f => (try (fn () => f action name) (); ())) (! hooks); |
7099 | 41 |
end; |
42 |
||
43 |
||
44 |
||
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
45 |
(** thy database **) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
46 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
47 |
(* messages *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
48 |
|
23871 | 49 |
fun loader_msg txt [] = "Theory loader: " ^ txt |
50 |
| loader_msg txt names = "Theory loader: " ^ txt ^ " " ^ commas_quote names; |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
51 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
52 |
val show_path = space_implode " via " o map quote; |
9332 | 53 |
fun cycle_msg names = loader_msg ("cyclic dependency of " ^ show_path names) []; |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
54 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
55 |
|
6666 | 56 |
(* derived graph operations *) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
57 |
|
9327 | 58 |
fun add_deps name parents G = Graph.add_deps_acyclic (name, parents) G |
9332 | 59 |
handle Graph.CYCLES namess => error (cat_lines (map cycle_msg namess)); |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
60 |
|
37984
f26352bd82cf
clarified register_thy: clean slate via kill_thy, more precise CRITICAL section;
wenzelm
parents:
37981
diff
changeset
|
61 |
fun new_entry name parents entry = |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
62 |
Graph.new_node (name, entry) #> add_deps name parents; |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
63 |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
64 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
65 |
(* thy database *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
66 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
67 |
type deps = |
40741
17d6293a1e26
moved file identification to thy_load.ML (where it is actually used);
wenzelm
parents:
40132
diff
changeset
|
68 |
{master: (Path.T * Thy_Load.file_ident), (*master dependencies for thy file*) |
17d6293a1e26
moved file identification to thy_load.ML (where it is actually used);
wenzelm
parents:
40132
diff
changeset
|
69 |
imports: string list}; (*source specification of imports (partially qualified)*) |
23886
f40fba467384
simplified ThyLoad interfaces: only one additional directory;
wenzelm
parents:
23871
diff
changeset
|
70 |
|
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
71 |
fun make_deps master imports : deps = {master = master, imports = imports}; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
72 |
|
37980
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
73 |
fun master_dir (d: deps option) = the_default Path.current (Option.map (Path.dir o #1 o #master) d); |
23967 | 74 |
fun base_name s = Path.implode (Path.base (Path.explode s)); |
75 |
||
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
76 |
local |
37905 | 77 |
val database = Unsynchronized.ref (Graph.empty: (deps option * theory option) Graph.T); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
78 |
in |
6362 | 79 |
fun get_thys () = ! database; |
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
80 |
fun change_thys f = NAMED_CRITICAL "Thy_Info" (fn () => Unsynchronized.change database f); |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
81 |
end; |
5209 | 82 |
|
83 |
||
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
84 |
(* access thy graph *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
85 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
86 |
fun thy_graph f x = f (get_thys ()) x; |
9417 | 87 |
|
23967 | 88 |
fun get_names () = Graph.topological_order (get_thys ()); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
89 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
90 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
91 |
(* access thy *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
92 |
|
7935 | 93 |
fun lookup_thy name = |
15531 | 94 |
SOME (thy_graph Graph.get_node name) handle Graph.UNDEF _ => NONE; |
7935 | 95 |
|
16047 | 96 |
val known_thy = is_some o lookup_thy; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
97 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
98 |
fun get_thy name = |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
99 |
(case lookup_thy name of |
15531 | 100 |
SOME thy => thy |
101 |
| NONE => error (loader_msg "nothing known about theory" [name])); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
102 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
103 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
104 |
(* access deps *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
105 |
|
15570 | 106 |
val lookup_deps = Option.map #1 o lookup_thy; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
107 |
val get_deps = #1 o get_thy; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
108 |
|
26983 | 109 |
val is_finished = is_none o get_deps; |
37980
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
110 |
val master_directory = master_dir o get_deps; |
7191 | 111 |
|
23871 | 112 |
fun get_parents name = |
23967 | 113 |
thy_graph Graph.imm_preds name handle Graph.UNDEF _ => |
6654 | 114 |
error (loader_msg "nothing known about theory" [name]); |
115 |
||
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
116 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
117 |
(* access theory *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
118 |
|
7687 | 119 |
fun lookup_theory name = |
120 |
(case lookup_thy name of |
|
38142 | 121 |
SOME (_, SOME theory) => SOME theory |
15531 | 122 |
| _ => NONE); |
7288 | 123 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
124 |
fun get_theory name = |
7288 | 125 |
(case lookup_theory name of |
23871 | 126 |
SOME theory => theory |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
127 |
| _ => error (loader_msg "undefined theory entry for" [name])); |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
128 |
|
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
129 |
fun loaded_files name = NAMED_CRITICAL "Thy_Info" (fn () => |
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37942
diff
changeset
|
130 |
(case get_deps name of |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37942
diff
changeset
|
131 |
NONE => [] |
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
132 |
| SOME {master = (thy_path, _), ...} => thy_path :: Thy_Load.loaded_files (get_theory name))); |
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37942
diff
changeset
|
133 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
134 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
135 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
136 |
(** thy operations **) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
137 |
|
29421
db532e37cda2
use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents:
29118
diff
changeset
|
138 |
(* remove theory *) |
db532e37cda2
use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents:
29118
diff
changeset
|
139 |
|
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
140 |
fun remove_thy name = NAMED_CRITICAL "Thy_Info" (fn () => |
37979 | 141 |
if is_finished name then error (loader_msg "attempt to change finished theory" [name]) |
29421
db532e37cda2
use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents:
29118
diff
changeset
|
142 |
else |
29434 | 143 |
let |
144 |
val succs = thy_graph Graph.all_succs [name]; |
|
40132
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
wenzelm
parents:
39557
diff
changeset
|
145 |
val _ = Output.urgent_message (loader_msg "removing" succs); |
38142 | 146 |
val _ = List.app (perform Remove) succs; |
147 |
val _ = change_thys (Graph.del_nodes succs); |
|
148 |
in () end); |
|
29421
db532e37cda2
use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents:
29118
diff
changeset
|
149 |
|
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
150 |
fun kill_thy name = NAMED_CRITICAL "Thy_Info" (fn () => |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
151 |
if known_thy name then remove_thy name |
38142 | 152 |
else ()); |
7099 | 153 |
|
154 |
||
24209 | 155 |
(* scheduling loader tasks *) |
156 |
||
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
157 |
datatype task = |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
158 |
Task of string list * (theory list -> (theory * (unit -> unit))) | |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
159 |
Finished of theory; |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
160 |
|
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
161 |
fun task_finished (Task _) = false |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
162 |
| task_finished (Finished _) = true; |
24209 | 163 |
|
29118 | 164 |
local |
165 |
||
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
166 |
fun schedule_seq task_graph = |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
167 |
((Graph.topological_order task_graph, Symtab.empty) |-> fold (fn name => fn tab => |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
168 |
(case Graph.get_node task_graph name of |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
169 |
Task (parents, body) => |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
170 |
let |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
171 |
val (thy, after_load) = body (map (the o Symtab.lookup tab) parents); |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
172 |
val _ = after_load (); |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
173 |
in Symtab.update (name, thy) tab end |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
174 |
| Finished thy => Symtab.update (name, thy) tab))) |> ignore; |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
175 |
|
32814
81897d30b97f
added Task_Queue.depend (again) -- light-weight version for transitive graph;
wenzelm
parents:
32794
diff
changeset
|
176 |
fun schedule_futures task_graph = uninterruptible (fn _ => fn () => |
28194 | 177 |
let |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
178 |
val tasks = Graph.topological_order task_graph; |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
179 |
val futures = (tasks, Symtab.empty) |-> fold (fn name => fn tab => |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
180 |
(case Graph.get_node task_graph name of |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
181 |
Task (parents, body) => |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
182 |
let |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
183 |
val get = the o Symtab.lookup tab; |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
184 |
val deps = map (`get) (Graph.imm_preds task_graph name); |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
185 |
fun failed (future, parent) = if can Future.join future then NONE else SOME parent; |
29000
5e03bc760355
improved future_schedule: more robust handling of failed parents (explicit join), final join of all futures, including Exn.release_all;
wenzelm
parents:
28980
diff
changeset
|
186 |
|
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
187 |
val future = Future.fork_deps (map #1 deps) (fn () => |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
188 |
(case map_filter failed deps of |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
189 |
[] => body (map (#1 o Future.join o get) parents) |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
190 |
| bad => error (loader_msg |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
191 |
("failed to load " ^ quote name ^ " (unresolved " ^ commas_quote bad ^ ")") []))); |
38143
3342c68d8782
schedule_futures: discontinued special treatment of non-parallel proofs, which might have affected memory usage at some point, but does not seem to make a difference with as little as 2GB RAM;
wenzelm
parents:
38142
diff
changeset
|
192 |
in Symtab.update (name, future) tab end |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
193 |
| Finished thy => Symtab.update (name, Future.value (thy, I)) tab)); |
37980
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
194 |
val _ = |
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
195 |
tasks |> maps (fn name => |
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
196 |
let |
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
197 |
val (thy, after_load) = Future.join (the (Symtab.lookup futures name)); |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39021
diff
changeset
|
198 |
val _ = Global_Theory.join_proofs thy; |
37980
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
199 |
val _ = after_load (); |
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
200 |
in [] end handle exn => [Exn.Exn exn]) |
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
201 |
|> rev |> Exn.release_all; |
34260
2524c1bbd087
kill failed theories in reverse order -- avoids cascaded warnings;
wenzelm
parents:
33522
diff
changeset
|
202 |
in () end) (); |
29429
a6c641f08af7
schedule_futures: tuned final consolidation, explicit after_load phase;
wenzelm
parents:
29421
diff
changeset
|
203 |
|
24209 | 204 |
in |
205 |
||
32794 | 206 |
fun schedule_tasks tasks = |
29118 | 207 |
if not (Multithreading.enabled ()) then schedule_seq tasks |
208 |
else if Multithreading.self_critical () then |
|
24209 | 209 |
(warning (loader_msg "no multithreading within critical section" []); |
210 |
schedule_seq tasks) |
|
29118 | 211 |
else schedule_futures tasks; |
24209 | 212 |
|
213 |
end; |
|
214 |
||
215 |
||
23967 | 216 |
(* require_thy -- checking database entries wrt. the file-system *) |
15065 | 217 |
|
7211 | 218 |
local |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
219 |
|
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
220 |
fun required_by _ [] = "" |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
221 |
| required_by s initiators = s ^ "(required by " ^ show_path (rev initiators) ^ ")"; |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
222 |
|
38134
3de75ca6f166
load_thy: refer to physical master directory (not accumulated source import directory) and enable loading files relatively to that;
wenzelm
parents:
37985
diff
changeset
|
223 |
fun load_thy initiators update_time (deps: deps) text name parent_thys = |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
224 |
let |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
225 |
val _ = kill_thy name; |
40132
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
wenzelm
parents:
39557
diff
changeset
|
226 |
val _ = Output.urgent_message ("Loading theory " ^ quote name ^ required_by " " initiators); |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
227 |
|
41548
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents:
41536
diff
changeset
|
228 |
val {master = (thy_path, _), imports} = deps; |
38134
3de75ca6f166
load_thy: refer to physical master directory (not accumulated source import directory) and enable loading files relatively to that;
wenzelm
parents:
37985
diff
changeset
|
229 |
val dir = Path.dir thy_path; |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
230 |
val pos = Path.position thy_path; |
37978
548f3f165d05
simplified Thy_Header.read -- include Source.of_string_limited here;
wenzelm
parents:
37977
diff
changeset
|
231 |
val uses = map (apfst Path.explode) (#3 (Thy_Header.read pos text)); |
41536
47fef6afe756
Toplevel.init_theory: maintain optional master directory, to allow bypassing global Thy_Load.master_path;
wenzelm
parents:
40741
diff
changeset
|
232 |
fun init _ = |
41548
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents:
41536
diff
changeset
|
233 |
Thy_Load.begin_theory dir name imports parent_thys uses |
38141
8a2bacb8ad87
removed unused Update_Time data (cf. ac94ff28e9e1);
wenzelm
parents:
38139
diff
changeset
|
234 |
|> Present.begin_theory update_time dir uses; |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
235 |
|
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
236 |
val (after_load, theory) = Outer_Syntax.load_thy name init pos text; |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
237 |
|
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
238 |
val parents = map Context.theory_name parent_thys; |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
239 |
fun after_load' () = |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
240 |
(after_load (); |
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
241 |
NAMED_CRITICAL "Thy_Info" (fn () => |
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
242 |
(map get_theory parents; |
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
243 |
change_thys (new_entry name parents (SOME deps, SOME theory)); |
38147
2b08a96a283e
load_thy/after_load: explicit check of parent theories, which might have failed to join proofs -- avoid uninformative crash via Graph.UNDEF;
wenzelm
parents:
38146
diff
changeset
|
244 |
perform Update name))); |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
245 |
|
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
246 |
in (theory, after_load') end; |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
247 |
|
24175
38a15a3a1aad
theory loader: removed obsolete update_thy (coincides with use_thy);
wenzelm
parents:
24151
diff
changeset
|
248 |
fun check_deps dir name = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
249 |
(case lookup_deps name of |
37980
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
250 |
SOME NONE => (true, NONE, get_parents name, NONE) |
23893
8babfcaaf129
deps: maintain source specification of parents (prevents repeated ThyLoad.deps_thy);
wenzelm
parents:
23886
diff
changeset
|
251 |
| NONE => |
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
252 |
let val {master, text, imports, ...} = Thy_Load.deps_thy dir name |
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
253 |
in (false, SOME (make_deps master imports), imports, SOME text) end |
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
254 |
| SOME (SOME {master, imports}) => |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
255 |
let val master' = Thy_Load.check_thy dir name in |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
256 |
if #2 master <> #2 master' then |
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
257 |
let val {text = text', imports = imports', ...} = Thy_Load.deps_thy dir name; |
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
258 |
in (false, SOME (make_deps master' imports'), imports', SOME text') end |
24175
38a15a3a1aad
theory loader: removed obsolete update_thy (coincides with use_thy);
wenzelm
parents:
24151
diff
changeset
|
259 |
else |
38a15a3a1aad
theory loader: removed obsolete update_thy (coincides with use_thy);
wenzelm
parents:
24151
diff
changeset
|
260 |
let |
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37942
diff
changeset
|
261 |
val current = |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37942
diff
changeset
|
262 |
(case lookup_theory name of |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37942
diff
changeset
|
263 |
NONE => false |
37985
e3ce42cb22dd
simplified handling of update_time -- do not store within deps;
wenzelm
parents:
37984
diff
changeset
|
264 |
| SOME theory => Thy_Load.all_current theory); |
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
265 |
val deps' = SOME (make_deps master' imports); |
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
266 |
in (current, deps', imports, NONE) end |
24175
38a15a3a1aad
theory loader: removed obsolete update_thy (coincides with use_thy);
wenzelm
parents:
24151
diff
changeset
|
267 |
end); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
268 |
|
23967 | 269 |
in |
270 |
||
37873
66d90b2b87bc
eliminated old time_use/time_use_thy variants -- timing is implicitly controlled via Output.timing;
wenzelm
parents:
37871
diff
changeset
|
271 |
fun require_thys initiators dir strs tasks = |
66d90b2b87bc
eliminated old time_use/time_use_thy variants -- timing is implicitly controlled via Output.timing;
wenzelm
parents:
37871
diff
changeset
|
272 |
fold_map (require_thy initiators dir) strs tasks |>> forall I |
66d90b2b87bc
eliminated old time_use/time_use_thy variants -- timing is implicitly controlled via Output.timing;
wenzelm
parents:
37871
diff
changeset
|
273 |
and require_thy initiators dir str tasks = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
274 |
let |
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
20664
diff
changeset
|
275 |
val path = Path.expand (Path.explode str); |
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
20664
diff
changeset
|
276 |
val name = Path.implode (Path.base path); |
23893
8babfcaaf129
deps: maintain source specification of parents (prevents repeated ThyLoad.deps_thy);
wenzelm
parents:
23886
diff
changeset
|
277 |
val dir' = Path.append dir (Path.dir path); |
23871 | 278 |
val _ = member (op =) initiators name andalso error (cycle_msg initiators); |
7066 | 279 |
in |
32794 | 280 |
(case try (Graph.get_node tasks) name of |
24209 | 281 |
SOME task => (task_finished task, tasks) |
23967 | 282 |
| NONE => |
283 |
let |
|
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
284 |
val (current, deps, imports, opt_text) = check_deps dir' name |
23967 | 285 |
handle ERROR msg => cat_error msg |
286 |
(loader_msg "the error(s) above occurred while examining theory" [name] ^ |
|
287 |
required_by "\n" initiators); |
|
37981
9a15982f41fe
theory loader: removed obsolete touch/outdate operations (require_thy no longer changes the database implicitly);
wenzelm
parents:
37980
diff
changeset
|
288 |
|
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
289 |
val parents = map base_name imports; |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
290 |
val (parents_current, tasks') = |
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
291 |
require_thys (name :: initiators) (Path.append dir (master_dir deps)) imports tasks; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
292 |
|
23967 | 293 |
val all_current = current andalso parents_current; |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
294 |
val task = |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
295 |
if all_current then Finished (get_theory name) |
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
296 |
else |
37980
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
297 |
(case deps of |
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
298 |
NONE => raise Fail "Malformed deps" |
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
299 |
| SOME (dep as {master = (thy_path, _), ...}) => |
37985
e3ce42cb22dd
simplified handling of update_time -- do not store within deps;
wenzelm
parents:
37984
diff
changeset
|
300 |
let |
e3ce42cb22dd
simplified handling of update_time -- do not store within deps;
wenzelm
parents:
37984
diff
changeset
|
301 |
val text = (case opt_text of SOME text => text | NONE => File.read thy_path); |
e3ce42cb22dd
simplified handling of update_time -- do not store within deps;
wenzelm
parents:
37984
diff
changeset
|
302 |
val update_time = serial (); |
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
303 |
in Task (parents, load_thy initiators update_time dep text name) end); |
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
304 |
in (all_current, new_entry name parents task tasks') end) |
7066 | 305 |
end; |
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
306 |
|
23967 | 307 |
end; |
308 |
||
309 |
||
37979 | 310 |
(* use_thy *) |
23967 | 311 |
|
38146 | 312 |
fun use_thys_wrt dir arg = |
37873
66d90b2b87bc
eliminated old time_use/time_use_thy variants -- timing is implicitly controlled via Output.timing;
wenzelm
parents:
37871
diff
changeset
|
313 |
schedule_tasks (snd (require_thys [] dir arg Graph.empty)); |
23967 | 314 |
|
38146 | 315 |
val use_thys = use_thys_wrt Path.current; |
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37942
diff
changeset
|
316 |
val use_thy = use_thys o single; |
7211 | 317 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
318 |
|
37979 | 319 |
(* toplevel begin theory -- without maintaining database *) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
320 |
|
41536
47fef6afe756
Toplevel.init_theory: maintain optional master directory, to allow bypassing global Thy_Load.master_path;
wenzelm
parents:
40741
diff
changeset
|
321 |
fun toplevel_begin_theory master name imports uses = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
322 |
let |
41536
47fef6afe756
Toplevel.init_theory: maintain optional master directory, to allow bypassing global Thy_Load.master_path;
wenzelm
parents:
40741
diff
changeset
|
323 |
val dir = (case master of SOME dir => dir | NONE => Thy_Load.get_master_path ()); |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
324 |
val _ = kill_thy name; |
38146 | 325 |
val _ = use_thys_wrt dir imports; |
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
326 |
val parent_thys = map (get_theory o base_name) imports; |
41548
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents:
41536
diff
changeset
|
327 |
in Thy_Load.begin_theory dir name imports parent_thys uses end; |
7244 | 328 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
329 |
|
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37955
diff
changeset
|
330 |
(* register theory *) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
331 |
|
37954
a2e73df0b1e0
simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents:
37953
diff
changeset
|
332 |
fun register_thy theory = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
333 |
let |
16454 | 334 |
val name = Context.theory_name theory; |
37954
a2e73df0b1e0
simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents:
37953
diff
changeset
|
335 |
val master = Thy_Load.check_thy (Thy_Load.master_directory theory) name; |
37984
f26352bd82cf
clarified register_thy: clean slate via kill_thy, more precise CRITICAL section;
wenzelm
parents:
37981
diff
changeset
|
336 |
val parents = map Context.theory_name (Theory.parents_of theory); |
41548
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents:
41536
diff
changeset
|
337 |
val imports = Thy_Load.imports_of theory; |
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents:
41536
diff
changeset
|
338 |
val deps = make_deps master imports; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
339 |
in |
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
340 |
NAMED_CRITICAL "Thy_Info" (fn () => |
38142 | 341 |
(kill_thy name; |
40132
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
wenzelm
parents:
39557
diff
changeset
|
342 |
Output.urgent_message ("Registering theory " ^ quote name); |
38142 | 343 |
map get_theory parents; |
37984
f26352bd82cf
clarified register_thy: clean slate via kill_thy, more precise CRITICAL section;
wenzelm
parents:
37981
diff
changeset
|
344 |
change_thys (new_entry name parents (SOME deps, SOME theory)); |
37954
a2e73df0b1e0
simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents:
37953
diff
changeset
|
345 |
perform Update name)) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
346 |
end; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
347 |
|
24080
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
348 |
|
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
349 |
(* finish all theories *) |
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
350 |
|
39021 | 351 |
fun finish () = change_thys (Graph.map (fn _ => fn (_, entry) => (NONE, entry))); |
24080
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
352 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
353 |
end; |