237 fun commit () = update_thy deps theory; |
237 fun commit () = update_thy deps theory; |
238 in (theory, present, commit) end; |
238 in (theory, present, commit) end; |
239 |
239 |
240 fun check_deps dir name = |
240 fun check_deps dir name = |
241 (case lookup_deps name of |
241 (case lookup_deps name of |
242 SOME NONE => (true, NONE, get_imports name, [], []) |
242 SOME NONE => (true, NONE, Position.none, get_imports name, [], []) |
243 | NONE => |
243 | NONE => |
244 let val {master, text, imports, keywords, uses} = Thy_Load.check_thy dir name |
244 let val {master, text, theory_pos, imports, keywords, uses} = Thy_Load.check_thy dir name |
245 in (false, SOME (make_deps master imports, text), imports, uses, keywords) end |
245 in (false, SOME (make_deps master imports, text), theory_pos, imports, uses, keywords) end |
246 | SOME (SOME {master, ...}) => |
246 | SOME (SOME {master, ...}) => |
247 let |
247 let |
248 val {master = master', text = text', imports = imports', uses = uses', keywords = keywords'} |
248 val {master = master', text = text', theory_pos = theory_pos', imports = imports', |
249 = Thy_Load.check_thy dir name; |
249 uses = uses', keywords = keywords'} = Thy_Load.check_thy dir name; |
250 val deps' = SOME (make_deps master' imports', text'); |
250 val deps' = SOME (make_deps master' imports', text'); |
251 val current = |
251 val current = |
252 #2 master = #2 master' andalso |
252 #2 master = #2 master' andalso |
253 (case lookup_theory name of |
253 (case lookup_theory name of |
254 NONE => false |
254 NONE => false |
255 | SOME theory => Thy_Load.load_current theory); |
255 | SOME theory => Thy_Load.load_current theory); |
256 in (current, deps', imports', uses', keywords') end); |
256 in (current, deps', theory_pos', imports', uses', keywords') end); |
257 |
257 |
258 in |
258 in |
259 |
259 |
260 fun require_thys initiators dir strs tasks = |
260 fun require_thys initiators dir strs tasks = |
261 fold_map (require_thy initiators dir) strs tasks |>> forall I |
261 fold_map (require_thy initiators dir) strs tasks |>> forall I |
262 and require_thy initiators dir (str, pos) tasks = |
262 and require_thy initiators dir (str, require_pos) tasks = |
263 let |
263 let |
264 val path = Path.expand (Path.explode str); |
264 val path = Path.expand (Path.explode str); |
265 val name = Path.implode (Path.base path); |
265 val name = Path.implode (Path.base path); |
266 in |
266 in |
267 (case try (Graph.get_node tasks) name of |
267 (case try (Graph.get_node tasks) name of |
269 | NONE => |
269 | NONE => |
270 let |
270 let |
271 val dir' = Path.append dir (Path.dir path); |
271 val dir' = Path.append dir (Path.dir path); |
272 val _ = member (op =) initiators name andalso error (cycle_msg initiators); |
272 val _ = member (op =) initiators name andalso error (cycle_msg initiators); |
273 |
273 |
274 val (current, deps, imports, uses, keywords) = check_deps dir' name |
274 val (current, deps, theory_pos, imports, uses, keywords) = check_deps dir' name |
275 handle ERROR msg => cat_error msg |
275 handle ERROR msg => cat_error msg |
276 (loader_msg "the error(s) above occurred while examining theory" [name] ^ |
276 (loader_msg "the error(s) above occurred while examining theory" [name] ^ |
277 Position.str_of pos ^ required_by "\n" initiators); |
277 Position.str_of require_pos ^ required_by "\n" initiators); |
278 |
278 |
279 val parents = map (base_name o #1) imports; |
279 val parents = map (base_name o #1) imports; |
280 val (parents_current, tasks') = |
280 val (parents_current, tasks') = |
281 require_thys (name :: initiators) |
281 require_thys (name :: initiators) |
282 (Path.append dir (master_dir (Option.map #1 deps))) imports tasks; |
282 (Path.append dir (master_dir (Option.map #1 deps))) imports tasks; |
288 (case deps of |
288 (case deps of |
289 NONE => raise Fail "Malformed deps" |
289 NONE => raise Fail "Malformed deps" |
290 | SOME (dep, text) => |
290 | SOME (dep, text) => |
291 let |
291 let |
292 val update_time = serial (); |
292 val update_time = serial (); |
293 val load = load_thy initiators update_time dep text (name, pos) uses keywords; |
293 val load = |
|
294 load_thy initiators update_time dep text (name, theory_pos) uses keywords; |
294 in Task (parents, load) end); |
295 in Task (parents, load) end); |
295 |
296 |
296 val tasks'' = new_entry name parents task tasks'; |
297 val tasks'' = new_entry name parents task tasks'; |
297 in (all_current, tasks'') end) |
298 in (all_current, tasks'') end) |
298 end; |
299 end; |