doc-src/IsarImplementation/Thy/Integration.thy
author wenzelm
Mon, 31 May 2010 21:06:57 +0200
changeset 37216 3165bc303f66
parent 34998 fd90fb0903c0
child 37306 2bde06a2a706
permissions -rw-r--r--
modernized some structure names, keeping a few legacy aliases;
wenzelm@30081
     1
theory Integration
wenzelm@30081
     2
imports Base
wenzelm@30081
     3
begin
wenzelm@18537
     4
wenzelm@18537
     5
chapter {* System integration *}
wenzelm@18537
     6
wenzelm@20447
     7
section {* Isar toplevel \label{sec:isar-toplevel} *}
wenzelm@18537
     8
wenzelm@18537
     9
text {* The Isar toplevel may be considered the centeral hub of the
wenzelm@18537
    10
  Isabelle/Isar system, where all key components and sub-systems are
wenzelm@20451
    11
  integrated into a single read-eval-print loop of Isar commands.  We
wenzelm@20451
    12
  shall even incorporate the existing {\ML} toplevel of the compiler
wenzelm@18537
    13
  and run-time system (cf.\ \secref{sec:ML-toplevel}).
wenzelm@18537
    14
wenzelm@20451
    15
  Isabelle/Isar departs from the original ``LCF system architecture''
wenzelm@18537
    16
  where {\ML} was really The Meta Language for defining theories and
wenzelm@20451
    17
  conducting proofs.  Instead, {\ML} now only serves as the
wenzelm@18537
    18
  implementation language for the system (and user extensions), while
wenzelm@20451
    19
  the specific Isar toplevel supports the concepts of theory and proof
wenzelm@20451
    20
  development natively.  This includes the graph structure of theories
wenzelm@20451
    21
  and the block structure of proofs, support for unlimited undo,
wenzelm@20451
    22
  facilities for tracing, debugging, timing, profiling etc.
wenzelm@18537
    23
wenzelm@18537
    24
  \medskip The toplevel maintains an implicit state, which is
wenzelm@18537
    25
  transformed by a sequence of transitions -- either interactively or
wenzelm@18537
    26
  in batch-mode.  In interactive mode, Isar state transitions are
wenzelm@18537
    27
  encapsulated as safe transactions, such that both failure and undo
wenzelm@18537
    28
  are handled conveniently without destroying the underlying draft
wenzelm@18537
    29
  theory (cf.~\secref{sec:context-theory}).  In batch mode,
wenzelm@20451
    30
  transitions operate in a linear (destructive) fashion, such that
wenzelm@20451
    31
  error conditions abort the present attempt to construct a theory or
wenzelm@20451
    32
  proof altogether.
wenzelm@18537
    33
wenzelm@18537
    34
  The toplevel state is a disjoint sum of empty @{text toplevel}, or
wenzelm@18537
    35
  @{text theory}, or @{text proof}.  On entering the main Isar loop we
wenzelm@18537
    36
  start with an empty toplevel.  A theory is commenced by giving a
wenzelm@18537
    37
  @{text \<THEORY>} header; within a theory we may issue theory
wenzelm@20025
    38
  commands such as @{text \<DEFINITION>}, or state a @{text
wenzelm@20025
    39
  \<THEOREM>} to be proven.  Now we are within a proof state, with a
wenzelm@20025
    40
  rich collection of Isar proof commands for structured proof
wenzelm@18537
    41
  composition, or unstructured proof scripts.  When the proof is
wenzelm@18537
    42
  concluded we get back to the theory, which is then updated by
wenzelm@18537
    43
  storing the resulting fact.  Further theory declarations or theorem
wenzelm@18537
    44
  statements with proofs may follow, until we eventually conclude the
wenzelm@18537
    45
  theory development by issuing @{text \<END>}.  The resulting theory
wenzelm@18537
    46
  is then stored within the theory database and we are back to the
wenzelm@18537
    47
  empty toplevel.
wenzelm@18537
    48
wenzelm@18537
    49
  In addition to these proper state transformations, there are also
wenzelm@18537
    50
  some diagnostic commands for peeking at the toplevel state without
wenzelm@18537
    51
  modifying it (e.g.\ \isakeyword{thm}, \isakeyword{term},
wenzelm@18537
    52
  \isakeyword{print-cases}).
wenzelm@18537
    53
*}
wenzelm@18537
    54
