src/Pure/context.ML
author wenzelm
Thu Oct 04 20:29:42 2007 +0200 (2007-10-04)
changeset 24850 0cfd722ab579
parent 24559 dae0972c0066
child 26413 003dd6155870
permissions -rw-r--r--
Name.uu, Name.aT;
     1 (*  Title:      Pure/context.ML
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     4 
     5 Generic theory contexts with unique identity, arbitrarily typed data,
     6 monotonic development graph and history support.  Generic proof
     7 contexts with arbitrarily typed data.
     8 *)
     9 
    10 signature BASIC_CONTEXT =
    11 sig
    12   type theory
    13   type theory_ref
    14   exception THEORY of string * theory list
    15 end;
    16 
    17 signature CONTEXT =
    18 sig
    19   include BASIC_CONTEXT
    20   (*theory context*)
    21   val theory_name: theory -> string
    22   val parents_of: theory -> theory list
    23   val ancestors_of: theory -> theory list
    24   val is_stale: theory -> bool
    25   val ProtoPureN: string
    26   val PureN: string
    27   val CPureN: string
    28   val draftN: string
    29   val exists_name: string -> theory -> bool
    30   val names_of: theory -> string list
    31   val pretty_thy: theory -> Pretty.T
    32   val string_of_thy: theory -> string
    33   val pprint_thy: theory -> pprint_args -> unit
    34   val pretty_abbrev_thy: theory -> Pretty.T
    35   val str_of_thy: theory -> string
    36   val deref: theory_ref -> theory
    37   val check_thy: theory -> theory_ref
    38   val eq_thy: theory * theory -> bool
    39   val subthy: theory * theory -> bool
    40   val joinable: theory * theory -> bool
    41   val merge: theory * theory -> theory
    42   val merge_refs: theory_ref * theory_ref -> theory_ref
    43   val copy_thy: theory -> theory
    44   val checkpoint_thy: theory -> theory
    45   val finish_thy: theory -> theory
    46   val pre_pure_thy: theory
    47   val begin_thy: (theory -> Pretty.pp) -> string -> theory list -> theory
    48   (*proof context*)
    49   type proof
    50   val theory_of_proof: proof -> theory
    51   val transfer_proof: theory -> proof -> proof
    52   val init_proof: theory -> proof
    53   (*generic context*)
    54   datatype generic = Theory of theory | Proof of proof
    55   val cases: (theory -> 'a) -> (proof -> 'a) -> generic -> 'a
    56   val mapping: (theory -> theory) -> (proof -> proof) -> generic -> generic
    57   val mapping_result: (theory -> 'a * theory) -> (proof -> 'a * proof) -> generic -> 'a * generic
    58   val the_theory: generic -> theory
    59   val the_proof: generic -> proof
    60   val map_theory: (theory -> theory) -> generic -> generic
    61   val map_proof: (proof -> proof) -> generic -> generic
    62   val theory_map: (generic -> generic) -> theory -> theory
    63   val proof_map: (generic -> generic) -> proof -> proof
    64   val theory_of: generic -> theory   (*total*)
    65   val proof_of: generic -> proof     (*total*)
    66   (*delayed setup*)
    67   val add_setup: (theory -> theory) -> unit
    68   val setup: unit -> theory -> theory
    69 end;
    70 
    71 signature PRIVATE_CONTEXT =
    72 sig
    73   include CONTEXT
    74   structure TheoryData:
    75   sig
    76     val declare: Object.T -> (Object.T -> Object.T) -> (Object.T -> Object.T) ->
    77       (Pretty.pp -> Object.T * Object.T -> Object.T) -> serial
    78     val get: serial -> (Object.T -> 'a) -> theory -> 'a
    79     val put: serial -> ('a -> Object.T) -> 'a -> theory -> theory
    80   end
    81   structure ProofData:
    82   sig
    83     val declare: (theory -> Object.T) -> serial
    84     val get: serial -> (Object.T -> 'a) -> proof -> 'a
    85     val put: serial -> ('a -> Object.T) -> 'a -> proof -> proof
    86   end
    87 end;
    88 
    89 structure Context: PRIVATE_CONTEXT =
    90 struct
    91 
    92 (*** theory context ***)
    93 
    94 (** theory data **)
    95 
    96 (* data kinds and access methods *)
    97 
    98 (*private copy avoids potential conflict of table exceptions*)
    99 structure Datatab = TableFun(type key = int val ord = int_ord);
   100 
   101 local
   102 
   103 type kind =
   104  {empty: Object.T,
   105   copy: Object.T -> Object.T,
   106   extend: Object.T -> Object.T,
   107   merge: Pretty.pp -> Object.T * Object.T -> Object.T};
   108 
   109 val kinds = ref (Datatab.empty: kind Datatab.table);
   110 
   111 fun invoke f k =
   112   (case Datatab.lookup (! kinds) k of
   113     SOME kind => f kind
   114   | NONE => sys_error "Invalid theory data identifier");
   115 
   116 in
   117 
   118 fun invoke_empty k   = invoke (K o #empty) k ();
   119 val invoke_copy      = invoke #copy;
   120 val invoke_extend    = invoke #extend;
   121 fun invoke_merge pp  = invoke (fn kind => #merge kind pp);
   122 
   123 fun declare_theory_data empty copy extend merge =
   124   let
   125     val k = serial ();
   126     val kind = {empty = empty, copy = copy, extend = extend, merge = merge};
   127     val _ = CRITICAL (fn () => change kinds (Datatab.update (k, kind)));
   128   in k end;
   129 
   130 val copy_data = Datatab.map' invoke_copy;
   131 val extend_data = Datatab.map' invoke_extend;
   132 fun merge_data pp = Datatab.join (invoke_merge pp) o pairself extend_data;
   133 
   134 end;
   135 
   136 
   137 
   138 (** datatype theory **)
   139 
   140 datatype theory =
   141   Theory of
   142    (*identity*)
   143    {self: theory ref option,            (*dynamic self reference -- follows theory changes*)
   144     id: serial * string,                (*identifier of this theory*)
   145     ids: string Inttab.table,           (*identifiers of ancestors*)
   146     iids: string Inttab.table} *        (*identifiers of intermediate checkpoints*)
   147    (*data*)
   148    Object.T Datatab.table *
   149    (*ancestry*)
   150    {parents: theory list,               (*immediate predecessors*)
   151     ancestors: theory list} *           (*all predecessors*)
   152    (*history*)
   153    {name: string,                       (*prospective name of finished theory*)
   154     version: int,                       (*checkpoint counter*)
   155     intermediates: theory list};        (*intermediate checkpoints*)
   156 
   157 exception THEORY of string * theory list;
   158 
   159 fun rep_theory (Theory args) = args;
   160 
   161 val identity_of = #1 o rep_theory;
   162 val data_of     = #2 o rep_theory;
   163 val ancestry_of = #3 o rep_theory;
   164 val history_of  = #4 o rep_theory;
   165 
   166 fun make_identity self id ids iids = {self = self, id = id, ids = ids, iids = iids};
   167 fun make_ancestry parents ancestors = {parents = parents, ancestors = ancestors};
   168 fun make_history name vers ints = {name = name, version = vers, intermediates = ints};
   169 
   170 val the_self = the o #self o identity_of;
   171 val parents_of = #parents o ancestry_of;
   172 val ancestors_of = #ancestors o ancestry_of;
   173 val theory_name = #name o history_of;
   174 
   175 
   176 (* staleness *)
   177 
   178 fun eq_id ((i: int, _), (j, _)) = (i = j);
   179 
   180 fun is_stale
   181     (Theory ({self = SOME (ref (Theory ({id = id', ...}, _, _, _))), id, ...}, _, _, _)) =
   182       not (eq_id (id, id'))
   183   | is_stale (Theory ({self = NONE, ...}, _, _, _)) = true;
   184 
   185 fun vitalize (thy as Theory ({self = SOME r, ...}, _, _, _)) = (r := thy; thy)
   186   | vitalize (thy as Theory ({self = NONE, id, ids, iids}, data, ancestry, history)) =
   187       let
   188         val r = ref thy;
   189         val thy' = Theory (make_identity (SOME r) id ids iids, data, ancestry, history);
   190       in r := thy'; thy' end;
   191 
   192 
   193 (* names *)
   194 
   195 val ProtoPureN = "ProtoPure";
   196 val PureN = "Pure";
   197 val CPureN = "CPure";
   198 
   199 val draftN = "#";
   200 fun draft_id (_, name) = (name = draftN);
   201 val is_draft = draft_id o #id o identity_of;
   202 
   203 fun exists_name name (thy as Theory ({id, ids, iids, ...}, _, _, _)) =
   204   name = theory_name thy orelse
   205   name = #2 id orelse
   206   Inttab.exists (equal name o #2) ids orelse
   207   Inttab.exists (equal name o #2) iids;
   208 
   209 fun names_of (Theory ({id, ids, iids, ...}, _, _, _)) =
   210   rev (#2 id :: Inttab.fold (cons o #2) iids (Inttab.fold (cons o #2) ids []));
   211 
   212 fun pretty_thy thy =
   213   Pretty.str_list "{" "}" (names_of thy @ (if is_stale thy then ["!"] else []));
   214 
   215 val string_of_thy = Pretty.string_of o pretty_thy;
   216 val pprint_thy = Pretty.pprint o pretty_thy;
   217 
   218 fun pretty_abbrev_thy thy =
   219   let
   220     val names = names_of thy;
   221     val n = length names;
   222     val abbrev = if n > 5 then "..." :: List.drop (names, n - 5) else names;
   223   in Pretty.str_list "{" "}" abbrev end;
   224 
   225 val str_of_thy = Pretty.str_of o pretty_abbrev_thy;
   226 
   227 
   228 (* theory references *)
   229 
   230 (*theory_ref provides a safe way to store dynamic references to a
   231   theory in external data structures -- a plain theory value would
   232   become stale as the self reference moves on*)
   233 
   234 datatype theory_ref = TheoryRef of theory ref;
   235 
   236 fun deref (TheoryRef (ref thy)) = thy;
   237 
   238 fun check_thy thy =  (*thread-safe version*)
   239   let val thy_ref = TheoryRef (the_self thy) in
   240     if is_stale thy then error ("Stale theory encountered:\n" ^ string_of_thy thy)
   241     else thy_ref
   242   end;
   243 
   244 
   245 (* consistency *)
   246 
   247 fun check_ins id ids =
   248   if draft_id id orelse Inttab.defined ids (#1 id) then ids
   249   else if Inttab.exists (equal (#2 id) o #2) ids then
   250     error ("Different versions of theory component " ^ quote (#2 id))
   251   else Inttab.update id ids;
   252 
   253 fun check_insert intermediate id (ids, iids) =
   254   let val ids' = check_ins id ids and iids' = check_ins id iids
   255   in if intermediate then (ids, iids') else (ids', iids) end;
   256 
   257 fun check_merge
   258     (Theory ({id = id1, ids = ids1, iids = iids1, ...}, _, _, history1))
   259     (Theory ({id = id2, ids = ids2, iids = iids2, ...}, _, _, history2)) =
   260   (Inttab.fold check_ins ids2 ids1, Inttab.fold check_ins iids2 iids1)
   261   |> check_insert (#version history1 > 0) id1
   262   |> check_insert (#version history2 > 0) id2;
   263 
   264 
   265 (* equality and inclusion *)
   266 
   267 val eq_thy = eq_id o pairself (#id o identity_of);
   268 
   269 fun proper_subthy
   270     (Theory ({id = (i, _), ...}, _, _, _), Theory ({ids, iids, ...}, _, _, _)) =
   271   Inttab.defined ids i orelse Inttab.defined iids i;
   272 
   273 fun subthy thys = eq_thy thys orelse proper_subthy thys;
   274 
   275 fun joinable (thy1, thy2) = subthy (thy1, thy2) orelse subthy (thy2, thy1);
   276 
   277 
   278 (* trivial merge *)
   279 
   280 fun merge (thy1, thy2) =
   281   if eq_thy (thy1, thy2) then thy1
   282   else if proper_subthy (thy2, thy1) then thy1
   283   else if proper_subthy (thy1, thy2) then thy2
   284   else (check_merge thy1 thy2;
   285     error (cat_lines ["Attempt to perform non-trivial merge of theories:",
   286       str_of_thy thy1, str_of_thy thy2]));
   287 
   288 fun merge_refs (ref1, ref2) =
   289   if ref1 = ref2 then ref1
   290   else check_thy (merge (deref ref1, deref ref2));
   291 
   292 
   293 
   294 (** build theories **)
   295 
   296 (* primitives *)
   297 
   298 fun create_thy name self id ids iids data ancestry history =
   299   let
   300     val {version, name = _, intermediates = _} = history;
   301     val intermediate = version > 0;
   302     val (ids', iids') = check_insert intermediate id (ids, iids);
   303     val id' = (serial (), name);
   304     val _ = check_insert intermediate id' (ids', iids');
   305     val identity' = make_identity self id' ids' iids';
   306   in vitalize (Theory (identity', data, ancestry, history)) end;
   307 
   308 fun change_thy name f thy =
   309   let
   310     val Theory ({self, id, ids, iids}, data, ancestry, history) = thy;
   311     val (self', data', ancestry') =
   312       if is_draft thy then (self, data, ancestry)    (*destructive change!*)
   313       else if #version history > 0
   314       then (NONE, copy_data data, ancestry)
   315       else (NONE, extend_data data, make_ancestry [thy] (thy :: #ancestors ancestry));
   316     val data'' = f data';
   317     val thy' = NAMED_CRITICAL "theory" (fn () =>
   318       (check_thy thy; create_thy name self' id ids iids data'' ancestry' history));
   319   in thy' end;
   320 
   321 fun name_thy name = change_thy name I;
   322 val modify_thy = change_thy draftN;
   323 val extend_thy = modify_thy I;
   324 
   325 fun copy_thy thy =
   326   let
   327     val Theory ({id, ids, iids, ...}, data, ancestry, history) = thy;
   328     val data' = copy_data data;
   329     val thy' = NAMED_CRITICAL "theory" (fn () =>
   330       (check_thy thy; create_thy draftN NONE id ids iids data' ancestry history));
   331   in thy' end;
   332 
   333 val pre_pure_thy = create_thy draftN NONE (serial (), draftN) Inttab.empty Inttab.empty
   334   Datatab.empty (make_ancestry [] []) (make_history ProtoPureN 0 []);
   335 
   336 
   337 (* named theory nodes *)
   338 
   339 fun merge_thys pp (thy1, thy2) =
   340   if exists_name CPureN thy1 <> exists_name CPureN thy2 then
   341     error "Cannot merge Pure and CPure developments"
   342   else
   343     let
   344       val (ids, iids) = check_merge thy1 thy2;
   345       val data = merge_data (pp thy1) (data_of thy1, data_of thy2);
   346       val ancestry = make_ancestry [] [];
   347       val history = make_history "" 0 [];
   348       val thy' = NAMED_CRITICAL "theory" (fn () =>
   349        (check_thy thy1; check_thy thy2;
   350         create_thy draftN NONE (serial (), draftN) ids iids data ancestry history))
   351     in thy' end;
   352 
   353 fun maximal_thys thys =
   354   thys |> filter (fn thy => not (exists (fn thy' => proper_subthy (thy, thy')) thys));
   355 
   356 fun begin_thy pp name imports =
   357   if name = draftN then error ("Illegal theory name: " ^ quote draftN)
   358   else
   359     let
   360       val parents = maximal_thys (distinct eq_thy imports);
   361       val ancestors = distinct eq_thy (parents @ maps ancestors_of parents);
   362       val Theory ({id, ids, iids, ...}, data, _, _) =
   363         (case parents of
   364           [] => error "No parent theories"
   365         | [thy] => extend_thy thy
   366         | thy :: thys => Library.foldl (merge_thys pp) (thy, thys));
   367       val ancestry = make_ancestry parents ancestors;
   368       val history = make_history name 0 [];
   369       val thy' = NAMED_CRITICAL "theory" (fn () =>
   370         (map check_thy imports; create_thy draftN NONE id ids iids data ancestry history));
   371     in thy' end;
   372 
   373 
   374 (* undoable checkpoints *)
   375 
   376 fun checkpoint_thy thy =
   377   if not (is_draft thy) then thy
   378   else
   379     let
   380       val {name, version, intermediates} = history_of thy;
   381       val thy' as Theory (identity', data', ancestry', _) =
   382         name_thy (name ^ ":" ^ string_of_int version) thy;
   383       val history' = make_history name (version + 1) (thy' :: intermediates);
   384       val thy'' = NAMED_CRITICAL "theory" (fn () =>
   385         (check_thy thy'; vitalize (Theory (identity', data', ancestry', history'))));
   386     in thy'' end;
   387 
   388 fun finish_thy thy = NAMED_CRITICAL "theory" (fn () =>
   389   let
   390     val {name, version, intermediates} = history_of thy;
   391     val rs = map ((fn TheoryRef r => r) o check_thy) intermediates;
   392     val thy' as Theory ({self, id, ids, ...}, data', ancestry', _) = name_thy name thy;
   393     val identity' = make_identity self id ids Inttab.empty;
   394     val history' = make_history name 0 [];
   395     val thy'' = vitalize (Theory (identity', data', ancestry', history'));
   396     val _ = List.app (fn r => r := thy'') rs;
   397   in thy'' end);
   398 
   399 
   400 (* theory data *)
   401 
   402 structure TheoryData =
   403 struct
   404 
   405 val declare = declare_theory_data;
   406 
   407 fun get k dest thy =
   408   dest ((case Datatab.lookup (data_of thy) k of
   409     SOME x => x
   410   | NONE => invoke_copy k (invoke_empty k)));   (*adhoc value*)
   411 
   412 fun put k mk x = modify_thy (Datatab.update (k, mk x));
   413 
   414 end;
   415 
   416 
   417 
   418 (*** proof context ***)
   419 
   420 (* datatype proof *)
   421 
   422 datatype proof = Prf of Object.T Datatab.table * theory_ref;
   423 
   424 fun theory_of_proof (Prf (_, thy_ref)) = deref thy_ref;
   425 fun data_of_proof (Prf (data, _)) = data;
   426 fun map_prf f (Prf (data, thy_ref)) = Prf (f data, thy_ref);
   427 
   428 
   429 (* proof data kinds *)
   430 
   431 local
   432 
   433 val kinds = ref (Datatab.empty: (theory -> Object.T) Datatab.table);
   434 
   435 fun invoke_init k =
   436   (case Datatab.lookup (! kinds) k of
   437     SOME init => init
   438   | NONE => sys_error "Invalid proof data identifier");
   439 
   440 fun init_data thy =
   441   Datatab.map' (fn k => fn _ => invoke_init k thy) (! kinds);
   442 
   443 fun init_new_data data thy =
   444   Datatab.merge (K true) (data, init_data thy);
   445 
   446 in
   447 
   448 fun init_proof thy = Prf (init_data thy, check_thy thy);
   449 
   450 fun transfer_proof thy' (prf as Prf (data, thy_ref)) =
   451   let
   452     val thy = deref thy_ref;
   453     val _ = subthy (thy, thy') orelse error "transfer proof context: not a super theory";
   454     val _ = check_thy thy;
   455     val data' = init_new_data data thy';
   456     val thy_ref' = check_thy thy';
   457   in Prf (data', thy_ref') end;
   458 
   459 
   460 structure ProofData =
   461 struct
   462 
   463 fun declare init =
   464   let
   465     val k = serial ();
   466     val _ = CRITICAL (fn () => change kinds (Datatab.update (k, init)));
   467   in k end;
   468 
   469 fun get k dest prf =
   470   dest (case Datatab.lookup (data_of_proof prf) k of
   471     SOME x => x
   472   | NONE => invoke_init k (theory_of_proof prf));   (*adhoc value*)
   473 
   474 fun put k mk x = map_prf (Datatab.update (k, mk x));
   475 
   476 end;
   477 
   478 end;
   479 
   480 
   481 
   482 (*** generic context ***)
   483 
   484 datatype generic = Theory of theory | Proof of proof;
   485 
   486 fun cases f _ (Theory thy) = f thy
   487   | cases _ g (Proof prf) = g prf;
   488 
   489 fun mapping f g = cases (Theory o f) (Proof o g);
   490 fun mapping_result f g = cases (apsnd Theory o f) (apsnd Proof o g);
   491 
   492 val the_theory = cases I (fn _ => error "Ill-typed context: theory expected");
   493 val the_proof = cases (fn _ => error "Ill-typed context: proof expected") I;
   494 
   495 fun map_theory f = Theory o f o the_theory;
   496 fun map_proof f = Proof o f o the_proof;
   497 
   498 fun theory_map f = the_theory o f o Theory;
   499 fun proof_map f = the_proof o f o Proof;
   500 
   501 val theory_of = cases I theory_of_proof;
   502 val proof_of = cases init_proof I;
   503 
   504 
   505 
   506 (** delayed theory setup **)
   507 
   508 local
   509   val setup_fn = ref (I: theory -> theory);
   510 in
   511   fun add_setup f = CRITICAL (fn () => setup_fn := (! setup_fn #> f));
   512   fun setup () = CRITICAL (fn () => let val f = ! setup_fn in setup_fn := I; f end);
   513 end;
   514 
   515 end;
   516 
   517 structure BasicContext: BASIC_CONTEXT = Context;
   518 open BasicContext;
   519 
   520 
   521 
   522 (*** type-safe interfaces for data declarations ***)
   523 
   524 (** theory data **)
   525 
   526 signature THEORY_DATA_ARGS =
   527 sig
   528   type T
   529   val empty: T
   530   val copy: T -> T
   531   val extend: T -> T
   532   val merge: Pretty.pp -> T * T -> T
   533 end;
   534 
   535 signature THEORY_DATA =
   536 sig
   537   type T
   538   val get: theory -> T
   539   val put: T -> theory -> theory
   540   val map: (T -> T) -> theory -> theory
   541   val init: theory -> theory
   542 end;
   543 
   544 functor TheoryDataFun(Data: THEORY_DATA_ARGS): THEORY_DATA =
   545 struct
   546 
   547 structure TheoryData = Context.TheoryData;
   548 
   549 type T = Data.T;
   550 exception Data of T;
   551 
   552 val kind = TheoryData.declare
   553   (Data Data.empty)
   554   (fn Data x => Data (Data.copy x))
   555   (fn Data x => Data (Data.extend x))
   556   (fn pp => fn (Data x1, Data x2) => Data (Data.merge pp (x1, x2)));
   557 
   558 val get = TheoryData.get kind (fn Data x => x);
   559 val put = TheoryData.put kind Data;
   560 fun map f thy = put (f (get thy)) thy;
   561 
   562 fun init thy = map I thy;
   563 
   564 end;
   565 
   566 
   567 
   568 (** proof data **)
   569 
   570 signature PROOF_DATA_ARGS =
   571 sig
   572   type T
   573   val init: theory -> T
   574 end;
   575 
   576 signature PROOF_DATA =
   577 sig
   578   type T
   579   val get: Context.proof -> T
   580   val put: T -> Context.proof -> Context.proof
   581   val map: (T -> T) -> Context.proof -> Context.proof
   582 end;
   583 
   584 functor ProofDataFun(Data: PROOF_DATA_ARGS): PROOF_DATA =
   585 struct
   586 
   587 structure ProofData = Context.ProofData;
   588 
   589 type T = Data.T;
   590 exception Data of T;
   591 
   592 val kind = ProofData.declare (Data o Data.init);
   593 
   594 val get = ProofData.get kind (fn Data x => x);
   595 val put = ProofData.put kind Data;
   596 fun map f prf = put (f (get prf)) prf;
   597 
   598 end;
   599 
   600 
   601 
   602 (** generic data **)
   603 
   604 signature GENERIC_DATA_ARGS =
   605 sig
   606   type T
   607   val empty: T
   608   val extend: T -> T
   609   val merge: Pretty.pp -> T * T -> T
   610 end;
   611 
   612 signature GENERIC_DATA =
   613 sig
   614   type T
   615   val get: Context.generic -> T
   616   val put: T -> Context.generic -> Context.generic
   617   val map: (T -> T) -> Context.generic -> Context.generic
   618 end;
   619 
   620 functor GenericDataFun(Data: GENERIC_DATA_ARGS): GENERIC_DATA =
   621 struct
   622 
   623 structure ThyData = TheoryDataFun(open Data val copy = I);
   624 structure PrfData = ProofDataFun(type T = Data.T val init = ThyData.get);
   625 
   626 type T = Data.T;
   627 
   628 fun get (Context.Theory thy) = ThyData.get thy
   629   | get (Context.Proof prf) = PrfData.get prf;
   630 
   631 fun put x (Context.Theory thy) = Context.Theory (ThyData.put x thy)
   632   | put x (Context.Proof prf) = Context.Proof (PrfData.put x prf);
   633 
   634 fun map f ctxt = put (f (get ctxt)) ctxt;
   635 
   636 end;
   637 
   638 (*hide private interface*)
   639 structure Context: CONTEXT = Context;
   640 
   641 (*fake predeclarations*)
   642 structure Proof = struct type context = Context.proof end;
   643 structure ProofContext =
   644 struct val theory_of = Context.theory_of_proof val init = Context.init_proof end;