check_deps: really do reload the master text if required;
authorwenzelm
Wed Aug 08 20:48:08 2007 +0200 (2007-08-08)
changeset 24186d7f267b806c9
parent 24185 cb0c4bd149a6
child 24187 8bdf5ca5871f
check_deps: really do reload the master text if required;
load_thy: more robust check of corrupted deps;
require_thy: outdate_thy if required;
tuned;
src/Pure/Thy/thy_info.ML
     1.1 --- a/src/Pure/Thy/thy_info.ML	Wed Aug 08 20:03:17 2007 +0200
     1.2 +++ b/src/Pure/Thy/thy_info.ML	Wed Aug 08 20:48:08 2007 +0200
     1.3 @@ -243,18 +243,18 @@
     1.4      SOME (SOME {update_time, ...}) => update_time < 0
     1.5    | _ => false);
     1.6  
     1.7 +fun check_unfinished name =
     1.8 +  if is_finished name then (warning (loader_msg "tried to touch finished theory" [name]); NONE)
     1.9 +  else SOME name;
    1.10 +
    1.11 +in
    1.12 +
    1.13  fun outdate_thy name =
    1.14    if is_finished name orelse is_outdated name then ()
    1.15    else CRITICAL (fn () =>
    1.16     (change_deps name (Option.map (fn {master, text, parents, files, ...} =>
    1.17      make_deps ~1 master text parents files)); perform Outdate name));
    1.18  
    1.19 -fun check_unfinished name =
    1.20 -  if is_finished name then (warning (loader_msg "tried to touch finished theory" [name]); NONE)
    1.21 -  else SOME name;
    1.22 -
    1.23 -in
    1.24 -
    1.25  fun touch_thys names =
    1.26    List.app outdate_thy (thy_graph Graph.all_succs (map_filter check_unfinished names));
    1.27  
    1.28 @@ -315,7 +315,7 @@
    1.29      val _ = priority ("Loading theory " ^ quote name ^ required_by " " initiators);
    1.30      val (pos, text, files) =
    1.31        (case get_deps name of
    1.32 -        SOME {master = SOME ((master_path, _), _), text, files, ...} =>
    1.33 +        SOME {master = SOME ((master_path, _), _), text as _ :: _, files, ...} =>
    1.34            (Position.path master_path, text, files)
    1.35        | _ => error (loader_msg "corrupted dependency information" [name]));
    1.36      val _ = touch_thy name;
    1.37 @@ -352,7 +352,7 @@
    1.38        let val {master, text, imports = parents, uses = files} = ThyLoad.deps_thy dir name true
    1.39        in (false, init_deps (SOME master) text parents files, parents) end
    1.40    | SOME (deps as SOME {update_time, master, text, parents, files}) =>
    1.41 -      let val master' = SOME (ThyLoad.check_thy dir name true) in
    1.42 +      let val master' as SOME ((thy_path, _), _) = SOME (ThyLoad.check_thy dir name true) in
    1.43          if master_idents master <> master_idents master'
    1.44          then
    1.45            let val {text = text', imports = parents', uses = files', ...} =
    1.46 @@ -360,17 +360,18 @@
    1.47            in (false, init_deps master' text' parents' files', parents') end
    1.48          else
    1.49            let
    1.50 -            val checked_files = map (check_ml master') files;
    1.51 -            val current = update_time >= 0 andalso forall (is_some o snd) checked_files;
    1.52 +            val files' = map (check_ml master') files;
    1.53 +            val current = update_time >= 0 andalso forall (is_some o snd) files';
    1.54              val update_time' = if current then update_time else ~1;
    1.55 -            val deps' = SOME (make_deps update_time' master' text parents checked_files);
    1.56 +            val text' = if current then text else explode (File.read thy_path);
    1.57 +            val deps' = SOME (make_deps update_time' master' text' parents files');
    1.58            in (current, deps', parents) end
    1.59        end);
    1.60  
    1.61  in
    1.62  
    1.63  fun require_thys time initiators dir strs tasks =
    1.64 -  fold_map (require_thy time initiators dir) strs tasks |>> forall I
    1.65 +      fold_map (require_thy time initiators dir) strs tasks |>> forall I
    1.66  and require_thy time initiators dir str tasks =
    1.67    let
    1.68      val path = Path.expand (Path.explode str);
    1.69 @@ -394,6 +395,7 @@
    1.70  
    1.71            val all_current = current andalso parents_current;
    1.72            val theory = if all_current then SOME (get_theory name) else NONE;
    1.73 +          val _ = if not all_current andalso known_thy name then outdate_thy name else ();
    1.74            val _ = change_thys (new_deps name parent_names (deps, theory));
    1.75  
    1.76            val upd_time = serial ();
    1.77 @@ -460,11 +462,11 @@
    1.78  
    1.79  in
    1.80  
    1.81 -val quiet_use_thys = gen_use_thy' (require_thys false);
    1.82 -val use_thys       = gen_use_thy' (require_thys false) Path.current;
    1.83 +val use_thys_dir = gen_use_thy' (require_thys false);
    1.84 +val use_thys = use_thys_dir Path.current;
    1.85  
    1.86 -val use_thy        = gen_use_thy (require_thy false);
    1.87 -val time_use_thy   = gen_use_thy (require_thy true);
    1.88 +val use_thy = gen_use_thy (require_thy false);
    1.89 +val time_use_thy = gen_use_thy (require_thy true);
    1.90  
    1.91  end;
    1.92  
    1.93 @@ -494,7 +496,7 @@
    1.94      val parent_names = map base_name parents;
    1.95      val dir = master_dir'' (lookup_deps name);
    1.96      val _ = check_unfinished error name;
    1.97 -    val _ = if int then quiet_use_thys dir parents else ();
    1.98 +    val _ = if int then use_thys_dir dir parents else ();
    1.99      (* FIXME tmp *)
   1.100      val _ = CRITICAL (fn () =>
   1.101        ML_Context.set_context (SOME (Context.Theory (get_theory (List.last parent_names)))));