wenzelm@18537
    55
text %mlref {*
wenzelm@18537
    56
  \begin{mldecls}
wenzelm@18537
    57
  @{index_ML_type Toplevel.state} \\
wenzelm@18537
    58
  @{index_ML Toplevel.UNDEF: "exn"} \\
wenzelm@18537
    59
  @{index_ML Toplevel.is_toplevel: "Toplevel.state -> bool"} \\
wenzelm@18537
    60
  @{index_ML Toplevel.theory_of: "Toplevel.state -> theory"} \\
wenzelm@18537
    61
  @{index_ML Toplevel.proof_of: "Toplevel.state -> Proof.state"} \\
wenzelm@32833
    62
  @{index_ML Toplevel.debug: "bool Unsynchronized.ref"} \\
wenzelm@32833
    63
  @{index_ML Toplevel.timing: "bool Unsynchronized.ref"} \\
wenzelm@32833
    64
  @{index_ML Toplevel.profiling: "int Unsynchronized.ref"} \\
wenzelm@18537
    65
  \end{mldecls}
wenzelm@18537
    66
wenzelm@18537
    67
  \begin{description}
wenzelm@18537
    68
wenzelm@18537
    69
  \item @{ML_type Toplevel.state} represents Isar toplevel states,
wenzelm@20451
    70
  which are normally manipulated through the concept of toplevel
wenzelm@20451
    71
  transitions only (\secref{sec:toplevel-transition}).  Also note that
wenzelm@20451
    72
  a raw toplevel state is subject to the same linearity restrictions
wenzelm@20451
    73
  as a theory context (cf.~\secref{sec:context-theory}).
wenzelm@18537
    74
wenzelm@18537
    75
  \item @{ML Toplevel.UNDEF} is raised for undefined toplevel
wenzelm@20451
    76
  operations.  Many operations work only partially for certain cases,
wenzelm@20451
    77
  since @{ML_type Toplevel.state} is a sum type.
wenzelm@18537
    78
wenzelm@20451
    79
  \item @{ML Toplevel.is_toplevel}~@{text "state"} checks for an empty
wenzelm@20451
    80
  toplevel state.
wenzelm@18537
    81
wenzelm@34998
    82
  \item @{ML Toplevel.theory_of}~@{text "state"} selects the
wenzelm@34998
    83
  background theory of @{text "state"}, raises @{ML Toplevel.UNDEF}
wenzelm@34998
    84
  for an empty toplevel state.
wenzelm@18537
    85
wenzelm@20451
    86
  \item @{ML Toplevel.proof_of}~@{text "state"} selects the Isar proof
wenzelm@20451
    87
  state if available, otherwise raises @{ML Toplevel.UNDEF}.
wenzelm@18537
    88
wenzelm@32833
    89
  \item @{ML "Toplevel.debug := true"} makes the toplevel print further
wenzelm@18537
    90
  details about internal error conditions, exceptions being raised
wenzelm@18537
    91
  etc.
wenzelm@18537
    92
wenzelm@32833
    93
  \item @{ML "Toplevel.timing := true"} makes the toplevel print timing
wenzelm@18537
    94
  information for each Isar command being executed.
wenzelm@18537
    95
wenzelm@20451
    96
  \item @{ML Toplevel.profiling}~@{verbatim ":="}~@{text "n"} controls
wenzelm@20451
    97
  low-level profiling of the underlying {\ML} runtime system.  For
wenzelm@20451
    98
  Poly/ML, @{text "n = 1"} means time and @{text "n = 2"} space
wenzelm@20451
    99
  profiling.
wenzelm@18537
   100
wenzelm@18537
   101
  \end{description}
wenzelm@18537
   102
*}
wenzelm@18537
   103
