| 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 | (** This files defines the basic mechanism of proofs: the [proofview] |
| 12 | type is the state which tactics manipulate (a global state for |
| 13 | existential variables, together with the list of goals), and the type |
| 14 | ['a tactic] is the (abstract) type of tactics modifying the proof |
| 15 | state and returning a value of type ['a]. *) |
| 16 | |
| 17 | open EConstr |
| 18 | |
| 19 | (** Main state of tactics *) |
| 20 | type proofview |
| 21 | |
| 22 | (** Returns a stylised view of a proofview for use by, for instance, |
| 23 | ide-s. *) |
| 24 | (* spiwack: the type of [proofview] will change as we push more |
| 25 | refined functions to ide-s. This would be better than spawning a |
| 26 | new nearly identical function every time. Hence the generic name. *) |
| 27 | (* In this version: returns the list of focused goals together with |
| 28 | the [evar_map] context. *) |
| 29 | val proofview : proofview -> Evar.t list * Evd.evar_map |
| 30 | |
| 31 | |
| 32 | (** {6 Starting and querying a proof view} *) |
| 33 | |
| 34 | (** Abstract representation of the initial goals of a proof. *) |
| 35 | type entry |
| 36 | |
| 37 | (** Optimize memory consumption *) |
| 38 | val compact : entry -> proofview -> entry * proofview |
| 39 | |
| 40 | (** Initialises a proofview, the main argument is a list of |
| 41 | environments (including a [named_context] which are used as |
| 42 | hypotheses) pair with conclusion types, creating accordingly many |
| 43 | initial goals. Because a proof does not necessarily starts in an |
| 44 | empty [evar_map] (indeed a proof can be triggered by an incomplete |
| 45 | pretyping), [init] takes an additional argument to represent the |
| 46 | initial [evar_map]. *) |
| 47 | val init : Evd.evar_map -> (Environ.env * types) list -> entry * proofview |
| 48 | |
| 49 | (** A [telescope] is a list of environment and conclusion like in |
| 50 | {!init}, except that each element may depend on the previous |
| 51 | goals. The telescope passes the goals in the form of a |
| 52 | [Term.constr] which represents the goal as an [evar]. The |
| 53 | [evar_map] is threaded in state passing style. *) |
| 54 | type telescope = |
| 55 | | TNil of Evd.evar_map |
| 56 | | TCons of Environ.env * Evd.evar_map * types * (Evd.evar_map -> constr -> telescope) |
| 57 | |
| 58 | (** Like {!init}, but goals are allowed to be dependent on one |
| 59 | another. Dependencies between goals is represented with the type |
| 60 | [telescope] instead of [list]. Note that the first [evar_map] of |
| 61 | the telescope plays the role of the [evar_map] argument in |
| 62 | [init]. *) |
| 63 | val dependent_init : telescope -> entry * proofview |
| 64 | |
| 65 | (** [finished pv] is [true] if and only if [pv] is complete. That is, |
| 66 | if it has an empty list of focused goals. There could still be |
| 67 | unsolved subgoals, but they would then be out of focus. *) |
| 68 | val finished : proofview -> bool |
| 69 | |
| 70 | (** Returns the current [evar] state. *) |
| 71 | val return : proofview -> Evd.evar_map |
| 72 | |
| 73 | val partial_proof : entry -> proofview -> constr list |
| 74 | val initial_goals : entry -> (Environ.named_context_val * constr * types) list |
| 75 | |
| 76 | (** goal <-> goal_with_state *) |
| 77 | |
| 78 | val with_empty_state : |
| 79 | Proofview_monad.goal -> Proofview_monad.goal_with_state |
| 80 | val drop_state : |
| 81 | Proofview_monad.goal_with_state -> Proofview_monad.goal |
| 82 | val goal_with_state : |
| 83 | Proofview_monad.goal -> Proofview_monad.StateStore.t -> |
| 84 | Proofview_monad.goal_with_state |
| 85 | |
| 86 | (** {6 Focusing commands} *) |
| 87 | |
| 88 | (** A [focus_context] represents the part of the proof view which has |
| 89 | been removed by a focusing action, it can be used to unfocus later |
| 90 | on. *) |
| 91 | type focus_context |
| 92 | |
| 93 | (** Returns a stylised view of a focus_context for use by, for |
| 94 | instance, ide-s. *) |
| 95 | (* spiwack: the type of [focus_context] will change as we push more |
| 96 | refined functions to ide-s. This would be better than spawning a |
| 97 | new nearly identical function every time. Hence the generic name. *) |
| 98 | (* In this version: the goals in the context, as a "zipper" (the first |
| 99 | list is in reversed order). *) |
| 100 | val focus_context : Evd.evar_map -> focus_context -> Evar.t list * Evar.t list |
| 101 | |
| 102 | (** [focus i j] focuses a proofview on the goals from index [i] to |
| 103 | index [j] (inclusive, goals are indexed from [1]). I.e. goals |
| 104 | number [i] to [j] become the only focused goals of the returned |
| 105 | proofview. It returns the focused proofview, and a context for |
| 106 | the focus stack. *) |
| 107 | val focus : int -> int -> proofview -> proofview * focus_context |
| 108 | |
| 109 | (** Unfocuses a proofview with respect to a context. *) |
| 110 | val unfocus : focus_context -> proofview -> proofview |
| 111 | |
| 112 | |
| 113 | (** {6 The tactic monad} *) |
| 114 | |
| 115 | (** - Tactics are objects which apply a transformation to all the |
| 116 | subgoals of the current view at the same time. By opposition to |
| 117 | the old vision of applying it to a single goal. It allows tactics |
| 118 | such as [shelve_unifiable], tactics to reorder the focused goals, |
| 119 | or global automation tactic for dependent subgoals (instantiating |
| 120 | an evar has influences on the other goals of the proof in |
| 121 | progress, not being able to take that into account causes the |
| 122 | current eauto tactic to fail on some instances where it could |
| 123 | succeed). Another benefit is that it is possible to write tactics |
| 124 | that can be executed even if there are no focused goals. |
| 125 | - Tactics form a monad ['a tactic], in a sense a tactic can be |
| 126 | seen as a function (without argument) which returns a value of |
| 127 | type 'a and modifies the environment (in our case: the view). |
| 128 | Tactics of course have arguments, but these are given at the |
| 129 | meta-level as OCaml functions. Most tactics in the sense we are |
| 130 | used to return [()], that is no really interesting values. But |
| 131 | some might pass information around. The tactics seen in Rocq's |
| 132 | Ltac are (for now at least) only [unit tactic], the return values |
| 133 | are kept for the OCaml toolkit. The operation or the monad are |
| 134 | [Proofview.tclUNIT] (which is the "return" of the tactic monad) |
| 135 | [Proofview.tclBIND] (which is the "bind") and [Proofview.tclTHEN] |
| 136 | (which is a specialized bind on unit-returning tactics). |
| 137 | - Tactics have support for full-backtracking. Tactics can be seen |
| 138 | having multiple success: if after returning the first success a |
| 139 | failure is encountered, the tactic can backtrack and use a second |
| 140 | success if available. The state is backtracked to its previous |
| 141 | value, except the non-logical state defined in the {!NonLogical} |
| 142 | module below. |
| 143 | *) |
| 144 | |
| 145 | |
| 146 | (** The abstract type of tactics *) |
| 147 | type +'a tactic |
| 148 | |
| 149 | (** Applies a tactic to the current proofview. Returns a tuple |
| 150 | [a,pv,(b,sh,gu)] where [a] is the return value of the tactic, [pv] |
| 151 | is the updated proofview, [b] a boolean which is [true] if the |
| 152 | tactic has not done any action considered unsafe (such as |
| 153 | admitting a lemma), [sh] is the list of goals which have been |
| 154 | shelved by the tactic, and [gu] the list of goals on which the |
| 155 | tactic has given up. In case of multiple success the first one is |
| 156 | selected. If there is no success, fails with |
| 157 | {!Logic_monad.TacticFailure}*) |
| 158 | val apply |
| 159 | : name:Names.Id.t |
| 160 | -> poly:PolyFlags.t |
| 161 | -> Environ.env |
| 162 | -> 'a tactic |
| 163 | -> proofview |
| 164 | -> 'a * proofview |
| 165 | * Environ.env |
| 166 | * bool |
| 167 | * Proofview_monad.Info.tree |
| 168 | |
| 169 | (** {7 Monadic primitives} *) |
| 170 | |
| 171 | (** Unit of the tactic monad. *) |
| 172 | val tclUNIT : 'a -> 'a tactic |
| 173 | |
| 174 | (** Bind operation of the tactic monad. *) |
| 175 | val tclBIND : 'a tactic -> ('a -> 'b tactic) -> 'b tactic |
| 176 | |
| 177 | (** Interprets the ";" (semicolon) of Ltac. As a monadic operation, |
| 178 | it's a specialized "bind". *) |
| 179 | val tclTHEN : unit tactic -> 'a tactic -> 'a tactic |
| 180 | |
| 181 | (** [tclIGNORE t] has the same operational content as [t], but drops |
| 182 | the returned value. *) |
| 183 | val tclIGNORE : 'a tactic -> unit tactic |
| 184 | |
| 185 | (** Generic monadic combinators for tactics. *) |
| 186 | module Monad : Monad.S with type +'a t = 'a tactic |
| 187 | |
| 188 | (** {7 Failure and backtracking} *) |
| 189 | |
| 190 | (** [tclZERO e] fails with exception [e]. It has no success. |
| 191 | Exception is supposed to be non critical *) |
| 192 | val tclZERO : ?info:Exninfo.info -> exn -> 'a tactic |
| 193 | |
| 194 | (** [tclOR t1 t2] behaves like [t1] as long as [t1] succeeds. Whenever |
| 195 | the successes of [t1] have been depleted and it failed with [e], |
| 196 | then it behaves as [t2 e]. In other words, [tclOR] inserts a |
| 197 | backtracking point. In [t2], exception can be assumed non critical. *) |
| 198 | val tclOR : 'a tactic -> (Exninfo.iexn -> 'a tactic) -> 'a tactic |
| 199 | |
| 200 | (** [tclORELSE t1 t2] is equal to [t1] if [t1] has at least one |
| 201 | success or [t2 e] if [t1] fails with [e]. It is analogous to |
| 202 | [try/with] handler of exception in that it is not a backtracking |
| 203 | point. In [t2], exception can be assumed non critical. *) |
| 204 | val tclORELSE : 'a tactic -> (Exninfo.iexn -> 'a tactic) -> 'a tactic |
| 205 | |
| 206 | (** [tclIFCATCH a s f] is a generalisation of {!tclORELSE}: if [a] |
| 207 | succeeds at least once then it behaves as [tclBIND a s] otherwise, |
| 208 | if [a] fails with [e], then it behaves as [f e]. In [f] |
| 209 | exception can be assumed non critical. *) |
| 210 | val tclIFCATCH : 'a tactic -> ('a -> 'b tactic) -> (Exninfo.iexn -> 'b tactic) -> 'b tactic |
| 211 | |
| 212 | (** [tclONCE t] behave like [t] except it has at most one success: |
| 213 | [tclONCE t] stops after the first success of [t]. If [t] fails |
| 214 | with [e], [tclONCE t] also fails with [e]. *) |
| 215 | val tclONCE : 'a tactic -> 'a tactic |
| 216 | |
| 217 | (** [tclEXACTLY_ONCE e t] succeeds as [t] if [t] has exactly one |
| 218 | success. Otherwise it fails. The tactic [t] is run until its |
| 219 | first success, then a failure with exception [e] is |
| 220 | simulated ([e] has to be non critical). If [t] |
| 221 | yields another success, then [tclEXACTLY_ONCE e t] fails with |
| 222 | [MoreThanOneSuccess] (it is a user error). Otherwise, |
| 223 | [tclEXACTLY_ONCE e t] succeeds with the first success of |
| 224 | [t]. Notice that the choice of [e] is relevant, as the presence of |
| 225 | further successes may depend on [e] (see {!tclOR}). *) |
| 226 | exception MoreThanOneSuccess |
| 227 | val tclEXACTLY_ONCE : exn -> 'a tactic -> 'a tactic |
| 228 | |
| 229 | (** [tclCASE t] splits [t] into its first success and a |
| 230 | continuation. It is the most general primitive to control |
| 231 | backtracking. *) |
| 232 | type 'a case = |
| 233 | | Fail of Exninfo.iexn |
| 234 | | Next of 'a * (Exninfo.iexn -> 'a tactic) |
| 235 | val tclCASE : 'a tactic -> 'a case tactic |
| 236 | |
| 237 | (** [tclBREAK p t] is a generalization of [tclONCE t]. Instead of |
| 238 | stopping after the first success, it succeeds like [t] until a |
| 239 | failure with an exception [e] such that [p e = Some e'] is raised. At |
| 240 | which point it drops the remaining successes, failing with [e']. |
| 241 | [tclONCE t] is equivalent to [tclBREAK (fun e -> Some e) t]. *) |
| 242 | val tclBREAK : (Exninfo.iexn -> Exninfo.iexn option) -> 'a tactic -> 'a tactic |
| 243 | |
| 244 | |
| 245 | (** {7 Focusing tactics} *) |
| 246 | |
| 247 | (** Represents a range selector as accepted by [tclFOCUSSELECTORLIST]. *) |
| 248 | type goal_range_selector = |
| 249 | | NthSelector of int |
| 250 | | RangeSelector of (int * int) |
| 251 | | IdSelector of Libnames.qualid |
| 252 | |
| 253 | exception NoSuchGoals of int |
| 254 | exception CannotSelectShelvedAndFocused |
| 255 | |
| 256 | (** [tclFOCUS i j t] applies [t] after focusing on the goals number |
| 257 | [i] to [j] (see {!focus}). The rest of the goals is restored after |
| 258 | the tactic action. If the specified range doesn't correspond to |
| 259 | existing goals, fails with the [nosuchgoal] argument, by default |
| 260 | raising [NoSuchGoals] (a user error). This exception is caught at |
| 261 | toplevel with a default message. *) |
| 262 | val tclFOCUS : ?nosuchgoal:'a tactic -> int -> int -> 'a tactic -> 'a tactic |
| 263 | |
| 264 | (** [tclFOCUSLIST li t] applies [t] on the list of focused goals |
| 265 | described by [li]. Each element of [li] is a pair [(i, j)] denoting |
| 266 | the goals numbered from [i] to [j] (inclusive, starting from 1). |
| 267 | It will try to apply [t] to all the valid goals in any of these |
| 268 | intervals. If the set of such goals is not a single range, then it |
| 269 | will move goals such that it is a single range. (So, for |
| 270 | instance, [[1, 3-5]; idtac.] is not the identity.) |
| 271 | If the set of such goals is empty, it will fail with [nosuchgoal], |
| 272 | by default raising [NoSuchGoals 0]. *) |
| 273 | val tclFOCUSLIST : ?nosuchgoal:'a tactic -> (int * int) list -> 'a tactic -> 'a tactic |
| 274 | |
| 275 | (** [tclFOCUSSELECTORLIST l t] applies [t] on the list of goal selectors |
| 276 | described by [l]. Each element of [l] is either a range selector |
| 277 | [RangeSelector (i, j)] denoting the focused goals numbered from [i] to [j] |
| 278 | (inclusive, starting from 1), or a named selector [IdSelector id] targetting |
| 279 | a goal which may or may not be shelved. |
| 280 | |
| 281 | All selected goals must be in focus, or all selected goals must be shelved. |
| 282 | If that is not the case, this method will fail with [CannotSelectShelvedAndFocused]. |
| 283 | This restriction is due to the fact that tactics applied to shelved goals |
| 284 | must shelve their subgoals, and it is currently hard to keep track of |
| 285 | subgoals. |
| 286 | |
| 287 | If all selected goals are in focus, then [tclFOCUSLIST] is called by |
| 288 | converting each goal selector to a range. |
| 289 | |
| 290 | If all selected goals are shelved, then [tclFOCUSSHELF] is called. *) |
| 291 | val tclFOCUSSELECTORLIST : ?nosuchgoal:'a tactic -> goal_range_selector list -> 'a tactic -> 'a tactic |
| 292 | |
| 293 | (** [tclFOCUSID x t] applies [t] on a (single) focused goal like |
| 294 | {!tclFOCUS}. The goal is found by its name rather than its |
| 295 | number. Fails with [nosuchgoal], by default raising [NoSuchGoals 1]. *) |
| 296 | val tclFOCUSID : ?nosuchgoal:'a tactic -> Libnames.qualid -> 'a tactic -> 'a tactic |
| 297 | |
| 298 | (** [tclTRYFOCUS i j t] behaves like {!tclFOCUS}, except that if the |
| 299 | specified range doesn't correspond to existing goals, behaves like |
| 300 | [tclUNIT ()] instead of failing. *) |
| 301 | val tclTRYFOCUS : int -> int -> unit tactic -> unit tactic |
| 302 | |
| 303 | |
| 304 | (** {7 Dispatching on goals} *) |
| 305 | |
| 306 | (** Dispatch tacticals are used to apply a different tactic to each |
| 307 | goal under focus. They come in two flavours: [tclDISPATCH] takes a |
| 308 | list of [unit tactic]-s and build a [unit tactic]. [tclDISPATCHL] |
| 309 | takes a list of ['a tactic] and returns an ['a list tactic]. |
| 310 | |
| 311 | They both work by applying each of the tactic in a focus |
| 312 | restricted to the corresponding goal (starting with the first |
| 313 | goal). In the case of [tclDISPATCHL], the tactic returns a list of |
| 314 | the same size as the argument list (of tactics), each element |
| 315 | being the result of the tactic executed in the corresponding goal. |
| 316 | |
| 317 | When the length of the tactic list is not the number of goal, |
| 318 | raises [SizeMismatch (g,t)] where [g] is the number of available |
| 319 | goals, and [t] the number of tactics passed. *) |
| 320 | exception SizeMismatch of int*int |
| 321 | val tclDISPATCH : unit tactic list -> unit tactic |
| 322 | val tclDISPATCHL : 'a tactic list -> 'a list tactic |
| 323 | |
| 324 | (** [tclEXTEND b r e] is a variant of {!tclDISPATCH}, where the [r] |
| 325 | tactic is "repeated" enough time such that every goal has a tactic |
| 326 | assigned to it ([b] is the list of tactics applied to the first |
| 327 | goals, [e] to the last goals, and [r] is applied to every goal in |
| 328 | between). *) |
| 329 | val tclEXTEND : unit tactic list -> unit tactic -> unit tactic list -> unit tactic |
| 330 | |
| 331 | (** [tclINDEPENDENT tac] runs [tac] on each goal successively, from |
| 332 | the first one to the last one. Backtracking in one goal is |
| 333 | independent of backtracking in another. It is equivalent to |
| 334 | [tclEXTEND [] tac []]. *) |
| 335 | val tclINDEPENDENT : unit tactic -> unit tactic |
| 336 | val tclINDEPENDENTL: 'a tactic -> 'a list tactic |
| 337 | |
| 338 | |
| 339 | (** {7 Goal manipulation} *) |
| 340 | |
| 341 | (** Shelves all the goals under focus. The goals are placed on the |
| 342 | shelf for later use (or being solved by side-effects). *) |
| 343 | val shelve : unit tactic |
| 344 | |
| 345 | (** Shelves the given list of goals, which might include some that are |
| 346 | under focus and some that aren't. All the goals are placed on the |
| 347 | shelf for later use (or being solved by side-effects). *) |
| 348 | val shelve_goals : Evar.t list -> unit tactic |
| 349 | |
| 350 | (** [unifiable sigma g l] checks whether [g] appears in another |
| 351 | subgoal of [l]. The list [l] may contain [g], but it does not |
| 352 | affect the result. Used by [shelve_unifiable]. *) |
| 353 | val unifiable : Evd.evar_map -> Evar.t -> Evar.t list -> bool |
| 354 | |
| 355 | (** Shelves the unifiable goals under focus, i.e. the goals which |
| 356 | appear in other goals under focus (the unfocused goals are not |
| 357 | considered). *) |
| 358 | val shelve_unifiable : unit tactic |
| 359 | |
| 360 | (** [guard_no_unifiable] returns the list of unifiable goals if some |
| 361 | goals are unifiable (see {!shelve_unifiable}) in the current focus. *) |
| 362 | val guard_no_unifiable : Names.Name.t list option tactic |
| 363 | |
| 364 | (** [unshelve l p] moves all the goals in [l] from the shelf and put them at |
| 365 | the end of the focused goals of p, if they are still undefined after [advance] *) |
| 366 | val unshelve : Evar.t list -> proofview -> proofview |
| 367 | |
| 368 | val filter_shelf : (Evar.t -> bool) -> proofview -> proofview |
| 369 | |
| 370 | (** [depends_on g1 g2 sigma] checks if g1 occurs in the type/ctx of g2 *) |
| 371 | val depends_on : Evd.evar_map -> Evar.t -> Evar.t -> bool |
| 372 | |
| 373 | (** [with_shelf tac] executes [tac] and returns its result together with |
| 374 | the set of goals shelved by [tac]. The current shelf is unchanged |
| 375 | and the returned list contains only unsolved goals. *) |
| 376 | val with_shelf : 'a tactic -> (Evar.t list * 'a) tactic |
| 377 | |
| 378 | (** If [n] is positive, [cycle n] puts the [n] first goals last. If [n] |
| 379 | is negative, then it puts the [n] last goals first.*) |
| 380 | val cycle : int -> unit tactic |
| 381 | |
| 382 | (** [swap i j] swaps the position of goals number [i] and [j] |
| 383 | (negative numbers can be used to address goals from the end. Goals |
| 384 | are indexed from [1]. For simplicity index [0] corresponds to goal |
| 385 | [1] as well, rather than raising an error. *) |
| 386 | val swap : int -> int -> unit tactic |
| 387 | |
| 388 | (** [revgoals] reverses the list of focused goals. *) |
| 389 | val revgoals : unit tactic |
| 390 | |
| 391 | (** [numgoals] returns the number of goals under focus. *) |
| 392 | val numgoals : int tactic |
| 393 | |
| 394 | |
| 395 | (** {7 Access primitives} *) |
| 396 | |
| 397 | (** [tclEVARMAP] doesn't affect the proof, it returns the current |
| 398 | [evar_map]. *) |
| 399 | val tclEVARMAP : Evd.evar_map tactic |
| 400 | |
| 401 | (** [tclENV] doesn't affect the proof, it returns the current |
| 402 | environment. It is not the environment of a particular goal, |
| 403 | rather the "global" environment of the proof. The goal-wise |
| 404 | environment is obtained via {!Proofview.Goal.env}. *) |
| 405 | val tclENV : Environ.env tactic |
| 406 | |
| 407 | |
| 408 | (** {7 Put-like primitives} *) |
| 409 | |
| 410 | (** [mark_as_unsafe] declares the current tactic is unsafe. *) |
| 411 | val mark_as_unsafe : unit tactic |
| 412 | |
| 413 | (** Gives up on the goal under focus. Reports an unsafe status. Proofs |
| 414 | with given up goals cannot be closed. *) |
| 415 | val give_up : unit tactic |
| 416 | |
| 417 | (** {7 Control primitives} *) |
| 418 | |
| 419 | (** [tclPROGRESS t] checks the state of the proof after [t]. It it is |
| 420 | identical to the state before, then [tclPROGRESS t] fails, otherwise |
| 421 | it succeeds like [t]. *) |
| 422 | val tclPROGRESS : 'a tactic -> 'a tactic |
| 423 | |
| 424 | module Progress : sig |
| 425 | (** [goal_equal ~evd ~extended_evd evar extended_evar] tests whether |
| 426 | the [evar_info] from [evd] corresponding to [evar] is equal to that |
| 427 | from [extended_evd] corresponding to [extended_evar], up to |
| 428 | existential variable instantiation and equalisable universes. The |
| 429 | universe constraints in [extended_evd] are assumed to be an |
| 430 | extension of the universe constraints in [evd]. *) |
| 431 | val goal_equal : |
| 432 | evd:Evd.evar_map -> |
| 433 | extended_evd:Evd.evar_map -> |
| 434 | Evar.t -> |
| 435 | Evar.t -> |
| 436 | bool |
| 437 | end |
| 438 | |
| 439 | (** Checks for interrupts *) |
| 440 | val tclCHECKINTERRUPT : unit tactic |
| 441 | |
| 442 | (** [tclTIMEOUT n t] can have only one success. |
| 443 | In case of timeout it fails with [tclZERO Tac_Timeout]. *) |
| 444 | val tclTIMEOUTF : float -> 'a tactic -> 'a tactic |
| 445 | val tclTIMEOUT : int -> 'a tactic -> 'a tactic |
| 446 | |
| 447 | (** [tclTIME s t] displays time for each atomic call to t, using s as an |
| 448 | identifying annotation if present *) |
| 449 | val tclTIME : string option -> 'a tactic -> 'a tactic |
| 450 | |
| 451 | (** Internal, don't use. *) |
| 452 | val tclProofInfo : (Names.Id.t * PolyFlags.t) tactic |
| 453 | [@@ocaml.deprecated "(8.10) internal, don't use"] |
| 454 | |
| 455 | (** {7 Unsafe primitives} *) |
| 456 | |
| 457 | (** The primitives in the [Unsafe] module should be avoided as much as |
| 458 | possible, since they can make the proof state inconsistent. They are |
| 459 | nevertheless helpful, in particular when interfacing the pretyping and |
| 460 | the proof engine. *) |
| 461 | module Unsafe : sig |
| 462 | |
| 463 | (** [tclEVARS sigma] replaces the current [evar_map] by [sigma]. If |
| 464 | [sigma] has new unresolved [evar]-s they will not appear as |
| 465 | goal. If goals have been solved in [sigma] they will still |
| 466 | appear as unsolved goals. *) |
| 467 | val tclEVARS : Evd.evar_map -> unit tactic |
| 468 | |
| 469 | (** Like {!tclEVARS} but also checks whether goals have been solved. *) |
| 470 | val tclEVARSADVANCE : Evd.evar_map -> unit tactic |
| 471 | |
| 472 | (** Set the global environment of the tactic *) |
| 473 | val tclSETENV : Environ.env -> unit tactic |
| 474 | |
| 475 | (** [tclNEWGOALS ~before gls] adds the goals [gls] to the ones currently |
| 476 | being proved. If [before] is true, it prepends them to the list of focused |
| 477 | goals, otherwise it appends them (default). If a goal is already |
| 478 | solved, it is not added. *) |
| 479 | val tclNEWGOALS : ?before:bool -> Proofview_monad.goal_with_state list -> unit tactic |
| 480 | |
| 481 | (** [tclNEWSHELVED gls] adds the goals [gls] to the shelf. If a |
| 482 | goal is already solved, it is not added. *) |
| 483 | val tclNEWSHELVED : Evar.t list -> unit tactic |
| 484 | |
| 485 | (** [tclSETGOALS gls] sets goals [gls] as the goals being under focus. If a |
| 486 | goal is already solved, it is not set. *) |
| 487 | val tclSETGOALS : Proofview_monad.goal_with_state list -> unit tactic |
| 488 | |
| 489 | (** [tclGETGOALS] returns the list of goals under focus. *) |
| 490 | val tclGETGOALS : Proofview_monad.goal_with_state list tactic |
| 491 | |
| 492 | (** [tclGETSHELF] returns the list of goals on the shelf. *) |
| 493 | val tclGETSHELF : Evar.t list tactic |
| 494 | |
| 495 | (** Sets the evar universe context. *) |
| 496 | val tclEVARUNIVCONTEXT : UState.t -> unit tactic |
| 497 | |
| 498 | (** Clears the future goals store in the proof view. *) |
| 499 | val push_future_goals : proofview -> proofview |
| 500 | |
| 501 | (** Give the evars the status of a goal (changes their source location |
| 502 | and makes them unresolvable for type classes. *) |
| 503 | val mark_as_goals : Evd.evar_map -> Evar.t list -> Evd.evar_map |
| 504 | |
| 505 | (** Make some evars unresolvable for type classes. |
| 506 | We need two functions as some functions use the proofview and others |
| 507 | directly manipulate the undelying evar_map. |
| 508 | *) |
| 509 | val mark_unresolvables : Evd.evar_map -> Evar.t list -> Evd.evar_map |
| 510 | |
| 511 | val mark_as_unresolvables : proofview -> Evar.t list -> proofview |
| 512 | |
| 513 | (** [advance sigma g] returns [Some g'] if [g'] is undefined and is |
| 514 | the current avatar of [g] (for instance [g] was changed by [clear] |
| 515 | into [g']). It returns [None] if [g] has been (partially) |
| 516 | solved. *) |
| 517 | val advance : Evd.evar_map -> Evar.t -> Evar.t option |
| 518 | |
| 519 | (** [undefined sigma l] applies [advance] to the goals of [l], then |
| 520 | returns the subset of resulting goals which have not yet been |
| 521 | defined *) |
| 522 | val undefined : Evd.evar_map -> Proofview_monad.goal_with_state list -> |
| 523 | Proofview_monad.goal_with_state list |
| 524 | |
| 525 | (** [update_sigma_univs] lifts [UState.update_sigma_univs] to the proofview *) |
| 526 | val update_sigma_univs : UGraph.t -> proofview -> proofview |
| 527 | |
| 528 | val purge_side_effects : proofview -> proofview * Evd.side_effects |
| 529 | |
| 530 | end |
| 531 | |
| 532 | (** This module gives access to the innards of the monad. Its use is |
| 533 | restricted to very specific cases. *) |
| 534 | module UnsafeRepr : |
| 535 | sig |
| 536 | type state = Proofview_monad.Logical.Unsafe.state |
| 537 | val repr : 'a tactic -> ('a, state, state, Exninfo.iexn) Logic_monad.BackState.t |
| 538 | val make : ('a, state, state, Exninfo.iexn) Logic_monad.BackState.t -> 'a tactic |
| 539 | end |
| 540 | |
| 541 | (** {6 Goal-dependent tactics} *) |
| 542 | |
| 543 | module Goal : sig |
| 544 | |
| 545 | (** Type of goals. *) |
| 546 | type t |
| 547 | |
| 548 | (** [concl], [hyps], [env] and [sigma] given a goal [gl] return |
| 549 | respectively the conclusion of [gl], the hypotheses of [gl], the |
| 550 | environment of [gl] (i.e. the global environment and the |
| 551 | hypotheses) and the current evar map. *) |
| 552 | val concl : t -> constr |
| 553 | val relevance : t -> ERelevance.t |
| 554 | val hyps : t -> named_context |
| 555 | val env : t -> Environ.env |
| 556 | val sigma : t -> Evd.evar_map |
| 557 | val state : t -> Proofview_monad.StateStore.t |
| 558 | |
| 559 | (** [enter t] applies the goal-dependent tactic [t] in each goal |
| 560 | independently, in the manner of {!tclINDEPENDENT} except that |
| 561 | the current goal is also given as an argument to [t]. *) |
| 562 | val enter : (t -> unit tactic) -> unit tactic |
| 563 | |
| 564 | (** Like {!enter}, but assumes exactly one goal under focus, raising |
| 565 | a fatal error otherwise. *) |
| 566 | val enter_one : ?__LOC__:string -> (t -> 'a tactic) -> 'a tactic |
| 567 | |
| 568 | (** Recover the list of current goals under focus, without evar-normalization. |
| 569 | FIXME: encapsulate the level in an existential type. *) |
| 570 | val goals : t tactic list tactic |
| 571 | |
| 572 | (** [unsolved g] is [true] if [g] is still unsolved in the current |
| 573 | proof state. *) |
| 574 | val unsolved : t -> bool tactic |
| 575 | |
| 576 | (** Compatibility: avoid if possible *) |
| 577 | val goal : t -> Evar.t |
| 578 | |
| 579 | end |
| 580 | |
| 581 | |
| 582 | (** {6 Trace} *) |
| 583 | |
| 584 | module Trace : sig |
| 585 | |
| 586 | (** [record_info_trace t] behaves like [t] except the [info] trace |
| 587 | is stored. *) |
| 588 | val record_info_trace : 'a tactic -> 'a tactic |
| 589 | |
| 590 | val log : Proofview_monad.lazy_msg -> unit tactic |
| 591 | val name_tactic : Proofview_monad.lazy_msg -> 'a tactic -> 'a tactic |
| 592 | |
| 593 | val pr_info : Environ.env -> Evd.evar_map -> ?lvl:int -> Proofview_monad.Info.tree -> Pp.t |
| 594 | |
| 595 | end |
| 596 | |
| 597 | |
| 598 | (** {6 Non-logical state} *) |
| 599 | |
| 600 | (** The [NonLogical] module allows the execution of effects (including |
| 601 | I/O) in tactics (non-logical side-effects are not discarded at |
| 602 | failures). *) |
| 603 | module NonLogical : module type of Logic_monad.NonLogical |
| 604 | |
| 605 | (** [tclLIFT c] is a tactic which behaves exactly as [c]. *) |
| 606 | val tclLIFT : 'a NonLogical.t -> 'a tactic |
| 607 | |
| 608 | (* transforms every Ocaml (catchable) exception into a failure in |
| 609 | the monad. *) |
| 610 | val wrap_exceptions : (unit -> 'a tactic) -> 'a tactic |
| 611 | |
| 612 | (** {7 Notations} *) |
| 613 | |
| 614 | module Notations : sig |
| 615 | |
| 616 | (** {!tclBIND} *) |
| 617 | val (>>=) : 'a tactic -> ('a -> 'b tactic) -> 'b tactic |
| 618 | |
| 619 | (** {!tclTHEN} *) |
| 620 | val (<*>) : unit tactic -> 'a tactic -> 'a tactic |
| 621 | |
| 622 | (** {!tclOR}: [t1+t2] = [tclOR t1 (fun _ -> t2)]. *) |
| 623 | val (<+>) : 'a tactic -> 'a tactic -> 'a tactic |
| 624 | |
| 625 | end |