src/Pure/Isar/locale.ML
changeset 17138 ad4c98fd367b
parent 17109 606c269d1e26
child 17142 76a5a2cc3171
equal deleted inserted replaced
17137:0f48fbb60a61 17138:ad4c98fd367b
    20 
    20 
    21 (* TODO:
    21 (* TODO:
    22 - beta-eta normalisation of interpretation parameters
    22 - beta-eta normalisation of interpretation parameters
    23 - dangling type frees in locales
    23 - dangling type frees in locales
    24 - test subsumption of interpretations when merging theories
    24 - test subsumption of interpretations when merging theories
       
    25 - var vs. fixes in locale to be interpreted (interpretation in locale)
       
    26   (implicit locale expressions generated by multiple registrations)
       
    27 - current finish_global adds unwanted lemmas to theory/locale
    25 *)
    28 *)
    26 
    29 
    27 signature LOCALE =
    30 signature LOCALE =
    28 sig
    31 sig
    29   type context
    32   type context
    63       (term * (term list * term list)) list list
    66       (term * (term list * term list)) list list
    64 
    67 
    65   (* Diagnostic functions *)
    68   (* Diagnostic functions *)
    66   val print_locales: theory -> unit
    69   val print_locales: theory -> unit
    67   val print_locale: theory -> expr -> element list -> unit
    70   val print_locale: theory -> expr -> element list -> unit
    68   val print_global_registrations: string -> theory -> unit
    71   val print_global_registrations: bool -> string -> theory -> unit
    69   val print_local_registrations': string -> context -> unit
    72   val print_local_registrations': bool -> string -> context -> unit
    70   val print_local_registrations: string -> context -> unit
    73   val print_local_registrations: bool -> string -> context -> unit
    71 
    74 
    72   (* Storing results *)
    75   (* Storing results *)
    73   val add_locale_context: bool -> bstring -> expr -> element list -> theory
    76   val add_locale_context: bool -> bstring -> expr -> element list -> theory
    74     -> theory * ProofContext.context
    77     -> theory * ProofContext.context
    75   val add_locale_context_i: bool -> bstring -> expr -> element_i list -> theory
    78   val add_locale_context_i: bool -> bstring -> expr -> element_i list -> theory
    96     string * Attrib.src list -> expr -> string option list -> context ->
    99     string * Attrib.src list -> expr -> string option list -> context ->
    97     ((string * term list) * term list) list * (thm list -> context -> context)
   100     ((string * term list) * term list) list * (thm list -> context -> context)
    98   val prep_registration_in_locale:
   101   val prep_registration_in_locale:
    99     string -> expr -> theory ->
   102     string -> expr -> theory ->
   100     ((string * string list) * term list) list * (thm list -> theory -> theory)
   103     ((string * string list) * term list) list * (thm list -> theory -> theory)
   101 
       
   102   (* Diagnostic *)
       
   103   val show_wits: bool ref;
       
   104 end;
   104 end;
   105 
   105 
   106 structure Locale: LOCALE =
   106 structure Locale: LOCALE =
   107 struct
   107 struct
   108 
       
   109 (** Diagnostic: whether to show witness theorems of registrations **)
       
   110 
       
   111 val show_wits = ref false;
       
   112 
   108 
   113 (** locale elements and expressions **)
   109 (** locale elements and expressions **)
   114 
   110 
   115 type context = ProofContext.context;
   111 type context = ProofContext.context;
   116 
   112 
   195                 ((map (fn (a, T) => (certT (TVar (valOf (assoc (al, a)))), certT T)) tinst'),
   191                 ((map (fn (a, T) => (certT (TVar (valOf (assoc (al, a)))), certT T)) tinst'),
   196                   []))
   192                   []))
   197             |> (fn th => Drule.implies_elim_list th
   193             |> (fn th => Drule.implies_elim_list th
   198                  (map (Thm.assume o cert o tinst_tab_term tinst) hyps))
   194                  (map (Thm.assume o cert o tinst_tab_term tinst) hyps))
   199         end;
   195         end;
   200 
       
   201 
   196 
   202 (* instantiate TFrees and Frees *)
   197 (* instantiate TFrees and Frees *)
   203 
   198 
   204 fun inst_tab_term (inst, tinst) = if Symtab.is_empty inst
   199 fun inst_tab_term (inst, tinst) = if Symtab.is_empty inst
   205       then tinst_tab_term tinst
   200       then tinst_tab_term tinst
   247             |> (fn th => Drule.implies_elim_list th
   242             |> (fn th => Drule.implies_elim_list th
   248                  (map (Thm.assume o cert o inst_tab_term (inst, tinst)) hyps))
   243                  (map (Thm.assume o cert o inst_tab_term (inst, tinst)) hyps))
   249         end;
   244         end;
   250 
   245 
   251 
   246 
       
   247 fun inst_tab_att thy (inst as (_, tinst)) =
       
   248     Args.map_values I (tinst_tab_type tinst)
       
   249     (inst_tab_term inst) (inst_tab_thm thy inst);
       
   250 
       
   251 fun inst_tab_atts thy inst = map (inst_tab_att thy inst);
       
   252 
       
   253 
   252 (** management of registrations in theories and proof contexts **)
   254 (** management of registrations in theories and proof contexts **)
   253 
   255 
   254 structure Registrations :
   256 structure Registrations :
   255   sig
   257   sig
   256     type T
   258     type T
   521   end;
   523   end;
   522 
   524 
   523 
   525 
   524 (* printing of registrations *)
   526 (* printing of registrations *)
   525 
   527 
   526 fun gen_print_registrations get_regs mk_ctxt msg loc thy_ctxt =
   528 fun gen_print_registrations get_regs mk_ctxt msg show_wits loc thy_ctxt =
   527   let
   529   let
   528     val ctxt = mk_ctxt thy_ctxt;
   530     val ctxt = mk_ctxt thy_ctxt;
   529     val thy = ProofContext.theory_of ctxt;
   531     val thy = ProofContext.theory_of ctxt;
   530 
   532 
   531     val prt_term = Pretty.quote o ProofContext.pretty_term ctxt;
   533     val prt_term = Pretty.quote o ProofContext.pretty_term ctxt;
   535         Pretty.breaks (Pretty.str prfx :: Args.pretty_attribs ctxt atts);
   537         Pretty.breaks (Pretty.str prfx :: Args.pretty_attribs ctxt atts);
   536     val prt_thm = Pretty.quote o ProofContext.pretty_thm ctxt;
   538     val prt_thm = Pretty.quote o ProofContext.pretty_thm ctxt;
   537     fun prt_thms thms =
   539     fun prt_thms thms =
   538         Pretty.enclose "[" "]" (Pretty.breaks (map prt_thm thms));
   540         Pretty.enclose "[" "]" (Pretty.breaks (map prt_thm thms));
   539     fun prt_reg (ts, (("", []), thms)) =
   541     fun prt_reg (ts, (("", []), thms)) =
   540         if ! show_wits
   542         if show_wits
   541           then Pretty.block [prt_inst ts, Pretty.fbrk, prt_thms thms]
   543           then Pretty.block [prt_inst ts, Pretty.fbrk, prt_thms thms]
   542           else prt_inst ts
   544           else prt_inst ts
   543       | prt_reg (ts, (attn, thms)) =
   545       | prt_reg (ts, (attn, thms)) =
   544         if ! show_wits
   546         if show_wits
   545           then Pretty.block ((prt_attn attn @
   547           then Pretty.block ((prt_attn attn @
   546             [Pretty.str ":", Pretty.brk 1, prt_inst ts, Pretty.fbrk,
   548             [Pretty.str ":", Pretty.brk 1, prt_inst ts, Pretty.fbrk,
   547               prt_thms thms]))
   549               prt_thms thms]))
   548           else Pretty.block ((prt_attn attn @
   550           else Pretty.block ((prt_attn attn @
   549             [Pretty.str ":", Pretty.brk 1, prt_inst ts]));
   551             [Pretty.str ":", Pretty.brk 1, prt_inst ts]));
   567      gen_print_registrations (#3 o GlobalLocalesData.get)
   569      gen_print_registrations (#3 o GlobalLocalesData.get)
   568        ProofContext.init "theory";
   570        ProofContext.init "theory";
   569 val print_local_registrations' =
   571 val print_local_registrations' =
   570      gen_print_registrations LocalLocalesData.get
   572      gen_print_registrations LocalLocalesData.get
   571        I "context";
   573        I "context";
   572 fun print_local_registrations loc ctxt =
   574 fun print_local_registrations show_wits loc ctxt =
   573   (print_global_registrations loc (ProofContext.theory_of ctxt);
   575   (print_global_registrations show_wits loc (ProofContext.theory_of ctxt);
   574    print_local_registrations' loc ctxt);
   576    print_local_registrations' show_wits loc ctxt);
   575 
   577 
   576 
   578 
   577 (* diagnostics *)
   579 (* diagnostics *)
   578 
   580 
   579 fun err_in_locale ctxt msg ids =
   581 fun err_in_locale ctxt msg ids =
   782    specification fragment to assumptions of other (assumed) specification
   784    specification fragment to assumptions of other (assumed) specification
   783    fragments. *)
   785    fragments. *)
   784 
   786 
   785 datatype 'a mode = Assumed of 'a | Derived of 'a;
   787 datatype 'a mode = Assumed of 'a | Derived of 'a;
   786 
   788 
   787 fun map_mode2 f _ (Assumed x) = Assumed (f x)
       
   788   | map_mode2 _ g (Derived x) = Derived (g x);
       
   789 
       
   790 fun map_mode f (Assumed x) = Assumed (f x)
   789 fun map_mode f (Assumed x) = Assumed (f x)
   791   | map_mode f (Derived x) = Derived (f x);
   790   | map_mode f (Derived x) = Derived (f x);
   792 
   791 
   793 (* flatten expressions *)
   792 (* flatten expressions *)
   794 
   793 
   961     fun identify top (Locale name) =
   960     fun identify top (Locale name) =
   962     (* CB: ids_ax is a list of tuples of the form ((name, ps), axs),
   961     (* CB: ids_ax is a list of tuples of the form ((name, ps), axs),
   963        where name is a locale name, ps a list of parameter names and axs
   962        where name is a locale name, ps a list of parameter names and axs
   964        a list of axioms relating to the identifier, axs is empty unless
   963        a list of axioms relating to the identifier, axs is empty unless
   965        identify at top level (top = true);
   964        identify at top level (top = true);
   966        ty is the parameter typing (empty if at top level);
       
   967        parms is accumulated list of parameters *)
   965        parms is accumulated list of parameters *)
   968           let
   966           let
   969             val {predicate = (_, axioms), import, params, ...} =
   967             val {predicate = (_, axioms), import, params, ...} =
   970               the_locale thy name;
   968               the_locale thy name;
   971             val ps = map (#1 o #1) (#1 params);
   969             val ps = map (#1 o #1) (#1 params);
  1729   |>> ProofContext.restore_naming ctxt;
  1727   |>> ProofContext.restore_naming ctxt;
  1730 
  1728 
  1731 end;
  1729 end;
  1732 
  1730 
  1733 
  1731 
       
  1732 (* collect witness theorems for global registration;
       
  1733    requires parameters and flattened list of (assumed!) identifiers
       
  1734    instead of recomputing it from the target *)
       
  1735 
       
  1736 fun collect_global_witnesses thy parms ids vts = let
       
  1737     val ts = map Logic.unvarify vts;
       
  1738     val (parms, parmTs) = split_list parms;
       
  1739     val parmvTs = map Type.varifyT parmTs;
       
  1740     val vtinst = fold (Sign.typ_match thy) (parmvTs ~~ map Term.fastype_of ts) Vartab.empty;
       
  1741     val tinst = Vartab.dest vtinst |> map (fn ((x, 0), (_, T)) => (x, T))
       
  1742         |> Symtab.make;            
       
  1743     (* replace parameter names in ids by instantiations *)
       
  1744     val vinst = Symtab.make (parms ~~ vts);
       
  1745     fun vinst_names ps = map (fn p => Symtab.lookup (vinst, p) |> valOf) ps;
       
  1746     val inst = Symtab.make (parms ~~ ts);
       
  1747     val ids' = map (apsnd vinst_names) ids;
       
  1748     val wits = List.concat (map (snd o valOf o get_global_registration thy) ids');
       
  1749   in ((inst, tinst), wits) end;
       
  1750 
       
  1751 
  1734 (* store instantiations of args for all registered interpretations
  1752 (* store instantiations of args for all registered interpretations
  1735    of the theory *)
  1753    of the theory *)
  1736 
  1754 
  1737 fun note_thmss_registrations kind target args thy =
  1755 fun note_thmss_registrations kind target args thy =
  1738   let
  1756   let
  1739     val (parms, parmTs) =
  1757     val parms = the_locale thy target |> #params |> fst |> map fst;
  1740           the_locale thy target |> #params |> fst |> map fst |> split_list;
       
  1741     val parmvTs = map Type.varifyT parmTs;
       
  1742     val ids = flatten (ProofContext.init thy, intern_expr thy)
  1758     val ids = flatten (ProofContext.init thy, intern_expr thy)
  1743       (([], Symtab.empty), Expr (Locale target)) |> fst |> fst
  1759       (([], Symtab.empty), Expr (Locale target)) |> fst |> fst
  1744       |> List.mapPartial (fn (id, (_, Assumed _)) => SOME id | _ => NONE)
  1760       |> List.mapPartial (fn (id, (_, Assumed _)) => SOME id | _ => NONE)
  1745 
  1761 
  1746     val regs = get_global_registrations thy target;
  1762     val regs = get_global_registrations thy target;
  1747 
  1763 
  1748     (* add args to thy for all registrations *)
  1764     (* add args to thy for all registrations *)
  1749 
  1765 
  1750     fun activate (thy, (vts, ((prfx, atts2), _))) =
  1766     fun activate (thy, (vts, ((prfx, atts2), _))) =
  1751       let
  1767       let
  1752         val ts = map Logic.unvarify vts;
  1768         val ((inst, tinst), prems) = collect_global_witnesses thy parms ids vts;
  1753         (* type instantiation *)
       
  1754         val vtinst = fold (Sign.typ_match thy) (parmvTs ~~ map Term.fastype_of ts) Vartab.empty;
       
  1755         val tinst = Vartab.dest vtinst |> map (fn ((x, 0), (_, T)) => (x, T))
       
  1756              |> Symtab.make;            
       
  1757         (* replace parameter names in ids by instantiations *)
       
  1758         val vinst = Symtab.make (parms ~~ vts);
       
  1759         fun vinst_names ps = map (fn p => Symtab.lookup (vinst, p) |> valOf) ps;
       
  1760         val inst = Symtab.make (parms ~~ ts);
       
  1761         val ids' = map (apsnd vinst_names) ids;
       
  1762         val prems = List.concat (map (snd o valOf o get_global_registration thy) ids');
       
  1763         val args' = map (fn ((n, atts), [(ths, [])]) =>
  1769         val args' = map (fn ((n, atts), [(ths, [])]) =>
  1764             ((NameSpace.qualified prfx n,
  1770             ((NameSpace.qualified prfx n,
  1765               map (Attrib.global_attribute_i thy) (atts @ atts2)),
  1771               map (Attrib.global_attribute_i thy)
  1766              [(map (Drule.standard o Drule.satisfy_hyps prems o inst_tab_thm thy (inst, tinst)) ths, [])]))
  1772                   (inst_tab_atts thy (inst, tinst) atts @ atts2)),
       
  1773              [(map (Drule.standard o Drule.satisfy_hyps prems o
       
  1774                 inst_tab_thm thy (inst, tinst)) ths, [])]))
  1767           args;
  1775           args;
  1768       in global_note_accesses_i (Drule.kind kind) prfx args' thy |> fst end;
  1776       in global_note_accesses_i (Drule.kind kind) prfx args' thy |> fst end;
  1769   in Library.foldl activate (thy, regs) end;
  1777   in Library.foldl activate (thy, regs) end;
  1770 
  1778 
  1771 
  1779 
  2025 
  2033 
  2026 local
  2034 local
  2027 
  2035 
  2028 (* extract proof obligations (assms and defs) from elements *)
  2036 (* extract proof obligations (assms and defs) from elements *)
  2029 
  2037 
  2030 fun extract_asms_elem (ts, Fixes _) = ts
  2038 fun extract_asms_elem (Fixes _) ts = ts
  2031   | extract_asms_elem (ts, Constrains _) = ts
  2039   | extract_asms_elem (Constrains _) ts = ts
  2032   | extract_asms_elem (ts, Assumes asms) =
  2040   | extract_asms_elem (Assumes asms) ts =
  2033       ts @ List.concat (map (fn (_, ams) => map (fn (t, _) => t) ams) asms)
  2041       ts @ List.concat (map (fn (_, ams) => map (fn (t, _) => t) ams) asms)
  2034   | extract_asms_elem (ts, Defines defs) =
  2042   | extract_asms_elem (Defines defs) ts =
  2035       ts @ map (fn (_, (def, _)) => def) defs
  2043       ts @ map (fn (_, (def, _)) => def) defs
  2036   | extract_asms_elem (ts, Notes _) = ts;
  2044   | extract_asms_elem (Notes _) ts = ts;
  2037 
  2045 
  2038 fun extract_asms_elems ((id, Assumed _), elems) =
  2046 fun extract_asms_elems ((id, Assumed _), elems) =
  2039       SOME (id, Library.foldl extract_asms_elem ([], elems))
  2047       (id, fold extract_asms_elem elems [])
  2040   | extract_asms_elems ((_, Derived _), _) = NONE;
  2048   | extract_asms_elems ((id, Derived _), _) = (id, []);
  2041 
  2049 
  2042 fun extract_asms_elemss elemss =
  2050 fun extract_asms_elemss elemss = map extract_asms_elems elemss;
  2043       List.mapPartial extract_asms_elems elemss;
       
  2044 
  2051 
  2045 (* activate instantiated facts in theory or context *)
  2052 (* activate instantiated facts in theory or context *)
  2046 
  2053 
  2047 fun gen_activate_facts_elemss get_reg note_thmss attrib std put_reg add_wit
  2054 fun gen_activate_facts_elemss get_reg note attrib std put_reg add_wit
  2048         attn all_elemss new_elemss propss result thy_ctxt =
  2055         attn all_elemss new_elemss propss result thy_ctxt =
  2049     let
  2056     let
  2050       fun activate_elem disch (prfx, atts) (Notes facts) thy_ctxt =
  2057       fun activate_elem disch (prfx, atts) (Notes facts) thy_ctxt =
  2051           let
  2058           let
  2052             val facts' = facts
  2059             val facts' = facts
  2056               |> map (apfst (apsnd (fn a => a @ map (attrib thy_ctxt) atts)))
  2063               |> map (apfst (apsnd (fn a => a @ map (attrib thy_ctxt) atts)))
  2057               (* discharge hyps *)
  2064               (* discharge hyps *)
  2058               |> map (apsnd (map (apfst (map disch))))
  2065               |> map (apsnd (map (apfst (map disch))))
  2059               (* prefix names *)
  2066               (* prefix names *)
  2060               |> map (apfst (apfst (NameSpace.qualified prfx)))
  2067               |> map (apfst (apfst (NameSpace.qualified prfx)))
  2061           in fst (note_thmss prfx facts' thy_ctxt) end
  2068           in fst (note prfx facts' thy_ctxt) end
  2062         | activate_elem _ _ _ thy_ctxt = thy_ctxt;
  2069         | activate_elem _ _ _ thy_ctxt = thy_ctxt;
  2063 
  2070 
  2064       fun activate_elems disch ((id, mode), elems) thy_ctxt =
  2071       fun activate_elems disch ((id, _), elems) thy_ctxt =
  2065           let
  2072           let
  2066             val ((prfx, atts2), _) = valOf (get_reg thy_ctxt id)
  2073             val ((prfx, atts2), _) = valOf (get_reg thy_ctxt id)
  2067                 handle Option => sys_error ("Unknown registration of " ^
  2074                 handle Option => sys_error ("Unknown registration of " ^
  2068                   quote (fst id) ^ " while activating facts.");
  2075                   quote (fst id) ^ " while activating facts.");
  2069           in
  2076           in
  2217 
  2224 
  2218 fun prep_registration_in_locale target expr thy =
  2225 fun prep_registration_in_locale target expr thy =
  2219   (* target already in internal form *)
  2226   (* target already in internal form *)
  2220   let
  2227   let
  2221     val ctxt = ProofContext.init thy;
  2228     val ctxt = ProofContext.init thy;
  2222     val ((target_ids, target_syn), target_elemss) = flatten (ctxt, I)
  2229     val ((raw_target_ids, target_syn), _) = flatten (ctxt, I)
  2223         (([], Symtab.empty), Expr (Locale target));
  2230         (([], Symtab.empty), Expr (Locale target));
  2224     val fixed = the_locale thy target |> #params |> #1 |> map #1;
  2231     val fixed = the_locale thy target |> #params |> #1 |> map #1;
  2225     val ((all_ids, syn), raw_elemss) = flatten (ctxt, intern_expr thy)
  2232     val ((all_ids, syn), raw_elemss) = flatten (ctxt, intern_expr thy)
  2226         ((target_ids, target_syn), Expr expr);
  2233         ((raw_target_ids, target_syn), Expr expr);
  2227     val ids = Library.drop (length target_ids, all_ids);
  2234     val (target_ids, ids) = splitAt (length raw_target_ids, all_ids);
  2228     val ((parms, elemss, _), _) =
  2235     val ((parms, elemss, _), _) = read_elemss false ctxt fixed raw_elemss [];
  2229         read_elemss false ctxt fixed raw_elemss [];
       
  2230 
  2236 
  2231     (** compute proof obligations **)
  2237     (** compute proof obligations **)
  2232 
  2238 
  2233     (* restore "small" ids, with mode *)
  2239     (* restore "small" ids, with mode *)
  2234     val ids' = map (apsnd snd) ids;
  2240     val ids' = map (apsnd snd) ids;
  2235     (* remove Int markers *)
  2241     (* remove Int markers *)
  2236     val elemss' = map (fn (_, es) =>
  2242     val elemss' = map (fn (_, es) =>
  2237         map (fn Int e => e) es) elemss
  2243         map (fn Int e => e) es) elemss
  2238     (* extract assumptions and defs *)
  2244     (* extract assumptions and defs *)
  2239     val propss = extract_asms_elemss (ids' ~~ elemss');
  2245     val ids_elemss = ids' ~~ elemss';
  2240 
  2246     val propss = extract_asms_elemss ids_elemss;
  2241     (** activation function: add registrations **)
  2247 
       
  2248     (** activation function:
       
  2249         - add registrations to the target locale
       
  2250         - add induced registrations for all global registrations of
       
  2251           the target, unless already present
       
  2252         - add facts of induced registrations to theory **)
       
  2253 
       
  2254     val t_ids = List.mapPartial
       
  2255         (fn (id, (_, Assumed _)) => SOME id | _ => NONE) target_ids;
       
  2256 
  2242     fun activate locale_results thy = let
  2257     fun activate locale_results thy = let
  2243         val thmss = unflat (map snd propss) locale_results;
  2258         val ids_elemss_thmss = ids_elemss ~~
  2244         fun activate_id (id, thms) thy =
  2259 	    unflat (map snd propss) locale_results;
       
  2260         val regs = get_global_registrations thy target;
       
  2261 
       
  2262         fun activate_id (((id, Assumed _), _), thms) thy =
  2245             thy |> put_registration_in_locale target id
  2263             thy |> put_registration_in_locale target id
  2246                 |> fold (add_witness_in_locale target id) thms;
  2264                 |> fold (add_witness_in_locale target id) thms
       
  2265           | activate_id _ thy = thy;
       
  2266 
       
  2267         fun activate_reg (vts, ((prfx, atts2), _)) thy = let
       
  2268             val ((inst, tinst), wits) =
       
  2269                 collect_global_witnesses thy fixed t_ids vts;
       
  2270             fun inst_parms ps = map (fn p =>
       
  2271                   valOf (assoc (map #1 fixed ~~ vts, p))) ps;
       
  2272             val disch = Drule.fconv_rule (Thm.beta_conversion true) o
       
  2273                 Drule.satisfy_hyps wits;
       
  2274             val new_elemss = List.filter (fn (((name, ps), _), _) =>
       
  2275                 not (test_global_registration thy (name, inst_parms ps))) (ids_elemss);
       
  2276             fun activate_assumed_id (((_, Derived _), _), _) thy = thy
       
  2277               | activate_assumed_id ((((name, ps), Assumed _), _), thms) thy = let
       
  2278                 val ps' = inst_parms ps;
       
  2279               in
       
  2280                 if test_global_registration thy (name, ps')
       
  2281                 then thy
       
  2282                 else thy
       
  2283                   |> put_global_registration (name, ps') (prfx, atts2)
       
  2284                   |> fold (fn thm => fn thy => add_global_witness (name, ps')
       
  2285                        ((disch o inst_tab_thm thy (inst, tinst)) thm) thy) thms
       
  2286               end;
       
  2287 
       
  2288             fun activate_derived_id ((_, Assumed _), _) thy = thy
       
  2289               | activate_derived_id (((name, ps), Derived ths), _) thy = let
       
  2290                 val ps' = inst_parms ps;
       
  2291               in
       
  2292                 if test_global_registration thy (name, ps')
       
  2293                 then thy
       
  2294                 else thy
       
  2295                   |> put_global_registration (name, ps') (prfx, atts2)
       
  2296                   |> fold (fn thm => fn thy => add_global_witness (name, ps')
       
  2297                        ((disch o inst_tab_thm thy (inst, tinst) o Drule.satisfy_hyps locale_results) thm) thy) ths
       
  2298               end;
       
  2299 
       
  2300             fun activate_elem (Notes facts) thy =
       
  2301                 let
       
  2302                   val facts' = facts
       
  2303                       |> Attrib.map_facts (Attrib.global_attribute_i thy o
       
  2304                          Args.map_values I (tinst_tab_type tinst)
       
  2305                            (inst_tab_term (inst, tinst))
       
  2306                            (disch o inst_tab_thm thy (inst, tinst) o
       
  2307                             Drule.satisfy_hyps locale_results))
       
  2308                       |> map (apfst (apsnd (fn a => a @ map (Attrib.global_attribute thy) atts2)))
       
  2309                       |> map (apsnd (map (apfst (map (disch o inst_tab_thm thy (inst, tinst) o Drule.satisfy_hyps locale_results)))))
       
  2310                       |> map (apfst (apfst (NameSpace.qualified prfx)))
       
  2311                 in
       
  2312                   fst (global_note_accesses_i (Drule.kind "") prfx facts' thy)
       
  2313                 end
       
  2314               | activate_elem _ thy = thy;
       
  2315 
       
  2316             fun activate_elems (_, elems) thy = fold activate_elem elems thy;
       
  2317 
       
  2318           in thy |> fold activate_assumed_id ids_elemss_thmss
       
  2319                  |> fold activate_derived_id ids_elemss
       
  2320                  |> fold activate_elems new_elemss end;
  2247       in
  2321       in
  2248         fold activate_id (map fst propss ~~ thmss) thy
  2322         thy |> fold activate_id ids_elemss_thmss
       
  2323             |> fold activate_reg regs
  2249       end;
  2324       end;
  2250 
  2325 
  2251   in (propss, activate) end;
  2326   in (propss, activate) end;
  2252 
  2327 
  2253 end;  (* local *)
  2328 end;  (* local *)