174 |
176 |
175 \end{description} |
177 \end{description} |
176 *} |
178 *} |
177 |
179 |
178 |
180 |
179 section {* Theory database \label{sec:theory-database} *} |
181 section {* Theory loader database *} |
180 |
182 |
181 text {* |
183 text {* |
182 %FIXME update |
184 In batch mode and within dumped logic images, the theory database maintains |
183 |
185 a collection of theories as a directed acyclic graph. A theory may refer to |
184 The theory database maintains a collection of theories, together |
186 other theories as @{keyword "imports"}, or to auxiliary files via special |
185 with some administrative information about their original sources, |
187 \emph{load commands} (e.g.\ @{command ML_file}). For each theory, the base |
186 which are held in an external store (i.e.\ some directory within the |
188 directory of its own theory file is called \emph{master directory}: this is |
187 regular file system). |
189 used as the relative location to refer to other files from that theory. |
188 |
|
189 The theory database is organized as a directed acyclic graph; |
|
190 entries are referenced by theory name. Although some additional |
|
191 interfaces allow to include a directory specification as well, this |
|
192 is only a hint to the underlying theory loader. The internal theory |
|
193 name space is flat! |
|
194 |
|
195 Theory @{text A} is associated with the main theory file @{text |
|
196 A}\verb,.thy,, which needs to be accessible through the theory |
|
197 loader path. Any number of additional ML source files may be |
|
198 associated with each theory, by declaring these dependencies in the |
|
199 theory header as @{text \<USES>}, and loading them consecutively |
|
200 within the theory context. The system keeps track of incoming ML |
|
201 sources and associates them with the current theory. |
|
202 |
|
203 The basic internal actions of the theory database are @{text |
|
204 "update"} and @{text "remove"}: |
|
205 |
|
206 \begin{itemize} |
|
207 |
|
208 \item @{text "update A"} introduces a link of @{text "A"} with a |
|
209 @{text "theory"} value of the same name; it asserts that the theory |
|
210 sources are now consistent with that value; |
|
211 |
|
212 \item @{text "remove A"} deletes entry @{text "A"} from the theory |
|
213 database. |
|
214 |
|
215 \end{itemize} |
|
216 |
|
217 These actions are propagated to sub- or super-graphs of a theory |
|
218 entry as expected, in order to preserve global consistency of the |
|
219 state of all loaded theories with the sources of the external store. |
|
220 This implies certain causalities between actions: @{text "update"} |
|
221 or @{text "remove"} of an entry will @{text "remove"} all |
|
222 descendants. |
|
223 |
|
224 \medskip There are separate user-level interfaces to operate on the |
|
225 theory database directly or indirectly. The primitive actions then |
|
226 just happen automatically while working with the system. In |
|
227 particular, processing a theory header @{text "\<THEORY> A |
|
228 \<IMPORTS> B\<^sub>1 \<dots> B\<^sub>n \<BEGIN>"} ensures that the |
|
229 sub-graph of the collective imports @{text "B\<^sub>1 \<dots> B\<^sub>n"} |
|
230 is up-to-date, too. Earlier theories are reloaded as required, with |
|
231 @{text update} actions proceeding in topological order according to |
|
232 theory dependencies. There may be also a wave of implied @{text |
|
233 remove} actions for derived theory nodes until a stable situation |
|
234 is achieved eventually. |
|
235 *} |
190 *} |
236 |
191 |
237 text %mlref {* |
192 text %mlref {* |
238 \begin{mldecls} |
193 \begin{mldecls} |
239 @{index_ML use_thy: "string -> unit"} \\ |
194 @{index_ML use_thy: "string -> unit"} \\ |
240 @{index_ML use_thys: "string list -> unit"} \\ |
195 @{index_ML use_thys: "string list -> unit"} \\ |
241 @{index_ML Thy_Info.get_theory: "string -> theory"} \\ |
196 @{index_ML Thy_Info.get_theory: "string -> theory"} \\ |
242 @{index_ML Thy_Info.remove_thy: "string -> unit"} \\[1ex] |
197 @{index_ML Thy_Info.remove_thy: "string -> unit"} \\ |
243 @{index_ML Thy_Info.register_thy: "theory -> unit"} \\[1ex] |
198 @{index_ML Thy_Info.register_thy: "theory -> unit"} \\ |
244 @{ML_text "datatype action = Update | Remove"} \\ |
|
245 @{index_ML Thy_Info.add_hook: "(Thy_Info.action -> string -> unit) -> unit"} \\ |
|
246 \end{mldecls} |
199 \end{mldecls} |
247 |
200 |
248 \begin{description} |
201 \begin{description} |
249 |
202 |
250 \item @{ML use_thy}~@{text A} ensures that theory @{text A} is fully |
203 \item @{ML use_thy}~@{text A} ensures that theory @{text A} is fully |
251 up-to-date wrt.\ the external file store, reloading outdated |
204 up-to-date wrt.\ the external file store, reloading outdated ancestors as |
252 ancestors as required. In batch mode, the simultaneous @{ML |
205 required. |
253 use_thys} should be used exclusively. |
206 |
254 |
207 \item @{ML use_thys} is similar to @{ML use_thy}, but handles several |
255 \item @{ML use_thys} is similar to @{ML use_thy}, but handles |
208 theories simultaneously. Thus it acts like processing the import header of a |
256 several theories simultaneously. Thus it acts like processing the |
209 theory, without performing the merge of the result. By loading a whole |
257 import header of a theory, without performing the merge of the |
210 sub-graph of theories, the intrinsic parallelism can be exploited by the |
258 result. By loading a whole sub-graph of theories like that, the |
211 system to speedup loading. |
259 intrinsic parallelism can be exploited by the system, to speedup |
|
260 loading. |
|
261 |
212 |
262 \item @{ML Thy_Info.get_theory}~@{text A} retrieves the theory value |
213 \item @{ML Thy_Info.get_theory}~@{text A} retrieves the theory value |
263 presently associated with name @{text A}. Note that the result |
214 presently associated with name @{text A}. Note that the result might be |
264 might be outdated. |
215 outdated wrt.\ the file-system content. |
265 |
216 |
266 \item @{ML Thy_Info.remove_thy}~@{text A} deletes theory @{text A} and all |
217 \item @{ML Thy_Info.remove_thy}~@{text A} deletes theory @{text A} and all |
267 descendants from the theory database. |
218 descendants from the theory database. |
268 |
219 |
269 \item @{ML Thy_Info.register_thy}~@{text "text thy"} registers an |
220 \item @{ML Thy_Info.register_thy}~@{text "text thy"} registers an existing |
270 existing theory value with the theory loader database and updates |
221 theory value with the theory loader database and updates source version |
271 source version information according to the current file-system |
222 information according to the current file-system state. |
272 state. |
|
273 |
|
274 \item @{ML "Thy_Info.add_hook"}~@{text f} registers function @{text |
|
275 f} as a hook for theory database actions. The function will be |
|
276 invoked with the action and theory name being involved; thus derived |
|
277 actions may be performed in associated system components, e.g.\ |
|
278 maintaining the state of an editor for the theory sources. |
|
279 |
|
280 The kind and order of actions occurring in practice depends both on |
|
281 user interactions and the internal process of resolving theory |
|
282 imports. Hooks should not rely on a particular policy here! Any |
|
283 exceptions raised by the hook are ignored. |
|
284 |
223 |
285 \end{description} |
224 \end{description} |
286 *} |
225 *} |
287 |
226 |
288 end |
227 end |