Debian Codegraph @

stm/stm.mli

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Names
12
13 (** state-transaction-machine interface *)
14
15 (* Flags *)
16 module AsyncOpts : sig
17
18 type cache = Force
19 type async_proofs = APoff
20 | APonLazy (* Delays proof checking, but does it in master *)
21 | APon
22 type tac_error_filter = FNone | FOnly of string list | FAll
23
24 type stm_opt = {
25 spawn_args : string list;
26
27 async_proofs_n_workers : int;
28 async_proofs_n_tacworkers : int;
29
30 async_proofs_cache : cache option;
31 async_proofs_mode : async_proofs;
32
33 async_proofs_private_flags : string option;
34 async_proofs_never_reopen_branch : bool;
35
36 async_proofs_tac_error_resilience : tac_error_filter;
37 async_proofs_cmd_error_resilience : bool;
38 async_proofs_delegation_threshold : float;
39
40 async_proofs_worker_priority : CoqworkmgrApi.priority;
41 }
42
43 val default_opts : spawn_args:string list -> stm_opt
44
45 end
46
47 (** The STM document type [stm_doc_type] determines some properties
48 such as what uncompleted proofs are allowed and what gets recorded
49 to aux files. *)
50 type stm_doc_type =
51 | VoDoc of string (* file path *)
52 | VosDoc of string (* file path *)
53 | Interactive of Coqargs.top (* module path *)
54
55 (** STM initialization options: *)
56 type stm_init_options =
57 { doc_type : stm_doc_type
58 (** The STM does set some internal flags differently depending on
59 the specified [doc_type]. This distinction should disappear at
60 some some point. *)
61
62 ; injections : Coqargs.injection_command list
63 (** Injects Require and Set/Unset commands before the initial
64 state is ready *)
65
66 }
67
68 (** The type of a STM document *)
69 type doc
70
71 (** [init_process] performs some low-level initialization, call early *)
72 val init_process : AsyncOpts.stm_opt -> unit
73
74 (** [init_core] snapshots the initial system state *)
75 val init_core : unit -> unit
76
77 (** [new_doc opt] Creates a new document with options [opt] *)
78 val new_doc : stm_init_options -> doc * Stateid.t
79
80 (** [parse_sentence sid entry pa] Reads a sentence from [pa] with parsing state
81 [sid] and non terminal [entry]. [entry] receives in input the current proof
82 mode. [sid] should be associated with a valid parsing state (which may not
83 be the case if an error was raised at parsing time). *)
84 val parse_sentence :
85 doc:doc -> Stateid.t ->
86 entry:(Pvernac.proof_mode option -> 'a Procq.Entry.t) -> Procq.Parsable.t -> 'a
87
88 (* Reminder: A parsable [pa] is constructed using
89 [Procq.Parsable.t stream], where [stream : char Stream.t]. *)
90
91 type add_focus = NewAddTip | Unfocus of Stateid.t
92
93 (* [add ~ontop ?newtip verbose cmd] adds a new command [cmd] ontop of
94 the state [ontop].
95 The [ontop] parameter just asserts that the GUI is on
96 sync, but it will eventually call edit_at on the fly if needed.
97 If [newtip] is provided, then the returned state id is guaranteed
98 to be [newtip] *)
99 val add : doc:doc -> ontop:Stateid.t -> ?newtip:Stateid.t ->
100 bool -> Vernacexpr.vernac_control ->
101 doc * Stateid.t * add_focus
102
103 (* Returns the proof state before the last tactic that was applied at or before
104 the specified state AND that has differences in the underlying proof (i.e.,
105 ignoring proofview-only changes). Used to compute proof diffs. *)
106 val get_prev_proof : doc:doc -> Stateid.t -> Proof.t option
107
108 val get_proof : doc:doc -> Stateid.t -> Proof.t option
109
110 (* [query at ?report_with cmd] Executes [cmd] at a given state [at],
111 throwing away side effects except messages. Feedback will
112 be sent with [report_with], which defaults to the dummy state id *)
113 val query : doc:doc ->
114 at:Stateid.t -> route:Feedback.route_id -> Procq.Parsable.t -> unit
115
116 (* [edit_at id] is issued to change the editing zone. [NewTip] is returned if
117 the requested id is the new document tip hence the document portion following
118 [id] is dropped by Rocq. [`Focus fo] is returned to say that [fo.tip] is the
119 new document tip, the document between [id] and [fo.stop] has been dropped.
120 The portion between [fo.stop] and [fo.tip] has been kept. [fo.start] is
121 just to tell the gui where the editing zone starts, in case it wants to
122 graphically denote it. All subsequent [add] happen on top of [id].
123 If Flags.async_proofs_full is set, then [id] is not [observe]d, else it is.
124 *)
125 type focus = { start : Stateid.t; stop : Stateid.t; tip : Stateid.t }
126 type edit_focus = NewTip | Focus of focus
127 val edit_at : doc:doc -> Stateid.t -> doc * edit_focus
128
129 (* [observe doc sid]] Check / execute span [sid] *)
130 val observe : doc:doc -> Stateid.t -> unit
131
132 (* [finish doc] Fully checks a document up to the "current" tip. *)
133 val finish : doc:doc -> Vernacstate.t
134
135 (* Internal use (fake_ide) only, do not use *)
136 val wait : doc:doc -> unit
137
138 val stop_worker : string -> unit
139
140 (* Joins the entire document. Implies finish, but also checks proofs *)
141 val join : doc:doc -> unit
142
143 (* Saves on the disk a .vos file. *)
144 val snapshot_vos : doc:doc -> output_native_objects:bool -> DirPath.t -> string -> unit
145
146 (* Empties the task queue, can be used only if the worker pool is empty (E.g.
147 * after having built a .vos in batch mode *)
148 val reset_task_queue : unit -> unit
149
150 type document
151
152 (* Id of the tip of the current branch *)
153 val get_current_state : doc:doc -> Stateid.t
154 val get_ldir : doc:doc -> Names.DirPath.t
155
156 (* This returns the node at that position *)
157 val get_ast : doc:doc -> Stateid.t -> Vernacexpr.vernac_control option
158
159 (* Filename *)
160 val set_compilation_hints : string -> unit
161
162 (** workers **************************************************************** **)
163
164 module ProofTask : AsyncTaskQueue.Task
165 module QueryTask : AsyncTaskQueue.Task
166
167 (** document structure customization *************************************** **)
168
169 (* A proof block delimiter defines a syntactic delimiter for sub proofs
170 that, when contain an error, do not impact the rest of the proof.
171 While checking a proof, if an error occurs in a (valid) block then
172 processing can skip the entire block and go on to give feedback
173 on the rest of the proof.
174
175 static_block_detection and dynamic_block_validation are run when
176 the closing block marker is parsed/executed respectively.
177
178 static_block_detection is for example called when "}" is parsed and
179 declares a block containing all proof steps between it and the matching
180 "{".
181
182 dynamic_block_validation is called when an error "crosses" the "}" statement.
183 Depending on the nature of the goal focused by "{" the block may absorb the
184 error or not. For example if the focused goal occurs in the type of
185 another goal, then the block is leaky.
186 Note that one can design proof commands that need no dynamic validation.
187
188 Example of document:
189
190 .. { tac1. tac2. } ..
191
192 Corresponding DAG:
193
194 .. (3) <-- { -- (4) <-- tac1 -- (5) <-- tac2 -- (6) <-- } -- (7) ..
195
196 Declaration of block [-------------------------------------------]
197
198 start = 5 the first state_id that could fail in the block
199 stop = 7 the node that may absorb the error
200 dynamic_switch = 4 dynamic check on this node
201 carry_on_data = () no need to carry extra data from static to dynamic
202 checks
203 *)
204
205 module DynBlockData : Dyn.S
206
207 type static_block_declaration = {
208 block_start : Stateid.t;
209 block_stop : Stateid.t;
210 dynamic_switch : Stateid.t;
211 carry_on_data : DynBlockData.t;
212 }
213
214 type document_node = {
215 indentation : int;
216 ast : Vernacexpr.vernac_control;
217 id : Stateid.t;
218 }
219
220 type document_view = {
221 entry_point : document_node;
222 prev_node : document_node -> document_node option;
223 }
224
225 type static_block_detection =
226 document_view -> static_block_declaration option
227
228 type recovery_action = {
229 base_state : Stateid.t;
230 goals_to_admit : Evar.t list;
231 recovery_command : Vernacexpr.vernac_control option;
232 }
233
234 type block_classification = ValidBlock of recovery_action | Leaks
235
236 type dynamic_block_error_recovery =
237 doc -> static_block_declaration -> block_classification
238
239 val register_proof_block_delimiter :
240 Vernacextend.proof_block_name ->
241 static_block_detection ->
242 dynamic_block_error_recovery ->
243 unit
244
245 (** customization ********************************************************** **)
246
247 (* From the master (or worker, but beware that to install the hook
248 * into a worker one has to build the worker toploop to do so and
249 * the alternative toploop for the worker can be selected by changing
250 * the name of the Task(s) above) *)
251
252 val state_computed_hook : (doc:doc -> Stateid.t -> in_cache:bool -> unit) -> unit
253 val unreachable_state_hook : (doc:doc -> Stateid.t -> Exninfo.iexn -> unit) -> unit
254
255 (* ready means that master has it at hand *)
256 val state_ready_hook : (doc:doc -> Stateid.t -> unit) -> unit
257
258 (* Messages from the workers to the master *)
259 val forward_feedback_hook : (Feedback.feedback -> unit) -> unit
260
261 (*
262 * Hooks into the UI for plugins (not for general use)
263 *)
264
265 (** User adds a sentence to the document (after parsing) *)
266 val document_add_hook : (Vernacexpr.vernac_control -> Stateid.t -> unit) -> unit
267
268 (** User edits a sentence in the document *)
269 val document_edit_hook : (Stateid.t -> unit) -> unit
270
271 (** User requests evaluation of a sentence *)
272 val sentence_exec_hook : (Stateid.t -> unit) -> unit
273
274 val get_doc : Feedback.doc_id -> doc
275
276 type state = Valid of Vernacstate.t option | Expired | Error of exn
277
278 val state_of_id : doc:doc ->
279 Stateid.t -> state
280
281 (* Queries for backward compatibility *)
282 val current_proof_depth : doc:doc -> int
283 val get_all_proof_names : doc:doc -> Id.t list
284
285 (** Enable STM debugging *)
286 val stm_debug : bool ref
287
288 val backup : unit -> document
289 val restore : document -> unit