| author | wenzelm |
| Wed, 13 Oct 2021 13:21:09 +0200 | |
| changeset 74510 | 21a20b990724 |
| parent 74463 | 7cc59201157d |
| child 74672 | 1a8fd26fedb6 |
| permissions | -rw-r--r-- |
| 5828 | 1 |
(* Title: Pure/Isar/toplevel.ML |
2 |
Author: Markus Wenzel, TU Muenchen |
|
3 |
||
|
26602
5534b6a6b810
made purely value-oriented, moved global state to structure Isar (cf. isar.ML);
wenzelm
parents:
26491
diff
changeset
|
4 |
Isabelle/Isar toplevel transactions. |
| 5828 | 5 |
*) |
6 |
||
7 |
signature TOPLEVEL = |
|
8 |
sig |
|
| 19063 | 9 |
exception UNDEF |
| 5828 | 10 |
type state |
| 69886 | 11 |
val init_toplevel: unit -> state |
|
62895
54c2abe7e9a4
treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
wenzelm
parents:
62889
diff
changeset
|
12 |
val theory_toplevel: theory -> state |
| 74463 | 13 |
val get_prev_theory: theory -> serial |
| 7732 | 14 |
val is_toplevel: state -> bool |
| 18589 | 15 |
val is_theory: state -> bool |
16 |
val is_proof: state -> bool |
|
| 51555 | 17 |
val is_skipped_proof: state -> bool |
| 17076 | 18 |
val level: state -> int |
| 67391 | 19 |
val previous_theory_of: state -> theory option |
| 21506 | 20 |
val context_of: state -> Proof.context |
| 22089 | 21 |
val generic_theory_of: state -> generic_theory |
| 5828 | 22 |
val theory_of: state -> theory |
23 |
val proof_of: state -> Proof.state |
|
| 18589 | 24 |
val proof_position_of: state -> int |
| 68505 | 25 |
val is_end_theory: state -> bool |
|
37953
ddc3b72f9a42
simplified handling of theory begin/end wrt. toplevel and theory loader;
wenzelm
parents:
37951
diff
changeset
|
26 |
val end_theory: Position.T -> state -> theory |
| 67381 | 27 |
val presentation_context: state -> Proof.context |
28 |
val presentation_state: Proof.context -> state |
|
| 56893 | 29 |
val pretty_context: state -> Pretty.T list |
|
56887
1ca814da47ae
clarified print_state, which goes back to TTY loop before Proof General, and before separate print_context;
wenzelm
parents:
56867
diff
changeset
|
30 |
val pretty_state: state -> Pretty.T list |
| 61208 | 31 |
val string_of_state: state -> string |
| 37858 | 32 |
val pretty_abstract: state -> Pretty.T |
| 16682 | 33 |
type transition |
| 5828 | 34 |
val empty: transition |
| 27427 | 35 |
val name_of: transition -> string |
| 28105 | 36 |
val pos_of: transition -> Position.T |
| 69877 | 37 |
val timing_of: transition -> Time.time |
| 60076 | 38 |
val type_error: transition -> string |
| 5828 | 39 |
val name: string -> transition -> transition |
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
40 |
val position: Position.T -> transition -> transition |
| 69887 | 41 |
val markers: Input.source list -> transition -> transition |
| 69877 | 42 |
val timing: Time.time -> transition -> transition |
|
44187
88d770052bac
simplified Toplevel.init_theory: discontinued special name argument;
wenzelm
parents:
44186
diff
changeset
|
43 |
val init_theory: (unit -> theory) -> transition -> transition |
|
88d770052bac
simplified Toplevel.init_theory: discontinued special name argument;
wenzelm
parents:
44186
diff
changeset
|
44 |
val is_init: transition -> bool |
|
44186
806f0ec1a43d
simplified Toplevel.init_theory: discontinued special master argument;
wenzelm
parents:
44185
diff
changeset
|
45 |
val modify_init: (unit -> theory) -> transition -> transition |
| 6689 | 46 |
val exit: transition -> transition |
| 5828 | 47 |
val keep: (state -> unit) -> transition -> transition |
| 7612 | 48 |
val keep': (bool -> state -> unit) -> transition -> transition |
|
60190
906de96ba68a
allow diagnostic proof commands with skip_proofs;
wenzelm
parents:
60189
diff
changeset
|
49 |
val keep_proof: (state -> unit) -> transition -> transition |
|
51268
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51241
diff
changeset
|
50 |
val is_ignored: transition -> bool |
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
51 |
val ignored: Position.T -> transition |
|
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
52 |
val malformed: Position.T -> string -> transition |
| 26491 | 53 |
val generic_theory: (generic_theory -> generic_theory) -> transition -> transition |
| 7612 | 54 |
val theory': (bool -> theory -> theory) -> transition -> transition |
|
49012
8686c36fa27d
refined treatment of forked proofs at transaction boundaries, including proof commands (see also 7ee000ce5390);
wenzelm
parents:
49011
diff
changeset
|
55 |
val theory: (theory -> theory) -> transition -> transition |
| 72434 | 56 |
val begin_main_target: bool -> (theory -> local_theory) -> transition -> transition |
57 |
val end_main_target: transition -> transition |
|
| 72453 | 58 |
val begin_nested_target: (Context.generic -> local_theory) -> transition -> transition |
| 72434 | 59 |
val end_nested_target: transition -> transition |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59923
diff
changeset
|
60 |
val local_theory': (bool * Position.T) option -> (xstring * Position.T) option -> |
|
59923
b21c82422d65
support private scope for individual local theory commands;
wenzelm
parents:
59472
diff
changeset
|
61 |
(bool -> local_theory -> local_theory) -> transition -> transition |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59923
diff
changeset
|
62 |
val local_theory: (bool * Position.T) option -> (xstring * Position.T) option -> |
|
59923
b21c82422d65
support private scope for individual local theory commands;
wenzelm
parents:
59472
diff
changeset
|
63 |
(local_theory -> local_theory) -> transition -> transition |
|
45488
6d71d9e52369
pass positions for named targets, for formal links in the document model;
wenzelm
parents:
44304
diff
changeset
|
64 |
val present_local_theory: (xstring * Position.T) option -> (state -> unit) -> |
| 24453 | 65 |
transition -> transition |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59923
diff
changeset
|
66 |
val local_theory_to_proof': (bool * Position.T) option -> (xstring * Position.T) option -> |
|
45488
6d71d9e52369
pass positions for named targets, for formal links in the document model;
wenzelm
parents:
44304
diff
changeset
|
67 |
(bool -> local_theory -> Proof.state) -> transition -> transition |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59923
diff
changeset
|
68 |
val local_theory_to_proof: (bool * Position.T) option -> (xstring * Position.T) option -> |
|
45488
6d71d9e52369
pass positions for named targets, for formal links in the document model;
wenzelm
parents:
44304
diff
changeset
|
69 |
(local_theory -> Proof.state) -> transition -> transition |
| 17363 | 70 |
val theory_to_proof: (theory -> Proof.state) -> transition -> transition |
| 21007 | 71 |
val end_proof: (bool -> Proof.state -> Proof.context) -> transition -> transition |
|
68876
cefaac3d24ff
no reset_proof for notepad: begin/end structure takes precedence over goal/proof structure;
wenzelm
parents:
68875
diff
changeset
|
72 |
val forget_proof: transition -> transition |
|
49863
b5fb6e7f8d81
more informative errors for 'proof' and 'apply' steps;
wenzelm
parents:
49062
diff
changeset
|
73 |
val proofs': (bool -> Proof.state -> Proof.state Seq.result Seq.seq) -> transition -> transition |
|
17904
21c6894b5998
simplified interfaces proof/proof' etc.: perform ProofHistory.apply(s)/current internally;
wenzelm
parents:
17513
diff
changeset
|
74 |
val proof': (bool -> Proof.state -> Proof.state) -> transition -> transition |
|
49863
b5fb6e7f8d81
more informative errors for 'proof' and 'apply' steps;
wenzelm
parents:
49062
diff
changeset
|
75 |
val proofs: (Proof.state -> Proof.state Seq.result Seq.seq) -> transition -> transition |
| 21177 | 76 |
val proof: (Proof.state -> Proof.state) -> transition -> transition |
| 33390 | 77 |
val actual_proof: (Proof_Node.T -> Proof_Node.T) -> transition -> transition |
|
60693
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60403
diff
changeset
|
78 |
val skip_proof: (unit -> unit) -> transition -> transition |
|
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60403
diff
changeset
|
79 |
val skip_proof_open: transition -> transition |
|
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60403
diff
changeset
|
80 |
val skip_proof_close: transition -> transition |
| 52536 | 81 |
val exec_id: Document_ID.exec -> transition -> transition |
| 28425 | 82 |
val setmp_thread_position: transition -> ('a -> 'b) -> 'a -> 'b
|
|
59055
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
59032
diff
changeset
|
83 |
val transition: bool -> transition -> state -> state * (exn * string) option |
| 51323 | 84 |
val command_errors: bool -> transition -> state -> Runtime.error list * state option |
|
51284
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51282
diff
changeset
|
85 |
val command_exception: bool -> transition -> state -> state |
| 56937 | 86 |
val reset_theory: state -> state option |
87 |
val reset_proof: state -> state option |
|
|
68877
33d78e5e0a00
more robust reset_state: begin/end structure takes precedence over goal/proof structure;
wenzelm
parents:
68876
diff
changeset
|
88 |
val reset_notepad: state -> state option |
| 69887 | 89 |
val fork_presentation: transition -> transition * transition |
|
51332
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
90 |
type result |
|
73687
54fe8cc0e1c6
clarified signature: provide access to previous state;
wenzelm
parents:
73614
diff
changeset
|
91 |
val join_results: result -> (state * transition * state) list |
| 68839 | 92 |
val element_result: Keyword.keywords -> transition Thy_Element.element -> state -> result * state |
| 5828 | 93 |
end; |
94 |
||
| 6965 | 95 |
structure Toplevel: TOPLEVEL = |
| 5828 | 96 |
struct |
97 |
||
98 |
(** toplevel state **) |
|
99 |
||
|
31476
c5d2899b6de9
moved Isar toplevel runtime support to runtime.ML, which is loaded early (before ml_compiler.ML);
wenzelm
parents:
31431
diff
changeset
|
100 |
exception UNDEF = Runtime.UNDEF; |
| 19063 | 101 |
|
102 |
||
|
21958
9dfd1ca4c0a0
refined notion of empty toplevel, admits undo of 'end';
wenzelm
parents:
21861
diff
changeset
|
103 |
(* datatype node *) |
| 21294 | 104 |
|
| 5828 | 105 |
datatype node = |
| 69883 | 106 |
Toplevel |
107 |
(*toplevel outside of theory body*) | |
|
| 69878 | 108 |
Theory of generic_theory |
109 |
(*global or local theory*) | |
|
| 33390 | 110 |
Proof of Proof_Node.T * ((Proof.context -> generic_theory) * generic_theory) |
|
27576
7afff36043e6
eliminated internal command history -- superceeded by global Isar state (cf. isar.ML);
wenzelm
parents:
27564
diff
changeset
|
111 |
(*proof node, finish, original theory*) | |
| 51555 | 112 |
Skipped_Proof of int * (generic_theory * generic_theory); |
|
27564
fc6d34e49e17
replaced obsolete ProofHistory by ProofNode (backtracking only);
wenzelm
parents:
27500
diff
changeset
|
113 |
(*proof depth, resulting theory, original theory*) |
| 5828 | 114 |
|
| 69878 | 115 |
val theory_node = fn Theory gthy => SOME gthy | _ => NONE; |
| 18589 | 116 |
val proof_node = fn Proof (prf, _) => SOME prf | _ => NONE; |
| 51555 | 117 |
val skipped_proof_node = fn Skipped_Proof _ => true | _ => false; |
| 18589 | 118 |
|
| 69883 | 119 |
fun cases_node f _ _ Toplevel = f () |
120 |
| cases_node _ g _ (Theory gthy) = g gthy |
|
121 |
| cases_node _ _ h (Proof (prf, _)) = h (Proof_Node.current prf) |
|
122 |
| cases_node _ g _ (Skipped_Proof (_, (gthy, _))) = g gthy; |
|
123 |
||
124 |
fun cases_proper_node g h = cases_node (fn () => raise UNDEF) g h; |
|
125 |
||
126 |
val get_theory = cases_node (K NONE) (SOME o Context.theory_of) (SOME o Proof.theory_of); |
|
| 19063 | 127 |
|
|
21958
9dfd1ca4c0a0
refined notion of empty toplevel, admits undo of 'end';
wenzelm
parents:
21861
diff
changeset
|
128 |
|
|
9dfd1ca4c0a0
refined notion of empty toplevel, admits undo of 'end';
wenzelm
parents:
21861
diff
changeset
|
129 |
(* datatype state *) |
|
9dfd1ca4c0a0
refined notion of empty toplevel, admits undo of 'end';
wenzelm
parents:
21861
diff
changeset
|
130 |
|
| 69883 | 131 |
type node_presentation = node * Proof.context; |
| 5828 | 132 |
|
| 69886 | 133 |
fun init_presentation () = |
134 |
Proof_Context.init_global (Theory.get_pure_bootstrap ()); |
|
135 |
||
136 |
fun node_presentation node = |
|
137 |
(node, cases_node init_presentation Context.proof_of Proof.context_of node); |
|
138 |
||
| 69878 | 139 |
|
| 69883 | 140 |
datatype state = |
141 |
State of node_presentation * theory option; |
|
142 |
(*current node with presentation context, previous theory*) |
|
|
62895
54c2abe7e9a4
treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
wenzelm
parents:
62889
diff
changeset
|
143 |
|
| 69883 | 144 |
fun node_of (State ((node, _), _)) = node; |
145 |
fun previous_theory_of (State (_, prev_thy)) = prev_thy; |
|
| 5828 | 146 |
|
| 69887 | 147 |
fun init_toplevel () = State (node_presentation Toplevel, NONE); |
148 |
fun theory_toplevel thy = State (node_presentation (Theory (Context.Theory thy)), NONE); |
|
| 69883 | 149 |
|
|
74462
b3d6bb2ebf77
maintain previous theory identifier to support semantic caching, notably in Isabelle/Naproche;
wenzelm
parents:
73691
diff
changeset
|
150 |
val prev_theory = Config.declare_int ("prev_theory", Position.none) (K 0);
|
| 74463 | 151 |
fun get_prev_theory thy = Config.get_global thy prev_theory; |
|
74462
b3d6bb2ebf77
maintain previous theory identifier to support semantic caching, notably in Isabelle/Naproche;
wenzelm
parents:
73691
diff
changeset
|
152 |
fun set_prev_theory (State (_, SOME prev_thy)) (Theory gthy) = |
|
b3d6bb2ebf77
maintain previous theory identifier to support semantic caching, notably in Isabelle/Naproche;
wenzelm
parents:
73691
diff
changeset
|
153 |
let |
|
b3d6bb2ebf77
maintain previous theory identifier to support semantic caching, notably in Isabelle/Naproche;
wenzelm
parents:
73691
diff
changeset
|
154 |
val put = Config.put_global prev_theory (Context.theory_identifier prev_thy); |
|
b3d6bb2ebf77
maintain previous theory identifier to support semantic caching, notably in Isabelle/Naproche;
wenzelm
parents:
73691
diff
changeset
|
155 |
val gthy' = gthy |> Context.mapping put (Local_Theory.raw_theory put); |
|
b3d6bb2ebf77
maintain previous theory identifier to support semantic caching, notably in Isabelle/Naproche;
wenzelm
parents:
73691
diff
changeset
|
156 |
in Theory gthy' end |
|
b3d6bb2ebf77
maintain previous theory identifier to support semantic caching, notably in Isabelle/Naproche;
wenzelm
parents:
73691
diff
changeset
|
157 |
| set_prev_theory _ node = node; |
| 69886 | 158 |
|
| 69883 | 159 |
fun level state = |
160 |
(case node_of state of |
|
161 |
Toplevel => 0 |
|
162 |
| Theory _ => 0 |
|
163 |
| Proof (prf, _) => Proof.level (Proof_Node.current prf) |
|
164 |
| Skipped_Proof (d, _) => d + 1); (*different notion of proof depth!*) |
|
| 17076 | 165 |
|
| 69883 | 166 |
fun str_of_state state = |
167 |
(case node_of state of |
|
168 |
Toplevel => |
|
169 |
(case previous_theory_of state of |
|
170 |
NONE => "at top level" |
|
171 |
| SOME thy => "at top level, result theory " ^ quote (Context.theory_name thy)) |
|
172 |
| Theory (Context.Theory _) => "in theory mode" |
|
173 |
| Theory (Context.Proof _) => "in local theory mode" |
|
174 |
| Proof _ => "in proof mode" |
|
175 |
| Skipped_Proof _ => "in skipped proof mode"); |
|
|
5946
a4600d21b59b
print_state hook, obeys Goals.current_goals_markers by default;
wenzelm
parents:
5939
diff
changeset
|
176 |
|
|
a4600d21b59b
print_state hook, obeys Goals.current_goals_markers by default;
wenzelm
parents:
5939
diff
changeset
|
177 |
|
|
27576
7afff36043e6
eliminated internal command history -- superceeded by global Isar state (cf. isar.ML);
wenzelm
parents:
27564
diff
changeset
|
178 |
(* current node *) |
| 5828 | 179 |
|
| 69883 | 180 |
fun is_toplevel state = (case node_of state of Toplevel => true | _ => false); |
| 5828 | 181 |
|
| 69883 | 182 |
fun is_theory state = |
183 |
not (is_toplevel state) andalso is_some (theory_node (node_of state)); |
|
| 18589 | 184 |
|
| 69883 | 185 |
fun is_proof state = |
186 |
not (is_toplevel state) andalso is_some (proof_node (node_of state)); |
|
| 5828 | 187 |
|
| 69883 | 188 |
fun is_skipped_proof state = |
189 |
not (is_toplevel state) andalso skipped_proof_node (node_of state); |
|
| 30801 | 190 |
|
| 69883 | 191 |
fun proper_node_of state = if is_toplevel state then raise UNDEF else node_of state; |
192 |
fun proper_node_case f g state = cases_proper_node f g (proper_node_of state); |
|
193 |
||
194 |
val context_of = proper_node_case Context.proof_of Proof.context_of; |
|
195 |
val generic_theory_of = proper_node_case I (Context.Proof o Proof.context_of); |
|
196 |
val theory_of = proper_node_case Context.theory_of Proof.theory_of; |
|
197 |
val proof_of = proper_node_case (fn _ => error "No proof state") I; |
|
| 17208 | 198 |
|
| 18589 | 199 |
fun proof_position_of state = |
| 69883 | 200 |
(case proper_node_of state of |
| 33390 | 201 |
Proof (prf, _) => Proof_Node.position prf |
| 60094 | 202 |
| _ => ~1); |
| 6664 | 203 |
|
| 69883 | 204 |
fun is_end_theory (State ((Toplevel, _), SOME _)) = true |
| 68505 | 205 |
| is_end_theory _ = false; |
206 |
||
| 69883 | 207 |
fun end_theory _ (State ((Toplevel, _), SOME thy)) = thy |
| 68869 | 208 |
| end_theory pos _ = error ("Malformed theory" ^ Position.here pos);
|
|
37953
ddc3b72f9a42
simplified handling of theory begin/end wrt. toplevel and theory loader;
wenzelm
parents:
37951
diff
changeset
|
209 |
|
| 5828 | 210 |
|
| 67381 | 211 |
(* presentation context *) |
212 |
||
213 |
structure Presentation_State = Proof_Data |
|
214 |
( |
|
215 |
type T = state option; |
|
216 |
fun init _ = NONE; |
|
217 |
); |
|
218 |
||
| 69883 | 219 |
fun presentation_context0 (State ((_, pr_ctxt), _)) = pr_ctxt; |
|
67642
10ff1f077119
more tight presentation context: avoid storing full Toplevel.state;
wenzelm
parents:
67641
diff
changeset
|
220 |
|
|
10ff1f077119
more tight presentation context: avoid storing full Toplevel.state;
wenzelm
parents:
67641
diff
changeset
|
221 |
fun presentation_context (state as State (current, _)) = |
|
10ff1f077119
more tight presentation context: avoid storing full Toplevel.state;
wenzelm
parents:
67641
diff
changeset
|
222 |
presentation_context0 state |
|
10ff1f077119
more tight presentation context: avoid storing full Toplevel.state;
wenzelm
parents:
67641
diff
changeset
|
223 |
|> Presentation_State.put (SOME (State (current, NONE))); |
| 67381 | 224 |
|
225 |
fun presentation_state ctxt = |
|
226 |
(case Presentation_State.get ctxt of |
|
| 69886 | 227 |
NONE => State (node_presentation (Theory (Context.Proof ctxt)), NONE) |
| 67381 | 228 |
| SOME state => state); |
229 |
||
230 |
||
| 16815 | 231 |
(* print state *) |
232 |
||
| 56893 | 233 |
fun pretty_context state = |
| 69883 | 234 |
if is_toplevel state then [] |
235 |
else |
|
236 |
let |
|
237 |
val gthy = |
|
238 |
(case node_of state of |
|
239 |
Toplevel => raise Match |
|
240 |
| Theory gthy => gthy |
|
241 |
| Proof (_, (_, gthy)) => gthy |
|
242 |
| Skipped_Proof (_, (_, gthy)) => gthy); |
|
243 |
val lthy = Context.cases Named_Target.theory_init I gthy; |
|
244 |
in Local_Theory.pretty lthy end; |
|
| 16815 | 245 |
|
|
56887
1ca814da47ae
clarified print_state, which goes back to TTY loop before Proof General, and before separate print_context;
wenzelm
parents:
56867
diff
changeset
|
246 |
fun pretty_state state = |
| 69883 | 247 |
(case node_of state of |
248 |
Toplevel => [] |
|
249 |
| Theory _ => [] |
|
250 |
| Proof (prf, _) => Proof.pretty_state (Proof_Node.current prf) |
|
251 |
| Skipped_Proof (d, _) => [Pretty.str ("skipped proof: depth " ^ string_of_int d)]);
|
|
| 56867 | 252 |
|
| 61208 | 253 |
val string_of_state = pretty_state #> Pretty.chunks #> Pretty.string_of; |
| 16815 | 254 |
|
| 37858 | 255 |
fun pretty_abstract state = Pretty.str ("<Isar " ^ str_of_state state ^ ">");
|
256 |
||
|
62819
d3ff367a16a0
careful export of type-dependent functions, without losing their special status;
wenzelm
parents:
62663
diff
changeset
|
257 |
val _ = ML_system_pp (fn _ => fn _ => Pretty.to_polyml o pretty_abstract); |
| 62663 | 258 |
|
| 16815 | 259 |
|
| 15668 | 260 |
|
| 5828 | 261 |
(** toplevel transitions **) |
262 |
||
| 69888 | 263 |
(* primitive transitions *) |
264 |
||
265 |
datatype trans = |
|
266 |
(*init theory*) |
|
267 |
Init of unit -> theory | |
|
268 |
(*formal exit of theory*) |
|
269 |
Exit | |
|
270 |
(*peek at state*) |
|
271 |
Keep of bool -> state -> unit | |
|
272 |
(*node transaction and presentation*) |
|
273 |
Transaction of (bool -> node -> node_presentation) * (state -> unit); |
|
274 |
||
275 |
local |
|
| 7022 | 276 |
|
|
31476
c5d2899b6de9
moved Isar toplevel runtime support to runtime.ML, which is loaded early (before ml_compiler.ML);
wenzelm
parents:
31431
diff
changeset
|
277 |
exception FAILURE of state * exn; |
|
c5d2899b6de9
moved Isar toplevel runtime support to runtime.ML, which is loaded early (before ml_compiler.ML);
wenzelm
parents:
31431
diff
changeset
|
278 |
|
| 69888 | 279 |
fun apply f g node = |
|
20128
8f0e07d7cf92
keep/transaction: unified execution model (with debugging etc.);
wenzelm
parents:
19996
diff
changeset
|
280 |
let |
| 69886 | 281 |
val node_pr = node_presentation node; |
| 69883 | 282 |
val context = cases_proper_node I (Context.Proof o Proof.context_of) node; |
283 |
fun state_error e node_pr' = (State (node_pr', get_theory node), e); |
|
| 6689 | 284 |
|
|
20128
8f0e07d7cf92
keep/transaction: unified execution model (with debugging etc.);
wenzelm
parents:
19996
diff
changeset
|
285 |
val (result, err) = |
| 69878 | 286 |
node |
|
56303
4cc3f4db3447
clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
wenzelm
parents:
56265
diff
changeset
|
287 |
|> Runtime.controlled_execution (SOME context) f |
|
26624
770265032999
transaction/init: ensure stable theory (non-draft);
wenzelm
parents:
26621
diff
changeset
|
288 |
|> state_error NONE |
| 69878 | 289 |
handle exn => state_error (SOME exn) node_pr; |
|
20128
8f0e07d7cf92
keep/transaction: unified execution model (with debugging etc.);
wenzelm
parents:
19996
diff
changeset
|
290 |
in |
|
52696
38466f4f3483
immutable theory values with full stamp record of every update (increase of stamp size for HOL: 20000 -> 100000, JinjaThreads: 65000 -> 300000) -- minimal measurable impact on inference kernel performance;
wenzelm
parents:
52565
diff
changeset
|
291 |
(case err of |
|
38466f4f3483
immutable theory values with full stamp record of every update (increase of stamp size for HOL: 20000 -> 100000, JinjaThreads: 65000 -> 300000) -- minimal measurable impact on inference kernel performance;
wenzelm
parents:
52565
diff
changeset
|
292 |
NONE => tap g result |
|
38466f4f3483
immutable theory values with full stamp record of every update (increase of stamp size for HOL: 20000 -> 100000, JinjaThreads: 65000 -> 300000) -- minimal measurable impact on inference kernel performance;
wenzelm
parents:
52565
diff
changeset
|
293 |
| SOME exn => raise FAILURE (result, exn)) |
|
20128
8f0e07d7cf92
keep/transaction: unified execution model (with debugging etc.);
wenzelm
parents:
19996
diff
changeset
|
294 |
end; |
| 6689 | 295 |
|
| 69887 | 296 |
fun apply_tr int trans state = |
297 |
(case (trans, node_of state) of |
|
298 |
(Init f, Toplevel) => |
|
299 |
Runtime.controlled_execution NONE (fn () => |
|
300 |
State (node_presentation (Theory (Context.Theory (f ()))), NONE)) () |
|
301 |
| (Exit, node as Theory (Context.Theory thy)) => |
|
| 69883 | 302 |
let |
303 |
val State ((node', pr_ctxt), _) = |
|
| 69888 | 304 |
node |> apply |
|
71023
35a8e15b7e03
more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents:
70398
diff
changeset
|
305 |
(fn _ => |
|
35a8e15b7e03
more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents:
70398
diff
changeset
|
306 |
node_presentation |
|
35a8e15b7e03
more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents:
70398
diff
changeset
|
307 |
(Theory (Context.Theory (tap Thm.expose_theory (Theory.end_theory thy))))) |
| 69883 | 308 |
(K ()); |
309 |
in State ((Toplevel, pr_ctxt), get_theory node') end |
|
| 69887 | 310 |
| (Keep f, node) => |
311 |
Runtime.controlled_execution (try generic_theory_of state) |
|
312 |
(fn () => (f int state; State (node_presentation node, previous_theory_of state))) () |
|
313 |
| (Transaction _, Toplevel) => raise UNDEF |
|
|
74462
b3d6bb2ebf77
maintain previous theory identifier to support semantic caching, notably in Isabelle/Naproche;
wenzelm
parents:
73691
diff
changeset
|
314 |
| (Transaction (f, g), node) => apply (fn x => f int x) g (set_prev_theory state node) |
| 69887 | 315 |
| _ => raise UNDEF); |
| 5828 | 316 |
|
| 32792 | 317 |
fun apply_union _ [] state = raise FAILURE (state, UNDEF) |
318 |
| apply_union int (tr :: trs) state = |
|
319 |
apply_union int trs state |
|
320 |
handle Runtime.UNDEF => apply_tr int tr state |
|
321 |
| FAILURE (alt_state, UNDEF) => apply_tr int tr alt_state |
|
| 6689 | 322 |
| exn as FAILURE _ => raise exn |
323 |
| exn => raise FAILURE (state, exn); |
|
324 |
||
| 70134 | 325 |
fun apply_markers name markers (state as State ((node, pr_ctxt), prev_thy)) = |
| 69887 | 326 |
let |
327 |
val state' = |
|
328 |
Runtime.controlled_execution (try generic_theory_of state) |
|
| 70134 | 329 |
(fn () => State ((node, fold (Document_Marker.evaluate name) markers pr_ctxt), prev_thy)) (); |
| 69887 | 330 |
in (state', NONE) end |
331 |
handle exn => (state, SOME exn); |
|
332 |
||
| 6689 | 333 |
in |
334 |
||
| 70134 | 335 |
fun apply_trans int name markers trans state = |
336 |
(apply_union int trans state |> apply_markers name markers) |
|
| 15531 | 337 |
handle FAILURE (alt_state, exn) => (alt_state, SOME exn) | exn => (state, SOME exn); |
| 6689 | 338 |
|
339 |
end; |
|
| 5828 | 340 |
|
341 |
||
342 |
(* datatype transition *) |
|
343 |
||
344 |
datatype transition = Transition of |
|
| 69887 | 345 |
{name: string, (*command name*)
|
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
346 |
pos: Position.T, (*source position*) |
| 69887 | 347 |
markers: Input.source list, (*semantic document markers*) |
348 |
timing: Time.time, (*prescient timing information*) |
|
349 |
trans: trans list}; (*primitive transitions (union)*) |
|
| 5828 | 350 |
|
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
351 |
fun make_transition (name, pos, markers, timing, trans) = |
|
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
352 |
Transition {name = name, pos = pos, markers = markers, timing = timing, trans = trans};
|
| 5828 | 353 |
|
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
354 |
fun map_transition f (Transition {name, pos, markers, timing, trans}) =
|
|
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
355 |
make_transition (f (name, pos, markers, timing, trans)); |
| 5828 | 356 |
|
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
357 |
val empty = make_transition ("", Position.none, [], Time.zeroTime, []);
|
| 5828 | 358 |
|
359 |
||
360 |
(* diagnostics *) |
|
361 |
||
| 27427 | 362 |
fun name_of (Transition {name, ...}) = name;
|
| 28105 | 363 |
fun pos_of (Transition {pos, ...}) = pos;
|
| 69877 | 364 |
fun timing_of (Transition {timing, ...}) = timing;
|
| 5828 | 365 |
|
| 60076 | 366 |
fun command_msg msg tr = |
367 |
msg ^ "command " ^ quote (Markup.markup Markup.keyword1 (name_of tr)) ^ |
|
368 |
Position.here (pos_of tr); |
|
| 5828 | 369 |
|
| 60076 | 370 |
fun at_command tr = command_msg "At " tr; |
371 |
fun type_error tr = command_msg "Bad context for " tr; |
|
| 5828 | 372 |
|
373 |
||
374 |
(* modify transitions *) |
|
375 |
||
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
376 |
fun name name = map_transition (fn (_, pos, markers, timing, trans) => |
|
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
377 |
(name, pos, markers, timing, trans)); |
| 9010 | 378 |
|
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
379 |
fun position pos = map_transition (fn (name, _, markers, timing, trans) => |
|
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
380 |
(name, pos, markers, timing, trans)); |
| 69887 | 381 |
|
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
382 |
fun markers markers = map_transition (fn (name, pos, _, timing, trans) => |
|
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
383 |
(name, pos, markers, timing, trans)); |
| 14923 | 384 |
|
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
385 |
fun timing timing = map_transition (fn (name, pos, markers, _, trans) => |
|
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
386 |
(name, pos, markers, timing, trans)); |
| 69877 | 387 |
|
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
388 |
fun add_trans tr = map_transition (fn (name, pos, markers, timing, trans) => |
|
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
389 |
(name, pos, markers, timing, tr :: trans)); |
| 16607 | 390 |
|
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
391 |
val reset_trans = map_transition (fn (name, pos, markers, timing, _) => |
|
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
392 |
(name, pos, markers, timing, [])); |
| 5828 | 393 |
|
394 |
||
| 21007 | 395 |
(* basic transitions *) |
| 5828 | 396 |
|
|
44187
88d770052bac
simplified Toplevel.init_theory: discontinued special name argument;
wenzelm
parents:
44186
diff
changeset
|
397 |
fun init_theory f = add_trans (Init f); |
|
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37953
diff
changeset
|
398 |
|
|
44187
88d770052bac
simplified Toplevel.init_theory: discontinued special name argument;
wenzelm
parents:
44186
diff
changeset
|
399 |
fun is_init (Transition {trans = [Init _], ...}) = true
|
|
88d770052bac
simplified Toplevel.init_theory: discontinued special name argument;
wenzelm
parents:
44186
diff
changeset
|
400 |
| is_init _ = false; |
|
88d770052bac
simplified Toplevel.init_theory: discontinued special name argument;
wenzelm
parents:
44186
diff
changeset
|
401 |
|
|
88d770052bac
simplified Toplevel.init_theory: discontinued special name argument;
wenzelm
parents:
44186
diff
changeset
|
402 |
fun modify_init f tr = if is_init tr then init_theory f (reset_trans tr) else tr; |
|
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37953
diff
changeset
|
403 |
|
| 6689 | 404 |
val exit = add_trans Exit; |
| 7612 | 405 |
val keep' = add_trans o Keep; |
|
30366
e3d788b9dffb
simplified presentation: built into transaction, pass state directly;
wenzelm
parents:
29516
diff
changeset
|
406 |
|
|
e3d788b9dffb
simplified presentation: built into transaction, pass state directly;
wenzelm
parents:
29516
diff
changeset
|
407 |
fun present_transaction f g = add_trans (Transaction (f, g)); |
|
e3d788b9dffb
simplified presentation: built into transaction, pass state directly;
wenzelm
parents:
29516
diff
changeset
|
408 |
fun transaction f = present_transaction f (K ()); |
| 69886 | 409 |
fun transaction0 f = present_transaction (node_presentation oo f) (K ()); |
| 5828 | 410 |
|
| 7612 | 411 |
fun keep f = add_trans (Keep (fn _ => f)); |
| 5828 | 412 |
|
|
60190
906de96ba68a
allow diagnostic proof commands with skip_proofs;
wenzelm
parents:
60189
diff
changeset
|
413 |
fun keep_proof f = |
|
906de96ba68a
allow diagnostic proof commands with skip_proofs;
wenzelm
parents:
60189
diff
changeset
|
414 |
keep (fn st => |
|
906de96ba68a
allow diagnostic proof commands with skip_proofs;
wenzelm
parents:
60189
diff
changeset
|
415 |
if is_proof st then f st |
|
906de96ba68a
allow diagnostic proof commands with skip_proofs;
wenzelm
parents:
60189
diff
changeset
|
416 |
else if is_skipped_proof st then () |
|
906de96ba68a
allow diagnostic proof commands with skip_proofs;
wenzelm
parents:
60189
diff
changeset
|
417 |
else warning "No proof state"); |
|
906de96ba68a
allow diagnostic proof commands with skip_proofs;
wenzelm
parents:
60189
diff
changeset
|
418 |
|
|
51268
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51241
diff
changeset
|
419 |
fun is_ignored tr = name_of tr = "<ignored>"; |
| 48772 | 420 |
|
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
421 |
fun ignored pos = |
|
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
422 |
empty |> name "<ignored>" |> position pos |> keep (fn _ => ()); |
|
73098
8a20737e4ebf
support more command positions, analogous to Command.core_range in Isabelle/Scala;
wenzelm
parents:
72505
diff
changeset
|
423 |
|
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
424 |
fun malformed pos msg = |
|
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
425 |
empty |> name "<malformed>" |> position pos |> keep (fn _ => error msg); |
| 27840 | 426 |
|
| 21007 | 427 |
|
|
49012
8686c36fa27d
refined treatment of forked proofs at transaction boundaries, including proof commands (see also 7ee000ce5390);
wenzelm
parents:
49011
diff
changeset
|
428 |
(* theory transitions *) |
|
44304
7ee000ce5390
maintain recent future proofs at transaction boundaries;
wenzelm
parents:
44270
diff
changeset
|
429 |
|
|
27601
6683cdb94af8
simplified commit_exit: operate on previous node of final state, include warning here;
wenzelm
parents:
27583
diff
changeset
|
430 |
fun generic_theory f = transaction (fn _ => |
| 69886 | 431 |
(fn Theory gthy => node_presentation (Theory (f gthy)) |
| 26491 | 432 |
| _ => raise UNDEF)); |
433 |
||
|
27601
6683cdb94af8
simplified commit_exit: operate on previous node of final state, include warning here;
wenzelm
parents:
27583
diff
changeset
|
434 |
fun theory' f = transaction (fn int => |
| 69878 | 435 |
(fn Theory (Context.Theory thy) => |
|
33725
a8481da77270
implicit name space grouping for theory/local_theory transactions;
wenzelm
parents:
33671
diff
changeset
|
436 |
let val thy' = thy |
|
49012
8686c36fa27d
refined treatment of forked proofs at transaction boundaries, including proof commands (see also 7ee000ce5390);
wenzelm
parents:
49011
diff
changeset
|
437 |
|> Sign.new_group |
|
33725
a8481da77270
implicit name space grouping for theory/local_theory transactions;
wenzelm
parents:
33671
diff
changeset
|
438 |
|> f int |
|
a8481da77270
implicit name space grouping for theory/local_theory transactions;
wenzelm
parents:
33671
diff
changeset
|
439 |
|> Sign.reset_group; |
| 69886 | 440 |
in node_presentation (Theory (Context.Theory thy')) end |
|
20963
a7fd8f05a2be
added type global_theory -- theory or local_theory;
wenzelm
parents:
20928
diff
changeset
|
441 |
| _ => raise UNDEF)); |
|
a7fd8f05a2be
added type global_theory -- theory or local_theory;
wenzelm
parents:
20928
diff
changeset
|
442 |
|
|
a7fd8f05a2be
added type global_theory -- theory or local_theory;
wenzelm
parents:
20928
diff
changeset
|
443 |
fun theory f = theory' (K f); |
|
a7fd8f05a2be
added type global_theory -- theory or local_theory;
wenzelm
parents:
20928
diff
changeset
|
444 |
|
| 72434 | 445 |
fun begin_main_target begin f = transaction (fn _ => |
| 69878 | 446 |
(fn Theory (Context.Theory thy) => |
|
20963
a7fd8f05a2be
added type global_theory -- theory or local_theory;
wenzelm
parents:
20928
diff
changeset
|
447 |
let |
| 20985 | 448 |
val lthy = f thy; |
| 72453 | 449 |
val gthy = |
450 |
if begin |
|
451 |
then Context.Proof lthy |
|
| 72505 | 452 |
else Target_Context.end_named_cmd lthy; |
|
56897
c668735fb8b5
print results as "state", to avoid intrusion into the source text;
wenzelm
parents:
56895
diff
changeset
|
453 |
val _ = |
| 60245 | 454 |
(case Local_Theory.pretty lthy of |
455 |
[] => () |
|
456 |
| prts => Output.state (Pretty.string_of (Pretty.chunks prts))); |
|
| 69878 | 457 |
in (Theory gthy, lthy) end |
|
20963
a7fd8f05a2be
added type global_theory -- theory or local_theory;
wenzelm
parents:
20928
diff
changeset
|
458 |
| _ => raise UNDEF)); |
| 17076 | 459 |
|
| 72434 | 460 |
val end_main_target = transaction (fn _ => |
| 72505 | 461 |
(fn Theory (Context.Proof lthy) => (Theory (Target_Context.end_named_cmd lthy), lthy) |
| 21007 | 462 |
| _ => raise UNDEF)); |
463 |
||
| 72434 | 464 |
fun begin_nested_target f = transaction0 (fn _ => |
| 69878 | 465 |
(fn Theory gthy => |
|
72449
e1ee4a9902bd
centralized case distinction for beginning and ending nested targets in one place
haftmann
parents:
72436
diff
changeset
|
466 |
let |
| 72453 | 467 |
val lthy' = f gthy; |
|
72449
e1ee4a9902bd
centralized case distinction for beginning and ending nested targets in one place
haftmann
parents:
72436
diff
changeset
|
468 |
in Theory (Context.Proof lthy') end |
| 47069 | 469 |
| _ => raise UNDEF)); |
470 |
||
| 72434 | 471 |
val end_nested_target = transaction (fn _ => |
| 69878 | 472 |
(fn Theory (Context.Proof lthy) => |
| 72505 | 473 |
(case try Target_Context.end_nested_cmd lthy of |
474 |
SOME gthy' => (Theory gthy', lthy) |
|
| 47069 | 475 |
| NONE => raise UNDEF) |
476 |
| _ => raise UNDEF)); |
|
477 |
||
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
478 |
fun restricted_context (SOME (strict, scope)) = |
|
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
479 |
Proof_Context.map_naming (Name_Space.restricted strict scope) |
|
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
480 |
| restricted_context NONE = I; |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59923
diff
changeset
|
481 |
|
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
482 |
fun local_theory' restricted target f = present_transaction (fn int => |
| 69878 | 483 |
(fn Theory gthy => |
| 21294 | 484 |
let |
| 72453 | 485 |
val (finish, lthy) = Target_Context.switch_named_cmd target gthy; |
| 47274 | 486 |
val lthy' = lthy |
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
487 |
|> restricted_context restricted |
|
49012
8686c36fa27d
refined treatment of forked proofs at transaction boundaries, including proof commands (see also 7ee000ce5390);
wenzelm
parents:
49011
diff
changeset
|
488 |
|> Local_Theory.new_group |
|
33725
a8481da77270
implicit name space grouping for theory/local_theory transactions;
wenzelm
parents:
33671
diff
changeset
|
489 |
|> f int |
|
a8481da77270
implicit name space grouping for theory/local_theory transactions;
wenzelm
parents:
33671
diff
changeset
|
490 |
|> Local_Theory.reset_group; |
| 69878 | 491 |
in (Theory (finish lthy'), lthy') end |
| 59032 | 492 |
| _ => raise UNDEF)) |
493 |
(K ()); |
|
| 15668 | 494 |
|
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
495 |
fun local_theory restricted target f = local_theory' restricted target (K f); |
| 21007 | 496 |
|
| 65054 | 497 |
fun present_local_theory target = present_transaction (fn _ => |
| 69878 | 498 |
(fn Theory gthy => |
| 72453 | 499 |
let val (finish, lthy) = Target_Context.switch_named_cmd target gthy; |
| 69878 | 500 |
in (Theory (finish lthy), lthy) end |
| 59032 | 501 |
| _ => raise UNDEF)); |
| 21007 | 502 |
|
503 |
||
504 |
(* proof transitions *) |
|
505 |
||
|
27601
6683cdb94af8
simplified commit_exit: operate on previous node of final state, include warning here;
wenzelm
parents:
27583
diff
changeset
|
506 |
fun end_proof f = transaction (fn int => |
|
24795
6f5cb7885fd7
print_state_context: local theory context, not proof context;
wenzelm
parents:
24780
diff
changeset
|
507 |
(fn Proof (prf, (finish, _)) => |
| 33390 | 508 |
let val state = Proof_Node.current prf in |
| 21007 | 509 |
if can (Proof.assert_bottom true) state then |
510 |
let |
|
511 |
val ctxt' = f int state; |
|
512 |
val gthy' = finish ctxt'; |
|
| 69878 | 513 |
in (Theory gthy', ctxt') end |
| 21007 | 514 |
else raise UNDEF |
515 |
end |
|
| 69886 | 516 |
| Skipped_Proof (0, (gthy, _)) => node_presentation (Theory gthy) |
| 21007 | 517 |
| _ => raise UNDEF)); |
518 |
||
| 21294 | 519 |
local |
520 |
||
| 69882 | 521 |
fun begin_proof init_proof = transaction0 (fn int => |
| 69878 | 522 |
(fn Theory gthy => |
| 21294 | 523 |
let |
| 69882 | 524 |
val (finish, prf) = init_proof int gthy; |
| 67157 | 525 |
val document = Options.default_string "document"; |
526 |
val skip = (document = "" orelse document = "false") andalso Goal.skip_proofs_enabled (); |
|
| 58795 | 527 |
val schematic_goal = try Proof.schematic_goal prf; |
| 47274 | 528 |
val _ = |
| 58795 | 529 |
if skip andalso schematic_goal = SOME true then |
| 47274 | 530 |
warning "Cannot skip proof of schematic goal statement" |
531 |
else (); |
|
| 21294 | 532 |
in |
| 58795 | 533 |
if skip andalso schematic_goal = SOME false then |
| 51555 | 534 |
Skipped_Proof (0, (finish (Proof.global_skip_proof true prf), gthy)) |
| 47274 | 535 |
else Proof (Proof_Node.init prf, (finish, gthy)) |
| 21294 | 536 |
end |
537 |
| _ => raise UNDEF)); |
|
538 |
||
539 |
in |
|
540 |
||
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
541 |
fun local_theory_to_proof' restricted target f = begin_proof |
| 47274 | 542 |
(fn int => fn gthy => |
|
59923
b21c82422d65
support private scope for individual local theory commands;
wenzelm
parents:
59472
diff
changeset
|
543 |
let |
| 72453 | 544 |
val (finish, lthy) = Target_Context.switch_named_cmd target gthy; |
|
59923
b21c82422d65
support private scope for individual local theory commands;
wenzelm
parents:
59472
diff
changeset
|
545 |
val prf = lthy |
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
546 |
|> restricted_context restricted |
|
59923
b21c82422d65
support private scope for individual local theory commands;
wenzelm
parents:
59472
diff
changeset
|
547 |
|> Local_Theory.new_group |
|
b21c82422d65
support private scope for individual local theory commands;
wenzelm
parents:
59472
diff
changeset
|
548 |
|> f int; |
|
b21c82422d65
support private scope for individual local theory commands;
wenzelm
parents:
59472
diff
changeset
|
549 |
in (finish o Local_Theory.reset_group, prf) end); |
|
24780
47bb1e380d83
local_theory transactions: more careful treatment of context position;
wenzelm
parents:
24634
diff
changeset
|
550 |
|
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
551 |
fun local_theory_to_proof restricted target f = |
|
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
552 |
local_theory_to_proof' restricted target (K f); |
| 21294 | 553 |
|
554 |
fun theory_to_proof f = begin_proof |
|
| 47274 | 555 |
(fn _ => fn gthy => |
|
56057
ad6bd8030d88
more explicit Sign.change_check -- detect structural mistakes where they emerge, not at later theory merges;
wenzelm
parents:
56055
diff
changeset
|
556 |
(Context.Theory o Sign.reset_group o Sign.change_check o Proof_Context.theory_of, |
|
49062
7e31dfd99ce7
discontinued complicated/unreliable notion of recent proofs within context;
wenzelm
parents:
49042
diff
changeset
|
557 |
(case gthy of |
| 52788 | 558 |
Context.Theory thy => f (Sign.new_group thy) |
|
49012
8686c36fa27d
refined treatment of forked proofs at transaction boundaries, including proof commands (see also 7ee000ce5390);
wenzelm
parents:
49011
diff
changeset
|
559 |
| _ => raise UNDEF))); |
| 21294 | 560 |
|
561 |
end; |
|
562 |
||
| 69878 | 563 |
val forget_proof = transaction0 (fn _ => |
|
58798
49ed5eea15d4
'oops' requires proper goal statement -- exclude 'notepad' to avoid disrupting begin/end structure;
wenzelm
parents:
58795
diff
changeset
|
564 |
(fn Proof (prf, (_, orig_gthy)) => |
|
68876
cefaac3d24ff
no reset_proof for notepad: begin/end structure takes precedence over goal/proof structure;
wenzelm
parents:
68875
diff
changeset
|
565 |
if Proof.is_notepad (Proof_Node.current prf) then raise UNDEF |
| 69878 | 566 |
else Theory orig_gthy |
567 |
| Skipped_Proof (_, (_, orig_gthy)) => Theory orig_gthy |
|
| 21007 | 568 |
| _ => raise UNDEF)); |
569 |
||
| 69878 | 570 |
fun proofs' f = transaction0 (fn int => |
|
49062
7e31dfd99ce7
discontinued complicated/unreliable notion of recent proofs within context;
wenzelm
parents:
49042
diff
changeset
|
571 |
(fn Proof (prf, x) => Proof (Proof_Node.applys (f int) prf, x) |
| 51555 | 572 |
| skip as Skipped_Proof _ => skip |
| 16815 | 573 |
| _ => raise UNDEF)); |
| 15668 | 574 |
|
|
49863
b5fb6e7f8d81
more informative errors for 'proof' and 'apply' steps;
wenzelm
parents:
49062
diff
changeset
|
575 |
fun proof' f = proofs' ((Seq.single o Seq.Result) oo f); |
|
17904
21c6894b5998
simplified interfaces proof/proof' etc.: perform ProofHistory.apply(s)/current internally;
wenzelm
parents:
17513
diff
changeset
|
576 |
val proofs = proofs' o K; |
| 6689 | 577 |
val proof = proof' o K; |
| 16815 | 578 |
|
|
60693
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60403
diff
changeset
|
579 |
|
|
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60403
diff
changeset
|
580 |
(* skipped proofs *) |
|
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60403
diff
changeset
|
581 |
|
| 69878 | 582 |
fun actual_proof f = transaction0 (fn _ => |
| 21007 | 583 |
(fn Proof (prf, x) => Proof (f prf, x) |
|
20963
a7fd8f05a2be
added type global_theory -- theory or local_theory;
wenzelm
parents:
20928
diff
changeset
|
584 |
| _ => raise UNDEF)); |
| 16815 | 585 |
|
| 69878 | 586 |
fun skip_proof f = transaction0 (fn _ => |
|
60693
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60403
diff
changeset
|
587 |
(fn skip as Skipped_Proof _ => (f (); skip) |
| 18563 | 588 |
| _ => raise UNDEF)); |
589 |
||
| 69878 | 590 |
val skip_proof_open = transaction0 (fn _ => |
|
60693
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60403
diff
changeset
|
591 |
(fn Skipped_Proof (d, x) => Skipped_Proof (d + 1, x) |
|
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60403
diff
changeset
|
592 |
| _ => raise UNDEF)); |
|
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60403
diff
changeset
|
593 |
|
| 69878 | 594 |
val skip_proof_close = transaction0 (fn _ => |
595 |
(fn Skipped_Proof (0, (gthy, _)) => Theory gthy |
|
|
60693
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60403
diff
changeset
|
596 |
| Skipped_Proof (d, x) => Skipped_Proof (d - 1, x) |
|
33725
a8481da77270
implicit name space grouping for theory/local_theory transactions;
wenzelm
parents:
33671
diff
changeset
|
597 |
| _ => raise UNDEF)); |
| 5828 | 598 |
|
599 |
||
600 |
||
601 |
(** toplevel transactions **) |
|
602 |
||
|
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52499
diff
changeset
|
603 |
(* runtime position *) |
| 27427 | 604 |
|
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
605 |
fun exec_id id (tr as Transition {pos, ...}) =
|
|
73098
8a20737e4ebf
support more command positions, analogous to Command.core_range in Isabelle/Scala;
wenzelm
parents:
72505
diff
changeset
|
606 |
let val put_id = Position.put_id (Document_ID.print id) |
|
73106
3df45de0c079
discontinued body_range (again): does not quite work, because Position.thread_data is plain Toplevel.pos_of only;
wenzelm
parents:
73098
diff
changeset
|
607 |
in position (put_id pos) tr end; |
| 25799 | 608 |
|
| 25960 | 609 |
fun setmp_thread_position (Transition {pos, ...}) f x =
|
|
25819
e6feb08b7f4b
replaced thread_properties by simplified version in position.ML;
wenzelm
parents:
25809
diff
changeset
|
610 |
Position.setmp_thread_data pos f x; |
| 25799 | 611 |
|
612 |
||
| 5828 | 613 |
(* apply transitions *) |
614 |
||
| 6664 | 615 |
local |
616 |
||
| 70134 | 617 |
fun app int (tr as Transition {name, markers, trans, ...}) =
|
| 67932 | 618 |
setmp_thread_position tr |
| 70134 | 619 |
(Timing.protocol (name_of tr) (pos_of tr) (apply_trans int name markers trans) |
| 67932 | 620 |
##> Option.map (fn UNDEF => ERROR (type_error tr) | exn => exn)); |
| 6664 | 621 |
|
622 |
in |
|
| 5828 | 623 |
|
|
26602
5534b6a6b810
made purely value-oriented, moved global state to structure Isar (cf. isar.ML);
wenzelm
parents:
26491
diff
changeset
|
624 |
fun transition int tr st = |
|
28095
7eaf0813bdc3
added add_hook interface for post-transition hooks;
wenzelm
parents:
27859
diff
changeset
|
625 |
let |
|
60895
501be4aa75b4
default ML context for all command transactions, e.g. relevant for debugging and toplevel pretty-printing;
wenzelm
parents:
60693
diff
changeset
|
626 |
val (st', opt_err) = |
|
67642
10ff1f077119
more tight presentation context: avoid storing full Toplevel.state;
wenzelm
parents:
67641
diff
changeset
|
627 |
Context.setmp_generic_context (try (Context.Proof o presentation_context0) st) |
|
60895
501be4aa75b4
default ML context for all command transactions, e.g. relevant for debugging and toplevel pretty-printing;
wenzelm
parents:
60693
diff
changeset
|
628 |
(fn () => app int tr st) (); |
|
59055
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
59032
diff
changeset
|
629 |
val opt_err' = opt_err |> Option.map |
|
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
59032
diff
changeset
|
630 |
(fn Runtime.EXCURSION_FAIL exn_info => exn_info |
|
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
59032
diff
changeset
|
631 |
| exn => (Runtime.exn_context (try context_of st) exn, at_command tr)); |
|
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
59032
diff
changeset
|
632 |
in (st', opt_err') end; |
| 6664 | 633 |
|
634 |
end; |
|
| 5828 | 635 |
|
636 |
||
|
51284
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51282
diff
changeset
|
637 |
(* managed commands *) |
| 5828 | 638 |
|
| 51323 | 639 |
fun command_errors int tr st = |
640 |
(case transition int tr st of |
|
|
59055
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
59032
diff
changeset
|
641 |
(st', NONE) => ([], SOME st') |
| 65948 | 642 |
| (_, SOME (exn, _)) => (Runtime.exn_messages exn, NONE)); |
| 51323 | 643 |
|
|
51284
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51282
diff
changeset
|
644 |
fun command_exception int tr st = |
|
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51282
diff
changeset
|
645 |
(case transition int tr st of |
|
59055
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
59032
diff
changeset
|
646 |
(st', NONE) => st' |
|
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
59032
diff
changeset
|
647 |
| (_, SOME (exn, info)) => |
| 62505 | 648 |
if Exn.is_interrupt exn then Exn.reraise exn |
|
59055
5a7157b8e870
more informative failure of protocol commands, with exception trace;
wenzelm
parents:
59032
diff
changeset
|
649 |
else raise Runtime.EXCURSION_FAIL (exn, info)); |
|
27576
7afff36043e6
eliminated internal command history -- superceeded by global Isar state (cf. isar.ML);
wenzelm
parents:
27564
diff
changeset
|
650 |
|
| 58848 | 651 |
val command = command_exception false; |
|
51284
59a03019f3bf
fork diagnostic commands (theory loader and PIDE interaction);
wenzelm
parents:
51282
diff
changeset
|
652 |
|
|
28433
b3dab95f098f
begin_proof: avoid race condition wrt. skip_proofs flag;
wenzelm
parents:
28425
diff
changeset
|
653 |
|
| 56937 | 654 |
(* reset state *) |
655 |
||
656 |
local |
|
657 |
||
658 |
fun reset_state check trans st = |
|
659 |
if check st then NONE |
|
660 |
else #2 (command_errors false (trans empty) st); |
|
661 |
||
662 |
in |
|
663 |
||
|
68876
cefaac3d24ff
no reset_proof for notepad: begin/end structure takes precedence over goal/proof structure;
wenzelm
parents:
68875
diff
changeset
|
664 |
val reset_theory = reset_state is_theory forget_proof; |
| 56937 | 665 |
|
666 |
val reset_proof = |
|
667 |
reset_state is_proof |
|
| 69878 | 668 |
(transaction0 (fn _ => |
669 |
(fn Theory gthy => Skipped_Proof (0, (gthy, gthy)) |
|
| 56937 | 670 |
| _ => raise UNDEF))); |
671 |
||
|
68877
33d78e5e0a00
more robust reset_state: begin/end structure takes precedence over goal/proof structure;
wenzelm
parents:
68876
diff
changeset
|
672 |
val reset_notepad = |
|
33d78e5e0a00
more robust reset_state: begin/end structure takes precedence over goal/proof structure;
wenzelm
parents:
68876
diff
changeset
|
673 |
reset_state |
|
33d78e5e0a00
more robust reset_state: begin/end structure takes precedence over goal/proof structure;
wenzelm
parents:
68876
diff
changeset
|
674 |
(fn st => |
|
33d78e5e0a00
more robust reset_state: begin/end structure takes precedence over goal/proof structure;
wenzelm
parents:
68876
diff
changeset
|
675 |
(case try proof_of st of |
|
33d78e5e0a00
more robust reset_state: begin/end structure takes precedence over goal/proof structure;
wenzelm
parents:
68876
diff
changeset
|
676 |
SOME state => not (Proof.is_notepad state) orelse can Proof.end_notepad state |
|
33d78e5e0a00
more robust reset_state: begin/end structure takes precedence over goal/proof structure;
wenzelm
parents:
68876
diff
changeset
|
677 |
| NONE => true)) |
| 68878 | 678 |
(proof Proof.reset_notepad); |
|
68877
33d78e5e0a00
more robust reset_state: begin/end structure takes precedence over goal/proof structure;
wenzelm
parents:
68876
diff
changeset
|
679 |
|
| 56937 | 680 |
end; |
681 |
||
682 |
||
|
46959
cdc791910460
defer actual parsing of command spans and thus allow new commands to be used in the same theory where defined;
wenzelm
parents:
45666
diff
changeset
|
683 |
(* scheduled proof result *) |
|
28433
b3dab95f098f
begin_proof: avoid race condition wrt. skip_proofs flag;
wenzelm
parents:
28425
diff
changeset
|
684 |
|
|
51332
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
685 |
datatype result = |
|
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
686 |
Result of transition * state | |
|
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
687 |
Result_List of result list | |
|
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
688 |
Result_Future of result future; |
|
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
689 |
|
|
73687
54fe8cc0e1c6
clarified signature: provide access to previous state;
wenzelm
parents:
73614
diff
changeset
|
690 |
fun join_results result = |
|
54fe8cc0e1c6
clarified signature: provide access to previous state;
wenzelm
parents:
73614
diff
changeset
|
691 |
let |
|
54fe8cc0e1c6
clarified signature: provide access to previous state;
wenzelm
parents:
73614
diff
changeset
|
692 |
fun add (tr, st') res = |
|
54fe8cc0e1c6
clarified signature: provide access to previous state;
wenzelm
parents:
73614
diff
changeset
|
693 |
(case res of |
|
54fe8cc0e1c6
clarified signature: provide access to previous state;
wenzelm
parents:
73614
diff
changeset
|
694 |
[] => [(init_toplevel (), tr, st')] |
|
54fe8cc0e1c6
clarified signature: provide access to previous state;
wenzelm
parents:
73614
diff
changeset
|
695 |
| (_, _, st) :: _ => (st, tr, st') :: res); |
|
54fe8cc0e1c6
clarified signature: provide access to previous state;
wenzelm
parents:
73614
diff
changeset
|
696 |
fun acc (Result r) = add r |
|
54fe8cc0e1c6
clarified signature: provide access to previous state;
wenzelm
parents:
73614
diff
changeset
|
697 |
| acc (Result_List rs) = fold acc rs |
|
54fe8cc0e1c6
clarified signature: provide access to previous state;
wenzelm
parents:
73614
diff
changeset
|
698 |
| acc (Result_Future x) = acc (Future.join x); |
|
54fe8cc0e1c6
clarified signature: provide access to previous state;
wenzelm
parents:
73614
diff
changeset
|
699 |
in rev (acc result []) end; |
|
51332
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
700 |
|
| 51323 | 701 |
local |
702 |
||
| 47417 | 703 |
structure Result = Proof_Data |
|
28974
d6b190efa01a
excursion: pass explicit proof states as result of future proof, replaced low-level Thm.join_futures by PureThy.force_proofs;
wenzelm
parents:
28645
diff
changeset
|
704 |
( |
|
51332
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
705 |
type T = result; |
| 59150 | 706 |
fun init _ = Result_List []; |
|
28974
d6b190efa01a
excursion: pass explicit proof states as result of future proof, replaced low-level Thm.join_futures by PureThy.force_proofs;
wenzelm
parents:
28645
diff
changeset
|
707 |
); |
|
d6b190efa01a
excursion: pass explicit proof states as result of future proof, replaced low-level Thm.join_futures by PureThy.force_proofs;
wenzelm
parents:
28645
diff
changeset
|
708 |
|
|
51332
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
709 |
val get_result = Result.get o Proof.context_of; |
|
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
710 |
val put_result = Proof.map_context o Result.put; |
| 51324 | 711 |
|
|
66169
8cfa8c7ee1f6
keep original bottom-up order of proof forks, which potentially reduces thread congestion due to Proofterm.consolidate;
wenzelm
parents:
65948
diff
changeset
|
712 |
fun timing_estimate elem = |
| 68839 | 713 |
let val trs = tl (Thy_Element.flat_element elem) |
| 69877 | 714 |
in fold (fn tr => fn t => timing_of tr + t) trs Time.zeroTime end; |
|
51423
e5f9a6d9ca82
clarified parallel_subproofs_saturation (blind guess) vs. parallel_subproofs_threshold (precient timing estimate);
wenzelm
parents:
51332
diff
changeset
|
715 |
|
|
68130
6fb85346cb79
clarified future scheduling parameters, with support for parallel_limit;
wenzelm
parents:
67932
diff
changeset
|
716 |
fun future_proofs_enabled estimate st = |
| 51324 | 717 |
(case try proof_of st of |
718 |
NONE => false |
|
719 |
| SOME state => |
|
| 70398 | 720 |
not (Proofterm.proofs_enabled ()) andalso |
| 51324 | 721 |
not (Proof.is_relevant state) andalso |
722 |
(if can (Proof.assert_bottom true) state |
|
|
68130
6fb85346cb79
clarified future scheduling parameters, with support for parallel_limit;
wenzelm
parents:
67932
diff
changeset
|
723 |
then Future.proofs_enabled 1 |
|
6fb85346cb79
clarified future scheduling parameters, with support for parallel_limit;
wenzelm
parents:
67932
diff
changeset
|
724 |
else Future.proofs_enabled 2 orelse Future.proofs_enabled_timing estimate)); |
| 51278 | 725 |
|
| 69887 | 726 |
val empty_markers = markers []; |
727 |
val empty_trans = reset_trans #> keep (K ()); |
|
728 |
||
729 |
in |
|
730 |
||
731 |
fun fork_presentation tr = (tr |> empty_markers, tr |> empty_trans); |
|
732 |
||
| 58923 | 733 |
fun atom_result keywords tr st = |
| 51323 | 734 |
let |
735 |
val st' = |
|
|
68130
6fb85346cb79
clarified future scheduling parameters, with support for parallel_limit;
wenzelm
parents:
67932
diff
changeset
|
736 |
if Future.proofs_enabled 1 andalso Keyword.is_diag keywords (name_of tr) then |
| 69887 | 737 |
let |
738 |
val (tr1, tr2) = fork_presentation tr; |
|
739 |
val _ = |
|
740 |
Execution.fork {name = "Toplevel.diag", pos = pos_of tr, pri = ~1}
|
|
741 |
(fn () => command tr1 st); |
|
742 |
in command tr2 st end |
|
| 51323 | 743 |
else command tr st; |
|
51332
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
744 |
in (Result (tr, st'), st') end; |
| 51323 | 745 |
|
| 68839 | 746 |
fun element_result keywords (Thy_Element.Element (tr, NONE)) st = atom_result keywords tr st |
747 |
| element_result keywords (elem as Thy_Element.Element (head_tr, SOME element_rest)) st = |
|
|
48633
7cd32f9d4293
recovered comination of Toplevel.skip_proofs and Goal.parallel_proofs from 9679bab23f93 (NB: skip_proofs leads to failure of Toplevel.proof_of);
wenzelm
parents:
47881
diff
changeset
|
748 |
let |
| 58923 | 749 |
val (head_result, st') = atom_result keywords head_tr st; |
|
51332
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
750 |
val (body_elems, end_tr) = element_rest; |
|
66169
8cfa8c7ee1f6
keep original bottom-up order of proof forks, which potentially reduces thread congestion due to Proofterm.consolidate;
wenzelm
parents:
65948
diff
changeset
|
751 |
val estimate = timing_estimate elem; |
| 51324 | 752 |
in |
|
68130
6fb85346cb79
clarified future scheduling parameters, with support for parallel_limit;
wenzelm
parents:
67932
diff
changeset
|
753 |
if not (future_proofs_enabled estimate st') |
| 51324 | 754 |
then |
|
51332
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
755 |
let |
| 68839 | 756 |
val proof_trs = maps Thy_Element.flat_element body_elems @ [end_tr]; |
| 58923 | 757 |
val (proof_results, st'') = fold_map (atom_result keywords) proof_trs st'; |
|
51332
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
758 |
in (Result_List (head_result :: proof_results), st'') end |
| 51324 | 759 |
else |
760 |
let |
|
| 69887 | 761 |
val (end_tr1, end_tr2) = fork_presentation end_tr; |
762 |
||
| 51324 | 763 |
val finish = Context.Theory o Proof_Context.theory_of; |
|
28974
d6b190efa01a
excursion: pass explicit proof states as result of future proof, replaced low-level Thm.join_futures by PureThy.force_proofs;
wenzelm
parents:
28645
diff
changeset
|
764 |
|
|
51605
eca8acb42e4a
more explicit Goal.fork_params -- avoid implicit arguments via thread data;
wenzelm
parents:
51595
diff
changeset
|
765 |
val future_proof = |
|
eca8acb42e4a
more explicit Goal.fork_params -- avoid implicit arguments via thread data;
wenzelm
parents:
51595
diff
changeset
|
766 |
Proof.future_proof (fn state => |
| 53192 | 767 |
Execution.fork |
|
66169
8cfa8c7ee1f6
keep original bottom-up order of proof forks, which potentially reduces thread congestion due to Proofterm.consolidate;
wenzelm
parents:
65948
diff
changeset
|
768 |
{name = "Toplevel.future_proof", pos = pos_of head_tr, pri = ~1}
|
|
51605
eca8acb42e4a
more explicit Goal.fork_params -- avoid implicit arguments via thread data;
wenzelm
parents:
51595
diff
changeset
|
769 |
(fn () => |
|
eca8acb42e4a
more explicit Goal.fork_params -- avoid implicit arguments via thread data;
wenzelm
parents:
51595
diff
changeset
|
770 |
let |
| 69883 | 771 |
val State ((Proof (prf, (_, orig_gthy)), _), prev_thy) = st'; |
| 69878 | 772 |
val node' = Proof (Proof_Node.apply (K state) prf, (finish, orig_gthy)); |
| 69887 | 773 |
val (results, result_state) = |
| 69886 | 774 |
State (node_presentation node', prev_thy) |
| 69887 | 775 |
|> fold_map (element_result keywords) body_elems ||> command end_tr1; |
776 |
in (Result_List results, presentation_context0 result_state) end)) |
|
|
51332
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
777 |
#> (fn (res, state') => state' |> put_result (Result_Future res)); |
|
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
778 |
|
|
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
779 |
val forked_proof = |
|
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
780 |
proof (future_proof #> |
|
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
781 |
(fn state => state |> Proof.local_done_proof |> put_result (get_result state))) o |
|
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
782 |
end_proof (fn _ => future_proof #> |
|
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51324
diff
changeset
|
783 |
(fn state => state |> Proof.global_done_proof |> Result.put (get_result state))); |
|
28974
d6b190efa01a
excursion: pass explicit proof states as result of future proof, replaced low-level Thm.join_futures by PureThy.force_proofs;
wenzelm
parents:
28645
diff
changeset
|
784 |
|
| 69887 | 785 |
val st'' = st' |> command (head_tr |> reset_trans |> forked_proof); |
786 |
val end_st = st'' |> command end_tr2; |
|
787 |
val end_result = Result (end_tr, end_st); |
|
| 51324 | 788 |
val result = |
|
67642
10ff1f077119
more tight presentation context: avoid storing full Toplevel.state;
wenzelm
parents:
67641
diff
changeset
|
789 |
Result_List [head_result, Result.get (presentation_context0 st''), end_result]; |
| 69887 | 790 |
in (result, end_st) end |
| 51324 | 791 |
end; |
|
28433
b3dab95f098f
begin_proof: avoid race condition wrt. skip_proofs flag;
wenzelm
parents:
28425
diff
changeset
|
792 |
|
| 6664 | 793 |
end; |
| 51323 | 794 |
|
795 |
end; |