wenzelm@18537
   104
wenzelm@20451
   105
subsection {* Toplevel transitions \label{sec:toplevel-transition} *}
wenzelm@18537
   106
wenzelm@20451
   107
text {*
wenzelm@20451
   108
  An Isar toplevel transition consists of a partial function on the
wenzelm@20451
   109
  toplevel state, with additional information for diagnostics and
wenzelm@20451
   110
  error reporting: there are fields for command name, source position,
wenzelm@20451
   111
  optional source text, as well as flags for interactive-only commands
wenzelm@20451
   112
  (which issue a warning in batch-mode), printing of result state,
wenzelm@20451
   113
  etc.
wenzelm@18537
   114
wenzelm@20451
   115
  The operational part is represented as the sequential union of a
wenzelm@20451
   116
  list of partial functions, which are tried in turn until the first
wenzelm@20475
   117
  one succeeds.  This acts like an outer case-expression for various
wenzelm@34998
   118
  alternative state transitions.  For example, \isakeyword{qed} works
wenzelm@20475
   119
  differently for a local proofs vs.\ the global ending of the main
wenzelm@20475
   120
  proof.
wenzelm@18537
   121
wenzelm@18537
   122
  Toplevel transitions are composed via transition transformers.
wenzelm@18537
   123
  Internally, Isar commands are put together from an empty transition
wenzelm@34998
   124
  extended by name and source position.  It is then left to the
wenzelm@34998
   125
  individual command parser to turn the given concrete syntax into a
wenzelm@34998
   126
  suitable transition transformer that adjoins actual operations on a
wenzelm@34998
   127
  theory or proof state etc.
wenzelm@18537
   128
*}
wenzelm@18537
   129
wenzelm@18537
   130
