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