src/Pure/Thy/thy_info.ML
author wenzelm
Tue, 27 Jul 2010 22:00:26 +0200
changeset 37977 3ceccd415145
parent 37955 f87d1105e181
child 37978 548f3f165d05
permissions -rw-r--r--
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps; explicit Thy_Info.toplevel_begin_theory, which does not maintain theory loader database; Outer_Syntax.load_thy: modify Toplevel.init for theory loading, and avoid slightly odd implicit batch mode of 'theory' command; added Thy_Load.begin_theory for clarity; structure ProofGeneral.ThyLoad.add_path appears to be old ThyLoad.add_path to Proof General, but actually operates on new Thy_Load.master_path instead -- for more precise imitation of theory loader; moved some basic commands from isar_cmd.ML to isar_syn.ML; misc tuning and simplification;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
     1
(*  Title:      Pure/Thy/thy_info.ML
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
     2
    Author:     Markus Wenzel, TU Muenchen
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
     3
15801
d2f5ca3c048d superceded by Pure.thy and CPure.thy;
wenzelm
parents: 15633
diff changeset
     4
Main part of theory loader database, including handling of theory and
d2f5ca3c048d superceded by Pure.thy and CPure.thy;
wenzelm
parents: 15633
diff changeset
     5
file dependencies.
3976
wenzelm
parents: 3604
diff changeset
     6
*)
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
     7
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
     8
signature THY_INFO =
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
     9
sig
7099
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
    10
  datatype action = Update | Outdate | Remove
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
    11
  val add_hook: (action -> string -> unit) -> unit
26614
1f09a22a1027 export get_names (formerly names);
wenzelm
parents: 26494
diff changeset
    12
  val get_names: unit -> string list
7288
21ff5bb68a5c lookup_theory;
wenzelm
parents: 7267
diff changeset
    13
  val lookup_theory: string -> theory option
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    14
  val get_theory: string -> theory
24563
f2edc70f8962 export is_finished;
wenzelm
parents: 24314
diff changeset
    15
  val is_finished: string -> bool
26983
e40f28cdd19b exported master_directory;
wenzelm
parents: 26881
diff changeset
    16
  val master_directory: string -> Path.T
24080
8c67d869531b added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents: 24071
diff changeset
    17
  val loaded_files: string -> Path.T list
27495
d2bb5d61b392 moved and renamed IsarCmd.kill_theory to ThyInfo.kill_thy;
wenzelm
parents: 27345
diff changeset
    18
  val touch_thy: string -> unit
32106
d7697e311d81 maintain Future.worker_group as management data;
wenzelm
parents: 32061
diff changeset
    19
  val thy_ord: theory * theory -> order
29421
db532e37cda2 use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents: 29118
diff changeset
    20
  val remove_thy: string -> unit
db532e37cda2 use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents: 29118
diff changeset
    21
  val kill_thy: string -> unit
24057
f42665561801 removed obsolete Output.ML_errors/toplevel_errors;
wenzelm
parents: 23982
diff changeset
    22
  val use_thys: string list -> unit
f42665561801 removed obsolete Output.ML_errors/toplevel_errors;
wenzelm
parents: 23982
diff changeset
    23
  val use_thy: string -> unit
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    24
  val toplevel_begin_theory: string -> string list -> (Path.T * bool) list -> theory
37954
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
    25
  val register_thy: theory -> unit
24080
8c67d869531b added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents: 24071
diff changeset
    26
  val finish: unit -> unit
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    27
end;
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    28
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36953
diff changeset
    29
structure Thy_Info: THY_INFO =
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    30
struct
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    31
7099
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
    32
(** theory loader actions and hooks **)
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
    33
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
    34
datatype action = Update | Outdate | Remove;
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
    35
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
    36
local
32738
15bb09ca0378 explicit indication of Unsynchronized.ref;
wenzelm
parents: 32106
diff changeset
    37
  val hooks = Unsynchronized.ref ([]: (action -> string -> unit) list);
7099
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
    38
in
32738
15bb09ca0378 explicit indication of Unsynchronized.ref;
wenzelm
parents: 32106
diff changeset
    39
  fun add_hook f = CRITICAL (fn () => Unsynchronized.change hooks (cons f));
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
    40
  fun perform action name = List.app (fn f => (try (fn () => f action name) (); ())) (! hooks);
7099
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
    41
