| author | wenzelm | 
| Tue, 08 Oct 2024 15:44:52 +0200 | |
| changeset 81129 | 9efe46ef839a | 
| parent 78757 | a094bf81a496 | 
| child 82677 | c603d41dc183 | 
| permissions | -rw-r--r-- | 
| 3604 
6bf9f09f3d61
Moved functions for theory information storage / retrieval
 berghofe parents: diff
changeset | 1 | (* Title: Pure/Thy/thy_info.ML | 
| 72651 | 2 | Author: Makarius | 
| 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: 
37977diff
changeset | 4 | Global theory info database, with auto-loading according to theory and | 
| 72651 | 5 | file dependencies, and presentation of theory documents. | 
| 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: 
68179diff
changeset | 10 | type presentation_context = | 
| 68184 
6c693b2700b3
support for dynamic document output while editing;
 wenzelm parents: 
68182diff
changeset | 11 |     {options: Options.T, file_pos: Position.T, adjust_pos: Position.T -> Position.T,
 | 
| 73761 | 12 | segments: Document_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: 
68179diff
changeset | 14 | val apply_presentation: presentation_context -> theory -> unit | 
| 
112d9624c020
more general presentation hook, with document preparation as application;
 wenzelm parents: 
68179diff
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 | 
| 76405 | 18 | val defined_theory: string -> bool | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 19 | val get_theory: string -> theory | 
| 78527 
374611eb3055
tuned signature: more operations for formal theory context vs. theory loader;
 wenzelm parents: 
78021diff
changeset | 20 | val check_theory: Proof.context -> string * Position.T -> theory | 
| 26983 | 21 | 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: 
29118diff
changeset | 22 | val remove_thy: string -> unit | 
| 73821 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 23 | val use_theories: Options.T -> string -> (string * Position.T) list -> | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 24 | (theory * Document_Output.segment list) list | 
| 65444 | 25 | val use_thy: string -> unit | 
| 58856 | 26 | val script_thy: Position.T -> string -> theory -> theory | 
| 37954 
a2e73df0b1e0
simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
 wenzelm parents: 
37953diff
changeset | 27 | val register_thy: theory -> unit | 
| 24080 
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
 wenzelm parents: 
24071diff
changeset | 28 | val finish: unit -> unit | 
| 3604 
6bf9f09f3d61
Moved functions for theory information storage / retrieval
 berghofe parents: diff
changeset | 29 | end; | 
| 
6bf9f09f3d61
Moved functions for theory information storage / retrieval
 berghofe parents: diff
changeset | 30 | |
| 37216 
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
 wenzelm parents: 
36953diff
changeset | 31 | structure Thy_Info: THY_INFO = | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 32 | struct | 
| 3604 
6bf9f09f3d61
Moved functions for theory information storage / retrieval
 berghofe parents: diff
changeset | 33 | |
| 72651 | 34 | (** theory presentation **) | 
| 35 | ||
| 36 | (* hook for consolidated theory *) | |
| 68153 | 37 | |
| 68180 
112d9624c020
more general presentation hook, with document preparation as application;
 wenzelm parents: 
68179diff
changeset | 38 | type presentation_context = | 
| 68184 
6c693b2700b3
support for dynamic document output while editing;
 wenzelm parents: 
68182diff
changeset | 39 |   {options: Options.T, file_pos: Position.T, adjust_pos: Position.T -> Position.T,
 | 
| 73761 | 40 | segments: Document_Output.segment list}; | 
| 68180 
112d9624c020
more general presentation hook, with document preparation as application;
 wenzelm parents: 
68179diff
changeset | 41 | |
| 71249 | 42 | fun adjust_pos_properties (context: presentation_context) pos = | 
| 77770 | 43 | let | 
| 44 | val props = Position.properties_of pos; | |
| 45 | val props' = Position.properties_of (#adjust_pos context pos); | |
| 46 | in | |
| 47 | filter (fn (a, _) => a = Markup.offsetN orelse a = Markup.end_offsetN) props' @ | |
| 78021 | 48 | filter (fn (a, _) => a = Markup.labelN orelse a = Markup.fileN orelse a = Markup.idN) props | 
| 77770 | 49 | end; | 
| 71249 | 50 | |
| 68153 | 51 | structure Presentation = Theory_Data | 
| 52 | ( | |
| 68180 
112d9624c020
more general presentation hook, with document preparation as application;
 wenzelm parents: 
68179diff
changeset | 53 | type T = ((presentation_context -> theory -> unit) * stamp) list; | 
| 68153 | 54 | val empty = []; | 
| 55 | fun merge data : T = Library.merge (eq_snd op =) data; | |
| 56 | ); | |
| 57 | ||
| 68180 
112d9624c020
more general presentation hook, with document preparation as application;
 wenzelm parents: 
68179diff
changeset | 58 | fun apply_presentation (context: presentation_context) thy = | 
| 73821 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 59 | ignore (Par_List.map (fn (f, _) => f context thy) (Presentation.get thy)); | 
| 68180 
112d9624c020
more general presentation hook, with document preparation as application;
 wenzelm parents: 
68179diff
changeset | 60 | |
| 68153 | 61 | fun add_presentation f = Presentation.map (cons (f, stamp ())); | 
| 62 | ||
| 68180 
112d9624c020
more general presentation hook, with document preparation as application;
 wenzelm parents: 
68179diff
changeset | 63 | val _ = | 
| 73819 | 64 |   Theory.setup (add_presentation (fn {options, segments, ...} => fn thy =>
 | 
| 68182 | 65 | if exists (Toplevel.is_skipped_proof o #state) segments then () | 
| 68180 
112d9624c020
more general presentation hook, with document preparation as application;
 wenzelm parents: 
68179diff
changeset | 66 | else | 
| 68181 
34592bf86424
export generated document.tex, unless explicit document=false;
 wenzelm parents: 
68180diff
changeset | 67 | let | 
| 76432 | 68 | val keywords = Thy_Header.get_keywords thy; | 
| 77889 
5db014c36f42
clarified signature: explicitly distinguish theory_base_name vs. theory_long_name;
 wenzelm parents: 
77770diff
changeset | 69 | val thy_name = Context.theory_base_name thy; | 
| 76432 | 70 | val latex = Document_Output.present_thy options keywords thy_name segments; | 
| 68181 
34592bf86424
export generated document.tex, unless explicit document=false;
 wenzelm parents: 
68180diff
changeset | 71 | in | 
| 72574 
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
 wenzelm parents: 
72511diff
changeset | 72 | if Options.string options "document" = "false" then () | 
| 76432 | 73 | else Export.export thy \<^path_binding>\<open>document/latex\<close> latex | 
| 72710 
6bc199a70bf9
more robust: include reports from Thy_Output.present_thy/output_document;
 wenzelm parents: 
72705diff
changeset | 74 | end)); | 
| 68153 | 75 | |
| 76 | ||
| 77 | ||
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 78 | (** thy database **) | 
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 79 | |
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 80 | (* messages *) | 
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 81 | |
| 55797 | 82 | val show_path = space_implode " via " o map quote; | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 83 | |
| 55797 | 84 | fun cycle_msg names = "Cyclic dependency of " ^ show_path names; | 
| 3604 
6bf9f09f3d61
Moved functions for theory information storage / retrieval
 berghofe parents: diff
changeset | 85 | |
| 
6bf9f09f3d61
Moved functions for theory information storage / retrieval
 berghofe parents: diff
changeset | 86 | |
| 6666 | 87 | (* derived graph operations *) | 
| 3604 
6bf9f09f3d61
Moved functions for theory information storage / retrieval
 berghofe parents: diff
changeset | 88 | |
| 50862 
5fc8b83322f5
more sensible order of theory nodes (correspondance to Scala version), e.g. relevant to theory progress;
 wenzelm parents: 
50845diff
changeset | 89 | 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: 
50845diff
changeset | 90 | 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 | 91 | |
| 37984 
f26352bd82cf
clarified register_thy: clean slate via kill_thy, more precise CRITICAL section;
 wenzelm parents: 
37981diff
changeset | 92 | 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: 
50845diff
changeset | 93 | 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: 
37955diff
changeset | 94 | |
| 3604 
6bf9f09f3d61
Moved functions for theory information storage / retrieval
 berghofe parents: diff
changeset | 95 | |
| 59178 | 96 | (* global thys *) | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 97 | |
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 98 | type deps = | 
| 41955 
703ea96b13c6
files are identified via SHA1 digests -- discontinued ISABELLE_FILE_IDENT;
 wenzelm parents: 
41678diff
changeset | 99 |  {master: (Path.T * SHA1.digest),  (*master dependencies for thy file*)
 | 
| 48927 
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
 wenzelm parents: 
48898diff
changeset | 100 | imports: (string * Position.T) list}; (*source specification of imports (partially qualified)*) | 
| 23886 
f40fba467384
simplified ThyLoad interfaces: only one additional directory;
 wenzelm parents: 
23871diff
changeset | 101 | |
| 38148 
d2f3c8d4a89f
uniform naming of imports (source specification) vs. parents (thy node names) vs. parent_thys (theory values);
 wenzelm parents: 
38147diff
changeset | 102 | fun make_deps master imports : deps = {master = master, imports = imports};
 | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 103 | |
| 65454 | 104 | fun master_dir_deps (d: deps option) = | 
| 59178 | 105 | the_default Path.current (Option.map (Path.dir o #1 o #master) d); | 
| 106 | ||
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 107 | local | 
| 59178 | 108 | val global_thys = | 
| 109 | Synchronized.var "Thy_Info.thys" | |
| 110 | (String_Graph.empty: (deps option * theory option) String_Graph.T); | |
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 111 | in | 
| 59178 | 112 | fun get_thys () = Synchronized.value global_thys; | 
| 113 | fun change_thys f = Synchronized.change global_thys f; | |
| 3604 
6bf9f09f3d61
Moved functions for theory information storage / retrieval
 berghofe parents: diff
changeset | 114 | end; | 
| 5209 | 115 | |
| 50862 
5fc8b83322f5
more sensible order of theory nodes (correspondance to Scala version), e.g. relevant to theory progress;
 wenzelm parents: 
50845diff
changeset | 116 | fun get_names () = String_Graph.topological_order (get_thys ()); | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 117 | |
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 118 | |
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 119 | (* access thy *) | 
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 120 | |
| 59178 | 121 | fun lookup thys name = try (String_Graph.get_node thys) name; | 
| 122 | fun lookup_thy name = lookup (get_thys ()) name; | |
| 7935 | 123 | |
| 59178 | 124 | fun get thys name = | 
| 125 | (case lookup thys name of | |
| 15531 | 126 | SOME thy => thy | 
| 55797 | 127 |   | NONE => error ("Theory loader: nothing known about theory " ^ quote name));
 | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 128 | |
| 59178 | 129 | fun get_thy name = get (get_thys ()) name; | 
| 130 | ||
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 131 | |
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 132 | (* access deps *) | 
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 133 | |
| 15570 | 134 | val lookup_deps = Option.map #1 o lookup_thy; | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 135 | |
| 65454 | 136 | val master_directory = master_dir_deps o #1 o get_thy; | 
| 7191 | 137 | |
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 138 | |
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 139 | (* access theory *) | 
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 140 | |
| 7687 | 141 | fun lookup_theory name = | 
| 142 | (case lookup_thy name of | |
| 38142 | 143 | SOME (_, SOME theory) => SOME theory | 
| 15531 | 144 | | _ => NONE); | 
| 7288 | 145 | |
| 76405 | 146 | val defined_theory = is_some o lookup_theory; | 
| 147 | ||
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 148 | fun get_theory name = | 
| 7288 | 149 | (case lookup_theory name of | 
| 23871 | 150 | SOME theory => theory | 
| 55797 | 151 |   | _ => error ("Theory loader: undefined entry for theory " ^ quote name));
 | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 152 | |
| 56208 | 153 | val get_imports = Resources.imports_of o get_theory; | 
| 44337 
d453faed4815
clarified get_imports -- should not rely on accidental order within graph;
 wenzelm parents: 
44302diff
changeset | 154 | |
| 78527 
374611eb3055
tuned signature: more operations for formal theory context vs. theory loader;
 wenzelm parents: 
78021diff
changeset | 155 | val check_theory = Theory.check_theory {get = get_theory, all = get_names};
 | 
| 
374611eb3055
tuned signature: more operations for formal theory context vs. theory loader;
 wenzelm parents: 
78021diff
changeset | 156 | |
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 157 | |
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 158 | |
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 159 | (** thy operations **) | 
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 160 | |
| 59178 | 161 | (* remove *) | 
| 29421 
db532e37cda2
use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
 wenzelm parents: 
29118diff
changeset | 162 | |
| 59178 | 163 | fun remove name thys = | 
| 164 | (case lookup thys name of | |
| 165 | NONE => thys | |
| 166 |   | SOME (NONE, _) => error ("Cannot update finished theory " ^ quote name)
 | |
| 167 | | SOME _ => | |
| 168 | let | |
| 169 | val succs = String_Graph.all_succs thys [name]; | |
| 170 |         val _ = writeln ("Theory loader: removing " ^ commas_quote succs);
 | |
| 171 | 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: 
29118diff
changeset | 172 | |
| 59178 | 173 | val remove_thy = change_thys o remove; | 
| 174 | ||
| 7099 | 175 | |
| 59178 | 176 | (* update *) | 
| 177 | ||
| 178 | fun update deps theory thys = | |
| 43640 | 179 | 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: 
65455diff
changeset | 180 | 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: 
65455diff
changeset | 181 | val parents = map Context.theory_long_name (Theory.parents_of theory); | 
| 59178 | 182 | |
| 183 | val thys' = remove name thys; | |
| 184 | val _ = map (get thys') parents; | |
| 185 | in new_entry name parents (SOME deps, SOME theory) thys' end; | |
| 186 | ||
| 187 | fun update_thy deps theory = change_thys (update deps theory); | |
| 43640 | 188 | |
| 7099 | 189 | |
| 24209 | 190 | (* scheduling loader tasks *) | 
| 191 | ||
| 51330 | 192 | datatype result = | 
| 73821 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 193 | Result of | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 194 |    {theory: theory,
 | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 195 | exec_id: Document_ID.exec, | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 196 | present: unit -> presentation_context option, | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 197 | commit: unit -> unit}; | 
| 51331 
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
 wenzelm parents: 
51330diff
changeset | 198 | |
| 53375 
78693e46a237
Execution.fork formally requires registered Execution.running;
 wenzelm parents: 
53192diff
changeset | 199 | fun theory_result theory = | 
| 73821 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 200 | Result | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 201 |    {theory = theory,
 | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 202 | exec_id = Document_ID.none, | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 203 | present = K NONE, | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 204 | commit = I}; | 
| 51330 | 205 | |
| 206 | fun result_theory (Result {theory, ...}) = theory;
 | |
| 51331 
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
 wenzelm parents: 
51330diff
changeset | 207 | fun result_commit (Result {commit, ...}) = commit;
 | 
| 
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
 wenzelm parents: 
51330diff
changeset | 208 | |
| 73825 | 209 | datatype task = | 
| 210 | Task of string list * (theory list -> result) | | |
| 211 | Finished of theory; | |
| 212 | ||
| 213 | local | |
| 214 | ||
| 73817 | 215 | fun consolidate_theory (Exn.Exn exn) = [Exn.Exn exn] | 
| 216 |   | consolidate_theory (Exn.Res (Result {theory, exec_id, ...})) =
 | |
| 217 | let | |
| 218 | val _ = Execution.join [exec_id]; | |
| 78717 | 219 | val result = Exn.capture Thm.consolidate_theory theory; | 
| 73817 | 220 | val exns = maps Task_Queue.group_status (Execution.peek exec_id); | 
| 78717 | 221 | in result :: map Exn.Exn exns end; | 
| 43641 
081e009549dc
uniform finish_thy -- always Global_Theory.join_proofs, even with sequential scheduling;
 wenzelm parents: 
43640diff
changeset | 222 | |
| 73821 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 223 | fun present_theory (Exn.Exn exn) = [Exn.Exn exn] | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 224 |   | present_theory (Exn.Res (Result {theory, present, ...})) =
 | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 225 | (case present () of | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 226 | NONE => [] | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 227 |       | SOME (context as {segments, ...}) =>
 | 
| 78757 | 228 | [Exn.capture_body (fn () => (apply_presentation context theory; (theory, segments)))]); | 
| 73821 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 229 | |
| 73825 | 230 | in | 
| 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: 
37955diff
changeset | 231 | |
| 73818 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 232 | val schedule_theories = Thread_Attributes.uninterruptible (fn _ => fn tasks => | 
| 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 233 | let | 
| 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 234 | fun join_parents deps name parents = | 
| 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 235 | (case map #1 (filter (not o can Future.join o #2) deps) of | 
| 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 236 | [] => map (result_theory o Future.join o the o AList.lookup (op =) deps) parents | 
| 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 237 | | bad => | 
| 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 238 |           error ("Failed to load theory " ^ quote name ^ " (unresolved " ^ commas_quote bad ^ ")"));
 | 
| 44162 | 239 | |
| 51331 
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
 wenzelm parents: 
51330diff
changeset | 240 | val futures = tasks | 
| 51284 
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
 wenzelm parents: 
51228diff
changeset | 241 | |> String_Graph.schedule (fn deps => fn (name, task) => | 
| 
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
 wenzelm parents: 
51228diff
changeset | 242 | (case task of | 
| 66711 
80fa1401cf76
discontinued extra checks (see ce676a750575 and 60c159d490a2) -- qualified theory names are meant to cover this;
 wenzelm parents: 
66377diff
changeset | 243 | Task (parents, body) => | 
| 73818 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 244 | if Multithreading.max_threads () > 1 then | 
| 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 245 | (singleton o Future.forks) | 
| 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 246 |                 {name = "theory:" ^ name, group = NONE,
 | 
| 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 247 | deps = map (Future.task_of o #2) deps, pri = 0, interrupts = true} | 
| 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 248 | (fn () => body (join_parents deps name parents)) | 
| 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 249 | else | 
| 78757 | 250 | Future.value_result (Exn.capture_body (fn () => body (join_parents deps name parents))) | 
| 51331 
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
 wenzelm parents: 
51330diff
changeset | 251 | | Finished theory => Future.value (theory_result theory))); | 
| 
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
 wenzelm parents: 
51330diff
changeset | 252 | |
| 73817 | 253 | val results1 = futures |> maps (consolidate_theory o Future.join_result); | 
| 51331 
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
 wenzelm parents: 
51330diff
changeset | 254 | |
| 73821 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 255 | val present_results = futures |> maps (present_theory o Future.join_result); | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 256 | val results2 = (map o Exn.map_res) (K ()) present_results; | 
| 51331 
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
 wenzelm parents: 
51330diff
changeset | 257 | |
| 
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
 wenzelm parents: 
51330diff
changeset | 258 | val results3 = futures | 
| 78757 | 259 | |> map (fn future => Exn.capture_body (fn () => result_commit (Future.join future) ())); | 
| 51284 
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
 wenzelm parents: 
51228diff
changeset | 260 | |
| 53192 | 261 | val results4 = map Exn.Exn (maps Task_Queue.group_status (Execution.reset ())); | 
| 51284 
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
 wenzelm parents: 
51228diff
changeset | 262 | |
| 73821 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 263 | val _ = Par_Exn.release_all (results1 @ results2 @ results3 @ results4); | 
| 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 264 | in Par_Exn.release_all present_results end); | 
| 29429 
a6c641f08af7
schedule_futures: tuned final consolidation, explicit after_load phase;
 wenzelm parents: 
29421diff
changeset | 265 | |
| 73825 | 266 | end; | 
| 267 | ||
| 24209 | 268 | |
| 65505 | 269 | (* eval theory *) | 
| 270 | ||
| 72705 | 271 | fun eval_thy options master_dir header text_pos text parents = | 
| 65505 | 272 | let | 
| 273 | val (name, _) = #name header; | |
| 274 | val keywords = | |
| 275 | fold (curry Keyword.merge_keywords o Thy_Header.get_keywords) parents | |
| 276 | (Keyword.add_keywords (#keywords header) Keyword.empty_keywords); | |
| 277 | ||
| 68178 | 278 | val spans = Outer_Syntax.parse_spans (Token.explode keywords text_pos text); | 
| 68839 | 279 | val elements = Thy_Element.parse_elements keywords spans; | 
| 65505 | 280 | |
| 73046 | 281 | val text_id = Position.copy_id text_pos Position.none; | 
| 282 | ||
| 72622 
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
 wenzelm parents: 
72620diff
changeset | 283 | fun init () = Resources.begin_theory master_dir header parents; | 
| 73046 | 284 | |
| 285 | fun excursion () = | |
| 286 | let | |
| 287 | fun element_result span_elem (st, _) = | |
| 288 | let | |
| 289 | fun prepare span = | |
| 290 | let | |
| 291 | val tr = | |
| 292 | Position.setmp_thread_data text_id | |
| 293 | (fn () => Command.read_span keywords st master_dir init span) (); | |
| 294 | in Toplevel.timing (Resources.last_timing tr) tr end; | |
| 295 | val elem = Thy_Element.map_element prepare span_elem; | |
| 296 | val (results, st') = Toplevel.element_result keywords elem st; | |
| 297 | val pos' = Toplevel.pos_of (Thy_Element.last_element elem); | |
| 298 | in (results, (st', pos')) end; | |
| 299 | ||
| 300 | val (results, (end_state, end_pos)) = | |
| 76415 | 301 | fold_map element_result elements (Toplevel.make_state NONE, Position.none); | 
| 73046 | 302 | |
| 303 | val thy = Toplevel.end_theory end_pos end_state; | |
| 304 | in (results, thy) end; | |
| 305 | ||
| 306 |     val (results, thy) = cond_timeit true ("theory " ^ quote name) excursion;
 | |
| 65505 | 307 | |
| 73821 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 308 | fun present () : presentation_context = | 
| 65505 | 309 | let | 
| 73687 
54fe8cc0e1c6
clarified signature: provide access to previous state;
 wenzelm parents: 
73559diff
changeset | 310 | val segments = | 
| 
54fe8cc0e1c6
clarified signature: provide access to previous state;
 wenzelm parents: 
73559diff
changeset | 311 | (spans ~~ maps Toplevel.join_results results) |> map (fn (span, (st, tr, st')) => | 
| 
54fe8cc0e1c6
clarified signature: provide access to previous state;
 wenzelm parents: 
73559diff
changeset | 312 |             {span = span, prev_state = st, command = tr, state = st'});
 | 
| 73821 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 313 |       in {options = options, file_pos = text_pos, adjust_pos = I, segments = segments} end;
 | 
| 73046 | 314 | |
| 73798 
1ca35197108f
more predictable sequential presentation (2f9877db82a1), without somewhat pointless result_ord (e7fab0b5dbe7);
 wenzelm parents: 
73785diff
changeset | 315 | in (thy, present) end; | 
| 65505 | 316 | |
| 317 | ||
| 23967 | 318 | (* require_thy -- checking database entries wrt. the file-system *) | 
| 15065 | 319 | |
| 7211 | 320 | local | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
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: 
37955diff
changeset | 322 | 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: 
37955diff
changeset | 323 | | 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: 
37955diff
changeset | 324 | |
| 73045 | 325 | fun load_thy options initiators deps text (name, header_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: 
37955diff
changeset | 326 | let | 
| 73045 | 327 |     val {master = (thy_path, _), imports} = deps;
 | 
| 328 | val dir = Path.dir thy_path; | |
| 329 | ||
| 72692 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 wenzelm parents: 
72669diff
changeset | 330 | val exec_id = Document_ID.make (); | 
| 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 wenzelm parents: 
72669diff
changeset | 331 | val id = Document_ID.print exec_id; | 
| 73045 | 332 | val put_id = Position.put_id id; | 
| 72692 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 wenzelm parents: 
72669diff
changeset | 333 | val _ = | 
| 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 wenzelm parents: 
72669diff
changeset | 334 | Execution.running Document_ID.none exec_id [] orelse | 
| 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 wenzelm parents: 
72669diff
changeset | 335 |         raise Fail ("Failed to register execution: " ^ id);
 | 
| 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: 
37955diff
changeset | 336 | |
| 76884 | 337 | val text_pos = put_id (Position.file (File.symbolic_path thy_path)); | 
| 72692 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 wenzelm parents: 
72669diff
changeset | 338 | val text_props = Position.properties_of text_pos; | 
| 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 wenzelm parents: 
72669diff
changeset | 339 | |
| 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 wenzelm parents: 
72669diff
changeset | 340 | val _ = remove_thy name; | 
| 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 wenzelm parents: 
72669diff
changeset | 341 |     val _ = writeln ("Loading theory " ^ quote name ^ required_by " " initiators);
 | 
| 73559 | 342 | val _ = Output.try_protocol_message (Markup.loading_theory name @ text_props) [XML.blob [text]]; | 
| 53375 
78693e46a237
Execution.fork formally requires registered Execution.running;
 wenzelm parents: 
53192diff
changeset | 343 | |
| 73045 | 344 | val _ = | 
| 345 | Position.setmp_thread_data (Position.id_only id) (fn () => | |
| 346 | (parents, map #2 imports) |> ListPair.app (fn (thy, pos) => | |
| 347 | Context_Position.reports_global thy [(put_id pos, Theory.get_markup thy)])) (); | |
| 348 | ||
| 66873 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 wenzelm parents: 
66711diff
changeset | 349 | val timing_start = Timing.start (); | 
| 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 wenzelm parents: 
66711diff
changeset | 350 | |
| 73045 | 351 | val header = Thy_Header.make (name, put_id header_pos) imports keywords; | 
| 73798 
1ca35197108f
more predictable sequential presentation (2f9877db82a1), without somewhat pointless result_ord (e7fab0b5dbe7);
 wenzelm parents: 
73785diff
changeset | 352 | val (theory, present) = | 
| 72705 | 353 | eval_thy options dir header text_pos text | 
| 62876 | 354 | (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: 
66711diff
changeset | 355 | |
| 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 wenzelm parents: 
66711diff
changeset | 356 | val timing_result = Timing.result timing_start; | 
| 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 wenzelm parents: 
66711diff
changeset | 357 | val timing_props = [Markup.theory_timing, (Markup.nameN, name)]; | 
| 73559 | 358 | val _ = Output.try_protocol_message (timing_props @ Markup.timing_properties timing_result) [] | 
| 66873 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 wenzelm parents: 
66711diff
changeset | 359 | |
| 43640 | 360 | fun commit () = update_thy deps theory; | 
| 73821 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 361 |   in Result {theory = theory, exec_id = exec_id, present = SOME o present, commit = 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: 
37955diff
changeset | 362 | |
| 70711 | 363 | fun check_thy_deps dir name = | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 364 | (case lookup_deps name of | 
| 51293 
05b1bbae748d
discontinued obsolete 'uses' within theory header;
 wenzelm parents: 
51284diff
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: 
23886diff
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: 
51284diff
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: 
42003diff
changeset | 369 |   | SOME (SOME {master, ...}) =>
 | 
| 42003 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
41955diff
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: 
41955diff
changeset | 373 | val deps' = SOME (make_deps master' imports', text'); | 
| 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
41955diff
changeset | 374 | val current = | 
| 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
41955diff
changeset | 375 | #2 master = #2 master' andalso | 
| 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
41955diff
changeset | 376 | (case lookup_theory name of | 
| 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
41955diff
changeset | 377 | NONE => false | 
| 56208 | 378 | | SOME theory => Resources.loaded_files_current theory); | 
| 51293 
05b1bbae748d
discontinued obsolete 'uses' within theory header;
 wenzelm parents: 
51284diff
changeset | 379 | in (current, deps', theory_pos', imports', keywords') end); | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 380 | |
| 73817 | 381 | fun task_finished (Task _) = false | 
| 382 | | task_finished (Finished _) = true; | |
| 383 | ||
| 23967 | 384 | in | 
| 385 | ||
| 72638 
2a7fc87495e0
refer to command_timings/last_timing via resources;
 wenzelm parents: 
72624diff
changeset | 386 | fun require_thys options initiators qualifier dir strs tasks = | 
| 
2a7fc87495e0
refer to command_timings/last_timing via resources;
 wenzelm parents: 
72624diff
changeset | 387 | fold_map (require_thy options initiators qualifier dir) strs tasks |>> forall I | 
| 
2a7fc87495e0
refer to command_timings/last_timing via resources;
 wenzelm parents: 
72624diff
changeset | 388 | and require_thy options initiators qualifier dir (s, require_pos) tasks = | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 389 | let | 
| 66711 
80fa1401cf76
discontinued extra checks (see ce676a750575 and 60c159d490a2) -- qualified theory names are meant to cover this;
 wenzelm parents: 
66377diff
changeset | 390 |     val {master_dir, theory_name, ...} = Resources.import_name qualifier dir s;
 | 
| 7066 | 391 | in | 
| 65443 
dccbfc715904
provide Resources.import_name in ML, similar to Scala version;
 wenzelm parents: 
65058diff
changeset | 392 | (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: 
66377diff
changeset | 393 | SOME task => (task_finished task, tasks) | 
| 23967 | 394 | | NONE => | 
| 395 | let | |
| 65443 
dccbfc715904
provide Resources.import_name in ML, similar to Scala version;
 wenzelm parents: 
65058diff
changeset | 396 | val _ = member (op =) initiators theory_name andalso error (cycle_msg initiators); | 
| 43651 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 wenzelm parents: 
43641diff
changeset | 397 | |
| 70711 | 398 | val (current, deps, theory_pos, imports, keywords) = check_thy_deps master_dir theory_name | 
| 55797 | 399 | handle ERROR msg => | 
| 400 | cat_error msg | |
| 65443 
dccbfc715904
provide Resources.import_name in ML, similar to Scala version;
 wenzelm parents: 
65058diff
changeset | 401 |                 ("The error(s) above occurred for theory " ^ quote theory_name ^
 | 
| 55797 | 402 | 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: 
37980diff
changeset | 403 | |
| 65455 | 404 | val qualifier' = Resources.theory_qualifier theory_name; | 
| 72511 
460d743010bc
clarified signature: overloaded "+" for Path.append;
 wenzelm parents: 
72311diff
changeset | 405 | val dir' = dir + master_dir_deps (Option.map #1 deps); | 
| 65455 | 406 | |
| 407 | 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: 
48888diff
changeset | 408 | val (parents_current, tasks') = | 
| 72638 
2a7fc87495e0
refer to command_timings/last_timing via resources;
 wenzelm parents: 
72624diff
changeset | 409 | require_thys options (theory_name :: initiators) qualifier' dir' imports tasks; | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 410 | |
| 23967 | 411 | 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: 
37955diff
changeset | 412 | val task = | 
| 65443 
dccbfc715904
provide Resources.import_name in ML, similar to Scala version;
 wenzelm parents: 
65058diff
changeset | 413 | 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: 
37955diff
changeset | 414 | else | 
| 37980 
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
 wenzelm parents: 
37979diff
changeset | 415 | (case deps of | 
| 
b8c3d4dc1e3e
avoid repeated File.read for theory text (as before);
 wenzelm parents: 
37979diff
changeset | 416 | NONE => raise Fail "Malformed deps" | 
| 42003 
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
 wenzelm parents: 
41955diff
changeset | 417 | | SOME (dep, text) => | 
| 72705 | 418 | Task (parents, | 
| 419 | load_thy options initiators dep text (theory_name, theory_pos) keywords)); | |
| 48874 
ff9cd47be39b
refined Thy_Load.check_thy: find more uses in body text, based on keywords;
 wenzelm parents: 
48710diff
changeset | 420 | |
| 65443 
dccbfc715904
provide Resources.import_name in ML, similar to Scala version;
 wenzelm parents: 
65058diff
changeset | 421 | 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: 
48888diff
changeset | 422 | in (all_current, tasks'') end) | 
| 7066 | 423 | end; | 
| 6484 
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
 wenzelm parents: 
6389diff
changeset | 424 | |
| 23967 | 425 | end; | 
| 426 | ||
| 427 | ||
| 65444 | 428 | (* use theories *) | 
| 23967 | 429 | |
| 72638 
2a7fc87495e0
refer to command_timings/last_timing via resources;
 wenzelm parents: 
72624diff
changeset | 430 | fun use_theories options qualifier imports = | 
| 73818 
d67688992bde
more uniform schedule_theories, notably for "present" and "commit" phase after loading;
 wenzelm parents: 
73817diff
changeset | 431 | schedule_theories (#2 (require_thys options [] qualifier Path.current imports String_Graph.empty)); | 
| 23967 | 432 | |
| 65444 | 433 | fun use_thy name = | 
| 73821 
9ead8d9be3ab
clarified hook for Mirabelle: provide all loaded theories at once (for each 'theories' section within the session ROOT);
 wenzelm parents: 
73819diff
changeset | 434 | ignore (use_theories (Options.default ()) Resources.default_qualifier [(name, Position.none)]); | 
| 7211 | 435 | |
| 59364 | 436 | |
| 57626 | 437 | (* toplevel scripting -- without maintaining database *) | 
| 438 | ||
| 58856 | 439 | fun script_thy pos txt thy = | 
| 57626 | 440 | let | 
| 69891 
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
 wenzelm parents: 
69886diff
changeset | 441 | val trs = Outer_Syntax.parse_text thy (K thy) pos txt; | 
| 57626 | 442 | val end_pos = if null trs then pos else Toplevel.pos_of (List.last trs); | 
| 76415 | 443 | val end_state = fold (Toplevel.command_exception true) trs (Toplevel.make_state NONE); | 
| 57626 | 444 | in Toplevel.end_theory end_pos end_state end; | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 445 | |
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 446 | |
| 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: 
37955diff
changeset | 447 | (* register theory *) | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 448 | |
| 37954 
a2e73df0b1e0
simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
 wenzelm parents: 
37953diff
changeset | 449 | fun register_thy theory = | 
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 450 | 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: 
65455diff
changeset | 451 | val name = Context.theory_long_name theory; | 
| 56208 | 452 |     val {master, ...} = Resources.check_thy (Resources.master_directory theory) name;
 | 
| 453 | val imports = Resources.imports_of theory; | |
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 454 | in | 
| 59178 | 455 | change_thys (fn thys => | 
| 456 | let | |
| 457 | val thys' = remove name thys; | |
| 458 |         val _ = writeln ("Registering theory " ^ quote name);
 | |
| 459 | in update (make_deps master imports) theory thys' end) | |
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 460 | end; | 
| 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 461 | |
| 24080 
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
 wenzelm parents: 
24071diff
changeset | 462 | |
| 
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
 wenzelm parents: 
24071diff
changeset | 463 | (* finish all theories *) | 
| 
8c67d869531b
added register_thy (replaces pretend_use_thy_only and really flag);
 wenzelm parents: 
24071diff
changeset | 464 | |
| 50862 
5fc8b83322f5
more sensible order of theory nodes (correspondance to Scala version), e.g. relevant to theory progress;
 wenzelm parents: 
50845diff
changeset | 465 | 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: 
24071diff
changeset | 466 | |
| 6211 
43d0efafa025
Theory loader database: theory and file dependencies, theory values
 wenzelm parents: 
5211diff
changeset | 467 | end; | 
| 62847 | 468 | |
| 65444 | 469 | fun use_thy name = Runtime.toplevel_program (fn () => Thy_Info.use_thy name); |