| author | wenzelm |
| Thu, 09 Jun 2005 12:04:53 +0200 | |
| changeset 16352 | d7f9978e5752 |
| parent 16047 | b2bf9a5cde37 |
| child 16454 | af39c6510b86 |
| permissions | -rw-r--r-- |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
1 |
(* Title: Pure/Thy/thy_info.ML |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
2 |
ID: $Id$ |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
4 |
|
| 15801 | 5 |
Main part of theory loader database, including handling of theory and |
6 |
file dependencies. |
|
| 3976 | 7 |
*) |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
8 |
|
| 5209 | 9 |
signature BASIC_THY_INFO = |
10 |
sig |
|
11 |
val theory: string -> theory |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
12 |
val theory_of_sign: Sign.sg -> theory |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
13 |
val theory_of_thm: thm -> theory |
| 6241 | 14 |
(*val use: string -> unit*) (*exported later*) |
15 |
val time_use: string -> unit |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
16 |
val touch_thy: string -> unit |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
17 |
val use_thy: string -> unit |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
18 |
val update_thy: string -> unit |
| 6666 | 19 |
val remove_thy: string -> unit |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
20 |
val time_use_thy: string -> unit |
| 6527 | 21 |
val use_thy_only: string -> unit |
| 7099 | 22 |
val update_thy_only: string -> unit |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
23 |
end; |
| 5209 | 24 |
|
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
25 |
signature THY_INFO = |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
26 |
sig |
| 5209 | 27 |
include BASIC_THY_INFO |
| 7099 | 28 |
datatype action = Update | Outdate | Remove |
29 |
val str_of_action: action -> string |
|
30 |
val add_hook: (action -> string -> unit) -> unit |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
31 |
val names: unit -> string list |
| 7910 | 32 |
val known_thy: string -> bool |
| 7935 | 33 |
val check_known_thy: string -> bool |
34 |
val if_known_thy: (string -> unit) -> string -> unit |
|
| 7288 | 35 |
val lookup_theory: string -> theory option |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
36 |
val get_theory: string -> theory |
| 6654 | 37 |
val get_preds: string -> string list |
| 7935 | 38 |
val loaded_files: string -> Path.T list |
| 7910 | 39 |
val touch_child_thys: string -> unit |
| 7099 | 40 |
val touch_all_thys: unit -> unit |
| 7941 | 41 |
val load_file: bool -> Path.T -> unit |
| 6241 | 42 |
val use: string -> unit |
| 7952 | 43 |
val quiet_update_thy: bool -> string -> unit |
| 9822 | 44 |
val pretend_use_thy_only: string -> unit |
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
45 |
val begin_theory: (Path.T option -> string -> string list -> |
|
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
46 |
(Path.T * bool) list -> theory -> theory) -> |
| 8805 | 47 |
bool -> string -> string list -> (Path.T * bool) list -> theory |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
48 |
val end_theory: theory -> theory |
| 6666 | 49 |
val finish: unit -> unit |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
50 |
val register_theory: theory -> unit |
| 15633 | 51 |
val pretty_theory: theory -> Pretty.T |
52 |
val pprint_theory: theory -> pprint_args -> unit |
|
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
53 |
end; |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
54 |
|
| 6362 | 55 |
structure ThyInfo: THY_INFO = |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
56 |
struct |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
57 |
|
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
58 |
|
| 7099 | 59 |
(** theory loader actions and hooks **) |
60 |
||
61 |
datatype action = Update | Outdate | Remove; |
|
62 |
val str_of_action = fn Update => "Update" | Outdate => "Outdate" | Remove => "Remove"; |
|
63 |
||
64 |
local |
|
65 |
val hooks = ref ([]: (action -> string -> unit) list); |
|
66 |
in |
|
67 |
fun add_hook f = hooks := f :: ! hooks; |
|
| 15570 | 68 |
fun perform action name = List.app (fn f => (try (fn () => f action name) (); ())) (! hooks); |
| 7099 | 69 |
end; |
70 |
||
71 |
||
72 |
||
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
73 |
(** thy database **) |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
74 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
75 |
(* messages *) |
|
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 |
fun gen_msg txt [] = txt |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
78 |
| gen_msg txt names = txt ^ " " ^ commas_quote names; |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
79 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
80 |
fun loader_msg txt names = gen_msg ("Theory loader: " ^ txt) names;
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
81 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
82 |
val show_path = space_implode " via " o map quote; |
| 9332 | 83 |
fun cycle_msg names = loader_msg ("cyclic dependency of " ^ show_path names) [];
|
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
84 |
|
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
85 |
|
| 6666 | 86 |
(* derived graph operations *) |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
87 |
|
| 9327 | 88 |
fun add_deps name parents G = Graph.add_deps_acyclic (name, parents) G |
| 9332 | 89 |
handle Graph.CYCLES namess => error (cat_lines (map cycle_msg namess)); |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
90 |
|
| 7952 | 91 |
fun upd_deps name entry G = |
| 15570 | 92 |
Library.foldl (fn (H, parent) => Graph.del_edge (parent, name) H) (G, Graph.imm_preds G name) |
| 7952 | 93 |
|> Graph.map_node name (K entry); |
| 3976 | 94 |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
95 |
fun update_node name parents entry G = |
| 7952 | 96 |
(if can (Graph.get_node G) name then upd_deps name entry G else Graph.new_node (name, entry) G) |
97 |
|> add_deps name parents; |
|
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
98 |
|
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
99 |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
100 |
(* thy database *) |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
101 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
102 |
type deps = |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
103 |
{present: bool, outdated: bool,
|
| 7941 | 104 |
master: ThyLoad.master option, files: (Path.T * (Path.T * File.info) option) list}; |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
105 |
|
| 6241 | 106 |
fun make_deps present outdated master files = |
107 |
{present = present, outdated = outdated, master = master, files = files}: deps;
|
|
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
108 |
|
| 15531 | 109 |
fun init_deps master files = SOME (make_deps false true master (map (rpair NONE) files)); |
| 7211 | 110 |
|
111 |
||
| 6362 | 112 |
type thy = deps option * theory option; |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
113 |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
114 |
local |
| 6362 | 115 |
val database = ref (Graph.empty: thy Graph.T); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
116 |
in |
| 6362 | 117 |
fun get_thys () = ! database; |
| 9137 | 118 |
val change_thys = Library.change database; |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
119 |
end; |
| 5209 | 120 |
|
121 |
||
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
122 |
(* access thy graph *) |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
123 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
124 |
fun thy_graph f x = f (get_thys ()) x; |
| 9417 | 125 |
|
126 |
(*theory names in topological order*) |
|
127 |
fun get_names () = |
|
128 |
let val G = get_thys () |
|
| 14774 | 129 |
in Graph.all_succs G (Graph.minimals G) end; |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
130 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
131 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
132 |
(* access thy *) |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
133 |
|
| 7935 | 134 |
fun lookup_thy name = |
| 15531 | 135 |
SOME (thy_graph Graph.get_node name) handle Graph.UNDEF _ => NONE; |
| 7935 | 136 |
|
| 16047 | 137 |
val known_thy = is_some o lookup_thy; |
| 7935 | 138 |
fun check_known_thy name = known_thy name orelse (warning ("Unknown theory " ^ quote name); false);
|
139 |
fun if_known_thy f name = if check_known_thy name then f name else (); |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
140 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
141 |
fun get_thy name = |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
142 |
(case lookup_thy name of |
| 15531 | 143 |
SOME thy => thy |
144 |
| NONE => error (loader_msg "nothing known about theory" [name])); |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
145 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
146 |
fun change_thy name f = (get_thy name; change_thys (Graph.map_node name f)); |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
147 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
148 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
149 |
(* access deps *) |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
150 |
|
| 15570 | 151 |
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
|
152 |
val get_deps = #1 o get_thy; |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
153 |
fun change_deps name f = change_thy name (fn (deps, x) => (f deps, x)); |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
154 |
|
| 6666 | 155 |
fun is_finished name = is_none (get_deps name); |
| 15531 | 156 |
fun get_files name = (case get_deps name of SOME {files, ...} => files | _ => []);
|
| 7191 | 157 |
|
158 |
fun loaded_files name = |
|
159 |
(case get_deps name of |
|
| 15531 | 160 |
NONE => [] |
161 |
| SOME {master, files, ...} =>
|
|
162 |
(case master of SOME m => [#1 (ThyLoad.get_thy m)] | NONE => []) @ |
|
| 15570 | 163 |
(List.mapPartial (Option.map #1 o #2) files)); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
164 |
|
| 6654 | 165 |
fun get_preds name = |
| 9327 | 166 |
(thy_graph Graph.imm_preds name) handle Graph.UNDEF _ => |
| 6654 | 167 |
error (loader_msg "nothing known about theory" [name]); |
168 |
||
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
169 |
|
| 16047 | 170 |
(* pretty printing a theory *) |
171 |
||
172 |
local |
|
| 15633 | 173 |
|
| 16047 | 174 |
fun relevant_names names = |
175 |
let |
|
176 |
val (finished, unfinished) = |
|
177 |
List.filter (equal "#" orf known_thy) names |
|
178 |
|> List.partition (not_equal "#" andf is_finished); |
|
179 |
in (if not (null finished) then [List.last finished] else []) @ unfinished end; |
|
| 15633 | 180 |
|
| 16047 | 181 |
fun pretty_sg sg = |
182 |
Pretty.str_list "{" "}" (relevant_names (Sign.stamp_names_of sg));
|
|
183 |
||
184 |
in |
|
| 15633 | 185 |
|
186 |
val pretty_theory = pretty_sg o Theory.sign_of; |
|
187 |
val pprint_theory = Pretty.pprint o pretty_theory; |
|
188 |
||
| 16047 | 189 |
end; |
190 |
||
| 15633 | 191 |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
192 |
(* access theory *) |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
193 |
|
| 7687 | 194 |
fun lookup_theory name = |
195 |
(case lookup_thy name of |
|
| 15531 | 196 |
SOME (_, SOME thy) => SOME thy |
197 |
| _ => NONE); |
|
| 7288 | 198 |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
199 |
fun get_theory name = |
| 7288 | 200 |
(case lookup_theory name of |
| 15531 | 201 |
(SOME theory) => theory |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
202 |
| _ => error (loader_msg "undefined theory entry for" [name])); |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
203 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
204 |
val theory_of_sign = get_theory o Sign.name_of; |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
205 |
val theory_of_thm = theory_of_sign o Thm.sign_of_thm; |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
206 |
|
| 15531 | 207 |
fun put_theory name theory = change_thy name (fn (deps, _) => (deps, SOME theory)); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
208 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
209 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
210 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
211 |
(** thy operations **) |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
212 |
|
| 6241 | 213 |
(* maintain 'outdated' flag *) |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
214 |
|
| 7099 | 215 |
local |
216 |
||
| 6241 | 217 |
fun is_outdated name = |
218 |
(case lookup_deps name of |
|
| 15531 | 219 |
SOME (SOME {outdated, ...}) => outdated
|
| 6241 | 220 |
| _ => false); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
221 |
|
| 6241 | 222 |
fun outdate_thy name = |
| 7099 | 223 |
if is_finished name orelse is_outdated name then () |
| 15570 | 224 |
else (change_deps name (Option.map (fn {present, outdated = _, master, files} =>
|
| 7099 | 225 |
make_deps present true master files)); perform Outdate name); |
226 |
||
| 7910 | 227 |
fun check_unfinished name = |
| 15531 | 228 |
if is_finished name then (warning (loader_msg "tried to touch finished theory" [name]); NONE) |
229 |
else SOME name; |
|
| 7910 | 230 |
|
| 7099 | 231 |
in |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
232 |
|
| 7910 | 233 |
fun touch_thys names = |
| 15570 | 234 |
List.app outdate_thy (thy_graph Graph.all_succs (List.mapPartial check_unfinished names)); |
| 7910 | 235 |
|
236 |
fun touch_thy name = touch_thys [name]; |
|
237 |
fun touch_child_thys name = touch_thys (thy_graph Graph.imm_succs name); |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
238 |
|
| 15570 | 239 |
fun touch_all_thys () = List.app outdate_thy (get_names ()); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
240 |
|
| 7099 | 241 |
end; |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
242 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
243 |
|
| 7244 | 244 |
(* check 'finished' state *) |
245 |
||
246 |
fun check_unfinished fail name = |
|
| 7910 | 247 |
if known_thy name andalso is_finished name then |
| 7288 | 248 |
fail (loader_msg "cannot update finished theory" [name]) |
| 7244 | 249 |
else (); |
250 |
||
251 |
||
| 7941 | 252 |
(* load_file *) |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
253 |
|
| 15570 | 254 |
val opt_path = Option.map (Path.dir o fst o ThyLoad.get_thy); |
| 16047 | 255 |
fun opt_path' (d: deps option) = if_none (Option.map (opt_path o #master) d) NONE; |
256 |
fun opt_path'' d = if_none (Option.map opt_path' d) NONE; |
|
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
257 |
|
| 7191 | 258 |
local |
259 |
||
| 15531 | 260 |
fun provide path name info (deps as SOME {present, outdated, master, files}) =
|
| 7941 | 261 |
(if exists (equal path o #1) files then () |
262 |
else warning (loader_msg "undeclared dependency of theory" [name] ^ |
|
263 |
" on file: " ^ quote (Path.pack path)); |
|
| 15531 | 264 |
SOME (make_deps present outdated master (overwrite (files, (path, SOME info))))) |
265 |
| provide _ _ _ NONE = NONE; |
|
| 7941 | 266 |
|
267 |
fun run_file path = |
|
| 15570 | 268 |
(case Option.map PureThy.get_name (Context.get_context ()) of |
| 15531 | 269 |
NONE => (ThyLoad.load_file NONE path; ()) |
270 |
| SOME name => (case lookup_deps name of |
|
271 |
SOME deps => change_deps name (provide path name |
|
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
272 |
(ThyLoad.load_file (opt_path' deps) path)) |
| 15531 | 273 |
| NONE => (ThyLoad.load_file NONE path; ()))); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
274 |
|
| 7191 | 275 |
in |
276 |
||
| 7941 | 277 |
fun load_file time path = |
278 |
if time then |
|
| 7244 | 279 |
let val name = Path.pack path in |
280 |
timeit (fn () => |
|
| 9778 | 281 |
(priority ("\n**** Starting file " ^ quote name ^ " ****");
|
| 9036 | 282 |
run_file path; |
| 9778 | 283 |
priority ("**** Finished file " ^ quote name ^ " ****\n")))
|
| 7244 | 284 |
end |
| 7941 | 285 |
else run_file path; |
286 |
||
287 |
val use = load_file false o Path.unpack; |
|
288 |
val time_use = load_file true o Path.unpack; |
|
| 7191 | 289 |
|
290 |
end; |
|
| 6233 | 291 |
|
292 |
||
| 7099 | 293 |
(* load_thy *) |
294 |
||
| 9490 | 295 |
fun required_by _ [] = "" |
296 |
| required_by s initiators = s ^ "(required by " ^ show_path (rev initiators) ^ ")"; |
|
| 7099 | 297 |
|
| 15065 | 298 |
fun load_thy really ml time initiators dir name = |
| 7099 | 299 |
let |
| 9822 | 300 |
val _ = |
301 |
if really then priority ("Loading theory " ^ quote name ^ required_by " " initiators)
|
|
302 |
else priority ("Registering theory " ^ quote name);
|
|
| 7099 | 303 |
|
304 |
val _ = touch_thy name; |
|
| 9822 | 305 |
val master = |
306 |
if really then ThyLoad.load_thy dir name ml time |
|
307 |
else #1 (ThyLoad.deps_thy dir name ml); |
|
| 7099 | 308 |
|
309 |
val files = get_files name; |
|
| 15570 | 310 |
val missing_files = List.mapPartial (fn (path, NONE) => SOME (Path.pack path) | _ => NONE) files; |
| 7099 | 311 |
in |
312 |
if null missing_files then () |
|
313 |
else warning (loader_msg "unresolved dependencies of theory" [name] ^ |
|
| 7223 | 314 |
" on file(s): " ^ commas_quote missing_files); |
| 15531 | 315 |
change_deps name (fn _ => SOME (make_deps true false (SOME master) files)); |
| 7099 | 316 |
perform Update name |
317 |
end; |
|
318 |
||
319 |
||
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
320 |
(* require_thy *) |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
321 |
|
| 15065 | 322 |
fun base_of_path s = Path.pack (Path.base (Path.unpack s)); |
323 |
||
| 7211 | 324 |
local |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
325 |
|
| 7941 | 326 |
fun load_deps ml dir name = |
327 |
let val (master, (parents, files)) = ThyLoad.deps_thy dir name ml |
|
| 15531 | 328 |
in (SOME (init_deps (SOME master) files), parents) end; |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
329 |
|
| 15531 | 330 |
fun file_current master (_, NONE) = false |
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
331 |
| file_current master (path, info) = |
|
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
332 |
(info = ThyLoad.check_file (opt_path master) path); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
333 |
|
| 7941 | 334 |
fun current_deps ml strict dir name = |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
335 |
(case lookup_deps name of |
| 15531 | 336 |
NONE => (false, load_deps ml dir name) |
337 |
| SOME deps => |
|
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
338 |
let |
| 15531 | 339 |
fun get_name s = (case opt_path'' (lookup_deps s) of NONE => s |
340 |
| SOME p => Path.pack (Path.append p (Path.basic s))); |
|
341 |
val same_deps = (NONE, map get_name (thy_graph Graph.imm_preds name)) |
|
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
342 |
in |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
343 |
(case deps of |
| 15531 | 344 |
NONE => (true, same_deps) |
345 |
| SOME {present, outdated, master, files} =>
|
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
346 |
if present andalso not strict then (true, same_deps) |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
347 |
else |
| 15531 | 348 |
let val master' = SOME (ThyLoad.check_thy dir name ml) in |
| 7941 | 349 |
if master <> master' then (false, load_deps ml dir name) |
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
350 |
else (not outdated andalso forall (file_current master') files, same_deps) |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
351 |
end) |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
352 |
end); |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
353 |
|
| 9822 | 354 |
fun require_thy really ml time strict keep_strict initiators prfx (visited, str) = |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
355 |
let |
| 7066 | 356 |
val path = Path.expand (Path.unpack str); |
|
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
357 |
val name = Path.pack (Path.base path); |
| 7066 | 358 |
in |
| 9332 | 359 |
if name mem_string initiators then error (cycle_msg initiators) else (); |
| 7952 | 360 |
if known_thy name andalso is_finished name orelse name mem_string visited then |
361 |
(visited, (true, name)) |
|
| 7066 | 362 |
else |
363 |
let |
|
364 |
val dir = Path.append prfx (Path.dir path); |
|
| 9822 | 365 |
val req_parent = require_thy true true time (strict andalso keep_strict) keep_strict |
| 15065 | 366 |
(name :: initiators); |
|
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
367 |
|
| 7941 | 368 |
val (current, (new_deps, parents)) = current_deps ml strict dir name handle ERROR => |
| 7099 | 369 |
error (loader_msg "the error(s) above occurred while examining theory" [name] ^ |
| 9490 | 370 |
(if null initiators then "" else required_by "\n" initiators)); |
| 16047 | 371 |
val dir' = if_none (opt_path'' new_deps) dir; |
| 15065 | 372 |
val (visited', parent_results) = foldl_map (req_parent dir') (name :: visited, parents); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
373 |
|
| 15531 | 374 |
val thy = if not really then SOME (get_theory name) else NONE; |
| 7066 | 375 |
val result = |
376 |
if current andalso forall #1 parent_results then true |
|
377 |
else |
|
378 |
((case new_deps of |
|
| 15531 | 379 |
SOME deps => change_thys (update_node name (map base_of_path parents) (deps, thy)) |
380 |
| NONE => ()); |
|
| 15065 | 381 |
load_thy really ml (time orelse ! Output.timing) initiators dir name; |
| 7099 | 382 |
false); |
| 7066 | 383 |
in (visited', (result, name)) end |
384 |
end; |
|
|
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
385 |
|
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
386 |
fun gen_use_thy' req prfx s = |
|
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
387 |
let val (_, (_, name)) = req [] prfx ([], s) |
| 7066 | 388 |
in Context.context (get_theory name) end; |
| 6241 | 389 |
|
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
390 |
fun gen_use_thy req = gen_use_thy' req Path.current; |
|
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
391 |
|
| 7244 | 392 |
fun warn_finished f name = (check_unfinished warning name; f name); |
393 |
||
| 7211 | 394 |
in |
395 |
||
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
396 |
val weak_use_thy = gen_use_thy' (require_thy true true false false false); |
|
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
397 |
fun quiet_update_thy' ml = gen_use_thy' (require_thy true ml false true true); |
|
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
398 |
fun quiet_update_thy ml = gen_use_thy (require_thy true ml false true true); |
| 7244 | 399 |
|
| 9822 | 400 |
val use_thy = warn_finished (gen_use_thy (require_thy true true false true false)); |
401 |
val time_use_thy = warn_finished (gen_use_thy (require_thy true true true true false)); |
|
402 |
val use_thy_only = warn_finished (gen_use_thy (require_thy true false false true false)); |
|
403 |
val update_thy = warn_finished (gen_use_thy (require_thy true true false true true)); |
|
404 |
val update_thy_only = warn_finished (gen_use_thy (require_thy true false false true true)); |
|
405 |
val pretend_use_thy_only = warn_finished (gen_use_thy (require_thy false false false true false)); |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
406 |
|
| 7211 | 407 |
end; |
408 |
||
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
409 |
|
| 6666 | 410 |
(* remove_thy *) |
411 |
||
412 |
fun remove_thy name = |
|
| 7910 | 413 |
if is_finished name then error (loader_msg "cannot remove finished theory" [name]) |
| 6666 | 414 |
else |
415 |
let val succs = thy_graph Graph.all_succs [name] in |
|
| 9778 | 416 |
priority (loader_msg "removing" succs); |
| 15570 | 417 |
List.app (perform Remove) succs; |
| 7191 | 418 |
change_thys (Graph.del_nodes succs) |
| 6666 | 419 |
end; |
420 |
||
421 |
||
| 7066 | 422 |
(* begin / end theory *) |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
423 |
|
| 8805 | 424 |
fun begin_theory present upd name parents paths = |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
425 |
let |
| 15065 | 426 |
val bparents = map base_of_path parents; |
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
427 |
val dir' = opt_path'' (lookup_deps name); |
| 16047 | 428 |
val dir = if_none dir' Path.current; |
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
429 |
val assert_thy = if upd then quiet_update_thy' true dir else weak_use_thy dir; |
| 7244 | 430 |
val _ = check_unfinished error name; |
| 15570 | 431 |
val _ = List.app assert_thy parents; |
| 15065 | 432 |
val theory = PureThy.begin_theory name (map get_theory bparents); |
| 7952 | 433 |
val deps = |
434 |
if known_thy name then get_deps name |
|
| 15531 | 435 |
else (init_deps NONE (map #1 paths)); (*records additional ML files only!*) |
| 15570 | 436 |
val use_paths = List.mapPartial (fn (x, true) => SOME x | _ => NONE) paths; |
| 9451 | 437 |
|
| 15531 | 438 |
val _ = change_thys (update_node name bparents (deps, SOME (Theory.copy theory))); |
|
15158
2281784015a5
Fixed several bugs related to path specifications in theory names.
berghofe
parents:
15065
diff
changeset
|
439 |
val theory' = theory |> present dir' name bparents paths; |
| 9451 | 440 |
val _ = put_theory name (Theory.copy theory'); |
| 15570 | 441 |
val ((), theory'') = Context.pass_theory theory' (List.app (load_file false)) use_paths; |
| 9451 | 442 |
val _ = put_theory name (Theory.copy theory''); |
| 8805 | 443 |
in theory'' end; |
| 7244 | 444 |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
445 |
fun end_theory theory = |
| 7099 | 446 |
let |
447 |
val theory' = PureThy.end_theory theory; |
|
448 |
val name = PureThy.get_name theory; |
|
449 |
in put_theory name theory'; theory' end; |
|
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
450 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
451 |
|
| 6666 | 452 |
(* finish all theories *) |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
453 |
|
| 15531 | 454 |
fun finish () = change_thys (Graph.map_nodes (fn (_, entry) => (NONE, entry))); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
455 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
456 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
457 |
(* register existing theories *) |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
458 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
459 |
fun register_theory theory = |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
460 |
let |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
461 |
val name = PureThy.get_name theory; |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
462 |
val parents = Theory.parents_of theory; |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
463 |
val parent_names = map PureThy.get_name parents; |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
464 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
465 |
fun err txt bads = |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
466 |
error (loader_msg txt bads ^ "\n" ^ gen_msg "cannot register theory" [name]); |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
467 |
|
| 6666 | 468 |
val nonfinished = filter_out is_finished parent_names; |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
469 |
fun get_variant (x, y_name) = |
| 15531 | 470 |
if Theory.eq_thy (x, get_theory y_name) then NONE |
471 |
else SOME y_name; |
|
| 15570 | 472 |
val variants = List.mapPartial get_variant (parents ~~ parent_names); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
473 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
474 |
fun register G = |
| 15531 | 475 |
(Graph.new_node (name, (NONE, SOME theory)) G |
| 9327 | 476 |
handle Graph.DUP _ => err "duplicate theory entry" []) |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
477 |
|> add_deps name parent_names; |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
478 |
in |
| 6666 | 479 |
if not (null nonfinished) then err "non-finished parent theories" nonfinished |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
480 |
else if not (null variants) then err "different versions of parent theories" variants |
| 7099 | 481 |
else (change_thys register; perform Update name) |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
482 |
end; |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
483 |
|
| 15801 | 484 |
val _ = register_theory ProtoPure.thy; |
485 |
||
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
486 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
487 |
(*final declarations of this structure*) |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
488 |
val theory = get_theory; |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
489 |
val names = get_names; |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
490 |
|
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
491 |
end; |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
492 |
|
| 5209 | 493 |
structure BasicThyInfo: BASIC_THY_INFO = ThyInfo; |
494 |
open BasicThyInfo; |