src/Pure/Isar/generic_target.ML
author wenzelm
Wed, 26 Mar 2014 14:41:52 +0100
changeset 56294 85911b8a6868
parent 56141 c06202417c4a
child 57057 e54713f22a88
permissions -rw-r--r--
prefer Context_Position where a context is available; prefer explicit Context_Position.is_visible -- avoid redundant message composition; tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 41228
diff changeset
     1
(*  Title:      Pure/Isar/generic_target.ML
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     2
    Author:     Makarius
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     3
    Author:     Florian Haftmann, TU Muenchen
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     4
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     5
Common target infrastructure.
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     6
*)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     7
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     8
signature GENERIC_TARGET =
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     9
sig
40782
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    10
  val define: (((binding * typ) * mixfix) * (binding * term) ->
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    11
      term list * term list -> local_theory -> (term * thm) * local_theory) ->
46992
eeea81b86b70 refined Local_Theory.define vs. Local_Theory.define_internal, which allows to pass alternative name to the foundational axiom -- expecially important for 'instantiation' or 'overloading', which loose name information due to Long_Name.base_name cooking etc.;
wenzelm
parents: 46916
diff changeset
    12
    bool -> (binding * mixfix) * (Attrib.binding * term) -> local_theory ->
40782
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    13
    (term * (string * thm)) * local_theory
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
    14
  val notes:
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
    15
    (string -> (Attrib.binding * (thm list * Args.src list) list) list ->
40782
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    16
      (Attrib.binding * (thm list * Args.src list) list) list -> local_theory -> local_theory) ->
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    17
    string -> (Attrib.binding * (thm list * Args.src list) list) list -> local_theory ->
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    18
    (string * thm list) list * local_theory
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
    19
  val locale_notes: string -> string ->
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
    20
    (Attrib.binding * (thm list * Args.src list) list) list ->
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
    21
    (Attrib.binding * (thm list * Args.src list) list) list ->
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
    22
    local_theory -> local_theory
40782
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    23
  val abbrev: (string * bool -> binding * mixfix -> term * term ->
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    24
      term list -> local_theory -> local_theory) ->
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
    25
    string * bool -> (binding * mixfix) * term -> local_theory -> (term * term) * local_theory
47081
5e70b457b704 uniform Generic_Target.standard_declaration, which uses the standard morphism for each context (NB: targets like "interpretation" appear like "theory" but declare local type parameters);
wenzelm
parents: 47080
diff changeset
    26
  val background_declaration: declaration -> local_theory -> local_theory
47280
wenzelm
parents: 47279
diff changeset
    27
  val locale_declaration: string -> bool -> declaration -> local_theory -> local_theory
47282
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
    28
  val standard_declaration: (int -> bool) -> declaration -> local_theory -> local_theory
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
    29
  val generic_const: bool -> Syntax.mode -> (binding * mixfix) * term ->
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
    30
    Context.generic -> Context.generic
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
    31
  val const_declaration: (int -> bool) -> Syntax.mode -> (binding * mixfix) * term ->
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
    32
    local_theory -> local_theory
47284
0e65b6a016dc clarified background_foundation vs. theory_foundation (with const_declaration);
wenzelm
parents: 47283
diff changeset
    33
  val background_foundation: ((binding * typ) * mixfix) * (binding * term) ->
0e65b6a016dc clarified background_foundation vs. theory_foundation (with const_declaration);
wenzelm
parents: 47283
diff changeset
    34
    term list * term list -> local_theory -> (term * thm) * local_theory
40782
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    35
  val theory_foundation: ((binding * typ) * mixfix) * (binding * term) ->
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    36
    term list * term list -> local_theory -> (term * thm) * local_theory
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
    37
  val theory_notes: string ->
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
    38
    (Attrib.binding * (thm list * Args.src list) list) list ->
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
    39
    (Attrib.binding * (thm list * Args.src list) list) list ->
40782
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    40
    local_theory -> local_theory
47286
392c4cd97e5c more uniform theory_abbrev with const_declaration;
wenzelm
parents: 47285
diff changeset
    41
  val theory_abbrev: Syntax.mode -> (binding * mixfix) -> term * term -> term list ->
392c4cd97e5c more uniform theory_abbrev with const_declaration;
wenzelm
parents: 47285
diff changeset
    42
    local_theory -> local_theory
