| 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 |
{ |
| 12 |
|
| 13 |
open Util |
| 14 |
open Locus |
| 15 |
open Tactypes |
| 16 |
open Genredexpr |
| 17 |
open Stdarg |
| 18 |
open Extraargs |
| 19 |
open Tacarg |
| 20 |
open Names |
| 21 |
open Logic |
| 22 |
|
| 23 |
} |
| 24 |
|
| 25 |
DECLARE PLUGIN "rocq-runtime.plugins.ltac" |
| 26 |
|
| 27 |
(** Basic tactics *) |
| 28 |
|
| 29 |
TACTIC EXTEND reflexivity |
| 30 |
| [ "reflexivity" ] -> { Tactics.intros_reflexivity } |
| 31 |
END |
| 32 |
|
| 33 |
TACTIC EXTEND exact |
| 34 |
| [ "exact" uconstr(c) ] -> { Internals.exact ist c } |
| 35 |
END |
| 36 |
|
| 37 |
TACTIC EXTEND assumption |
| 38 |
| [ "assumption" ] -> { Tactics.assumption } |
| 39 |
END |
| 40 |
|
| 41 |
TACTIC EXTEND etransitivity |
| 42 |
| [ "etransitivity" ] -> { Tactics.intros_transitivity None } |
| 43 |
END |
| 44 |
|
| 45 |
TACTIC EXTEND cut |
| 46 |
| [ "cut" constr(c) ] -> { Tactics.cut c } |
| 47 |
END |
| 48 |
|
| 49 |
TACTIC EXTEND exact_no_check |
| 50 |
| [ "exact_no_check" constr(c) ] -> { Tactics.exact_no_check c } |
| 51 |
END |
| 52 |
|
| 53 |
TACTIC EXTEND vm_cast_no_check |
| 54 |
| [ "vm_cast_no_check" constr(c) ] -> { Tactics.vm_cast_no_check c } |
| 55 |
END |
| 56 |
|
| 57 |
TACTIC EXTEND native_cast_no_check |
| 58 |
| [ "native_cast_no_check" constr(c) ] -> { Tactics.native_cast_no_check c } |
| 59 |
END |
| 60 |
|
| 61 |
TACTIC EXTEND exfalso |
| 62 |
| [ "exfalso" ] -> { Tactics.exfalso } |
| 63 |
END |
| 64 |
|
| 65 |
TACTIC EXTEND lapply |
| 66 |
| [ "lapply" constr(c) ] -> { Tactics.cut_and_apply c } |
| 67 |
END |
| 68 |
|
| 69 |
TACTIC EXTEND transitivity |
| 70 |
| [ "transitivity" constr(c) ] -> { Tactics.intros_transitivity (Some c) } |
| 71 |
END |
| 72 |
|
| 73 |
(** Left *) |
| 74 |
|
| 75 |
TACTIC EXTEND left |
| 76 |
| [ "left" ] -> { Tactics.left_with_bindings false NoBindings } |
| 77 |
END |
| 78 |
|
| 79 |
TACTIC EXTEND eleft |
| 80 |
| [ "eleft" ] -> { Tactics.left_with_bindings true NoBindings } |
| 81 |
END |
| 82 |
|
| 83 |
TACTIC EXTEND left_with |
| 84 |
| [ "left" "with" bindings(bl) ] -> { |
| 85 |
Tacticals.tclDELAYEDWITHHOLES false bl (fun bl -> Tactics.left_with_bindings false bl) |
| 86 |
} |
| 87 |
END |
| 88 |
|
| 89 |
TACTIC EXTEND eleft_with |
| 90 |
| [ "eleft" "with" bindings(bl) ] -> { |
| 91 |
Tacticals.tclDELAYEDWITHHOLES true bl (fun bl -> Tactics.left_with_bindings true bl) |
| 92 |
} |
| 93 |
END |
| 94 |
|
| 95 |
(** Right *) |
| 96 |
|
| 97 |
TACTIC EXTEND right |
| 98 |
| [ "right" ] -> { Tactics.right_with_bindings false NoBindings } |
| 99 |
END |
| 100 |
|
| 101 |
TACTIC EXTEND eright |
| 102 |
| [ "eright" ] -> { Tactics.right_with_bindings true NoBindings } |
| 103 |
END |
| 104 |
|
| 105 |
TACTIC EXTEND right_with |
| 106 |
| [ "right" "with" bindings(bl) ] -> { |
| 107 |
Tacticals.tclDELAYEDWITHHOLES false bl (fun bl -> Tactics.right_with_bindings false bl) |
| 108 |
} |
| 109 |
END |
| 110 |
|
| 111 |
TACTIC EXTEND eright_with |
| 112 |
| [ "eright" "with" bindings(bl) ] -> { |
| 113 |
Tacticals.tclDELAYEDWITHHOLES true bl (fun bl -> Tactics.right_with_bindings true bl) |
| 114 |
} |
| 115 |
END |
| 116 |
|
| 117 |
(** Constructor *) |
| 118 |
|
| 119 |
TACTIC EXTEND constructor |
| 120 |
| [ "constructor" ] -> { Tactics.any_constructor false None } |
| 121 |
| [ "constructor" nat_or_var(i) ] -> { |
| 122 |
Tactics.constructor_tac false None i NoBindings |
| 123 |
} |
| 124 |
| [ "constructor" nat_or_var(i) "with" bindings(bl) ] -> { |
| 125 |
let tac bl = Tactics.constructor_tac false None i bl in |
| 126 |
Tacticals.tclDELAYEDWITHHOLES false bl tac |
| 127 |
} |
| 128 |
END |
| 129 |
|
| 130 |
TACTIC EXTEND econstructor |
| 131 |
| [ "econstructor" ] -> { Tactics.any_constructor true None } |
| 132 |
| [ "econstructor" nat_or_var(i) ] -> { |
| 133 |
Tactics.constructor_tac true None i NoBindings |
| 134 |
} |
| 135 |
| [ "econstructor" nat_or_var(i) "with" bindings(bl) ] -> { |
| 136 |
let tac bl = Tactics.constructor_tac true None i bl in |
| 137 |
Tacticals.tclDELAYEDWITHHOLES true bl tac |
| 138 |
} |
| 139 |
END |
| 140 |
|
| 141 |
(** Specialize *) |
| 142 |
|
| 143 |
TACTIC EXTEND specialize |
| 144 |
| [ "specialize" constr_with_bindings(c) ] -> { |
| 145 |
Tacticals.tclDELAYEDWITHHOLES false c (fun c -> Tactics.specialize c None) |
| 146 |
} |
| 147 |
| [ "specialize" constr_with_bindings(c) "as" simple_intropattern(ipat) ] -> { |
| 148 |
Tacticals.tclDELAYEDWITHHOLES false c (fun c -> Tactics.specialize c (Some ipat)) |
| 149 |
} |
| 150 |
END |
| 151 |
|
| 152 |
TACTIC EXTEND symmetry |
| 153 |
| [ "symmetry" ] -> { Tactics.intros_symmetry {onhyps=Some[];concl_occs=AllOccurrences} } |
| 154 |
END |
| 155 |
|
| 156 |
TACTIC EXTEND symmetry_in |
| 157 |
| [ "symmetry" "in" in_clause(cl) ] -> { Tactics.intros_symmetry cl } |
| 158 |
END |
| 159 |
|
| 160 |
(** Split *) |
| 161 |
|
| 162 |
TACTIC EXTEND split |
| 163 |
| [ "split" ] -> { Tactics.split_with_bindings false [NoBindings] } |
| 164 |
END |
| 165 |
|
| 166 |
TACTIC EXTEND esplit |
| 167 |
| [ "esplit" ] -> { Tactics.split_with_bindings true [NoBindings] } |
| 168 |
END |
| 169 |
|
| 170 |
TACTIC EXTEND split_with |
| 171 |
| [ "split" "with" bindings(bl) ] -> { |
| 172 |
Tacticals.tclDELAYEDWITHHOLES false bl (fun bl -> Tactics.split_with_bindings false [bl]) |
| 173 |
} |
| 174 |
END |
| 175 |
|
| 176 |
TACTIC EXTEND esplit_with |
| 177 |
| [ "esplit" "with" bindings(bl) ] -> { |
| 178 |
Tacticals.tclDELAYEDWITHHOLES true bl (fun bl -> Tactics.split_with_bindings true [bl]) |
| 179 |
} |
| 180 |
END |
| 181 |
|
| 182 |
TACTIC EXTEND exists |
| 183 |
| [ "exists" ] -> { Tactics.split_with_bindings false [NoBindings] } |
| 184 |
| [ "exists" ne_bindings_list_sep(bll, ",") ] -> { Tactics.split_with_delayed_bindings false bll } |
| 185 |
END |
| 186 |
|
| 187 |
TACTIC EXTEND eexists |
| 188 |
| [ "eexists" ] -> { Tactics.split_with_bindings true [NoBindings] } |
| 189 |
| [ "eexists" ne_bindings_list_sep(bll, ",") ] -> { Tactics.split_with_delayed_bindings true bll } |
| 190 |
END |
| 191 |
|
| 192 |
(** Intro *) |
| 193 |
|
| 194 |
TACTIC EXTEND intros_until |
| 195 |
| [ "intros" "until" quantified_hypothesis(h) ] -> { Tactics.intros_until h } |
| 196 |
END |
| 197 |
|
| 198 |
TACTIC EXTEND intro |
| 199 |
| [ "intro" ] -> { Tactics.intro_move None MoveLast } |
| 200 |
| [ "intro" ident(id) ] -> { Tactics.intro_move (Some id) MoveLast } |
| 201 |
| [ "intro" ident(id) "at" "top" ] -> { Tactics.intro_move (Some id) MoveFirst } |
| 202 |
| [ "intro" ident(id) "at" "bottom" ] -> { Tactics.intro_move (Some id) MoveLast } |
| 203 |
| [ "intro" ident(id) "after" hyp(h) ] -> { Tactics.intro_move (Some id) (MoveAfter h) } |
| 204 |
| [ "intro" ident(id) "before" hyp(h) ] -> { Tactics.intro_move (Some id) (MoveBefore h) } |
| 205 |
| [ "intro" "at" "top" ] -> { Tactics.intro_move None MoveFirst } |
| 206 |
| [ "intro" "at" "bottom" ] -> { Tactics.intro_move None MoveLast } |
| 207 |
| [ "intro" "after" hyp(h) ] -> { Tactics.intro_move None (MoveAfter h) } |
| 208 |
| [ "intro" "before" hyp(h) ] -> { Tactics.intro_move None (MoveBefore h) } |
| 209 |
END |
| 210 |
|
| 211 |
(** Move *) |
| 212 |
|
| 213 |
TACTIC EXTEND move |
| 214 |
| [ "move" hyp(id) "at" "top" ] -> { Tactics.move_hyp id MoveFirst } |
| 215 |
| [ "move" hyp(id) "at" "bottom" ] -> { Tactics.move_hyp id MoveLast } |
| 216 |
| [ "move" hyp(id) "after" hyp(h) ] -> { Tactics.move_hyp id (MoveAfter h) } |
| 217 |
| [ "move" hyp(id) "before" hyp(h) ] -> { Tactics.move_hyp id (MoveBefore h) } |
| 218 |
END |
| 219 |
|
| 220 |
(** Rename *) |
| 221 |
|
| 222 |
TACTIC EXTEND rename |
| 223 |
| [ "rename" ne_rename_list_sep(ids, ",") ] -> { Tactics.rename_hyp ids } |
| 224 |
END |
| 225 |
|
| 226 |
(** Revert *) |
| 227 |
|
| 228 |
TACTIC EXTEND revert |
| 229 |
| [ "revert" ne_hyp_list(hl) ] -> { Generalize.revert hl } |
| 230 |
END |
| 231 |
|
| 232 |
(** Simple induction / destruct *) |
| 233 |
|
| 234 |
{ |
| 235 |
|
| 236 |
let simple_induct h = |
| 237 |
Tacticals.tclTHEN (Tactics.intros_until h) |
| 238 |
(Tacticals.onLastHyp Tactics.simplest_elim) |
| 239 |
|
| 240 |
} |
| 241 |
|
| 242 |
TACTIC EXTEND simple_induction |
| 243 |
| [ "simple" "induction" quantified_hypothesis(h) ] -> { simple_induct h } |
| 244 |
END |
| 245 |
|
| 246 |
{ |
| 247 |
|
| 248 |
let simple_destruct h = |
| 249 |
Tacticals.tclTHEN (Tactics.intros_until h) |
| 250 |
(Tacticals.onLastHyp Tactics.simplest_case) |
| 251 |
|
| 252 |
} |
| 253 |
|
| 254 |
TACTIC EXTEND simple_destruct |
| 255 |
| [ "simple" "destruct" quantified_hypothesis(h) ] -> { simple_destruct h } |
| 256 |
END |
| 257 |
|
| 258 |
(* Admit *) |
| 259 |
|
| 260 |
TACTIC EXTEND admit |
| 261 |
|[ "admit" ] -> { Proofview.give_up } |
| 262 |
END |
| 263 |
|
| 264 |
(* Fix *) |
| 265 |
|
| 266 |
TACTIC EXTEND fix |
| 267 |
| [ "fix" ident(id) natural(n) ] -> { FixTactics.fix id n } |
| 268 |
END |
| 269 |
|
| 270 |
(* Cofix *) |
| 271 |
|
| 272 |
TACTIC EXTEND cofix |
| 273 |
| [ "cofix" ident(id) ] -> { FixTactics.cofix id } |
| 274 |
END |
| 275 |
|
| 276 |
(* Clear *) |
| 277 |
|
| 278 |
TACTIC EXTEND clear |
| 279 |
| [ "clear" hyp_list(ids) ] -> { |
| 280 |
if List.is_empty ids then Tactics.keep [] |
| 281 |
else Tactics.clear ids |
| 282 |
} |
| 283 |
| [ "clear" "-" ne_hyp_list(ids) ] -> { Tactics.keep ids } |
| 284 |
END |
| 285 |
|
| 286 |
(* Clearbody *) |
| 287 |
|
| 288 |
TACTIC EXTEND clearbody |
| 289 |
| [ "clearbody" ne_hyp_list(ids) ] -> { Tactics.clear_body ids } |
| 290 |
END |
| 291 |
|
| 292 |
(* Generalize dependent *) |
| 293 |
|
| 294 |
TACTIC EXTEND generalize_dependent |
| 295 |
| [ "generalize" "dependent" constr(c) ] -> { Generalize.generalize_dep c } |
| 296 |
END |
| 297 |
|
| 298 |
(* Table of "pervasives" macros tactics (e.g. auto, simpl, etc.) *) |
| 299 |
|
| 300 |
{ |
| 301 |
|
| 302 |
open Tacexpr |
| 303 |
|
| 304 |
let initial_atomic () = |
| 305 |
let nocl = {onhyps=Some[];concl_occs=AllOccurrences} in |
| 306 |
let iter (s, t) = |
| 307 |
let body = CAst.make (TacAtom t) in |
| 308 |
Tacenv.register_ltac false false (Names.Id.of_string s) body |
| 309 |
in |
| 310 |
let () = List.iter iter |
| 311 |
[ "red", TacReduce (Red, nocl); |
| 312 |
"hnf", TacReduce(Hnf,nocl); |
| 313 |
"simpl", TacReduce(Simpl (Redops.all_flags,None),nocl); |
| 314 |
"compute", TacReduce(Cbv Redops.all_flags,nocl); |
| 315 |
"intros", TacIntroPattern (false,[]); |
| 316 |
] |
| 317 |
in |
| 318 |
let iter (s, t) = Tacenv.register_ltac false false (Names.Id.of_string s) t in |
| 319 |
List.iter iter |
| 320 |
[ "idtac", CAst.make (TacId []); |
| 321 |
"fail", CAst.make (TacFail (TacLocal,ArgArg 0,[])); |
| 322 |
"fresh", CAst.make @@ TacArg(TacFreshId []) |
| 323 |
] |
| 324 |
|
| 325 |
let () = Mltop.(declare_cache_obj_full (interp_only_obj initial_atomic) "rocq-runtime.plugins.ltac") |
| 326 |
|
| 327 |
(* First-class Ltac access to primitive blocks *) |
| 328 |
|
| 329 |
let initial_name s = { mltac_plugin = "rocq-runtime.plugins.ltac"; mltac_tactic = s; } |
| 330 |
let initial_entry s = { mltac_name = initial_name s; mltac_index = 0; } |
| 331 |
|
| 332 |
let register_list_tactical name f = |
| 333 |
let tac args ist = match args with |
| 334 |
| [v] -> |
| 335 |
begin match Tacinterp.Value.to_list v with |
| 336 |
| None -> Tacticals.tclZEROMSG (Pp.str "Expected a list") |
| 337 |
| Some tacs -> |
| 338 |
let tacs = List.map (fun tac -> Tacinterp.tactic_of_value ist tac) tacs in |
| 339 |
f tacs |
| 340 |
end |
| 341 |
| _ -> assert false |
| 342 |
in |
| 343 |
Tacenv.register_ml_tactic (initial_name name) [|tac|] |
| 344 |
|
| 345 |
let () = register_list_tactical "first" Tacticals.tclFIRST |
| 346 |
let () = register_list_tactical "solve" Tacticals.tclSOLVE |
| 347 |
|
| 348 |
let initial_tacticals () = |
| 349 |
let idn n = Id.of_string (Printf.sprintf "_%i" n) in |
| 350 |
let varn n = Reference (ArgVar (CAst.make (idn n))) in |
| 351 |
let iter (s, t) = Tacenv.register_ltac false false (Id.of_string s) t in |
| 352 |
List.iter iter [ |
| 353 |
"first", CAst.make (TacFun |
| 354 |
([Name (idn 0)], CAst.make (TacML (initial_entry "first", [varn 0])))); |
| 355 |
"solve", CAst.make (TacFun |
| 356 |
([Name (idn 0)], CAst.make (TacML (initial_entry "solve", [varn 0])))); |
| 357 |
] |
| 358 |
|
| 359 |
let () = Mltop.(declare_cache_obj_full (interp_only_obj initial_tacticals) "rocq-runtime.plugins.ltac") |
| 360 |
|
| 361 |
} |