text %mlref {*
wenzelm@18537
   131
  \begin{mldecls}
wenzelm@18537
   132
  @{index_ML Toplevel.print: "Toplevel.transition -> Toplevel.transition"} \\
wenzelm@18537
   133
  @{index_ML Toplevel.no_timing: "Toplevel.transition -> Toplevel.transition"} \\
wenzelm@18537
   134
  @{index_ML Toplevel.keep: "(Toplevel.state -> unit) ->
wenzelm@18537
   135
  Toplevel.transition -> Toplevel.transition"} \\
wenzelm@18537
   136
  @{index_ML Toplevel.theory: "(theory -> theory) ->
wenzelm@18537
   137
  Toplevel.transition -> Toplevel.transition"} \\
wenzelm@18537
   138
  @{index_ML Toplevel.theory_to_proof: "(theory -> Proof.state) ->
wenzelm@18537
   139
  Toplevel.transition -> Toplevel.transition"} \\
wenzelm@18537
   140
  @{index_ML Toplevel.proof: "(Proof.state -> Proof.state) ->
wenzelm@18537
   141
  Toplevel.transition -> Toplevel.transition"} \\
wenzelm@18537
   142
  @{index_ML Toplevel.proofs: "(Proof.state -> Proof.state Seq.seq) ->
wenzelm@18537
   143
  Toplevel.transition -> Toplevel.transition"} \\
wenzelm@21168
   144
  @{index_ML Toplevel.end_proof: "(bool -> Proof.state -> Proof.context) ->
wenzelm@18537
   145
  Toplevel.transition -> Toplevel.transition"} \\
wenzelm@18537
   146
  \end{mldecls}
wenzelm@18537
   147
wenzelm@18537
   148
  \begin{description}
wenzelm@18537
   149
wenzelm@20451
   150
  \item @{ML Toplevel.print}~@{text "tr"} sets the print flag, which
wenzelm@20451
   151
  causes the toplevel loop to echo the result state (in interactive
wenzelm@20451
   152
  mode).
wenzelm@18537
   153
wenzelm@20451
   154
  \item @{ML Toplevel.no_timing}~@{text "tr"} indicates that the
wenzelm@20451
   155
  transition should never show timing information, e.g.\ because it is
wenzelm@20451
   156
  a diagnostic command.
wenzelm@18537
   157
wenzelm@20451
   158
  \item @{ML Toplevel.keep}~@{text "tr"} adjoins a diagnostic
wenzelm@20451
   159
  function.
wenzelm@18537
   160
wenzelm@20451
   161
  \item @{ML Toplevel.theory}~@{text "tr"} adjoins a theory
wenzelm@20451
   162
  transformer.
wenzelm@18537
   163
wenzelm@20451
   164
  \item @{ML Toplevel.theory_to_proof}~@{text "tr"} adjoins a global
wenzelm@20451
   165
  goal function, which turns a theory into a proof state.  The theory
wenzelm@20451
   166
  may be changed before entering the proof; the generic Isar goal
wenzelm@20451
   167
  setup includes an argument that specifies how to apply the proven
wenzelm@20451
   168
  result to the theory, when the proof is finished.
wenzelm@18558
   169
wenzelm@20451
   170
  \item @{ML Toplevel.proof}~@{text "tr"} adjoins a deterministic
wenzelm@20451
   171
  proof command, with a singleton result.
wenzelm@18537
   172
wenzelm@20451
   173
  \item @{ML Toplevel.proofs}~@{text "tr"} adjoins a general proof
wenzelm@20451
   174
  command, with zero or more result states (represented as a lazy
wenzelm@20451
   175
  list).
wenzelm@18537
   176
wenzelm@21168
   177
  \item @{ML Toplevel.end_proof}~@{text "tr"} adjoins a concluding
wenzelm@21168
   178
  proof command, that returns the resulting theory, after storing the
wenzelm@21168
   179
  resulting facts in the context etc.
wenzelm@18537
   180
wenzelm@18537
   181
  \end{description}
wenzelm@18537
   182
*}
wenzelm@18537
   183
wenzelm@18537
   184
wenzelm@18537
   185
subsection {* Toplevel control *}
wenzelm@18537
   186
wenzelm@20451
   187
text {*
wenzelm@20451
   188
  There are a few special control commands that modify the behavior
wenzelm@20451
   189
  the toplevel itself, and only make sense in interactive mode.  Under
wenzelm@20451
   190
  normal circumstances, the user encounters these only implicitly as
wenzelm@20451
   191
  part of the protocol between the Isabelle/Isar system and a
wenzelm@34998
   192
  user-interface such as Proof~General.
wenzelm@18537
   193
wenzelm@18537
   194
  \begin{description}
wenzelm@18537
   195
wenzelm@18537
   196
  \item \isacommand{undo} follows the three-level hierarchy of empty
wenzelm@18537
   197
  toplevel vs.\ theory vs.\ proof: undo within a proof reverts to the
wenzelm@18537
   198
  previous proof context, undo after a proof reverts to the theory
wenzelm@18537
   199
  before the initial goal statement, undo of a theory command reverts
wenzelm@18537
   200
  to the previous theory value, undo of a theory header discontinues
wenzelm@18537
   201
  the current theory development and removes it from the theory
wenzelm@18537
   202
  database (\secref{sec:theory-database}).
wenzelm@18537
   203
wenzelm@18537
   204
  \item \isacommand{kill} aborts the current level of development:
wenzelm@18537
   205
  kill in a proof context reverts to the theory before the initial
wenzelm@18537
   206
  goal statement, kill in a theory context aborts the current theory
wenzelm@18537
   207
  development, removing it from the database.
wenzelm@18537
   208
wenzelm@18537
   209
  \item \isacommand{exit} drops out of the Isar toplevel into the
wenzelm@18537
   210
  underlying {\ML} toplevel (\secref{sec:ML-toplevel}).  The Isar
wenzelm@18537
   211
  toplevel state is preserved and may be continued later.
wenzelm@18537
   212
wenzelm@18537
   213
  \item \isacommand{quit} terminates the Isabelle/Isar process without
wenzelm@18537
   214
  saving.
wenzelm@18537
   215
wenzelm@18537
   216
  \end{description}
wenzelm@18537
   217
*}
wenzelm@18537
   218
wenzelm@18537
   219
wenzelm@18537
   220
section {* ML toplevel \label{sec:ML-toplevel} *}
wenzelm@18537
   221
wenzelm@20475
   222
text {*
wenzelm@20475
   223
  The {\ML} toplevel provides a read-compile-eval-print loop for {\ML}
wenzelm@20475
   224
  values, types, structures, and functors.  {\ML} declarations operate
wenzelm@20475
   225
  on the global system state, which consists of the compiler
wenzelm@18537
   226
  environment plus the values of {\ML} reference variables.  There is
wenzelm@18537
   227
  no clean way to undo {\ML} declarations, except for reverting to a
wenzelm@18537
   228
  previously saved state of the whole Isabelle process.  {\ML} input
wenzelm@18537
   229
  is either read interactively from a TTY, or from a string (usually
wenzelm@20451
   230
  within a theory text), or from a source file (usually loaded from a
wenzelm@20451
   231
  theory).
wenzelm@18537
   232
wenzelm@18537
   233
  Whenever the {\ML} toplevel is active, the current Isabelle theory
wenzelm@18537
   234
  context is passed as an internal reference variable.  Thus {\ML}
wenzelm@18537
   235
  code may access the theory context during compilation, it may even
wenzelm@20451
   236
  change the value of a theory being under construction --- while
wenzelm@20451
   237
  observing the usual linearity restrictions
wenzelm@20451
   238
  (cf.~\secref{sec:context-theory}).
wenzelm@18537
   239
*}
wenzelm@18537
   240
wenzelm@18537
   241
text %mlref {*
wenzelm@18537
   242
  \begin{mldecls}
wenzelm@32189
   243
  @{index_ML ML_Context.the_generic_context: "unit -> Context.generic"} \\
wenzelm@26463
   244
  @{index_ML "Context.>> ": "(Context.generic -> Context.generic) -> unit"} \\
wenzelm@18537
   245
  \end{mldecls}
wenzelm@18537
   246
wenzelm@18537
   247
  \begin{description}
wenzelm@18537
   248
wenzelm@32189
   249
  \item @{ML "ML_Context.the_generic_context ()"} refers to the theory
wenzelm@32189
   250
  context of the {\ML} toplevel --- at compile time!  {\ML} code needs
wenzelm@32189
   251
  to take care to refer to @{ML "ML_Context.the_generic_context ()"}
wenzelm@32189
   252
  correctly.  Recall that evaluation of a function body is delayed
wenzelm@32189
   253
  until actual runtime.  Moreover, persistent {\ML} toplevel bindings
wenzelm@32189
   254
  to an unfinished theory should be avoided: code should either
wenzelm@32189
   255
  project out the desired information immediately, or produce an
wenzelm@32189
   256
  explicit @{ML_type theory_ref} (cf.\ \secref{sec:context-theory}).
wenzelm@18537
   257
wenzelm@26463
   258
  \item @{ML "Context.>>"}~@{text f} applies context transformation
wenzelm@26463
   259
  @{text f} to the implicit context of the {\ML} toplevel.
wenzelm@18537
   260
wenzelm@18537
   261
  \end{description}
wenzelm@18537
   262
wenzelm@18537
   263
  It is very important to note that the above functions are really
wenzelm@18537
   264
  restricted to the compile time, even though the {\ML} compiler is
wenzelm@18537
   265
  invoked at runtime!  The majority of {\ML} code uses explicit
wenzelm@20451
   266
  functional arguments of a theory or proof context instead.  Thus it
wenzelm@20451
   267
  may be invoked for an arbitrary context later on, without having to
wenzelm@20451
   268
  worry about any operational details.
wenzelm@18537
   269
wenzelm@18537
   270
  \bigskip
wenzelm@18537
   271
wenzelm@18537
   272
  \begin{mldecls}
wenzelm@18537
   273
  @{index_ML Isar.main: "unit -> unit"} \\
wenzelm@18537
   274
  @{index_ML Isar.loop: "unit -> unit"} \\
wenzelm@18537
   275
  @{index_ML Isar.state: "unit -> Toplevel.state"} \\
wenzelm@21401
   276
  @{index_ML Isar.exn: "unit -> (exn * string) option"} \\
wenzelm@20025
   277
  @{index_ML Isar.context: "unit -> Proof.context"} \\
wenzelm@33293
   278
  @{index_ML Isar.goal: "unit ->
wenzelm@33293
   279
  {context: Proof.context, facts: thm list, goal: thm}"} \\
wenzelm@18537
   280
  \end{mldecls}
wenzelm@18537
   281
wenzelm@18537
   282
  \begin{description}
wenzelm@18537
   283
wenzelm@18537
   284
  \item @{ML "Isar.main ()"} invokes the Isar toplevel from {\ML},
wenzelm@20451
   285
  initializing an empty toplevel state.
wenzelm@18537
   286
wenzelm@18537
   287
  \item @{ML "Isar.loop ()"} continues the Isar toplevel with the
wenzelm@20451
   288
  current state, after having dropped out of the Isar toplevel loop.
wenzelm@18537
   289
wenzelm@18537
   290
  \item @{ML "Isar.state ()"} and @{ML "Isar.exn ()"} get current
wenzelm@20451
   291
  toplevel state and error condition, respectively.  This only works
wenzelm@20451
   292
  after having dropped out of the Isar toplevel loop.
wenzelm@18537
   293
wenzelm@20025
   294
  \item @{ML "Isar.context ()"} produces the proof context from @{ML
wenzelm@20451
   295
  "Isar.state ()"}, analogous to @{ML Context.proof_of}
wenzelm@20451
   296
  (\secref{sec:generic-context}).
wenzelm@20025
   297
wenzelm@33293
   298
  \item @{ML "Isar.goal ()"} produces the full Isar goal state,
wenzelm@33293
   299
  consisting of proof context, facts that have been indicated for
wenzelm@33293
   300
  immediate use, and the tactical goal according to
wenzelm@26617
   301
  \secref{sec:tactical-goals}.
wenzelm@21401
   302
wenzelm@18537
   303
  \end{description}
wenzelm@18537
   304
*}
wenzelm@18537
   305
wenzelm@18537
   306
wenzelm@20451
   307
section {* Theory database \label{sec:theory-database} *}
wenzelm@18537
   308
wenzelm@20451
   309
text {*
wenzelm@20451
   310
  The theory database maintains a collection of theories, together
wenzelm@20451
   311
  with some administrative information about their original sources,
wenzelm@20451
   312
  which are held in an external store (i.e.\ some directory within the
wenzelm@20451
   313
  regular file system).
wenzelm@18537
   314
wenzelm@20451
   315
  The theory database is organized as a directed acyclic graph;
wenzelm@20451
   316
  entries are referenced by theory name.  Although some additional
wenzelm@20451
   317
  interfaces allow to include a directory specification as well, this
wenzelm@20451
   318
  is only a hint to the underlying theory loader.  The internal theory
wenzelm@20451
   319
  name space is flat!
wenzelm@18537
   320
wenzelm@18537
   321
  Theory @{text A} is associated with the main theory file @{text
wenzelm@18537
   322
  A}\verb,.thy,, which needs to be accessible through the theory
wenzelm@20451
   323
  loader path.  Any number of additional {\ML} source files may be
wenzelm@18537
   324
  associated with each theory, by declaring these dependencies in the
wenzelm@18537
   325
  theory header as @{text \<USES>}, and loading them consecutively
wenzelm@18537
   326
  within the theory context.  The system keeps track of incoming {\ML}
wenzelm@34998
   327
  sources and associates them with the current theory.
wenzelm@18537
   328
wenzelm@18537
   329
  The basic internal actions of the theory database are @{text
wenzelm@18554
   330
  "update"}, @{text "outdate"}, and @{text "remove"}:
wenzelm@18537
   331
wenzelm@18537
   332
  \begin{itemize}
wenzelm@18537
   333
wenzelm@18537
   334
  \item @{text "update A"} introduces a link of @{text "A"} with a
wenzelm@18537
   335
  @{text "theory"} value of the same name; it asserts that the theory
wenzelm@20451
   336
  sources are now consistent with that value;
wenzelm@18537
   337
wenzelm@18537
   338
  \item @{text "outdate A"} invalidates the link of a theory database
wenzelm@20451
   339
  entry to its sources, but retains the present theory value;
wenzelm@18537
   340
wenzelm@20451
   341
  \item @{text "remove A"} deletes entry @{text "A"} from the theory
wenzelm@18537
   342
  database.
wenzelm@18537
   343
  
wenzelm@18537
   344
  \end{itemize}
wenzelm@18537
   345
wenzelm@18537
   346
  These actions are propagated to sub- or super-graphs of a theory
wenzelm@20451
   347
  entry as expected, in order to preserve global consistency of the
wenzelm@20451
   348
  state of all loaded theories with the sources of the external store.
wenzelm@20451
   349
  This implies certain causalities between actions: @{text "update"}
wenzelm@20451
   350
  or @{text "outdate"} of an entry will @{text "outdate"} all
wenzelm@20451
   351
  descendants; @{text "remove"} will @{text "remove"} all descendants.
wenzelm@18537
   352
wenzelm@18537
   353
  \medskip There are separate user-level interfaces to operate on the
wenzelm@18537
   354
  theory database directly or indirectly.  The primitive actions then
wenzelm@18537
   355
  just happen automatically while working with the system.  In
wenzelm@18537
   356
  particular, processing a theory header @{text "\<THEORY> A
wenzelm@20451
   357
  \<IMPORTS> B\<^sub>1 \<dots> B\<^sub>n \<BEGIN>"} ensures that the
wenzelm@18537
   358
  sub-graph of the collective imports @{text "B\<^sub>1 \<dots> B\<^sub>n"}
wenzelm@20451
   359
  is up-to-date, too.  Earlier theories are reloaded as required, with
wenzelm@18537
   360
  @{text update} actions proceeding in topological order according to
wenzelm@18537
   361
  theory dependencies.  There may be also a wave of implied @{text
wenzelm@18537
   362
  outdate} actions for derived theory nodes until a stable situation
wenzelm@18537
   363
  is achieved eventually.
wenzelm@18537
   364
*}
wenzelm@18537
   365
wenzelm@18537
   366
text %mlref {*
wenzelm@18537
   367
  \begin{mldecls}
wenzelm@18537
   368
  @{index_ML theory: "string -> theory"} \\
wenzelm@18537
   369
  @{index_ML use_thy: "string -> unit"} \\
wenzelm@24173
   370
  @{index_ML use_thys: "string list -> unit"} \\
wenzelm@37216
   371
  @{index_ML Thy_Info.touch_thy: "string -> unit"} \\
wenzelm@37216
   372
  @{index_ML Thy_Info.remove_thy: "string -> unit"} \\[1ex]
wenzelm@37216
   373
  @{index_ML Thy_Info.begin_theory}@{verbatim ": ... -> bool -> theory"} \\
wenzelm@37216
   374
  @{index_ML Thy_Info.end_theory: "theory -> unit"} \\
wenzelm@37216
   375
  @{index_ML Thy_Info.register_theory: "theory -> unit"} \\[1ex]
wenzelm@18537
   376
  @{verbatim "datatype action = Update | Outdate | Remove"} \\
wenzelm@37216
   377
  @{index_ML Thy_Info.add_hook: "(Thy_Info.action -> string -> unit) -> unit"} \\
wenzelm@18537
   378
  \end{mldecls}
wenzelm@18537
   379
wenzelm@18537
   380
  \begin{description}
wenzelm@18537
   381
wenzelm@18537
   382
  \item @{ML theory}~@{text A} retrieves the theory value presently
wenzelm@20451
   383
  associated with name @{text A}.  Note that the result might be
wenzelm@20451
   384
  outdated.
wenzelm@18537
   385
wenzelm@24173
   386
  \item @{ML use_thy}~@{text A} ensures that theory @{text A} is fully
wenzelm@24173
   387
  up-to-date wrt.\ the external file store, reloading outdated
wenzelm@34998
   388
  ancestors as required.  In batch mode, the simultaneous @{ML
wenzelm@34998
   389
  use_thys} should be used exclusively.
wenzelm@18537
   390
wenzelm@24173
   391
  \item @{ML use_thys} is similar to @{ML use_thy}, but handles
wenzelm@24173
   392
  several theories simultaneously.  Thus it acts like processing the
wenzelm@24173
   393
  import header of a theory, without performing the merge of the
wenzelm@34998
   394
  result.  By loading a whole sub-graph of theories like that, the
wenzelm@34998
   395
  intrinsic parallelism can be exploited by the system, to speedup
wenzelm@34998
   396
  loading.
wenzelm@18537
   397
wenzelm@37216
   398
  \item @{ML Thy_Info.touch_thy}~@{text A} performs and @{text outdate} action
wenzelm@20451
   399
  on theory @{text A} and all descendants.
wenzelm@18537
   400
wenzelm@37216
   401
  \item @{ML Thy_Info.remove_thy}~@{text A} deletes theory @{text A} and all
wenzelm@18537
   402
  descendants from the theory database.
wenzelm@18537
   403
wenzelm@37216
   404
  \item @{ML Thy_Info.begin_theory} is the basic operation behind a
wenzelm@34988
   405
  @{text \<THEORY>} header declaration.  This {\ML} function is
wenzelm@18537
   406
  normally not invoked directly.
wenzelm@18537
   407
wenzelm@37216
   408
  \item @{ML Thy_Info.end_theory} concludes the loading of a theory
wenzelm@27597
   409
  proper and stores the result in the theory database.
wenzelm@18537
   410
wenzelm@37216
   411
  \item @{ML Thy_Info.register_theory}~@{text "text thy"} registers an
wenzelm@20451
   412
  existing theory value with the theory loader database.  There is no
wenzelm@20451
   413
  management of associated sources.
wenzelm@18537
   414
wenzelm@37216
   415
  \item @{ML "Thy_Info.add_hook"}~@{text f} registers function @{text
wenzelm@18537
   416
  f} as a hook for theory database actions.  The function will be
wenzelm@18537
   417
  invoked with the action and theory name being involved; thus derived
wenzelm@18537
   418
  actions may be performed in associated system components, e.g.\
wenzelm@20451
   419
  maintaining the state of an editor for the theory sources.
wenzelm@18537
   420
wenzelm@18537
   421
  The kind and order of actions occurring in practice depends both on
wenzelm@18537
   422
  user interactions and the internal process of resolving theory
wenzelm@18537
   423
  imports.  Hooks should not rely on a particular policy here!  Any
wenzelm@20451
   424
  exceptions raised by the hook are ignored.
wenzelm@18537
   425
wenzelm@18537
   426
  \end{description}
wenzelm@18537
   427
*}
wenzelm@30273
   428
wenzelm@18537
   429
end