47279
4bab649dedf0 clarified standard_declaration vs. theory_declaration;
wenzelm
parents: 47276
diff changeset
    43
  val theory_declaration: declaration -> local_theory -> local_theory
52153
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
    44
  val theory_registration: string * morphism -> (morphism * bool) option -> morphism ->
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
    45
    local_theory -> local_theory
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
    46
  val locale_dependency: string -> string * morphism -> (morphism * bool) option -> morphism ->
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
    47
    local_theory -> local_theory
45353
wenzelm
parents: 45352
diff changeset
    48
end
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    49
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    50
structure Generic_Target: GENERIC_TARGET =
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    51
struct
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    52
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
    53
(** lifting primitive to target operations **)
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
    54
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
    55
(* mixfix syntax *)
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
    56
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
    57
fun check_mixfix ctxt (b, extra_tfrees) mx =
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
    58
  if null extra_tfrees then mx
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
    59
  else
56294
85911b8a6868 prefer Context_Position where a context is available;
wenzelm
parents: 56141
diff changeset
    60
   (if Context_Position.is_visible ctxt then
85911b8a6868 prefer Context_Position where a context is available;
wenzelm
parents: 56141
diff changeset
    61
      warning
85911b8a6868 prefer Context_Position where a context is available;
wenzelm
parents: 56141
diff changeset
    62
        ("Additional type variable(s) in specification of " ^ Binding.print b ^ ": " ^
85911b8a6868 prefer Context_Position where a context is available;
wenzelm
parents: 56141
diff changeset
    63
          commas (map (Syntax.string_of_typ ctxt o TFree) (sort_wrt #1 extra_tfrees)) ^
85911b8a6868 prefer Context_Position where a context is available;
wenzelm
parents: 56141
diff changeset
    64
          (if mx = NoSyn then ""
85911b8a6868 prefer Context_Position where a context is available;
wenzelm
parents: 56141
diff changeset
    65
           else "\nDropping mixfix syntax " ^ Pretty.string_of (Mixfix.pretty_mixfix mx)))
85911b8a6868 prefer Context_Position where a context is available;
wenzelm
parents: 56141
diff changeset
    66
    else (); NoSyn);
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
    67
47291
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
    68
fun check_mixfix_global (b, no_params) mx =
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
    69
  if no_params orelse mx = NoSyn then mx
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
    70
  else (warning ("Dropping global mixfix syntax: " ^ Binding.print b ^ " " ^
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
    71
    Pretty.string_of (Mixfix.pretty_mixfix mx)); NoSyn);
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
    72
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
    73
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    74
(* define *)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    75
46992
eeea81b86b70 refined Local_Theory.define vs. Local_Theory.define_internal, which allows to pass alternative name to the foundational axiom -- expecially important for 'instantiation' or 'overloading', which loose name information due to Long_Name.base_name cooking etc.;
wenzelm
parents: 46916
diff changeset
    76
fun define foundation internal ((b, mx), ((b_def, atts), rhs)) lthy =
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    77
  let
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42287
diff changeset
    78
    val thy = Proof_Context.theory_of lthy;
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42287
diff changeset
    79
    val thy_ctxt = Proof_Context.init_global thy;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    80
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    81
    (*term and type parameters*)
47276
wenzelm
parents: 47272
diff changeset
    82
    val ((defs, _), rhs') = Thm.cterm_of thy rhs
wenzelm
parents: 47272
diff changeset
    83
      |> Local_Defs.export_cterm lthy thy_ctxt ||> Thm.term_of;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    84
47272
ca31cfa509b1 refined define/abbrev: allow extra fixes in aux. context vs. bottom target (NB: export_term expands defined variables, leaving fixed ones);
wenzelm
parents: 47250
diff changeset
    85
    val xs = Variable.add_fixed lthy rhs' [];
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    86
    val T = Term.fastype_of rhs;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    87
    val tfreesT = Term.add_tfreesT T (fold (Term.add_tfreesT o #2) xs []);
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    88
    val extra_tfrees = rev (subtract (op =) tfreesT (Term.add_tfrees rhs []));
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
    89
    val mx' = check_mixfix lthy (b, extra_tfrees) mx;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    90
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    91
    val type_params = map (Logic.mk_type o TFree) extra_tfrees;
47272
ca31cfa509b1 refined define/abbrev: allow extra fixes in aux. context vs. bottom target (NB: export_term expands defined variables, leaving fixed ones);
wenzelm
parents: 47250
diff changeset
    92
    val term_params = map Free (sort (Variable.fixed_ord lthy o pairself #1) xs);
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    93
    val params = type_params @ term_params;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    94
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    95
    val U = map Term.fastype_of params ---> T;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    96
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    97
    (*foundation*)
45353
wenzelm
parents: 45352
diff changeset
    98
    val ((lhs', global_def), lthy2) = lthy
wenzelm
parents: 45352
diff changeset
    99
      |> foundation (((b, U), mx'), (b_def, rhs')) (type_params, term_params);
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   100
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   101
    (*local definition*)
38315
fa3f90cf6d9c basic renumbering
haftmann
parents: 38313
diff changeset
   102
    val ((lhs, local_def), lthy3) = lthy2
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   103
      |> Local_Defs.add_def ((b, NoSyn), lhs');
47240
wenzelm
parents: 47238
diff changeset
   104
wenzelm
parents: 47238
diff changeset
   105
    (*result*)
47238
289dcbdd5984 more direct Local_Defs.contract;
wenzelm
parents: 47081
diff changeset
   106
    val def =
47240
wenzelm
parents: 47238
diff changeset
   107
      Thm.transitive local_def global_def
54742
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 52230
diff changeset
   108
      |> Local_Defs.contract lthy3 defs
47240
wenzelm
parents: 47238
diff changeset
   109
          (Thm.cterm_of (Proof_Context.theory_of lthy3) (Logic.mk_equals (lhs, rhs)));
38315
fa3f90cf6d9c basic renumbering
haftmann
parents: 38313
diff changeset
   110
    val ([(res_name, [res])], lthy4) = lthy3
47080
wenzelm
parents: 46992
diff changeset
   111
      |> Local_Theory.notes [((if internal then Binding.empty else b_def, atts), [([def], [])])];
38315
fa3f90cf6d9c basic renumbering
haftmann
parents: 38313
diff changeset
   112
  in ((lhs, (res_name, res)), lthy4) end;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   113
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   114
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   115
(* notes *)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   116
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   117
local
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   118
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   119
fun import_export_proof ctxt (name, raw_th) =
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   120
  let
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42287
diff changeset
   121
    val thy = Proof_Context.theory_of ctxt;
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42287
diff changeset
   122
    val thy_ctxt = Proof_Context.init_global thy;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   123
    val certT = Thm.ctyp_of thy;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   124
    val cert = Thm.cterm_of thy;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   125
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   126
    (*export assumes/defines*)
54883
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 54742
diff changeset
   127
    val th = Goal.norm_result ctxt raw_th;
45407
a83574606719 more specific treatment of defines/assumes -- avoid normalizing defs by themselves (NB: locale specifications and Local_Theory.define may lead to arbitrary mixture);
wenzelm
parents: 45390
diff changeset
   128
    val ((defs, asms), th') = Local_Defs.export ctxt thy_ctxt th;
54742
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 52230
diff changeset
   129
    val asms' = map (rewrite_rule ctxt (Drule.norm_hhf_eqs @ defs)) asms;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   130
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   131
    (*export fixes*)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   132
    val tfrees = map TFree (Thm.fold_terms Term.add_tfrees th' []);
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   133
    val frees = map Free (Thm.fold_terms Term.add_frees th' []);
45352
0b4038361a3a misc tuning;
wenzelm
parents: 45310
diff changeset
   134
    val (th'' :: vs) =
0b4038361a3a misc tuning;
wenzelm
parents: 45310
diff changeset
   135
      (th' :: map (Drule.mk_term o cert) (map Logic.mk_type tfrees @ frees))
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   136
      |> Variable.export ctxt thy_ctxt
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   137
      |> Drule.zero_var_indexes_list;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   138
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   139
    (*thm definition*)
45413
117ff038f8f7 disabled Thm.compress (again) -- costs for building tables tend to be higher than potential benefit;
wenzelm
parents: 45407
diff changeset
   140
    val result = Global_Theory.name_thm true true name th'';
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   141
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   142
    (*import fixes*)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   143
    val (tvars, vars) =
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   144
      chop (length tfrees) (map (Thm.term_of o Drule.dest_term) vs)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   145
      |>> map Logic.dest_type;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   146
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   147
    val instT = map_filter (fn (TVar v, T) => SOME (v, T) | _ => NONE) (tvars ~~ tfrees);
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   148
    val inst = filter (is_Var o fst) (vars ~~ frees);
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   149
    val cinstT = map (pairself certT o apfst TVar) instT;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   150
    val cinst = map (pairself (cert o Term.map_types (Term_Subst.instantiateT instT))) inst;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   151
    val result' = Thm.instantiate (cinstT, cinst) result;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   152
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   153
    (*import assumes/defines*)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   154
    val result'' =
45407
a83574606719 more specific treatment of defines/assumes -- avoid normalizing defs by themselves (NB: locale specifications and Local_Theory.define may lead to arbitrary mixture);
wenzelm
parents: 45390
diff changeset
   155
      (fold (curry op COMP) asms' result'
a83574606719 more specific treatment of defines/assumes -- avoid normalizing defs by themselves (NB: locale specifications and Local_Theory.define may lead to arbitrary mixture);
wenzelm
parents: 45390
diff changeset
   156
        handle THM _ => raise THM ("Failed to re-import result", 0, result' :: asms'))
54742
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 52230
diff changeset
   157
      |> Local_Defs.contract ctxt defs (Thm.cprop_of th)
54883
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 54742
diff changeset
   158
      |> Goal.norm_result ctxt
39557
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 38831
diff changeset
   159
      |> Global_Theory.name_thm false false name;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   160
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   161
  in (result'', result) end;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   162
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   163
fun standard_facts lthy ctxt =
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   164
  Element.transform_facts (Local_Theory.standard_morphism lthy ctxt);
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   165
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   166
in
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   167
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   168
fun notes target_notes kind facts lthy =
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   169
  let
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   170
    val facts' = facts
39557
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 38831
diff changeset
   171
      |> map (fn (a, bs) => (a, Global_Theory.burrow_fact (Global_Theory.name_multi
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   172
          (Local_Theory.full_name lthy (fst a))) bs))
39557
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 38831
diff changeset
   173
      |> Global_Theory.map_facts (import_export_proof lthy);
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 38831
diff changeset
   174
    val local_facts = Global_Theory.map_facts #1 facts';
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 38831
diff changeset
   175
    val global_facts = Global_Theory.map_facts #2 facts';
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   176
  in
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   177
    lthy
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   178
    |> target_notes kind global_facts (Attrib.partial_evaluation lthy local_facts)
47249
c0481c3c2a6c added Attrib.global_notes/local_notes/generic_notes convenience;
wenzelm
parents: 47246
diff changeset
   179
    |> Attrib.local_notes kind local_facts
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   180
  end;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   181
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   182
fun locale_notes locale kind global_facts local_facts =
56141
c06202417c4a back to a form of hybrid facts, to reduce performance impact of ed92ce2ac88e;
wenzelm
parents: 56140
diff changeset
   183
  Local_Theory.background_theory
c06202417c4a back to a form of hybrid facts, to reduce performance impact of ed92ce2ac88e;
wenzelm
parents: 56140
diff changeset
   184
    (Attrib.global_notes kind (Attrib.map_facts (K []) global_facts) #> snd) #>
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   185
  (fn lthy => lthy |>
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   186
    Local_Theory.target (fn ctxt => ctxt |>
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   187
      Locale.add_thmss locale kind (standard_facts lthy ctxt local_facts))) #>
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   188
  (fn lthy => lthy |>
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   189
    Local_Theory.map_contexts (fn level => fn ctxt =>
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   190
      if level = 0 orelse level = Local_Theory.level lthy then ctxt
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   191
      else ctxt |> Attrib.local_notes kind (standard_facts lthy ctxt local_facts) |> snd));
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   192
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   193
end;
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   194
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   195
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   196
(* abbrev *)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   197
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   198
fun abbrev target_abbrev prmode ((b, mx), t) lthy =
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   199
  let
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42287
diff changeset
   200
    val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of lthy);
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   201
47292
1884d34e9aab export into target context (again), to retain its 'defines' (e.g. abbreviation lcoeff in theory HOL/Algebra/UnivPoly);
wenzelm
parents: 47291
diff changeset
   202
    val t' = Assumption.export_term lthy (Local_Theory.target_of lthy) t;
47290
ba9c8613ad9b more uniform abbrev vs. define;
wenzelm
parents: 47288
diff changeset
   203
    val xs = map Free (sort (Variable.fixed_ord lthy o pairself #1) (Variable.add_fixed lthy t' []));
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   204
    val u = fold_rev lambda xs t';
47290
ba9c8613ad9b more uniform abbrev vs. define;
wenzelm
parents: 47288
diff changeset
   205
    val global_rhs = singleton (Variable.polymorphic thy_ctxt) u;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   206
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   207
    val extra_tfrees =
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   208
      subtract (op =) (Term.add_tfreesT (Term.fastype_of u) []) (Term.add_tfrees u []);
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
   209
    val mx' = check_mixfix lthy (b, extra_tfrees) mx;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   210
  in
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   211
    lthy
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
   212
    |> target_abbrev prmode (b, mx') (global_rhs, t') xs
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42287
diff changeset
   213
    |> Proof_Context.add_abbrev Print_Mode.internal (b, t) |> snd
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   214
    |> Local_Defs.fixed_abbrev ((b, NoSyn), t)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   215
  end;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   216
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
   217
47081
5e70b457b704 uniform Generic_Target.standard_declaration, which uses the standard morphism for each context (NB: targets like "interpretation" appear like "theory" but declare local type parameters);
wenzelm
parents: 47080
diff changeset
   218
(* declaration *)
5e70b457b704 uniform Generic_Target.standard_declaration, which uses the standard morphism for each context (NB: targets like "interpretation" appear like "theory" but declare local type parameters);
wenzelm
parents: 47080
diff changeset
   219
5e70b457b704 uniform Generic_Target.standard_declaration, which uses the standard morphism for each context (NB: targets like "interpretation" appear like "theory" but declare local type parameters);
wenzelm
parents: 47080
diff changeset
   220
fun background_declaration decl lthy =
5e70b457b704 uniform Generic_Target.standard_declaration, which uses the standard morphism for each context (NB: targets like "interpretation" appear like "theory" but declare local type parameters);
wenzelm
parents: 47080
diff changeset
   221
  let
5e70b457b704 uniform Generic_Target.standard_declaration, which uses the standard morphism for each context (NB: targets like "interpretation" appear like "theory" but declare local type parameters);
wenzelm
parents: 47080
diff changeset
   222
    val theory_decl =
5e70b457b704 uniform Generic_Target.standard_declaration, which uses the standard morphism for each context (NB: targets like "interpretation" appear like "theory" but declare local type parameters);
wenzelm
parents: 47080
diff changeset
   223
      Local_Theory.standard_form lthy
5e70b457b704 uniform Generic_Target.standard_declaration, which uses the standard morphism for each context (NB: targets like "interpretation" appear like "theory" but declare local type parameters);
wenzelm
parents: 47080
diff changeset
   224
        (Proof_Context.init_global (Proof_Context.theory_of lthy)) decl;
5e70b457b704 uniform Generic_Target.standard_declaration, which uses the standard morphism for each context (NB: targets like "interpretation" appear like "theory" but declare local type parameters);
wenzelm
parents: 47080
diff changeset
   225
  in Local_Theory.background_theory (Context.theory_map theory_decl) lthy end;
5e70b457b704 uniform Generic_Target.standard_declaration, which uses the standard morphism for each context (NB: targets like "interpretation" appear like "theory" but declare local type parameters);
wenzelm
parents: 47080
diff changeset
   226
47246
2bbab021c0e6 clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents: 47245
diff changeset
   227
fun locale_declaration locale syntax decl lthy = lthy
2bbab021c0e6 clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents: 47245
diff changeset
   228
  |> Local_Theory.target (fn ctxt => ctxt |>
2bbab021c0e6 clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents: 47245
diff changeset
   229
    Locale.add_declaration locale syntax
2bbab021c0e6 clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents: 47245
diff changeset
   230
      (Morphism.transform (Local_Theory.standard_morphism lthy ctxt) decl));
2bbab021c0e6 clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents: 47245
diff changeset
   231
47282
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   232
fun standard_declaration pred decl lthy =
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   233
  Local_Theory.map_contexts (fn level => fn ctxt =>
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   234
    if pred level then Context.proof_map (Local_Theory.standard_form lthy ctxt decl) ctxt
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   235
    else ctxt) lthy;
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   236
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   237
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   238
(* const declaration *)
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   239
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   240
fun generic_const same_shape prmode ((b, mx), t) context =
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   241
  let
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   242
    val const_alias =
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   243
      if same_shape then
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   244
        (case t of
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   245
          Const (c, T) =>
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   246
            let
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   247
              val thy = Context.theory_of context;
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   248
              val ctxt = Context.proof_of context;
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   249
            in
47291
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   250
              (case Type_Infer_Context.const_type ctxt c of
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   251
                SOME T' => if Sign.typ_equiv thy (T, T') then SOME c else NONE
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   252
              | NONE => NONE)
47282
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   253
            end
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   254
        | _ => NONE)
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   255
      else NONE;
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   256
  in
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   257
    (case const_alias of
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   258
      SOME c =>
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   259
        context
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   260
        |> Context.mapping (Sign.const_alias b c) (Proof_Context.const_alias b c)
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   261
        |> Morphism.form (Proof_Context.generic_notation true prmode [(t, mx)])
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   262
    | NONE =>
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   263
        context
47288
b79bf8288b29 clarified generic_const vs. close_schematic_term;
wenzelm
parents: 47286
diff changeset
   264
        |> Proof_Context.generic_add_abbrev Print_Mode.internal (b, Term.close_schematic_term t)
47282
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   265
        |-> (fn (const as Const (c, _), _) => same_shape ?
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   266
              (Proof_Context.generic_revert_abbrev (#1 prmode) c #>
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   267
               Morphism.form (Proof_Context.generic_notation true prmode [(const, mx)]))))
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   268
  end;
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   269
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   270
fun const_declaration pred prmode ((b, mx), rhs) =
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   271
  standard_declaration pred (fn phi =>
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   272
    let
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   273
      val b' = Morphism.binding phi b;
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   274
      val rhs' = Morphism.term phi rhs;
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   275
      val same_shape = Term.aconv_untyped (rhs, rhs');
47288
b79bf8288b29 clarified generic_const vs. close_schematic_term;
wenzelm
parents: 47286
diff changeset
   276
    in generic_const same_shape prmode ((b', mx), rhs') end);
47280
wenzelm
parents: 47279
diff changeset
   277
47081
5e70b457b704 uniform Generic_Target.standard_declaration, which uses the standard morphism for each context (NB: targets like "interpretation" appear like "theory" but declare local type parameters);
wenzelm
parents: 47080
diff changeset
   278
52153
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
   279
(* registrations and dependencies *)
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
   280
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
   281
val theory_registration =
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
   282
  Local_Theory.raw_theory o Context.theory_map ooo Locale.add_registration;
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
   283
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
   284
fun locale_dependency locale dep_morph mixin export =
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
   285
  (Local_Theory.raw_theory ooo Locale.add_dependency locale) dep_morph mixin export
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
   286
  #> Local_Theory.activate_nonbrittle dep_morph mixin export;
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
   287
f5773a46cf05 more specific structure for registration into theory and dependency onto locale
haftmann
parents: 47313
diff changeset
   288
45352
0b4038361a3a misc tuning;
wenzelm
parents: 45310
diff changeset
   289
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
   290
(** primitive theory operations **)
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
   291
47284
0e65b6a016dc clarified background_foundation vs. theory_foundation (with const_declaration);
wenzelm
parents: 47283
diff changeset
   292
fun background_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) lthy =
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
   293
  let
47291
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   294
    val params = type_params @ term_params;
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   295
    val mx' = check_mixfix_global (b, null params) mx;
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   296
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 42360
diff changeset
   297
    val (const, lthy2) = lthy
47291
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   298
      |> Local_Theory.background_theory_result (Sign.declare_const lthy ((b, U), mx'));
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   299
    val lhs = Term.list_comb (const, params);
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   300
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 42360
diff changeset
   301
    val ((_, def), lthy3) = lthy2
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 42360
diff changeset
   302
      |> Local_Theory.background_theory_result
46916
e7ea35b41e2d Local_Theory.define no longer hard-wires default theorem name -- targets/packages need to take care of it;
wenzelm
parents: 45413
diff changeset
   303
        (Thm.add_def lthy2 false false
e7ea35b41e2d Local_Theory.define no longer hard-wires default theorem name -- targets/packages need to take care of it;
wenzelm
parents: 45413
diff changeset
   304
          (Thm.def_binding_optional b b_def, Logic.mk_equals (lhs, rhs)));
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
   305
  in ((lhs, def), lthy3) end;
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
   306
47284
0e65b6a016dc clarified background_foundation vs. theory_foundation (with const_declaration);
wenzelm
parents: 47283
diff changeset
   307
fun theory_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) =
0e65b6a016dc clarified background_foundation vs. theory_foundation (with const_declaration);
wenzelm
parents: 47283
diff changeset
   308
  background_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params)
47285
ca4cf5de366c avoid const_declaration in aux. context (cf. locale_foundation);
wenzelm
parents: 47284
diff changeset
   309
  #-> (fn (lhs, def) => fn lthy' => lthy' |>
ca4cf5de366c avoid const_declaration in aux. context (cf. locale_foundation);
wenzelm
parents: 47284
diff changeset
   310
        const_declaration (fn level => level <> Local_Theory.level lthy')
ca4cf5de366c avoid const_declaration in aux. context (cf. locale_foundation);
wenzelm
parents: 47284
diff changeset
   311
          Syntax.mode_default ((b, mx), lhs)
ca4cf5de366c avoid const_declaration in aux. context (cf. locale_foundation);
wenzelm
parents: 47284
diff changeset
   312
    |> pair (lhs, def));
47284
0e65b6a016dc clarified background_foundation vs. theory_foundation (with const_declaration);
wenzelm
parents: 47283
diff changeset
   313
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   314
fun theory_notes kind global_facts local_facts =
56141
c06202417c4a back to a form of hybrid facts, to reduce performance impact of ed92ce2ac88e;
wenzelm
parents: 56140
diff changeset
   315
  Local_Theory.background_theory (Attrib.global_notes kind global_facts #> snd) #>
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   316
  (fn lthy => lthy |> Local_Theory.map_contexts (fn level => fn ctxt =>
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   317
    if level = Local_Theory.level lthy then ctxt
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   318
    else
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   319
      ctxt |> Attrib.local_notes kind
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   320
        (Element.transform_facts (Local_Theory.standard_morphism lthy ctxt) local_facts) |> snd));
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
   321
47286
392c4cd97e5c more uniform theory_abbrev with const_declaration;
wenzelm
parents: 47285
diff changeset
   322
fun theory_abbrev prmode (b, mx) (t, _) xs =
392c4cd97e5c more uniform theory_abbrev with const_declaration;
wenzelm
parents: 47285
diff changeset
   323
  Local_Theory.background_theory_result
38757
2b3e054ae6fc renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents: 38341
diff changeset
   324
    (Sign.add_abbrev (#1 prmode) (b, t) #->
47291
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   325
      (fn (lhs, _) =>  (* FIXME type_params!? *)
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   326
        Sign.notation true prmode [(lhs, check_mixfix_global (b, null xs) mx)] #> pair lhs))
47286
392c4cd97e5c more uniform theory_abbrev with const_declaration;
wenzelm
parents: 47285
diff changeset
   327
  #-> (fn lhs => fn lthy' => lthy' |>
392c4cd97e5c more uniform theory_abbrev with const_declaration;
wenzelm
parents: 47285
diff changeset
   328
        const_declaration (fn level => level <> Local_Theory.level lthy') prmode
47293
052cd5f1a591 another attempt to avoid duplication of global vs. local syntax (reminiscent of old fork_mixfix);
wenzelm
parents: 47292
diff changeset
   329
          ((b, if null xs then NoSyn else mx), Term.list_comb (Logic.unvarify_global lhs, xs)));
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
   330
47279
4bab649dedf0 clarified standard_declaration vs. theory_declaration;
wenzelm
parents: 47276
diff changeset
   331
fun theory_declaration decl =
47282
57d486231c92 more general standard_declaration;
wenzelm
parents: 47280
diff changeset
   332
  background_declaration decl #> standard_declaration (K true) decl;
47279
4bab649dedf0 clarified standard_declaration vs. theory_declaration;
wenzelm
parents: 47276
diff changeset
   333
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   334
end;