author | wenzelm |
Sat, 21 Jul 2012 22:13:50 +0200 | |
changeset 48421 | c4d337782de4 |
parent 46958 | 0ec8f04e753a |
child 48638 | 22d65e375c01 |
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 |
43673
29eb1cd29961
Thy_Info.dependencies: ignore already loaded theories, according to initial prover session status;
wenzelm
parents:
43651
diff
changeset
|
13 |
val status: unit -> unit |
7288 | 14 |
val lookup_theory: string -> theory option |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
15 |
val get_theory: string -> theory |
24563 | 16 |
val is_finished: string -> bool |
26983 | 17 |
val master_directory: string -> Path.T |
24080
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
18 |
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
|
19 |
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
|
20 |
val kill_thy: string -> unit |
38146 | 21 |
val use_thys_wrt: Path.T -> string list -> unit |
24057
f42665561801
removed obsolete Output.ML_errors/toplevel_errors;
wenzelm
parents:
23982
diff
changeset
|
22 |
val use_thys: string list -> unit |
f42665561801
removed obsolete Output.ML_errors/toplevel_errors;
wenzelm
parents:
23982
diff
changeset
|
23 |
val use_thy: string -> unit |
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46774
diff
changeset
|
24 |
val toplevel_begin_theory: Path.T -> Thy_Header.header -> 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 |
|
43640 | 37 |
val hooks = Synchronized.var "Thy_Info.hooks" ([]: (action -> string -> unit) list); |
7099 | 38 |
in |
43640 | 39 |
fun add_hook f = Synchronized.change hooks (cons f); |
40 |
fun perform action name = |
|
41 |
List.app (fn f => (try (fn () => f action name) (); ())) (Synchronized.value hooks); |
|
7099 | 42 |
end; |
43 |
||
44 |
||
45 |
||
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
46 |
(** thy database **) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
47 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
48 |
(* messages *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
49 |
|
23871 | 50 |
fun loader_msg txt [] = "Theory loader: " ^ txt |
51 |
| 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
|
52 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
53 |
val show_path = space_implode " via " o map quote; |
9332 | 54 |
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
|
55 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
56 |
|
6666 | 57 |
(* derived graph operations *) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
58 |
|
9327 | 59 |
fun add_deps name parents G = Graph.add_deps_acyclic (name, parents) G |
9332 | 60 |
handle Graph.CYCLES namess => error (cat_lines (map cycle_msg namess)); |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
61 |
|
37984
f26352bd82cf
clarified register_thy: clean slate via kill_thy, more precise CRITICAL section;
wenzelm
parents:
37981
diff
changeset
|
62 |
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
|
63 |
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
|
64 |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
65 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
66 |
(* thy database *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
67 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
68 |
type deps = |
41955
703ea96b13c6
files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
wenzelm
parents:
41678
diff
changeset
|
69 |
{master: (Path.T * SHA1.digest), (*master dependencies for thy file*) |
40741
17d6293a1e26
moved file identification to thy_load.ML (where it is actually used);
wenzelm
parents:
40132
diff
changeset
|
70 |
imports: string list}; (*source specification of imports (partially qualified)*) |
23886
f40fba467384
simplified ThyLoad interfaces: only one additional directory;
wenzelm
parents:
23871
diff
changeset
|
71 |
|
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
72 |
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
|
73 |
|
37980
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
74 |
fun master_dir (d: deps option) = the_default Path.current (Option.map (Path.dir o #1 o #master) d); |
44225
a8f921e6484f
more robust Thy_Header.base_name, with minimal assumptions about path syntax;
wenzelm
parents:
44222
diff
changeset
|
75 |
fun base_name s = Path.implode (Path.base (Path.explode s)); |
23967 | 76 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
77 |
local |
37905 | 78 |
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
|
79 |
in |
6362 | 80 |
fun get_thys () = ! database; |
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
81 |
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
|
82 |
end; |
5209 | 83 |
|
84 |
||
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
85 |
(* access thy graph *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
86 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
87 |
fun thy_graph f x = f (get_thys ()) x; |
9417 | 88 |
|
23967 | 89 |
fun get_names () = Graph.topological_order (get_thys ()); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
90 |
|
43673
29eb1cd29961
Thy_Info.dependencies: ignore already loaded theories, according to initial prover session status;
wenzelm
parents:
43651
diff
changeset
|
91 |
fun status () = |
46774 | 92 |
List.app (fn name => Output.protocol_message (Isabelle_Markup.loaded_theory name) "") |
93 |
(get_names ()); |
|
43673
29eb1cd29961
Thy_Info.dependencies: ignore already loaded theories, according to initial prover session status;
wenzelm
parents:
43651
diff
changeset
|
94 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
95 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
96 |
(* access thy *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
97 |
|
7935 | 98 |
fun lookup_thy name = |
15531 | 99 |
SOME (thy_graph Graph.get_node name) handle Graph.UNDEF _ => NONE; |
7935 | 100 |
|
16047 | 101 |
val known_thy = is_some o lookup_thy; |
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 |
fun get_thy name = |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
104 |
(case lookup_thy name of |
15531 | 105 |
SOME thy => thy |
106 |
| 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
|
107 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
108 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
109 |
(* access deps *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
110 |
|
15570 | 111 |
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
|
112 |
val get_deps = #1 o get_thy; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
113 |
|
26983 | 114 |
val is_finished = is_none o get_deps; |
37980
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
115 |
val master_directory = master_dir o get_deps; |
7191 | 116 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
117 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
118 |
(* access theory *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
119 |
|
7687 | 120 |
fun lookup_theory name = |
121 |
(case lookup_thy name of |
|
38142 | 122 |
SOME (_, SOME theory) => SOME theory |
15531 | 123 |
| _ => NONE); |
7288 | 124 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
125 |
fun get_theory name = |
7288 | 126 |
(case lookup_theory name of |
23871 | 127 |
SOME theory => theory |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
128 |
| _ => error (loader_msg "undefined theory entry for" [name])); |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
129 |
|
44337
d453faed4815
clarified get_imports -- should not rely on accidental order within graph;
wenzelm
parents:
44302
diff
changeset
|
130 |
val get_imports = Thy_Load.imports_of o get_theory; |
d453faed4815
clarified get_imports -- should not rely on accidental order within graph;
wenzelm
parents:
44302
diff
changeset
|
131 |
|
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
132 |
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
|
133 |
(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
|
134 |
NONE => [] |
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
135 |
| 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
|
136 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
137 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
138 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
139 |
(** thy operations **) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
140 |
|
43640 | 141 |
(* main loader actions *) |
29421
db532e37cda2
use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents:
29118
diff
changeset
|
142 |
|
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
143 |
fun remove_thy name = NAMED_CRITICAL "Thy_Info" (fn () => |
37979 | 144 |
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
|
145 |
else |
29434 | 146 |
let |
147 |
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
|
148 |
val _ = Output.urgent_message (loader_msg "removing" succs); |
38142 | 149 |
val _ = List.app (perform Remove) succs; |
46665
919dfcdf6d8a
discontinued slightly odd Graph.del_nodes (inefficient due to full Table.map);
wenzelm
parents:
46122
diff
changeset
|
150 |
val _ = change_thys (fold Graph.del_node succs); |
38142 | 151 |
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
|
152 |
|
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
153 |
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
|
154 |
if known_thy name then remove_thy name |
38142 | 155 |
else ()); |
7099 | 156 |
|
43640 | 157 |
fun update_thy deps theory = NAMED_CRITICAL "Thy_Info" (fn () => |
158 |
let |
|
159 |
val name = Context.theory_name theory; |
|
160 |
val parents = map Context.theory_name (Theory.parents_of theory); |
|
161 |
val _ = kill_thy name; |
|
162 |
val _ = map get_theory parents; |
|
163 |
val _ = change_thys (new_entry name parents (SOME deps, SOME theory)); |
|
164 |
val _ = perform Update name; |
|
165 |
in () end); |
|
166 |
||
7099 | 167 |
|
24209 | 168 |
(* scheduling loader tasks *) |
169 |
||
43641
081e009549dc
uniform finish_thy -- always Global_Theory.join_proofs, even with sequential scheduling;
wenzelm
parents:
43640
diff
changeset
|
170 |
type result = theory * unit future * (unit -> unit); |
081e009549dc
uniform finish_thy -- always Global_Theory.join_proofs, even with sequential scheduling;
wenzelm
parents:
43640
diff
changeset
|
171 |
|
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
|
172 |
datatype task = |
43641
081e009549dc
uniform finish_thy -- always Global_Theory.join_proofs, even with sequential scheduling;
wenzelm
parents:
43640
diff
changeset
|
173 |
Task of string list * (theory list -> result) | |
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
|
174 |
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
|
175 |
|
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
|
176 |
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
|
177 |
| task_finished (Finished _) = true; |
24209 | 178 |
|
44162 | 179 |
fun task_parents deps (parents: string list) = map (the o AList.lookup (op =) deps) parents; |
180 |
||
29118 | 181 |
local |
182 |
||
43641
081e009549dc
uniform finish_thy -- always Global_Theory.join_proofs, even with sequential scheduling;
wenzelm
parents:
43640
diff
changeset
|
183 |
fun finish_thy ((thy, present, commit): result) = |
081e009549dc
uniform finish_thy -- always Global_Theory.join_proofs, even with sequential scheduling;
wenzelm
parents:
43640
diff
changeset
|
184 |
(Global_Theory.join_proofs thy; Future.join present; commit (); thy); |
081e009549dc
uniform finish_thy -- always Global_Theory.join_proofs, even with sequential scheduling;
wenzelm
parents:
43640
diff
changeset
|
185 |
|
44162 | 186 |
val schedule_seq = |
187 |
Graph.schedule (fn deps => fn (_, task) => |
|
188 |
(case task of |
|
189 |
Task (parents, body) => finish_thy (body (task_parents deps parents)) |
|
190 |
| Finished thy => thy)) #> ignore; |
|
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
|
191 |
|
44162 | 192 |
val schedule_futures = uninterruptible (fn _ => |
193 |
Graph.schedule (fn deps => fn (name, task) => |
|
194 |
(case task of |
|
195 |
Task (parents, body) => |
|
44302 | 196 |
(singleton o Future.forks) |
197 |
{name = "theory:" ^ name, group = NONE, |
|
198 |
deps = map (Future.task_of o #2) deps, pri = 0, interrupts = true} |
|
44162 | 199 |
(fn () => |
200 |
(case filter (not o can Future.join o #2) deps of |
|
201 |
[] => body (map (#1 o Future.join) (task_parents deps parents)) |
|
202 |
| bad => |
|
203 |
error (loader_msg ("failed to load " ^ quote name ^ |
|
204 |
" (unresolved " ^ commas_quote (map #1 bad) ^ ")") []))) |
|
205 |
| Finished thy => Future.value (thy, Future.value (), I))) |
|
206 |
#> maps (fn result => (finish_thy (Future.join result); []) handle exn => [Exn.Exn exn]) |
|
44247 | 207 |
#> rev #> Par_Exn.release_all) #> ignore; |
29429
a6c641f08af7
schedule_futures: tuned final consolidation, explicit after_load phase;
wenzelm
parents:
29421
diff
changeset
|
208 |
|
24209 | 209 |
in |
210 |
||
32794 | 211 |
fun schedule_tasks tasks = |
29118 | 212 |
if not (Multithreading.enabled ()) then schedule_seq tasks |
213 |
else if Multithreading.self_critical () then |
|
24209 | 214 |
(warning (loader_msg "no multithreading within critical section" []); |
215 |
schedule_seq tasks) |
|
29118 | 216 |
else schedule_futures tasks; |
24209 | 217 |
|
218 |
end; |
|
219 |
||
220 |
||
23967 | 221 |
(* require_thy -- checking database entries wrt. the file-system *) |
15065 | 222 |
|
7211 | 223 |
local |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
224 |
|
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
|
225 |
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
|
226 |
| 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
|
227 |
|
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43673
diff
changeset
|
228 |
fun load_thy initiators update_time deps text name parents = |
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
|
229 |
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
|
230 |
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
|
231 |
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
|
232 |
|
41548
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents:
41536
diff
changeset
|
233 |
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
|
234 |
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
|
235 |
val pos = Path.position thy_path; |
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46774
diff
changeset
|
236 |
val {uses, keywords, ...} = Thy_Header.read pos text; |
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46774
diff
changeset
|
237 |
val header = Thy_Header.make name imports keywords 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
|
238 |
|
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46774
diff
changeset
|
239 |
val (theory, present) = Thy_Load.load_thy update_time dir header pos text parents; |
43640 | 240 |
fun commit () = update_thy deps theory; |
42129
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42003
diff
changeset
|
241 |
in (theory, present, commit) 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
|
242 |
|
24175
38a15a3a1aad
theory loader: removed obsolete update_thy (coincides with use_thy);
wenzelm
parents:
24151
diff
changeset
|
243 |
fun check_deps dir name = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
244 |
(case lookup_deps name of |
44337
d453faed4815
clarified get_imports -- should not rely on accidental order within graph;
wenzelm
parents:
44302
diff
changeset
|
245 |
SOME NONE => (true, NONE, get_imports name) |
23893
8babfcaaf129
deps: maintain source specification of parents (prevents repeated ThyLoad.deps_thy);
wenzelm
parents:
23886
diff
changeset
|
246 |
| NONE => |
42003
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
247 |
let val {master, text, imports, ...} = Thy_Load.check_thy dir name |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
248 |
in (false, SOME (make_deps master imports, text), imports) end |
42129
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42003
diff
changeset
|
249 |
| SOME (SOME {master, ...}) => |
42003
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
250 |
let |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
251 |
val {master = master', text = text', imports = imports', ...} = Thy_Load.check_thy dir name; |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
252 |
val deps' = SOME (make_deps master' imports', text'); |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
253 |
val current = |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
254 |
#2 master = #2 master' andalso |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
255 |
(case lookup_theory name of |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
256 |
NONE => false |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
257 |
| SOME theory => Thy_Load.all_current theory); |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
258 |
in (current, deps', imports') end); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
259 |
|
23967 | 260 |
in |
261 |
||
37873
66d90b2b87bc
eliminated old time_use/time_use_thy variants -- timing is implicitly controlled via Output.timing;
wenzelm
parents:
37871
diff
changeset
|
262 |
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
|
263 |
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
|
264 |
and require_thy initiators dir str tasks = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
265 |
let |
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
20664
diff
changeset
|
266 |
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
|
267 |
val name = Path.implode (Path.base path); |
7066 | 268 |
in |
32794 | 269 |
(case try (Graph.get_node tasks) name of |
24209 | 270 |
SOME task => (task_finished task, tasks) |
23967 | 271 |
| NONE => |
272 |
let |
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43641
diff
changeset
|
273 |
val dir' = Path.append dir (Path.dir path); |
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43641
diff
changeset
|
274 |
val _ = member (op =) initiators name andalso error (cycle_msg initiators); |
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43641
diff
changeset
|
275 |
|
42003
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
276 |
val (current, deps, imports) = check_deps dir' name |
23967 | 277 |
handle ERROR msg => cat_error msg |
278 |
(loader_msg "the error(s) above occurred while examining theory" [name] ^ |
|
279 |
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
|
280 |
|
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
281 |
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
|
282 |
val (parents_current, tasks') = |
42003
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
283 |
require_thys (name :: initiators) |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
284 |
(Path.append dir (master_dir (Option.map #1 deps))) imports tasks; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
285 |
|
23967 | 286 |
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
|
287 |
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
|
288 |
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
|
289 |
else |
37980
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
290 |
(case deps of |
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
291 |
NONE => raise Fail "Malformed deps" |
42003
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
292 |
| SOME (dep, text) => |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
293 |
let 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
|
294 |
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
|
295 |
in (all_current, new_entry name parents task tasks') end) |
7066 | 296 |
end; |
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
297 |
|
23967 | 298 |
end; |
299 |
||
300 |
||
37979 | 301 |
(* use_thy *) |
23967 | 302 |
|
38146 | 303 |
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
|
304 |
schedule_tasks (snd (require_thys [] dir arg Graph.empty)); |
23967 | 305 |
|
38146 | 306 |
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
|
307 |
val use_thy = use_thys o single; |
7211 | 308 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
309 |
|
37979 | 310 |
(* toplevel begin theory -- without maintaining database *) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
311 |
|
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46774
diff
changeset
|
312 |
fun toplevel_begin_theory dir (header: Thy_Header.header) = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
313 |
let |
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46774
diff
changeset
|
314 |
val {name, imports, ...} = header; |
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
|
315 |
val _ = kill_thy name; |
38146 | 316 |
val _ = use_thys_wrt dir imports; |
46958
0ec8f04e753a
define keywords early when processing the theory header, before running the body commands;
wenzelm
parents:
46938
diff
changeset
|
317 |
val _ = Thy_Header.define_keywords header; |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43673
diff
changeset
|
318 |
val parents = map (get_theory o base_name) imports; |
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46774
diff
changeset
|
319 |
in Thy_Load.begin_theory dir header parents end; |
7244 | 320 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
321 |
|
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
|
322 |
(* register theory *) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
323 |
|
37954
a2e73df0b1e0
simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents:
37953
diff
changeset
|
324 |
fun register_thy theory = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
325 |
let |
16454 | 326 |
val name = Context.theory_name theory; |
42003
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
327 |
val {master, ...} = Thy_Load.check_thy (Thy_Load.master_directory theory) name; |
41548
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents:
41536
diff
changeset
|
328 |
val imports = Thy_Load.imports_of theory; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
329 |
in |
38145
675827e61eb9
more precise CRITICAL sections, using NAMED_CRITICAL uniformly;
wenzelm
parents:
38143
diff
changeset
|
330 |
NAMED_CRITICAL "Thy_Info" (fn () => |
38142 | 331 |
(kill_thy name; |
40132
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
wenzelm
parents:
39557
diff
changeset
|
332 |
Output.urgent_message ("Registering theory " ^ quote name); |
43640 | 333 |
update_thy (make_deps master imports) theory)) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
334 |
end; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
335 |
|
24080
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
336 |
|
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
337 |
(* finish all theories *) |
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
338 |
|
39021 | 339 |
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
|
340 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
341 |
end; |