end;
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
    42
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
    43
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
    44
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    45
(** thy database **)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    46
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    47
(* messages *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    48
23871
0dd5696f58b6 removed obsolete use/update_thy_only;
wenzelm
parents: 22215
diff changeset
    49
fun loader_msg txt [] = "Theory loader: " ^ txt
0dd5696f58b6 removed obsolete use/update_thy_only;
wenzelm
parents: 22215
diff changeset
    50
  | loader_msg txt names = "Theory loader: " ^ txt ^ " " ^ commas_quote names;
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    51
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    52
val show_path = space_implode " via " o map quote;
9332
ff3a86a00ea5 tuned cycle_msg;
wenzelm
parents: 9327
diff changeset
    53
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
    54
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    55
6666
be06ed5d0b4c cleaned comments;
wenzelm
parents: 6654
diff changeset
    56
(* derived graph operations *)
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    57
9327
wenzelm
parents: 9137
diff changeset
    58
fun add_deps name parents G = Graph.add_deps_acyclic (name, parents) G
9332
ff3a86a00ea5 tuned cycle_msg;
wenzelm
parents: 9327
diff changeset
    59
  handle Graph.CYCLES namess => error (cat_lines (map cycle_msg namess));
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    60
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    61
fun new_node name parents entry =
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    62
  Graph.new_node (name, entry) #> add_deps name parents;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    63
7952
43d3e087688c quiet_update_thy: ml flag;
wenzelm
parents: 7941
diff changeset
    64
fun upd_deps name entry G =
19473
wenzelm
parents: 19305
diff changeset
    65
  fold (fn parent => Graph.del_edge (parent, name)) (Graph.imm_preds G name) G
7952
43d3e087688c quiet_update_thy: ml flag;
wenzelm
parents: 7941
diff changeset
    66
  |> Graph.map_node name (K entry);
3976
wenzelm
parents: 3604
diff changeset
    67
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
    68
fun new_deps name parents entry G =
7952
43d3e087688c quiet_update_thy: ml flag;
wenzelm
parents: 7941
diff changeset
    69
  (if can (Graph.get_node G) name then upd_deps name entry G else Graph.new_node (name, entry) G)
43d3e087688c quiet_update_thy: ml flag;
wenzelm
parents: 7941
diff changeset
    70
  |> add_deps name parents;
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    71
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    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
type deps =
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    76
 {update_time: int,               (*symbolic time of update; negative value means outdated*)
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    77
  master: (Path.T * File.ident),  (*master dependencies for thy file*)
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    78
  parents: string list};          (*source specification of parents (partially qualified)*)
23886
f40fba467384 simplified ThyLoad interfaces: only one additional directory;
wenzelm
parents: 23871
diff changeset
    79
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    80
fun make_deps update_time master parents : deps =
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    81
  {update_time = update_time, master = master, parents = parents};
23871
0dd5696f58b6 removed obsolete use/update_thy_only;
wenzelm
parents: 22215
diff changeset
    82
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    83
fun init_deps master parents = SOME (make_deps (serial ()) master parents);
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    84
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    85
fun master_dir (path, _) = Path.dir path;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    86
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
    87
fun master_dir' (d: deps option) = the_default Path.current (Option.map (Path.dir o #1 o #master) d);
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    88
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
    89
fun base_name s = Path.implode (Path.base (Path.explode s));
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
    90
7211
8e4aa9044599 fixed thy_only;
wenzelm
parents: 7191
diff changeset
    91
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    92
local
37905
wenzelm
parents: 37902
diff changeset
    93
  val database = Unsynchronized.ref (Graph.empty: (deps option * theory option) Graph.T);
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    94
in
6362
bbbea7fecb93 removed obsolete user data stuff;
wenzelm
parents: 6329
diff changeset
    95
  fun get_thys () = ! database;
32738
15bb09ca0378 explicit indication of Unsynchronized.ref;
wenzelm
parents: 32106
diff changeset
    96
  fun change_thys f = CRITICAL (fn () => Unsynchronized.change database f);
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    97
end;
5209
a69fe5a61b6c theory_of renamed to theory (and made public);
wenzelm
parents: 4975
diff changeset
    98
a69fe5a61b6c theory_of renamed to theory (and made public);
wenzelm
parents: 4975
diff changeset
    99
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   100
(* access thy graph *)
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
fun thy_graph f x = f (get_thys ()) x;
9417
c4f7c959eaee get_names: topologically sorted;
wenzelm
parents: 9332
diff changeset
   103
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   104
fun get_names () = Graph.topological_order (get_thys ());
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   105
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
(* access thy *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   108
7935
ac62465ed06c added check_known_thy, if_known_thy;
wenzelm
parents: 7910
diff changeset
   109
fun lookup_thy name =
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15158
diff changeset
   110
  SOME (thy_graph Graph.get_node name) handle Graph.UNDEF _ => NONE;
7935
ac62465ed06c added check_known_thy, if_known_thy;
wenzelm
parents: 7910
diff changeset
   111
16047
b2bf9a5cde37 tuned pretty_sg;
wenzelm
parents: 15801
diff changeset
   112
val known_thy = is_some o lookup_thy;
6211
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 get_thy name =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   115
  (case lookup_thy name of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15158
diff changeset
   116
    SOME thy => thy
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15158
diff changeset
   117
  | 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
   118
23939
e543359fe8b6 marked some CRITICAL sections;
wenzelm
parents: 23910
diff changeset
   119
fun change_thy name f = CRITICAL (fn () =>
e543359fe8b6 marked some CRITICAL sections;
wenzelm
parents: 23910
diff changeset
   120
  (get_thy name; change_thys (Graph.map_node name f)));
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   121
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   122
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   123
(* access deps *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   124
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   125
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
   126
val get_deps = #1 o get_thy;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   127
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
   128
26983
e40f28cdd19b exported master_directory;
wenzelm
parents: 26881
diff changeset
   129
val is_finished = is_none o get_deps;
e40f28cdd19b exported master_directory;
wenzelm
parents: 26881
diff changeset
   130
val master_directory = master_dir' o get_deps;
7191
fcce2387ad6d added pretend_use;
wenzelm
parents: 7099
diff changeset
   131
23871
0dd5696f58b6 removed obsolete use/update_thy_only;
wenzelm
parents: 22215
diff changeset
   132
fun get_parents name =
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   133
  thy_graph Graph.imm_preds name handle Graph.UNDEF _ =>
6654
c3686d75e9d6 Added function get_preds.
berghofe
parents: 6527
diff changeset
   134
    error (loader_msg "nothing known about theory" [name]);
c3686d75e9d6 Added function get_preds.
berghofe
parents: 6527
diff changeset
   135
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   136
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   137
(* access theory *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   138
7687
3383b8223e46 fixed lookup_theory;
wenzelm
parents: 7589
diff changeset
   139
fun lookup_theory name =
3383b8223e46 fixed lookup_theory;
wenzelm
parents: 7589
diff changeset
   140
  (case lookup_thy name of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15158
diff changeset
   141
    SOME (_, SOME thy) => SOME thy
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15158
diff changeset
   142
  | _ => NONE);
7288
21ff5bb68a5c lookup_theory;
wenzelm
parents: 7267
diff changeset
   143
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   144
fun get_theory name =
7288
21ff5bb68a5c lookup_theory;
wenzelm
parents: 7267
diff changeset
   145
  (case lookup_theory name of
23871
0dd5696f58b6 removed obsolete use/update_thy_only;
wenzelm
parents: 22215
diff changeset
   146
    SOME theory => theory
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   147
  | _ => error (loader_msg "undefined theory entry for" [name]));
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   148
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37942
diff changeset
   149
fun loaded_files name =
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37942
diff changeset
   150
  (case get_deps name of
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37942
diff changeset
   151
    NONE => []
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   152
  | SOME {master = (thy_path, _), ...} => thy_path :: Thy_Load.loaded_files (get_theory name));
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37942
diff changeset
   153
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   154
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   155
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   156
(** thy operations **)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   157
24151
255f76dcc16b replaced outdated flag by update_time (multithreading-safe presentation order);
wenzelm
parents: 24133
diff changeset
   158
(* maintain update_time *)
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   159
7099
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
   160
local
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
   161
6241
d3c6184ca6c5 time_use made pervasive;
wenzelm
parents: 6233
diff changeset
   162
fun is_outdated name =
d3c6184ca6c5 time_use made pervasive;
wenzelm
parents: 6233
diff changeset
   163
  (case lookup_deps name of
24151
255f76dcc16b replaced outdated flag by update_time (multithreading-safe presentation order);
wenzelm
parents: 24133
diff changeset
   164
    SOME (SOME {update_time, ...}) => update_time < 0
6241
d3c6184ca6c5 time_use made pervasive;
wenzelm
parents: 6233
diff changeset
   165
  | _ => false);
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   166
25013
bf4f7571407f added generic provide_file;
wenzelm
parents: 24696
diff changeset
   167
fun unfinished name =
24186
d7f267b806c9 check_deps: really do reload the master text if required;
wenzelm
parents: 24175
diff changeset
   168
  if is_finished name then (warning (loader_msg "tried to touch finished theory" [name]); NONE)
d7f267b806c9 check_deps: really do reload the master text if required;
wenzelm
parents: 24175
diff changeset
   169
  else SOME name;
d7f267b806c9 check_deps: really do reload the master text if required;
wenzelm
parents: 24175
diff changeset
   170
d7f267b806c9 check_deps: really do reload the master text if required;
wenzelm
parents: 24175
diff changeset
   171
in
d7f267b806c9 check_deps: really do reload the master text if required;
wenzelm
parents: 24175
diff changeset
   172
6241
d3c6184ca6c5 time_use made pervasive;
wenzelm
parents: 6233
diff changeset
   173
fun outdate_thy name =
7099
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
   174
  if is_finished name orelse is_outdated name then ()
23939
e543359fe8b6 marked some CRITICAL sections;
wenzelm
parents: 23910
diff changeset
   175
  else CRITICAL (fn () =>
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   176
   (change_deps name (Option.map (fn {master, parents, ...} =>
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   177
    make_deps ~1 master parents)); perform Outdate name));
7099
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
   178
7910
e54db490c537 added known_thy;
wenzelm
parents: 7892
diff changeset
   179
fun touch_thys names =
25013
bf4f7571407f added generic provide_file;
wenzelm
parents: 24696
diff changeset
   180
  List.app outdate_thy (thy_graph Graph.all_succs (map_filter unfinished names));
7910
e54db490c537 added known_thy;
wenzelm
parents: 7892
diff changeset
   181
e54db490c537 added known_thy;
wenzelm
parents: 7892
diff changeset
   182
fun touch_thy name = touch_thys [name];
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   183
7099
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
   184
end;
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   185
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   186
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   187
(* abstract update time *)
32106
d7697e311d81 maintain Future.worker_group as management data;
wenzelm
parents: 32061
diff changeset
   188
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   189
structure Update_Time = Theory_Data
32106
d7697e311d81 maintain Future.worker_group as management data;
wenzelm
parents: 32061
diff changeset
   190
(
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   191
  type T = int;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   192
  val empty = 0;
32106
d7697e311d81 maintain Future.worker_group as management data;
wenzelm
parents: 32061
diff changeset
   193
  fun extend _ = empty;
33522
737589bb9bb8 adapted Theory_Data;
wenzelm
parents: 32814
diff changeset
   194
  fun merge _ = empty;
32106
d7697e311d81 maintain Future.worker_group as management data;
wenzelm
parents: 32061
diff changeset
   195
);
d7697e311d81 maintain Future.worker_group as management data;
wenzelm
parents: 32061
diff changeset
   196
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   197
val thy_ord = int_ord o pairself Update_Time.get;
29434
3f49ae779bdd remove_thy: perform PureThy.cancel_proofs;
wenzelm
parents: 29429
diff changeset
   198
3f49ae779bdd remove_thy: perform PureThy.cancel_proofs;
wenzelm
parents: 29429
diff changeset
   199
29421
db532e37cda2 use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents: 29118
diff changeset
   200
(* remove theory *)
db532e37cda2 use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents: 29118
diff changeset
   201
db532e37cda2 use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents: 29118
diff changeset
   202
fun remove_thy name =
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   203
  if is_finished name then error (loader_msg "cannot change finished theory" [name])
29421
db532e37cda2 use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents: 29118
diff changeset
   204
  else
29434
3f49ae779bdd remove_thy: perform PureThy.cancel_proofs;
wenzelm
parents: 29429
diff changeset
   205
    let
3f49ae779bdd remove_thy: perform PureThy.cancel_proofs;
wenzelm
parents: 29429
diff changeset
   206
      val succs = thy_graph Graph.all_succs [name];
3f49ae779bdd remove_thy: perform PureThy.cancel_proofs;
wenzelm
parents: 29429
diff changeset
   207
      val _ = priority (loader_msg "removing" succs);
3f49ae779bdd remove_thy: perform PureThy.cancel_proofs;
wenzelm
parents: 29429
diff changeset
   208
      val _ = CRITICAL (fn () =>
3f49ae779bdd remove_thy: perform PureThy.cancel_proofs;
wenzelm
parents: 29429
diff changeset
   209
        (List.app (perform Remove) succs; change_thys (Graph.del_nodes succs)));
3f49ae779bdd remove_thy: perform PureThy.cancel_proofs;
wenzelm
parents: 29429
diff changeset
   210
    in () end;
29421
db532e37cda2 use_thys: perform consolidate_thy on loaded theories, which removes failed nodes in post-hoc fashion;
wenzelm
parents: 29118
diff changeset
   211
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   212
fun kill_thy name =
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   213
  if known_thy name then remove_thy name
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   214
  else ();
7099
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
   215
8142ccd13963 added update_thy_only;
wenzelm
parents: 7066
diff changeset
   216
24209
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   217
(* scheduling loader tasks *)
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   218
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   219
datatype task =
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   220
  Task of string list * (theory list -> (theory * (unit -> unit))) |
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   221
  Finished of theory;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   222
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   223
fun task_finished (Task _) = false
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   224
  | task_finished (Finished _) = true;
24209
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   225
29118
8f2481aa363d removed old scheduler;
wenzelm
parents: 29088
diff changeset
   226
local
8f2481aa363d removed old scheduler;
wenzelm
parents: 29088
diff changeset
   227
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   228
fun schedule_seq task_graph =
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   229
  ((Graph.topological_order task_graph, Symtab.empty) |-> fold (fn name => fn tab =>
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   230
    (case Graph.get_node task_graph name of
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   231
      Task (parents, body) =>
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   232
        let
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   233
          val (thy, after_load) = body (map (the o Symtab.lookup tab) parents);
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   234
          val _ = after_load ();
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   235
        in Symtab.update (name, thy) tab end
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   236
    | Finished thy => Symtab.update (name, thy) tab))) |> ignore;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   237
32814
81897d30b97f added Task_Queue.depend (again) -- light-weight version for transitive graph;
wenzelm
parents: 32794
diff changeset
   238
fun schedule_futures task_graph = uninterruptible (fn _ => fn () =>
28194
c6dad24124f1 added future_scheduler (default false);
wenzelm
parents: 28126
diff changeset
   239
  let
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   240
    val tasks = Graph.topological_order task_graph;
32061
11f8ee55662d parallel_proofs: more fine-grained control with optional parallel checking of nested Isar proofs;
wenzelm
parents: 31542
diff changeset
   241
    val par_proofs = ! parallel_proofs >= 1;
29437
a96236886804 schedule_futures: save memory for non-parallel proofs, by applying after_load as soon as possible here;
wenzelm
parents: 29434
diff changeset
   242
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   243
    val futures = (tasks, Symtab.empty) |-> fold (fn name => fn tab =>
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   244
      (case Graph.get_node task_graph name of
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   245
        Task (parents, body) =>
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   246
          let
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   247
            val get = the o Symtab.lookup tab;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   248
            val deps = map (`get) (Graph.imm_preds task_graph name);
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   249
            fun failed (future, parent) = if can Future.join future then NONE else SOME parent;
29000
5e03bc760355 improved future_schedule: more robust handling of failed parents (explicit join), final join of all futures, including Exn.release_all;
wenzelm
parents: 28980
diff changeset
   250
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   251
            val future = Future.fork_deps (map #1 deps) (fn () =>
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   252
              (case map_filter failed deps of
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   253
                [] => body (map (#1 o Future.join o get) parents)
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   254
              | bad => error (loader_msg
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   255
                  ("failed to load " ^ quote name ^ " (unresolved " ^ commas_quote bad ^ ")") [])));
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   256
            val future' =
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   257
              if par_proofs then future
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   258
              else Future.map (fn (thy, after_load) => (after_load (); (thy, I))) future;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   259
          in Symtab.update (name, future') tab end
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   260
      | Finished thy => Symtab.update (name, Future.value (thy, I)) tab));
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   261
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   262
    val exns = tasks |> maps (fn name =>
29429
a6c641f08af7 schedule_futures: tuned final consolidation, explicit after_load phase;
wenzelm
parents: 29421
diff changeset
   263
      let
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   264
        val (thy, after_load) = Future.join (the (Symtab.lookup futures name));
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   265
        val _ = PureThy.join_proofs thy;
29429
a6c641f08af7 schedule_futures: tuned final consolidation, explicit after_load phase;
wenzelm
parents: 29421
diff changeset
   266
        val _ = after_load ();
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   267
      in [] end handle exn => [exn]) |> rev;
29429
a6c641f08af7 schedule_futures: tuned final consolidation, explicit after_load phase;
wenzelm
parents: 29421
diff changeset
   268
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   269
    val _ = Exn.release_all (map Exn.Exn exns);
34260
2524c1bbd087 kill failed theories in reverse order -- avoids cascaded warnings;
wenzelm
parents: 33522
diff changeset
   270
  in () end) ();
29429
a6c641f08af7 schedule_futures: tuned final consolidation, explicit after_load phase;
wenzelm
parents: 29421
diff changeset
   271
24209
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   272
in
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   273
32794
7b100d30eb32 eliminated redundant bindings;
wenzelm
parents: 32738
diff changeset
   274
fun schedule_tasks tasks =
29118
8f2481aa363d removed old scheduler;
wenzelm
parents: 29088
diff changeset
   275
  if not (Multithreading.enabled ()) then schedule_seq tasks
8f2481aa363d removed old scheduler;
wenzelm
parents: 29088
diff changeset
   276
  else if Multithreading.self_critical () then
24209
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   277
     (warning (loader_msg "no multithreading within critical section" []);
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   278
      schedule_seq tasks)
29118
8f2481aa363d removed old scheduler;
wenzelm
parents: 29088
diff changeset
   279
  else schedule_futures tasks;
24209
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   280
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   281
end;
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   282
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   283
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   284
(* require_thy -- checking database entries wrt. the file-system *)
15065
9feac0b7f935 Some changes to allow qualified theory import.
berghofe
parents: 14981
diff changeset
   285
7211
8e4aa9044599 fixed thy_only;
wenzelm
parents: 7191
diff changeset
   286
local
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   287
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   288
fun required_by _ [] = ""
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   289
  | required_by s initiators = s ^ "(required by " ^ show_path (rev initiators) ^ ")";
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   290
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   291
fun load_thy initiators (deps: deps) text dir name parent_thys =
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   292
  let
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   293
    val _ = kill_thy name;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   294
    val _ = priority ("Loading theory " ^ quote name ^ required_by " " initiators);
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   295
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   296
    val {update_time, master = (thy_path, _), ...} = deps;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   297
    val pos = Path.position thy_path;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   298
    val uses =
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   299
      map (apfst Path.explode) (#3 (Thy_Header.read pos (Source.of_string_limited 8000 text)));
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   300
    fun init () =
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   301
      Thy_Load.begin_theory dir name parent_thys uses
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   302
      |> Present.begin_theory update_time dir uses
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   303
      |> Update_Time.put update_time;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   304
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   305
    val (after_load, theory) = Outer_Syntax.load_thy name init pos text;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   306
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   307
    val parent_names = map Context.theory_name parent_thys;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   308
    fun after_load' () =
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   309
     (after_load ();
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   310
      CRITICAL (fn () =>
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   311
        (change_thys (new_node name parent_names (SOME deps, SOME theory));
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   312
          perform Update name)));
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   313
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   314
  in (theory, after_load') end;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   315
24175
38a15a3a1aad theory loader: removed obsolete update_thy (coincides with use_thy);
wenzelm
parents: 24151
diff changeset
   316
fun check_deps dir name =
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   317
  (case lookup_deps name of
23893
8babfcaaf129 deps: maintain source specification of parents (prevents repeated ThyLoad.deps_thy);
wenzelm
parents: 23886
diff changeset
   318
    SOME NONE => (true, NONE, get_parents name)
8babfcaaf129 deps: maintain source specification of parents (prevents repeated ThyLoad.deps_thy);
wenzelm
parents: 23886
diff changeset
   319
  | NONE =>
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   320
      let val {master, imports = parents, ...} = Thy_Load.deps_thy dir name
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   321
      in (false, init_deps master parents, parents) end
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   322
  | SOME (SOME {update_time, master, parents}) =>
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   323
      let val master' = Thy_Load.check_thy dir name in
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   324
        if #2 master <> #2 master' then
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   325
          let val {imports = parents', ...} = Thy_Load.deps_thy dir name;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   326
          in (false, init_deps master' parents', parents') end
24175
38a15a3a1aad theory loader: removed obsolete update_thy (coincides with use_thy);
wenzelm
parents: 24151
diff changeset
   327
        else
38a15a3a1aad theory loader: removed obsolete update_thy (coincides with use_thy);
wenzelm
parents: 24151
diff changeset
   328
          let
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37942
diff changeset
   329
            val current =
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37942
diff changeset
   330
              (case lookup_theory name of
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37942
diff changeset
   331
                NONE => false
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37942
diff changeset
   332
              | SOME theory => update_time >= 0 andalso Thy_Load.all_current theory);
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   333
            val update_time' = if current then update_time else serial ();
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   334
            val deps' = SOME (make_deps update_time' master' parents);
24175
38a15a3a1aad theory loader: removed obsolete update_thy (coincides with use_thy);
wenzelm
parents: 24151
diff changeset
   335
          in (current, deps', parents) end
38a15a3a1aad theory loader: removed obsolete update_thy (coincides with use_thy);
wenzelm
parents: 24151
diff changeset
   336
      end);
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   337
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   338
in
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   339
37873
66d90b2b87bc eliminated old time_use/time_use_thy variants -- timing is implicitly controlled via Output.timing;
wenzelm
parents: 37871
diff changeset
   340
fun require_thys initiators dir strs tasks =
66d90b2b87bc eliminated old time_use/time_use_thy variants -- timing is implicitly controlled via Output.timing;
wenzelm
parents: 37871
diff changeset
   341
      fold_map (require_thy initiators dir) strs tasks |>> forall I
66d90b2b87bc eliminated old time_use/time_use_thy variants -- timing is implicitly controlled via Output.timing;
wenzelm
parents: 37871
diff changeset
   342
and require_thy initiators dir str tasks =
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   343
  let
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 20664
diff changeset
   344
    val path = Path.expand (Path.explode str);
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 20664
diff changeset
   345
    val name = Path.implode (Path.base path);
23893
8babfcaaf129 deps: maintain source specification of parents (prevents repeated ThyLoad.deps_thy);
wenzelm
parents: 23886
diff changeset
   346
    val dir' = Path.append dir (Path.dir path);
23871
0dd5696f58b6 removed obsolete use/update_thy_only;
wenzelm
parents: 22215
diff changeset
   347
    val _ = member (op =) initiators name andalso error (cycle_msg initiators);
7066
febce8eee487 require_thy: fixed performance leak;
wenzelm
parents: 6900
diff changeset
   348
  in
32794
7b100d30eb32 eliminated redundant bindings;
wenzelm
parents: 32738
diff changeset
   349
    (case try (Graph.get_node tasks) name of
24209
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   350
      SOME task => (task_finished task, tasks)
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   351
    | NONE =>
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   352
        let
24175
38a15a3a1aad theory loader: removed obsolete update_thy (coincides with use_thy);
wenzelm
parents: 24151
diff changeset
   353
          val (current, deps, parents) = check_deps dir' name
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   354
            handle ERROR msg => cat_error msg
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   355
              (loader_msg "the error(s) above occurred while examining theory" [name] ^
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   356
                required_by "\n" initiators);
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   357
          val parent_names = map base_name parents;
23871
0dd5696f58b6 removed obsolete use/update_thy_only;
wenzelm
parents: 22215
diff changeset
   358
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   359
          val (parents_current, tasks') =
37873
66d90b2b87bc eliminated old time_use/time_use_thy variants -- timing is implicitly controlled via Output.timing;
wenzelm
parents: 37871
diff changeset
   360
            require_thys (name :: initiators) (Path.append dir (master_dir' deps)) parents tasks;
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   361
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   362
          val all_current = current andalso parents_current;
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   363
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   364
          (* FIXME ?? *)
24186
d7f267b806c9 check_deps: really do reload the master text if required;
wenzelm
parents: 24175
diff changeset
   365
          val _ = if not all_current andalso known_thy name then outdate_thy name else ();
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   366
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   367
          val task =
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   368
            if all_current then Finished (get_theory name)
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   369
            else
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   370
              let
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   371
                val SOME {master = (thy_path, _), ...} = deps;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   372
                val text = File.read thy_path;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   373
              in Task (parent_names, load_thy initiators (the deps) text dir' name) end;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   374
        in (all_current, new_node name parent_names task tasks') end)
7066
febce8eee487 require_thy: fixed performance leak;
wenzelm
parents: 6900
diff changeset
   375
  end;
6484
3f098b0ec683 use_thy etc.: may specify path prefix, which is temporarily used as load path;
wenzelm
parents: 6389
diff changeset
   376
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   377
end;
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   378
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   379
24209
8a2c8d623e43 schedule: misc cleanup, more precise task model;
wenzelm
parents: 24190
diff changeset
   380
(* use_thy etc. *)
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   381
37873
66d90b2b87bc eliminated old time_use/time_use_thy variants -- timing is implicitly controlled via Output.timing;
wenzelm
parents: 37871
diff changeset
   382
fun use_thys_dir dir arg =
66d90b2b87bc eliminated old time_use/time_use_thy variants -- timing is implicitly controlled via Output.timing;
wenzelm
parents: 37871
diff changeset
   383
  schedule_tasks (snd (require_thys [] dir arg Graph.empty));
23967
92130b24e87f require_thy: explicit tasks graph;
wenzelm
parents: 23939
diff changeset
   384
37873
66d90b2b87bc eliminated old time_use/time_use_thy variants -- timing is implicitly controlled via Output.timing;
wenzelm
parents: 37871
diff changeset
   385
val use_thys = use_thys_dir Path.current;
37949
48a874444164 moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents: 37942
diff changeset
   386
val use_thy = use_thys o single;
7211
8e4aa9044599 fixed thy_only;
wenzelm
parents: 7191
diff changeset
   387
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   388
37953
ddc3b72f9a42 simplified handling of theory begin/end wrt. toplevel and theory loader;
wenzelm
parents: 37949
diff changeset
   389
(* begin theory *)
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   390
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   391
fun toplevel_begin_theory name imports uses =
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   392
  let
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   393
    val dir = Thy_Load.get_master_path ();
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   394
    val _ = kill_thy name;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   395
    val _ = use_thys_dir dir imports;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   396
    val parents = map (get_theory o base_name) imports;
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   397
  in Thy_Load.begin_theory dir name parents uses end;
7244
ad714526c23e may_load_file;
wenzelm
parents: 7223
diff changeset
   398
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   399
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   400
(* register theory *)
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   401
37954
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   402
fun register_thy theory =
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   403
  let
16454
af39c6510b86 removed obsolete theory_of_sign, theory_of_thm;
wenzelm
parents: 16047
diff changeset
   404
    val name = Context.theory_name theory;
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   405
    (* FIXME kill_thy name (??) *)
37954
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   406
    val _ = priority ("Registering theory " ^ quote name);
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   407
    val parent_names = map Context.theory_name (Theory.parents_of theory);
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   408
    val _ = map get_theory parent_names;
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   409
37954
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   410
    val master = Thy_Load.check_thy (Thy_Load.master_directory theory) name;
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   411
    val update_time = Update_Time.get theory;
37954
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   412
    val parents =
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   413
      (case lookup_deps name of
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   414
        SOME (SOME {parents, ...}) => parents
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   415
      | _ => parent_names);
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37955
diff changeset
   416
    val deps = make_deps update_time master parents;
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   417
  in
37954
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   418
    CRITICAL (fn () =>
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   419
     (if known_thy name then
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   420
        (List.app remove_thy (thy_graph Graph.imm_succs name);
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   421
          change_thys (Graph.del_nodes [name]))
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   422
      else ();
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   423
      change_thys (new_deps name parents (SOME deps, SOME theory));
a2e73df0b1e0 simplified/clarified register_thy: more precise treatment of new dependencies, remove descendants;
wenzelm
parents: 37953
diff changeset
   424
      perform Update name))
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   425
  end;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   426
24080
8c67d869531b added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents: 24071
diff changeset
   427
8c67d869531b added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents: 24071
diff changeset
   428
(* finish all theories *)
8c67d869531b added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents: 24071
diff changeset
   429
28976
53c96f58e38f future_scheduler: no global task group, exceptions via collective join;
wenzelm
parents: 28844
diff changeset
   430
fun finish () = change_thys (Graph.map_nodes (fn (_, entry) => (NONE, entry)));
24080
8c67d869531b added register_thy (replaces pretend_use_thy_only and really flag);
wenzelm
parents: 24071
diff changeset
   431
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   432
end;