author | wenzelm |
Mon, 16 Nov 2020 22:23:04 +0100 | |
changeset 72622 | 830222403681 |
parent 72620 | 429afd0d1a79 |
child 72624 | 35524fade6a4 |
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 |
68180
112d9624c020
more general presentation hook, with document preparation as application;
wenzelm
parents:
68179
diff
changeset
|
10 |
type presentation_context = |
68184
6c693b2700b3
support for dynamic document output while editing;
wenzelm
parents:
68182
diff
changeset
|
11 |
{options: Options.T, file_pos: Position.T, adjust_pos: Position.T -> Position.T, |
6c693b2700b3
support for dynamic document output while editing;
wenzelm
parents:
68182
diff
changeset
|
12 |
segments: Thy_Output.segment list} |
71249 | 13 |
val adjust_pos_properties: presentation_context -> Position.T -> Properties.T |
68180
112d9624c020
more general presentation hook, with document preparation as application;
wenzelm
parents:
68179
diff
changeset
|
14 |
val apply_presentation: presentation_context -> theory -> unit |
112d9624c020
more general presentation hook, with document preparation as application;
wenzelm
parents:
68179
diff
changeset
|
15 |
val add_presentation: (presentation_context -> theory -> unit) -> theory -> theory |
26614 | 16 |
val get_names: unit -> string list |
7288 | 17 |
val lookup_theory: string -> theory option |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
18 |
val get_theory: string -> theory |
26983 | 19 |
val master_directory: string -> Path.T |
29421
db532e37cda2
use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents:
29118
diff
changeset
|
20 |
val remove_thy: string -> unit |
72620 | 21 |
type context = {options: Options.T, last_timing: Toplevel.transition -> Time.time} |
68179
da70c9e91135
clarified signature: more explicit type "context" with full options;
wenzelm
parents:
68178
diff
changeset
|
22 |
val use_theories: context -> string -> Path.T -> (string * Position.T) list -> unit |
65444 | 23 |
val use_thy: string -> unit |
58856 | 24 |
val script_thy: Position.T -> string -> theory -> 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 |
|
68153 | 32 |
(** presentation of consolidated theory **) |
33 |
||
68180
112d9624c020
more general presentation hook, with document preparation as application;
wenzelm
parents:
68179
diff
changeset
|
34 |
type presentation_context = |
68184
6c693b2700b3
support for dynamic document output while editing;
wenzelm
parents:
68182
diff
changeset
|
35 |
{options: Options.T, file_pos: Position.T, adjust_pos: Position.T -> Position.T, |
6c693b2700b3
support for dynamic document output while editing;
wenzelm
parents:
68182
diff
changeset
|
36 |
segments: Thy_Output.segment list}; |
68180
112d9624c020
more general presentation hook, with document preparation as application;
wenzelm
parents:
68179
diff
changeset
|
37 |
|
71249 | 38 |
fun adjust_pos_properties (context: presentation_context) pos = |
39 |
Position.offset_properties_of (#adjust_pos context pos) @ Position.id_properties_of pos; |
|
40 |
||
68153 | 41 |
structure Presentation = Theory_Data |
42 |
( |
|
68180
112d9624c020
more general presentation hook, with document preparation as application;
wenzelm
parents:
68179
diff
changeset
|
43 |
type T = ((presentation_context -> theory -> unit) * stamp) list; |
68153 | 44 |
val empty = []; |
45 |
val extend = I; |
|
46 |
fun merge data : T = Library.merge (eq_snd op =) data; |
|
47 |
); |
|
48 |
||
68180
112d9624c020
more general presentation hook, with document preparation as application;
wenzelm
parents:
68179
diff
changeset
|
49 |
fun apply_presentation (context: presentation_context) thy = |
112d9624c020
more general presentation hook, with document preparation as application;
wenzelm
parents:
68179
diff
changeset
|
50 |
ignore (Presentation.get thy |> Par_List.map (fn (f, _) => f context thy)); |
112d9624c020
more general presentation hook, with document preparation as application;
wenzelm
parents:
68179
diff
changeset
|
51 |
|
68153 | 52 |
fun add_presentation f = Presentation.map (cons (f, stamp ())); |
53 |
||
68180
112d9624c020
more general presentation hook, with document preparation as application;
wenzelm
parents:
68179
diff
changeset
|
54 |
val _ = |
68184
6c693b2700b3
support for dynamic document output while editing;
wenzelm
parents:
68182
diff
changeset
|
55 |
Theory.setup (add_presentation (fn {options, file_pos, segments, ...} => fn thy => |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72620
diff
changeset
|
56 |
(Present.export_html thy (map #span segments); |
68182 | 57 |
if exists (Toplevel.is_skipped_proof o #state) segments then () |
68180
112d9624c020
more general presentation hook, with document preparation as application;
wenzelm
parents:
68179
diff
changeset
|
58 |
else |
68181
34592bf86424
export generated document.tex, unless explicit document=false;
wenzelm
parents:
68180
diff
changeset
|
59 |
let |
68506 | 60 |
val body = Thy_Output.present_thy options thy segments; |
68181
34592bf86424
export generated document.tex, unless explicit document=false;
wenzelm
parents:
68180
diff
changeset
|
61 |
in |
72574
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72511
diff
changeset
|
62 |
if Options.string options "document" = "false" then () |
68181
34592bf86424
export generated document.tex, unless explicit document=false;
wenzelm
parents:
68180
diff
changeset
|
63 |
else |
34592bf86424
export generated document.tex, unless explicit document=false;
wenzelm
parents:
68180
diff
changeset
|
64 |
let |
72311 | 65 |
val thy_name = Context.theory_name thy; |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72620
diff
changeset
|
66 |
val document_tex_name = Present.document_tex_name thy; |
72620 | 67 |
|
72311 | 68 |
val latex = Latex.isabelle_body thy_name body; |
68184
6c693b2700b3
support for dynamic document output while editing;
wenzelm
parents:
68182
diff
changeset
|
69 |
val output = [Latex.output_text latex, Latex.output_positions file_pos latex]; |
72612 | 70 |
in Export.export thy document_tex_name (XML.blob output) end |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72620
diff
changeset
|
71 |
end))); |
68153 | 72 |
|
73 |
||
74 |
||
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
75 |
(** thy database **) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
76 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
77 |
(* messages *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
78 |
|
55797 | 79 |
val show_path = space_implode " via " o map quote; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
80 |
|
55797 | 81 |
fun cycle_msg names = "Cyclic dependency of " ^ show_path names; |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
82 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
83 |
|
6666 | 84 |
(* derived graph operations *) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
85 |
|
50862
5fc8b83322f5
more sensible order of theory nodes (correspondance to Scala version), e.g. relevant to theory progress;
wenzelm
parents:
50845
diff
changeset
|
86 |
fun add_deps name parents G = String_Graph.add_deps_acyclic (name, parents) G |
5fc8b83322f5
more sensible order of theory nodes (correspondance to Scala version), e.g. relevant to theory progress;
wenzelm
parents:
50845
diff
changeset
|
87 |
handle String_Graph.CYCLES namess => error (cat_lines (map cycle_msg namess)); |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
88 |
|
37984
f26352bd82cf
clarified register_thy: clean slate via kill_thy, more precise CRITICAL section;
wenzelm
parents:
37981
diff
changeset
|
89 |
fun new_entry name parents entry = |
50862
5fc8b83322f5
more sensible order of theory nodes (correspondance to Scala version), e.g. relevant to theory progress;
wenzelm
parents:
50845
diff
changeset
|
90 |
String_Graph.new_node (name, entry) #> add_deps 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
|
91 |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
92 |
|
59178 | 93 |
(* global thys *) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
94 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
95 |
type deps = |
41955
703ea96b13c6
files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
wenzelm
parents:
41678
diff
changeset
|
96 |
{master: (Path.T * SHA1.digest), (*master dependencies for thy file*) |
48927
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents:
48898
diff
changeset
|
97 |
imports: (string * Position.T) list}; (*source specification of imports (partially qualified)*) |
23886
f40fba467384
simplified ThyLoad interfaces: only one additional directory;
wenzelm
parents:
23871
diff
changeset
|
98 |
|
38148
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
wenzelm
parents:
38147
diff
changeset
|
99 |
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
|
100 |
|
65454 | 101 |
fun master_dir_deps (d: deps option) = |
59178 | 102 |
the_default Path.current (Option.map (Path.dir o #1 o #master) d); |
103 |
||
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
104 |
local |
59178 | 105 |
val global_thys = |
106 |
Synchronized.var "Thy_Info.thys" |
|
107 |
(String_Graph.empty: (deps option * theory option) String_Graph.T); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
108 |
in |
59178 | 109 |
fun get_thys () = Synchronized.value global_thys; |
110 |
fun change_thys f = Synchronized.change global_thys f; |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
111 |
end; |
5209 | 112 |
|
50862
5fc8b83322f5
more sensible order of theory nodes (correspondance to Scala version), e.g. relevant to theory progress;
wenzelm
parents:
50845
diff
changeset
|
113 |
fun get_names () = String_Graph.topological_order (get_thys ()); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
114 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
115 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
116 |
(* access thy *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
117 |
|
59178 | 118 |
fun lookup thys name = try (String_Graph.get_node thys) name; |
119 |
fun lookup_thy name = lookup (get_thys ()) name; |
|
7935 | 120 |
|
59178 | 121 |
fun get thys name = |
122 |
(case lookup thys name of |
|
15531 | 123 |
SOME thy => thy |
55797 | 124 |
| NONE => error ("Theory loader: nothing known about theory " ^ quote name)); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
125 |
|
59178 | 126 |
fun get_thy name = get (get_thys ()) name; |
127 |
||
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
128 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
129 |
(* access deps *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
130 |
|
15570 | 131 |
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
|
132 |
|
65454 | 133 |
val master_directory = master_dir_deps o #1 o get_thy; |
7191 | 134 |
|
6211
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 |
(* access theory *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
137 |
|
7687 | 138 |
fun lookup_theory name = |
139 |
(case lookup_thy name of |
|
38142 | 140 |
SOME (_, SOME theory) => SOME theory |
15531 | 141 |
| _ => NONE); |
7288 | 142 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
143 |
fun get_theory name = |
7288 | 144 |
(case lookup_theory name of |
23871 | 145 |
SOME theory => theory |
55797 | 146 |
| _ => error ("Theory loader: undefined entry for theory " ^ quote name)); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
147 |
|
56208 | 148 |
val get_imports = Resources.imports_of o get_theory; |
44337
d453faed4815
clarified get_imports -- should not rely on accidental order within graph;
wenzelm
parents:
44302
diff
changeset
|
149 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
150 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
151 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
152 |
(** thy operations **) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
153 |
|
59178 | 154 |
(* remove *) |
29421
db532e37cda2
use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents:
29118
diff
changeset
|
155 |
|
59178 | 156 |
fun remove name thys = |
157 |
(case lookup thys name of |
|
158 |
NONE => thys |
|
159 |
| SOME (NONE, _) => error ("Cannot update finished theory " ^ quote name) |
|
160 |
| SOME _ => |
|
161 |
let |
|
162 |
val succs = String_Graph.all_succs thys [name]; |
|
163 |
val _ = writeln ("Theory loader: removing " ^ commas_quote succs); |
|
164 |
in fold String_Graph.del_node succs thys end); |
|
29421
db532e37cda2
use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents:
29118
diff
changeset
|
165 |
|
59178 | 166 |
val remove_thy = change_thys o remove; |
167 |
||
7099 | 168 |
|
59178 | 169 |
(* update *) |
170 |
||
171 |
fun update deps theory thys = |
|
43640 | 172 |
let |
65459
da59e8e0a663
clarified theory_long_name (for qualified access to Thy_Info) vs. short theory_name (which is unique within any given theory context);
wenzelm
parents:
65455
diff
changeset
|
173 |
val name = Context.theory_long_name theory; |
da59e8e0a663
clarified theory_long_name (for qualified access to Thy_Info) vs. short theory_name (which is unique within any given theory context);
wenzelm
parents:
65455
diff
changeset
|
174 |
val parents = map Context.theory_long_name (Theory.parents_of theory); |
59178 | 175 |
|
176 |
val thys' = remove name thys; |
|
177 |
val _ = map (get thys') parents; |
|
178 |
in new_entry name parents (SOME deps, SOME theory) thys' end; |
|
179 |
||
180 |
fun update_thy deps theory = change_thys (update deps theory); |
|
43640 | 181 |
|
7099 | 182 |
|
68179
da70c9e91135
clarified signature: more explicit type "context" with full options;
wenzelm
parents:
68178
diff
changeset
|
183 |
(* context *) |
da70c9e91135
clarified signature: more explicit type "context" with full options;
wenzelm
parents:
68178
diff
changeset
|
184 |
|
72620 | 185 |
type context = {options: Options.T, last_timing: Toplevel.transition -> Time.time}; |
68179
da70c9e91135
clarified signature: more explicit type "context" with full options;
wenzelm
parents:
68178
diff
changeset
|
186 |
|
da70c9e91135
clarified signature: more explicit type "context" with full options;
wenzelm
parents:
68178
diff
changeset
|
187 |
fun default_context (): context = |
72620 | 188 |
{options = Options.default (), last_timing = K Time.zeroTime}; |
68179
da70c9e91135
clarified signature: more explicit type "context" with full options;
wenzelm
parents:
68178
diff
changeset
|
189 |
|
da70c9e91135
clarified signature: more explicit type "context" with full options;
wenzelm
parents:
68178
diff
changeset
|
190 |
|
24209 | 191 |
(* scheduling loader tasks *) |
192 |
||
51330 | 193 |
datatype result = |
53375
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
194 |
Result of {theory: theory, exec_id: Document_ID.exec, |
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
195 |
present: unit -> unit, commit: unit -> unit, weight: int}; |
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
196 |
|
53375
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
197 |
fun theory_result theory = |
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
198 |
Result {theory = theory, exec_id = Document_ID.none, present = I, commit = I, weight = 0}; |
51330 | 199 |
|
200 |
fun result_theory (Result {theory, ...}) = theory; |
|
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
201 |
fun result_present (Result {present, ...}) = present; |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
202 |
fun result_commit (Result {commit, ...}) = commit; |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
203 |
fun result_ord (Result {weight = i, ...}, Result {weight = j, ...}) = int_ord (j, i); |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
204 |
|
53375
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
205 |
fun join_theory (Result {theory, exec_id, ...}) = |
54370
39ac1a02c60c
join all theory body forks, notably Toplevel.atom_result (diagnostic commands), before peeking at full status;
wenzelm
parents:
53375
diff
changeset
|
206 |
let |
66371
6ce1afc01040
more thorough Execution.join, under the assumption that nested Execution.fork only happens from given exed_ids;
wenzelm
parents:
66370
diff
changeset
|
207 |
val _ = Execution.join [exec_id]; |
64574
1134e4d5e5b7
consolidate nested thms with persistent result, for improved performance;
wenzelm
parents:
62942
diff
changeset
|
208 |
val res = Exn.capture Thm.consolidate_theory theory; |
66377 | 209 |
val exns = maps Task_Queue.group_status (Execution.peek exec_id); |
210 |
in res :: map Exn.Exn exns end; |
|
43641
081e009549dc
uniform finish_thy -- always Global_Theory.join_proofs, even with sequential scheduling;
wenzelm
parents:
43640
diff
changeset
|
211 |
|
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
|
212 |
datatype task = |
66711
80fa1401cf76
discontinued extra checks (see ce676a750575 and 60c159d490a2) -- qualified theory names are meant to cover this;
wenzelm
parents:
66377
diff
changeset
|
213 |
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
|
214 |
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
|
215 |
|
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
|
216 |
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
|
217 |
| task_finished (Finished _) = true; |
24209 | 218 |
|
44162 | 219 |
fun task_parents deps (parents: string list) = map (the o AList.lookup (op =) deps) parents; |
220 |
||
221 |
val schedule_seq = |
|
50862
5fc8b83322f5
more sensible order of theory nodes (correspondance to Scala version), e.g. relevant to theory progress;
wenzelm
parents:
50845
diff
changeset
|
222 |
String_Graph.schedule (fn deps => fn (_, task) => |
44162 | 223 |
(case task of |
66711
80fa1401cf76
discontinued extra checks (see ce676a750575 and 60c159d490a2) -- qualified theory names are meant to cover this;
wenzelm
parents:
66377
diff
changeset
|
224 |
Task (parents, body) => |
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
225 |
let |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
226 |
val result = body (task_parents deps parents); |
53190
5d92649a310e
simplified Goal.forked_proofs: status is determined via group instead of dummy future (see also Pure/PIDE/execution.ML);
wenzelm
parents:
51661
diff
changeset
|
227 |
val _ = Par_Exn.release_all (join_theory result); |
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
228 |
val _ = result_present result (); |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
229 |
val _ = result_commit result (); |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
230 |
in result_theory result end |
44162 | 231 |
| 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
|
232 |
|
62923 | 233 |
val schedule_futures = Thread_Attributes.uninterruptible (fn _ => fn tasks => |
51284
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51228
diff
changeset
|
234 |
let |
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
235 |
val futures = tasks |
51284
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51228
diff
changeset
|
236 |
|> String_Graph.schedule (fn deps => fn (name, task) => |
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51228
diff
changeset
|
237 |
(case task of |
66711
80fa1401cf76
discontinued extra checks (see ce676a750575 and 60c159d490a2) -- qualified theory names are meant to cover this;
wenzelm
parents:
66377
diff
changeset
|
238 |
Task (parents, body) => |
51284
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51228
diff
changeset
|
239 |
(singleton o Future.forks) |
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51228
diff
changeset
|
240 |
{name = "theory:" ^ name, group = NONE, |
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51228
diff
changeset
|
241 |
deps = map (Future.task_of o #2) deps, pri = 0, interrupts = true} |
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51228
diff
changeset
|
242 |
(fn () => |
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51228
diff
changeset
|
243 |
(case filter (not o can Future.join o #2) deps of |
51330 | 244 |
[] => body (map (result_theory o Future.join) (task_parents deps parents)) |
51284
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51228
diff
changeset
|
245 |
| bad => |
55797 | 246 |
error |
247 |
("Failed to load theory " ^ quote name ^ |
|
248 |
" (unresolved " ^ commas_quote (map #1 bad) ^ ")"))) |
|
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
249 |
| Finished theory => Future.value (theory_result theory))); |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
250 |
|
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
251 |
val results1 = futures |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
252 |
|> maps (fn future => |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
253 |
(case Future.join_result future of |
53190
5d92649a310e
simplified Goal.forked_proofs: status is determined via group instead of dummy future (see also Pure/PIDE/execution.ML);
wenzelm
parents:
51661
diff
changeset
|
254 |
Exn.Res result => join_theory result |
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
255 |
| Exn.Exn exn => [Exn.Exn exn])); |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
256 |
|
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
257 |
val results2 = futures |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
258 |
|> map_filter (Exn.get_res o Future.join_result) |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
259 |
|> sort result_ord |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
260 |
|> Par_List.map (fn result => Exn.capture (result_present result) ()); |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
261 |
|
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
262 |
(* FIXME more precise commit order (!?) *) |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
263 |
val results3 = futures |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
264 |
|> map (fn future => Exn.capture (fn () => result_commit (Future.join future) ()) ()); |
51284
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51228
diff
changeset
|
265 |
|
54370
39ac1a02c60c
join all theory body forks, notably Toplevel.atom_result (diagnostic commands), before peeking at full status;
wenzelm
parents:
53375
diff
changeset
|
266 |
(* FIXME avoid global Execution.reset (!??) *) |
53192 | 267 |
val results4 = map Exn.Exn (maps Task_Queue.group_status (Execution.reset ())); |
51284
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51228
diff
changeset
|
268 |
|
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
269 |
val _ = Par_Exn.release_all (results1 @ results2 @ results3 @ results4); |
51284
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51228
diff
changeset
|
270 |
in () end); |
29429
a6c641f08af7
schedule_futures: tuned final consolidation, explicit after_load phase;
wenzelm
parents:
29421
diff
changeset
|
271 |
|
24209 | 272 |
|
65505 | 273 |
(* eval theory *) |
274 |
||
275 |
fun excursion keywords master_dir last_timing init elements = |
|
276 |
let |
|
277 |
fun prepare_span st span = |
|
278 |
Command_Span.content span |
|
279 |
|> Command.read keywords (Command.read_thy st) master_dir init ([], ~1) |
|
69877 | 280 |
|> (fn tr => Toplevel.timing (last_timing tr) tr); |
65505 | 281 |
|
282 |
fun element_result span_elem (st, _) = |
|
283 |
let |
|
68839 | 284 |
val elem = Thy_Element.map_element (prepare_span st) span_elem; |
65505 | 285 |
val (results, st') = Toplevel.element_result keywords elem st; |
68839 | 286 |
val pos' = Toplevel.pos_of (Thy_Element.last_element elem); |
65505 | 287 |
in (results, (st', pos')) end; |
288 |
||
289 |
val (results, (end_state, end_pos)) = |
|
69886 | 290 |
fold_map element_result elements (Toplevel.init_toplevel (), Position.none); |
65505 | 291 |
|
292 |
val thy = Toplevel.end_theory end_pos end_state; |
|
293 |
in (results, thy) end; |
|
294 |
||
68179
da70c9e91135
clarified signature: more explicit type "context" with full options;
wenzelm
parents:
68178
diff
changeset
|
295 |
fun eval_thy (context: context) update_time master_dir header text_pos text parents = |
65505 | 296 |
let |
72620 | 297 |
val {options, last_timing} = context; |
65505 | 298 |
val (name, _) = #name header; |
299 |
val keywords = |
|
300 |
fold (curry Keyword.merge_keywords o Thy_Header.get_keywords) parents |
|
301 |
(Keyword.add_keywords (#keywords header) Keyword.empty_keywords); |
|
302 |
||
68178 | 303 |
val spans = Outer_Syntax.parse_spans (Token.explode keywords text_pos text); |
68839 | 304 |
val elements = Thy_Element.parse_elements keywords spans; |
65505 | 305 |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72620
diff
changeset
|
306 |
fun init () = Resources.begin_theory master_dir header parents; |
65505 | 307 |
val (results, thy) = |
308 |
cond_timeit true ("theory " ^ quote name) |
|
309 |
(fn () => excursion keywords master_dir last_timing init elements); |
|
310 |
||
311 |
fun present () = |
|
312 |
let |
|
68178 | 313 |
val segments = (spans ~~ maps Toplevel.join_results results) |
68182 | 314 |
|> map (fn (span, (tr, st')) => {span = span, command = tr, state = st'}); |
68184
6c693b2700b3
support for dynamic document output while editing;
wenzelm
parents:
68182
diff
changeset
|
315 |
val context: presentation_context = |
6c693b2700b3
support for dynamic document output while editing;
wenzelm
parents:
68182
diff
changeset
|
316 |
{options = options, file_pos = text_pos, adjust_pos = I, segments = segments}; |
68180
112d9624c020
more general presentation hook, with document preparation as application;
wenzelm
parents:
68179
diff
changeset
|
317 |
in apply_presentation context thy end; |
65505 | 318 |
in (thy, present, size text) end; |
319 |
||
320 |
||
23967 | 321 |
(* require_thy -- checking database entries wrt. the file-system *) |
15065 | 322 |
|
7211 | 323 |
local |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
324 |
|
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
|
325 |
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
|
326 |
| 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
|
327 |
|
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67194
diff
changeset
|
328 |
fun load_thy context initiators update_time deps text (name, pos) keywords 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
|
329 |
let |
59178 | 330 |
val _ = remove_thy name; |
58843 | 331 |
val _ = writeln ("Loading theory " ^ quote name ^ required_by " " initiators); |
56333
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents:
56208
diff
changeset
|
332 |
val _ = Output.try_protocol_message (Markup.loading_theory 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
|
333 |
|
41548
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents:
41536
diff
changeset
|
334 |
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
|
335 |
val dir = Path.dir thy_path; |
51294
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents:
51293
diff
changeset
|
336 |
val header = Thy_Header.make (name, pos) imports keywords; |
48927
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents:
48898
diff
changeset
|
337 |
|
71674 | 338 |
val _ = |
339 |
(imports ~~ parents) |> List.app (fn ((_, pos), thy) => |
|
340 |
Context_Position.reports_global thy [(pos, Theory.get_markup thy)]); |
|
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
|
341 |
|
53375
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
342 |
val exec_id = Document_ID.make (); |
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
343 |
val _ = |
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
344 |
Execution.running Document_ID.none exec_id [] orelse |
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
345 |
raise Fail ("Failed to register execution: " ^ Document_ID.print exec_id); |
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
346 |
|
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66711
diff
changeset
|
347 |
val timing_start = Timing.start (); |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66711
diff
changeset
|
348 |
|
53375
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
349 |
val text_pos = Position.put_id (Document_ID.print exec_id) (Path.position thy_path); |
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51330
diff
changeset
|
350 |
val (theory, present, weight) = |
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67194
diff
changeset
|
351 |
eval_thy context update_time dir header text_pos text |
62876 | 352 |
(if name = Context.PureN then [Context.the_global_context ()] else parents); |
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66711
diff
changeset
|
353 |
|
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66711
diff
changeset
|
354 |
val timing_result = Timing.result timing_start; |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66711
diff
changeset
|
355 |
val timing_props = [Markup.theory_timing, (Markup.nameN, name)]; |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66711
diff
changeset
|
356 |
val _ = Output.try_protocol_message (timing_props @ Markup.timing_properties timing_result) [] |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66711
diff
changeset
|
357 |
|
43640 | 358 |
fun commit () = update_thy deps theory; |
53375
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
359 |
in |
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
360 |
Result {theory = theory, exec_id = exec_id, present = present, commit = commit, weight = weight} |
78693e46a237
Execution.fork formally requires registered Execution.running;
wenzelm
parents:
53192
diff
changeset
|
361 |
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
|
362 |
|
70711 | 363 |
fun check_thy_deps dir name = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
364 |
(case lookup_deps name of |
51293
05b1bbae748d
discontinued obsolete 'uses' within theory header;
wenzelm
parents:
51284
diff
changeset
|
365 |
SOME NONE => (true, NONE, Position.none, get_imports name, []) |
23893
8babfcaaf129
deps: maintain source specification of parents (prevents repeated ThyLoad.deps_thy);
wenzelm
parents:
23886
diff
changeset
|
366 |
| NONE => |
56208 | 367 |
let val {master, text, theory_pos, imports, keywords} = Resources.check_thy dir name |
51293
05b1bbae748d
discontinued obsolete 'uses' within theory header;
wenzelm
parents:
51284
diff
changeset
|
368 |
in (false, SOME (make_deps master imports, text), theory_pos, imports, keywords) 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
|
369 |
| SOME (SOME {master, ...}) => |
42003
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
370 |
let |
48928 | 371 |
val {master = master', text = text', theory_pos = theory_pos', imports = imports', |
56208 | 372 |
keywords = keywords'} = Resources.check_thy dir name; |
42003
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
373 |
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
|
374 |
val current = |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
375 |
#2 master = #2 master' andalso |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
376 |
(case lookup_theory name of |
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
377 |
NONE => false |
56208 | 378 |
| SOME theory => Resources.loaded_files_current theory); |
51293
05b1bbae748d
discontinued obsolete 'uses' within theory header;
wenzelm
parents:
51284
diff
changeset
|
379 |
in (current, deps', theory_pos', imports', keywords') end); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
380 |
|
23967 | 381 |
in |
382 |
||
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67194
diff
changeset
|
383 |
fun require_thys context initiators qualifier dir strs tasks = |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67194
diff
changeset
|
384 |
fold_map (require_thy context initiators qualifier dir) strs tasks |>> forall I |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67194
diff
changeset
|
385 |
and require_thy context initiators qualifier dir (s, require_pos) tasks = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
386 |
let |
66711
80fa1401cf76
discontinued extra checks (see ce676a750575 and 60c159d490a2) -- qualified theory names are meant to cover this;
wenzelm
parents:
66377
diff
changeset
|
387 |
val {master_dir, theory_name, ...} = Resources.import_name qualifier dir s; |
7066 | 388 |
in |
65443
dccbfc715904
provide Resources.import_name in ML, similar to Scala version;
wenzelm
parents:
65058
diff
changeset
|
389 |
(case try (String_Graph.get_node tasks) theory_name of |
66711
80fa1401cf76
discontinued extra checks (see ce676a750575 and 60c159d490a2) -- qualified theory names are meant to cover this;
wenzelm
parents:
66377
diff
changeset
|
390 |
SOME task => (task_finished task, tasks) |
23967 | 391 |
| NONE => |
392 |
let |
|
65443
dccbfc715904
provide Resources.import_name in ML, similar to Scala version;
wenzelm
parents:
65058
diff
changeset
|
393 |
val _ = member (op =) initiators theory_name andalso error (cycle_msg initiators); |
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43641
diff
changeset
|
394 |
|
70711 | 395 |
val (current, deps, theory_pos, imports, keywords) = check_thy_deps master_dir theory_name |
55797 | 396 |
handle ERROR msg => |
397 |
cat_error msg |
|
65443
dccbfc715904
provide Resources.import_name in ML, similar to Scala version;
wenzelm
parents:
65058
diff
changeset
|
398 |
("The error(s) above occurred for theory " ^ quote theory_name ^ |
55797 | 399 |
Position.here require_pos ^ 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
|
400 |
|
65455 | 401 |
val qualifier' = Resources.theory_qualifier theory_name; |
72511
460d743010bc
clarified signature: overloaded "+" for Path.append;
wenzelm
parents:
72311
diff
changeset
|
402 |
val dir' = dir + master_dir_deps (Option.map #1 deps); |
65455 | 403 |
|
404 |
val parents = map (#theory_name o Resources.import_name qualifier' dir' o #1) imports; |
|
48898
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48888
diff
changeset
|
405 |
val (parents_current, tasks') = |
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67194
diff
changeset
|
406 |
require_thys context (theory_name :: initiators) qualifier' dir' imports tasks; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
407 |
|
23967 | 408 |
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
|
409 |
val task = |
65443
dccbfc715904
provide Resources.import_name in ML, similar to Scala version;
wenzelm
parents:
65058
diff
changeset
|
410 |
if all_current then Finished (get_theory theory_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
|
411 |
else |
37980
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
412 |
(case deps of |
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
wenzelm
parents:
37979
diff
changeset
|
413 |
NONE => raise Fail "Malformed deps" |
42003
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
41955
diff
changeset
|
414 |
| SOME (dep, text) => |
48876
157dd47032e0
more standard Thy_Load.check_thy for Pure.thy, relying on its header;
wenzelm
parents:
48874
diff
changeset
|
415 |
let |
157dd47032e0
more standard Thy_Load.check_thy for Pure.thy, relying on its header;
wenzelm
parents:
48874
diff
changeset
|
416 |
val update_time = serial (); |
48928 | 417 |
val load = |
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67194
diff
changeset
|
418 |
load_thy context initiators update_time |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67194
diff
changeset
|
419 |
dep text (theory_name, theory_pos) keywords; |
66711
80fa1401cf76
discontinued extra checks (see ce676a750575 and 60c159d490a2) -- qualified theory names are meant to cover this;
wenzelm
parents:
66377
diff
changeset
|
420 |
in Task (parents, load) end); |
48874
ff9cd47be39b
refined Thy_Load.check_thy: find more uses in body text, based on keywords;
wenzelm
parents:
48710
diff
changeset
|
421 |
|
65443
dccbfc715904
provide Resources.import_name in ML, similar to Scala version;
wenzelm
parents:
65058
diff
changeset
|
422 |
val tasks'' = new_entry theory_name parents task tasks'; |
48898
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48888
diff
changeset
|
423 |
in (all_current, tasks'') end) |
7066 | 424 |
end; |
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
425 |
|
23967 | 426 |
end; |
427 |
||
428 |
||
65444 | 429 |
(* use theories *) |
23967 | 430 |
|
68179
da70c9e91135
clarified signature: more explicit type "context" with full options;
wenzelm
parents:
68178
diff
changeset
|
431 |
fun use_theories context qualifier master_dir imports = |
da70c9e91135
clarified signature: more explicit type "context" with full options;
wenzelm
parents:
68178
diff
changeset
|
432 |
let val (_, tasks) = require_thys context [] qualifier master_dir imports String_Graph.empty |
68130
6fb85346cb79
clarified future scheduling parameters, with support for parallel_limit;
wenzelm
parents:
67380
diff
changeset
|
433 |
in if Multithreading.max_threads () > 1 then schedule_futures tasks else schedule_seq tasks end; |
23967 | 434 |
|
65444 | 435 |
fun use_thy name = |
68179
da70c9e91135
clarified signature: more explicit type "context" with full options;
wenzelm
parents:
68178
diff
changeset
|
436 |
use_theories (default_context ()) Resources.default_qualifier |
da70c9e91135
clarified signature: more explicit type "context" with full options;
wenzelm
parents:
68178
diff
changeset
|
437 |
Path.current [(name, Position.none)]; |
7211 | 438 |
|
59364 | 439 |
|
57626 | 440 |
(* toplevel scripting -- without maintaining database *) |
441 |
||
58856 | 442 |
fun script_thy pos txt thy = |
57626 | 443 |
let |
69891
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69886
diff
changeset
|
444 |
val trs = Outer_Syntax.parse_text thy (K thy) pos txt; |
57626 | 445 |
val end_pos = if null trs then pos else Toplevel.pos_of (List.last trs); |
69886 | 446 |
val end_state = fold (Toplevel.command_exception true) trs (Toplevel.init_toplevel ()); |
57626 | 447 |
in Toplevel.end_theory end_pos end_state end; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
448 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
449 |
|
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
|
450 |
(* register theory *) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
451 |
|
37954
a2e73df0b1e0
simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents:
37953
diff
changeset
|
452 |
fun register_thy theory = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
453 |
let |
65459
da59e8e0a663
clarified theory_long_name (for qualified access to Thy_Info) vs. short theory_name (which is unique within any given theory context);
wenzelm
parents:
65455
diff
changeset
|
454 |
val name = Context.theory_long_name theory; |
56208 | 455 |
val {master, ...} = Resources.check_thy (Resources.master_directory theory) name; |
456 |
val imports = Resources.imports_of theory; |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
457 |
in |
59178 | 458 |
change_thys (fn thys => |
459 |
let |
|
460 |
val thys' = remove name thys; |
|
461 |
val _ = writeln ("Registering theory " ^ quote name); |
|
462 |
in update (make_deps master imports) theory thys' end) |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
463 |
end; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
464 |
|
24080
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
465 |
|
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
466 |
(* finish all theories *) |
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents:
24071
diff
changeset
|
467 |
|
50862
5fc8b83322f5
more sensible order of theory nodes (correspondance to Scala version), e.g. relevant to theory progress;
wenzelm
parents:
50845
diff
changeset
|
468 |
fun finish () = change_thys (String_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
|
469 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
470 |
end; |
62847 | 471 |
|
65444 | 472 |
fun use_thy name = Runtime.toplevel_program (fn () => Thy_Info.use_thy name); |