| 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 | (** Rocq : Interaction with the Rocq toplevel *) |
| 12 | |
| 13 | (** {5 General structures} *) |
| 14 | |
| 15 | type rocqtop |
| 16 | (** The structure describing a rocqtop sub-process . |
| 17 | |
| 18 | Liveness management of rocqtop is automatic. Whenever a rocqtop dies abruptly, |
| 19 | this module is responsible for relaunching the whole process. The reset |
| 20 | handler set through [set_reset_handler] will be called after such an |
| 21 | abrupt failure. It is also called when explicitly requesting rocqtop to |
| 22 | reset. *) |
| 23 | |
| 24 | type status = New | Ready | Busy | Closed |
| 25 | (** Rocqtop process status : |
| 26 | - New : a process has been spawned, but not initialized via [init_rocqtop]. |
| 27 | It will reject tasks given via [try_grab]. |
| 28 | - Ready : no current task, accepts new tasks via [try_grab]. |
| 29 | - Busy : has accepted a task via [init_rocqtop] or [try_grab], |
| 30 | - Closed : the rocqide buffer has been closed, we discard any further task. |
| 31 | *) |
| 32 | |
| 33 | type 'a task |
| 34 | (** Rocqtop tasks. |
| 35 | |
| 36 | A task is a group of sequential calls to be performed on a rocqtop process, |
| 37 | that ultimately return some content. |
| 38 | |
| 39 | If a task is already sent to rocqtop, it is considered busy |
| 40 | ([is_computing] will answer [true]), and any other task submission |
| 41 | will be rejected by [try_grab]. |
| 42 | |
| 43 | Any exception occurring within the task will trigger a rocqtop reset. |
| 44 | |
| 45 | Beware, because of the GTK scheduler, you never know when a task will |
| 46 | actually be executed. If you need to sequentialize imperative actions, you |
| 47 | should do so using the monadic primitives. |
| 48 | *) |
| 49 | |
| 50 | val return : 'a -> 'a task |
| 51 | (** Monadic return of values as tasks. *) |
| 52 | |
| 53 | val bind : 'a task -> ('a -> 'b task) -> 'b task |
| 54 | (** Monadic binding of tasks *) |
| 55 | |
| 56 | val lift : (unit -> 'a) -> 'a task |
| 57 | (** Return the imperative computation waiting to be processed. *) |
| 58 | |
| 59 | val seq : unit task -> 'a task -> 'a task |
| 60 | (** Sequential composition *) |
| 61 | |
| 62 | (** {5 Rocqtop process management} *) |
| 63 | |
| 64 | type reset_kind = Planned | Unexpected |
| 65 | (** A reset may occur accidentally or voluntarily, so we discriminate between |
| 66 | these. *) |
| 67 | |
| 68 | val is_computing : rocqtop -> bool |
| 69 | (** Check if rocqtop is computing, i.e. already has a current task *) |
| 70 | |
| 71 | val is_stopped_in_debugger : rocqtop -> bool |
| 72 | (** Returns true if rocqtop is stopped in the debugger *) |
| 73 | |
| 74 | val is_ready_or_stopped_in_debugger : rocqtop -> bool |
| 75 | (** Check if rocqtop is Ready or stopped in the debugger *) |
| 76 | |
| 77 | val set_stopped_in_debugger : rocqtop -> bool -> unit |
| 78 | (** Records whether rocqtop is stopped in the debugger *) |
| 79 | |
| 80 | val spawn_rocqtop : string -> string list -> rocqtop |
| 81 | (** Create a rocqtop process with some command-line arguments. *) |
| 82 | |
| 83 | val set_restore_bpts : rocqtop -> (unit -> unit) -> unit |
| 84 | (** Register callback to restore breakpoints after a session has been reset *) |
| 85 | |
| 86 | val set_reset_handler : rocqtop -> unit task -> unit |
| 87 | (** Register a handler called when a rocqtop dies (badly or on purpose) *) |
| 88 | |
| 89 | val set_feedback_handler : rocqtop -> (Feedback.feedback -> unit) -> unit |
| 90 | (** Register a handler called when rocqtop sends a feedback message *) |
| 91 | |
| 92 | val set_debug_prompt_handler : rocqtop -> (tag:string -> Pp.t -> unit) -> unit |
| 93 | (** Register a handler called when the Ltac debugger sends a feedback message *) |
| 94 | |
| 95 | val add_do_when_ready : rocqtop -> (unit -> unit) -> unit |
| 96 | (** Register a function to be called when rocqtop becomes Ready *) |
| 97 | |
| 98 | val setup_script_editable : rocqtop -> (bool -> unit) -> unit |
| 99 | (** Register setter function to make proof script panel editable or not, |
| 100 | e.g. to disable editing while any non-debugger message is being processed *) |
| 101 | |
| 102 | val init_rocqtop : rocqtop -> unit task -> unit |
| 103 | (** Finish initializing a freshly spawned rocqtop, by running a first task on it. |
| 104 | The task should run its inner continuation at the end. *) |
| 105 | |
| 106 | val interrupt_rocqtop : rocqtop -> string list -> unit |
| 107 | (** Terminate the current computation of rocqtop or the worker if rocqtop is not running. *) |
| 108 | |
| 109 | val close_rocqtop : rocqtop -> unit |
| 110 | (** Close rocqtop. Subsequent requests will be discarded. Hook ignored. *) |
| 111 | |
| 112 | val reset_rocqtop : rocqtop -> unit |
| 113 | (** Reset rocqtop. Pending requests will be discarded. The reset handler |
| 114 | of rocqtop will be called with [Planned] as first argument *) |
| 115 | |
| 116 | val get_arguments : rocqtop -> string list |
| 117 | (** Get the current arguments used by rocqtop. *) |
| 118 | |
| 119 | val set_arguments : rocqtop -> string list -> unit |
| 120 | (** Set process arguments. This also forces a planned reset. *) |
| 121 | |
| 122 | (** {5 Task processing} *) |
| 123 | |
| 124 | val try_grab : ?db:bool -> rocqtop -> unit task -> (unit -> unit) -> bool |
| 125 | (** Try to schedule a task on a rocqtop. If rocqtop is available, the task |
| 126 | callback is run (asynchronously), otherwise the [(unit->unit)] callback |
| 127 | is triggered. Returns true if the task is run. |
| 128 | - If rocqtop ever dies during the computation, this function restarts rocqtop |
| 129 | and calls the restart hook with the fresh rocqtop. |
| 130 | - If the argument function raises an exception, a rocqtop reset occurs. |
| 131 | - The task may be discarded if a [close_rocqtop] or [reset_rocqtop] occurs |
| 132 | before its completion. |
| 133 | - The task callback should run its inner continuation at the end. *) |
| 134 | |
| 135 | (** {5 Atomic calls to rocqtop} *) |
| 136 | |
| 137 | (** |
| 138 | These atomic calls can be combined to form arbitrary multi-call tasks. |
| 139 | They correspond to the protocol calls (cf [Serialize] for more details). |
| 140 | Note that each call is asynchronous: it will return immediately, |
| 141 | but the inner callback will be executed later to handle the call answer |
| 142 | when this answer is available. |
| 143 | Except for interp, we use the default logger for any call. *) |
| 144 | |
| 145 | type 'a query = 'a Interface.value task |
| 146 | (** A type abbreviation for rocqtop specific answers *) |
| 147 | |
| 148 | val add : Interface.add_sty -> Interface.add_rty query |
| 149 | val edit_at : Interface.edit_at_sty -> Interface.edit_at_rty query |
| 150 | val query : Interface.query_sty -> Interface.query_rty query |
| 151 | val status : Interface.status_sty -> Interface.status_rty query |
| 152 | val goals : Interface.goals_sty -> Interface.goals_rty query |
| 153 | val subgoals : Interface.subgoals_sty -> Interface.subgoals_rty query |
| 154 | val evars : Interface.evars_sty -> Interface.evars_rty query |
| 155 | val hints : Interface.hints_sty -> Interface.hints_rty query |
| 156 | val mkcases : Interface.mkcases_sty -> Interface.mkcases_rty query |
| 157 | val search : Interface.search_sty -> Interface.search_rty query |
| 158 | val init : Interface.init_sty -> Interface.init_rty query |
| 159 | val proof_diff : Interface.proof_diff_sty -> Interface.proof_diff_rty query |
| 160 | val db_cmd : Interface.db_cmd_sty -> Interface.db_cmd_rty query |
| 161 | val db_upd_bpts: Interface.db_upd_bpts_sty-> Interface.db_upd_bpts_rty query |
| 162 | val db_continue: Interface.db_continue_sty-> Interface.db_continue_rty query |
| 163 | val db_stack : Interface.db_stack_sty -> Interface.db_stack_rty query |
| 164 | val db_vars : Interface.db_vars_sty -> Interface.db_vars_rty query |
| 165 | val db_configd : Interface.db_configd_sty -> Interface.db_configd_rty query |
| 166 | |
| 167 | val stop_worker: Interface.stop_worker_sty-> Interface.stop_worker_rty query |
| 168 | |
| 169 | (** A specialized version of [raw_interp] dedicated to set/unset options. *) |
| 170 | |
| 171 | module PrintOpt : |
| 172 | sig |
| 173 | type 'a t (** Representation of an option *) |
| 174 | |
| 175 | type 'a descr = { opts : 'a t list; init : 'a; label : string } |
| 176 | |
| 177 | val bool_items : bool descr list |
| 178 | |
| 179 | val diff_item : string descr |
| 180 | |
| 181 | val set : 'a t -> 'a -> unit |
| 182 | |
| 183 | val get : 'a t -> Interface.option_value |
| 184 | |
| 185 | val diff : string t |
| 186 | |
| 187 | val printing_unfocused: unit -> bool |
| 188 | |
| 189 | (** [enforce] transmits to rocq the current option values. |
| 190 | It is also called by [goals] and [evars] above. *) |
| 191 | |
| 192 | val enforce : unit task |
| 193 | end |
| 194 | |
| 195 | (** {5 Miscellaneous} *) |
| 196 | |
| 197 | val short_version : unit -> string |
| 198 | (** Return a short phrase identifying rocqtop version and date of compilation, as |
| 199 | given by the [configure] script. *) |
| 200 | |
| 201 | val version : unit -> string |
| 202 | (** More verbose description, including details about libraries and |
| 203 | architecture. *) |
| 204 | |
| 205 | val filter_rocq_opts : string list -> string list |
| 206 | (** * Launch a test rocqtop processes, ask for a correct rocqtop if it fails. |
| 207 | @return the list of arguments that rocqtop did not understand |
| 208 | (the files probably ..). This command may terminate rocqide in |
| 209 | case of trouble. *) |
| 210 | |
| 211 | val check_connection : string list -> unit |
| 212 | (** Launch a rocqtop with the user args in order to be sure that it works, |
| 213 | checking in particular that Prelude.vo is found. This command |
| 214 | may terminate rocqide in case of trouble *) |
| 215 | |
| 216 | val interrupter : (int -> unit) ref |
| 217 | val breaker : (int -> unit) ref |
| 218 | val send_break : rocqtop -> unit |
| 219 | |
| 220 | val save_all : (unit -> unit) ref |
| 221 | |
| 222 | (* Flags to be used for ideslave *) |
| 223 | val ideslave_rocqtop_flags : string option ref |