author | berghofe |
Mon, 17 May 1999 17:07:54 +0200 | |
changeset 6654 | c3686d75e9d6 |
parent 6527 | f7a7ac2b9926 |
child 6666 | be06ed5d0b4c |
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 |
|
6362 | 5 |
Theory loader database, including theory and file dependencies. |
3976 | 6 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
7 |
TODO: |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
8 |
- remove operation (GC!?); |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
9 |
- update_all operation (!?); |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
10 |
- put_theory: |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
11 |
. allow for undef entry only; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
12 |
. elim (via theory_ref); |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
13 |
- stronger handling of missing files (!?!?); |
6241 | 14 |
- register_theory: do not require final parents (!?) (no?); |
6377 | 15 |
- hooks for init, update, finish operations (!?); |
3976 | 16 |
*) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
17 |
|
5209 | 18 |
signature BASIC_THY_INFO = |
19 |
sig |
|
20 |
val theory: string -> theory |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
21 |
val theory_of_sign: Sign.sg -> theory |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
22 |
val theory_of_thm: thm -> theory |
6241 | 23 |
(*val use: string -> unit*) (*exported later*) |
24 |
val time_use: string -> unit |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
25 |
val touch_thy: string -> unit |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
26 |
val use_thy: string -> unit |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
27 |
val update_thy: string -> unit |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
28 |
val time_use_thy: string -> unit |
6527 | 29 |
val use_thy_only: string -> unit |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
30 |
end; |
5209 | 31 |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
32 |
signature THY_INFO = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
33 |
sig |
5209 | 34 |
include BASIC_THY_INFO |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
35 |
val names: unit -> string list |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
36 |
val get_theory: string -> theory |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
37 |
val put_theory: theory -> unit |
6654 | 38 |
val get_preds: string -> string list |
6241 | 39 |
val loaded_files: string -> (Path.T * File.info) list |
40 |
val load_file: bool -> Path.T -> unit |
|
6329 | 41 |
val use_path: Path.T -> unit |
6241 | 42 |
val use: string -> unit |
6329 | 43 |
val begin_theory: string -> string list -> (Path.T * bool) list -> theory |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
44 |
val end_theory: theory -> theory |
6241 | 45 |
val finalize_all: unit -> unit |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
46 |
val register_theory: theory -> unit |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
47 |
end; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
48 |
|
6362 | 49 |
structure ThyInfo: THY_INFO = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
50 |
struct |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
51 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
52 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
53 |
(** thy database **) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
54 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
55 |
(* messages *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
56 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
57 |
fun gen_msg txt [] = txt |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
58 |
| gen_msg txt names = txt ^ " " ^ commas_quote names; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
59 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
60 |
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
|
61 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
62 |
val show_path = space_implode " via " o map quote; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
63 |
fun cycle_msg name names = loader_msg ("cyclic dependency of " ^ show_path (name :: names)) []; |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
64 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
65 |
|
6241 | 66 |
(* derived graph operations *) (* FIXME more abstract (!?) *) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
67 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
68 |
fun add_deps name parents G = |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
69 |
foldl (fn (H, parent) => Graph.add_edge_acyclic (parent, name) H) (G, parents) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
70 |
handle Graph.CYCLES namess => error (cat_lines (map (cycle_msg name) namess)); |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
71 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
72 |
fun del_deps name G = (* FIXME GC (!?!?) *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
73 |
foldl (fn (H, parent) => Graph.del_edge (parent, name) H) (G, Graph.imm_preds G name); |
3976 | 74 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
75 |
fun update_node name parents entry G = |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
76 |
add_deps name parents |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
77 |
(if can (Graph.get_node G) name then del_deps name G else Graph.new_node (name, entry) G); |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
78 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
79 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
80 |
(* thy database *) |
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 |
type deps = |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
83 |
{present: bool, outdated: bool, |
6241 | 84 |
master: (Path.T * File.info) list, 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
|
85 |
|
6241 | 86 |
fun make_deps present outdated master files = |
87 |
{present = present, outdated = outdated, master = master, files = files}: deps; |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
88 |
|
6362 | 89 |
type thy = deps option * theory option; |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
90 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
91 |
local |
6362 | 92 |
val database = ref (Graph.empty: thy Graph.T); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
93 |
in |
6362 | 94 |
fun get_thys () = ! database; |
95 |
fun change_thys f = database := (f (! database)); |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
96 |
end; |
5209 | 97 |
|
98 |
||
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
99 |
(* access thy graph *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
100 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
101 |
fun thy_graph f x = f (get_thys ()) x; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
102 |
fun get_names () = map #1 (Graph.get_nodes (get_thys ())); |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
103 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
104 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
105 |
(* access thy *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
106 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
107 |
fun lookup_thy name = Some (thy_graph Graph.get_node name) handle Graph.UNDEFINED _ => None; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
108 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
109 |
fun get_thy name = |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
110 |
(case lookup_thy name of |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
111 |
Some thy => thy |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
112 |
| None => error (loader_msg "nothing known about theory" [name])); |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
113 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
114 |
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
|
115 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
116 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
117 |
(* access deps *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
118 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
119 |
val lookup_deps = apsome #1 o lookup_thy; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
120 |
val get_deps = #1 o get_thy; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
121 |
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
|
122 |
|
6241 | 123 |
fun is_final name = is_none (get_deps name); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
124 |
fun get_files name = (case get_deps name of Some {files, ...} => files | _ => []); |
6241 | 125 |
val loaded_files = mapfilter #2 o get_files; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
126 |
|
6654 | 127 |
fun get_preds name = |
128 |
(thy_graph Graph.imm_preds name) handle Graph.UNDEFINED _ => |
|
129 |
error (loader_msg "nothing known about theory" [name]); |
|
130 |
||
6211
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 theory *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
133 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
134 |
fun get_theory name = |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
135 |
(case get_thy name of |
6362 | 136 |
(_, Some theory) => theory |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
137 |
| _ => error (loader_msg "undefined theory entry for" [name])); |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
138 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
142 |
fun put_theory theory = |
6362 | 143 |
change_thy (PureThy.get_name theory) (fn (deps, _) => (deps, Some theory)); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
144 |
|
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 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
147 |
(** thy operations **) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
148 |
|
6241 | 149 |
(* maintain 'outdated' flag *) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
150 |
|
6241 | 151 |
fun is_outdated name = |
152 |
(case lookup_deps name of |
|
153 |
Some (Some {outdated, ...}) => outdated |
|
154 |
| _ => false); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
155 |
|
6241 | 156 |
fun outdate_thy name = |
157 |
if is_final name then () |
|
158 |
else change_deps name (apsome (fn {present, outdated = _, master, files} => |
|
159 |
make_deps present true master files)); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
160 |
|
6241 | 161 |
fun touch_thy name = |
162 |
if is_outdated name then () |
|
163 |
else if is_final name then warning (loader_msg "tried to touch final theory" [name]) |
|
164 |
else |
|
165 |
(case filter_out is_outdated (thy_graph Graph.all_succs [name]) \ name of |
|
166 |
[] => outdate_thy name |
|
167 |
| names => |
|
168 |
(warning (loader_msg "the following theories become out-of-date:" names); |
|
169 |
seq outdate_thy names; outdate_thy name)); |
|
170 |
||
171 |
val untouch_deps = apsome (fn {present, outdated = _, master, files}: deps => |
|
172 |
make_deps present false master files); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
173 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
174 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
175 |
(* load_thy *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
176 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
177 |
fun required_by [] = "" |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
178 |
| required_by initiators = " (required by " ^ show_path (rev initiators) ^ ")"; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
179 |
|
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
180 |
fun load_thy ml time initiators dir name parents = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
181 |
let |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
182 |
val _ = if name mem_string initiators then error (cycle_msg name (rev initiators)) else (); |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
183 |
val _ = writeln ("Loading theory " ^ quote name ^ required_by initiators); |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
184 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
185 |
val _ = seq touch_thy (thy_graph Graph.all_succs [name]); |
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
186 |
val master = ThyLoad.load_thy dir name ml time; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
187 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
188 |
val files = get_files name; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
189 |
val missing_files = mapfilter (fn (path, None) => Some (Path.pack path) | _ => None) files; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
190 |
in |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
191 |
if null missing_files then () |
6263 | 192 |
else warning (loader_msg "unresolved dependencies of theory" [name] ^ |
193 |
"\nfile(s): " ^ commas_quote missing_files); |
|
6241 | 194 |
change_deps name (fn _ => Some (make_deps true false master files)) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
195 |
end; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
196 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
197 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
198 |
(* load_file *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
199 |
|
6241 | 200 |
fun run_file path = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
201 |
let |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
202 |
fun provide name info (deps as Some {present, outdated, master, files}) = |
6263 | 203 |
if exists (equal path o #1) files then |
6241 | 204 |
Some (make_deps present outdated master (overwrite (files, (path, Some info)))) |
205 |
else (warning (loader_msg "undeclared dependency of theory" [name] ^ |
|
6389 | 206 |
" on file: " ^ quote (Path.pack path)); deps) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
207 |
| provide _ _ None = None; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
208 |
in |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
209 |
(case apsome PureThy.get_name (Context.get_context ()) of |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
210 |
None => (ThyLoad.load_file path; ()) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
211 |
| Some name => |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
212 |
if is_some (lookup_thy name) then change_deps name (provide name (ThyLoad.load_file path)) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
213 |
else (ThyLoad.load_file path; ())) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
214 |
end; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
215 |
|
6241 | 216 |
fun load_file false path = run_file path |
217 |
| load_file true path = |
|
218 |
let val name = Path.pack path in |
|
219 |
timeit (fn () => |
|
220 |
(writeln ("\n**** Starting file " ^ quote name ^ " ****"); |
|
221 |
run_file path; |
|
222 |
writeln ("**** Finished file " ^ quote name ^ " ****\n"))) |
|
223 |
end; |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
224 |
|
6329 | 225 |
val use_path = load_file false; |
226 |
val use = use_path o Path.unpack; |
|
6241 | 227 |
val time_use = load_file true o Path.unpack; |
6233 | 228 |
|
229 |
||
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
230 |
(* require_thy *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
231 |
|
6241 | 232 |
fun init_deps master files = Some (make_deps false false master (map (rpair None) files)); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
233 |
|
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
234 |
fun load_deps dir name ml = |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
235 |
let val (master, (parents, files)) = ThyLoad.deps_thy dir name ml |
6233 | 236 |
in (Some (init_deps master files), parents) end; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
237 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
238 |
fun file_current (_, None) = false |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
239 |
| file_current (path, info) = info = ThyLoad.check_file path; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
240 |
|
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
241 |
fun current_deps ml strict dir name = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
242 |
(case lookup_deps name of |
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
243 |
None => (false, load_deps dir name ml) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
244 |
| Some deps => |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
245 |
let val same_deps = (None, thy_graph Graph.imm_preds name) in |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
246 |
(case deps of |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
247 |
None => (true, same_deps) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
248 |
| Some {present, outdated, master, files} => |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
249 |
if present andalso not strict then (true, same_deps) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
250 |
else |
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
251 |
let val master' = ThyLoad.check_thy dir name ml in |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
252 |
if master <> master' then (false, load_deps dir name ml) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
253 |
else (not outdated andalso forall file_current files, same_deps) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
254 |
end) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
255 |
end); |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
256 |
|
6487 | 257 |
fun require_thy ml time strict keep_strict initiators prfx s = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
258 |
let |
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
259 |
val path = Path.expand (Path.unpack s); |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
260 |
val name = Path.pack (Path.base path); |
6487 | 261 |
val dir = Path.append prfx (Path.dir path); |
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
262 |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
263 |
val require_parent = |
6487 | 264 |
#1 o require_thy ml time (strict andalso keep_strict) keep_strict (name :: initiators) dir; |
265 |
val (current, (new_deps, parents)) = current_deps ml strict dir name handle ERROR => |
|
6241 | 266 |
error (loader_msg "The error(s) above occurred while examining theory" [name] ^ |
267 |
(if null initiators then "" else "\n" ^ required_by initiators)); |
|
6233 | 268 |
val parents_current = map require_parent parents; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
269 |
|
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
270 |
val result = |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
271 |
if current andalso forall I parents_current then true |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
272 |
else |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
273 |
((case new_deps of |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
274 |
Some deps => change_thys (update_node name parents (untouch_deps deps, None)) |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
275 |
| None => ()); |
6487 | 276 |
load_thy ml time initiators dir name parents; |
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
277 |
false); |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
278 |
in (result, name) end; |
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
279 |
|
6487 | 280 |
fun gen_use_thy f s = |
281 |
let val (_, name) = f Path.current s in Context.context (get_theory name) end; |
|
6241 | 282 |
|
283 |
val weak_use_thy = gen_use_thy (require_thy true false false false []); |
|
284 |
val use_thy = gen_use_thy (require_thy true false true false []); |
|
285 |
val update_thy = gen_use_thy (require_thy true false true true []); |
|
286 |
val time_use_thy = gen_use_thy (require_thy true true true false []); |
|
287 |
val use_thy_only = gen_use_thy (require_thy false false true false []); |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
288 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
289 |
|
6329 | 290 |
(* begin / end theory *) (* FIXME tune *) (* FIXME files vs. paths (!?!?) *) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
291 |
|
6329 | 292 |
fun begin_theory name parents paths = |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
293 |
let |
6484
3f098b0ec683
use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents:
6389
diff
changeset
|
294 |
val _ = (map Path.basic parents; seq weak_use_thy parents); |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
295 |
val theory = PureThy.begin_theory name (map get_theory parents); |
6362 | 296 |
val _ = change_thys (update_node name parents (init_deps [] [], Some theory)); |
6329 | 297 |
val use_paths = mapfilter (fn (x, true) => Some x | _ => None) paths; |
298 |
in Context.setmp (Some theory) (seq use_path) use_paths; theory end; |
|
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
299 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
300 |
fun end_theory theory = |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
301 |
let val theory' = PureThy.end_theory theory |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
302 |
in put_theory theory'; theory' end; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
303 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
304 |
|
6241 | 305 |
(* finalize entries *) |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
306 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
307 |
fun update_all () = (); (* FIXME fake *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
308 |
|
6241 | 309 |
fun finalize_all () = |
6233 | 310 |
(update_all (); 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
|
311 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
312 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
313 |
(* register existing theories *) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
314 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
315 |
fun register_theory theory = |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
316 |
let |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
317 |
val name = PureThy.get_name theory; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
318 |
val parents = Theory.parents_of theory; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
319 |
val parent_names = map PureThy.get_name parents; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
320 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
321 |
fun err txt bads = |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
322 |
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
|
323 |
|
6241 | 324 |
val nonfinal = filter_out is_final parent_names; |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
325 |
fun get_variant (x, y_name) = |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
326 |
if Theory.eq_thy (x, get_theory y_name) then None |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
327 |
else Some y_name; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
328 |
val variants = mapfilter get_variant (parents ~~ parent_names); |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
329 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
330 |
fun register G = |
6362 | 331 |
(Graph.new_node (name, (None, Some theory)) G |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
332 |
handle Graph.DUPLICATE _ => err "duplicate theory entry" []) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
333 |
|> add_deps name parent_names; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
334 |
in |
6241 | 335 |
if not (null nonfinal) then err "non-final parent theories" nonfinal |
6211
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
336 |
else if not (null variants) then err "different versions of parent theories" variants |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
337 |
else change_thys register |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
338 |
end; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
339 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
340 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
341 |
(*final declarations of this structure*) |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
342 |
val theory = get_theory; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
343 |
val names = get_names; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
344 |
|
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
345 |
end; |
43d0efafa025
Theory loader database: theory and file dependencies, theory values
wenzelm
parents:
5211
diff
changeset
|
346 |
|
5209 | 347 |
structure BasicThyInfo: BASIC_THY_INFO = ThyInfo; |
348 |
open BasicThyInfo; |