| 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 |
Require Import Corelib.Init.Ltac. |
| 12 |
Require Import Ltac2.Init. |
| 13 |
Require Ltac2.Control Ltac2.Fresh Ltac2.Option Ltac2.Pattern Ltac2.Array Ltac2.Int Ltac2.Std Ltac2.Constr. |
| 14 |
|
| 15 |
(** Constr matching *) |
| 16 |
|
| 17 |
Ltac2 Notation "lazy_match!" t(tactic(6)) "with" m(constr_matching) "end" : 0 := |
| 18 |
Pattern.lazy_match0 t m. |
| 19 |
|
| 20 |
Ltac2 Notation "multi_match!" t(tactic(6)) "with" m(constr_matching) "end" : 0 := |
| 21 |
Pattern.multi_match0 t m. |
| 22 |
|
| 23 |
Ltac2 Notation "match!" t(tactic(6)) "with" m(constr_matching) "end" : 0 := |
| 24 |
Pattern.one_match0 t m. |
| 25 |
|
| 26 |
(** Goal matching *) |
| 27 |
|
| 28 |
Ltac2 Notation "lazy_match!" "goal" "with" m(goal_matching) "end" : 0 := |
| 29 |
Pattern.lazy_goal_match0 false m. |
| 30 |
|
| 31 |
Ltac2 Notation "multi_match!" "goal" "with" m(goal_matching) "end" : 0 := |
| 32 |
Pattern.multi_goal_match0 false m. |
| 33 |
|
| 34 |
Ltac2 Notation "match!" "goal" "with" m(goal_matching) "end" : 0 := |
| 35 |
Pattern.one_goal_match0 false m. |
| 36 |
|
| 37 |
Ltac2 Notation "lazy_match!" "reverse" "goal" "with" m(goal_matching) "end" : 0 := |
| 38 |
Pattern.lazy_goal_match0 true m. |
| 39 |
|
| 40 |
Ltac2 Notation "multi_match!" "reverse" "goal" "with" m(goal_matching) "end" : 0 := |
| 41 |
Pattern.multi_goal_match0 true m. |
| 42 |
|
| 43 |
Ltac2 Notation "match!" "reverse" "goal" "with" m(goal_matching) "end" : 0 := |
| 44 |
Pattern.one_goal_match0 true m. |
| 45 |
|
| 46 |
(** Tacticals *) |
| 47 |
|
| 48 |
Ltac2 orelse t f := |
| 49 |
match Control.case t with |
| 50 |
| Err e => f e |
| 51 |
| Val ans => |
| 52 |
let (x, k) := ans in |
| 53 |
Control.plus (fun _ => x) k |
| 54 |
end. |
| 55 |
|
| 56 |
Ltac2 ifcatch t s f := |
| 57 |
match Control.case t with |
| 58 |
| Err e => f e |
| 59 |
| Val ans => |
| 60 |
let (x, k) := ans in |
| 61 |
Control.plus (fun _ => s x) (fun e => s (k e)) |
| 62 |
end. |
| 63 |
|
| 64 |
Ltac2 fail0 (_ : unit) := Control.enter (fun _ => Control.zero (Tactic_failure None)). |
| 65 |
|
| 66 |
Ltac2 Abbreviation fail := fail0 (). |
| 67 |
|
| 68 |
Ltac2 try0 t := Control.enter (fun _ => orelse t (fun _ => ())). |
| 69 |
|
| 70 |
Ltac2 Abbreviation try := try0. |
| 71 |
|
| 72 |
Ltac2 rec repeat0 (t : unit -> unit) := |
| 73 |
Control.enter (fun () => |
| 74 |
ifcatch (fun _ => Control.progress t) |
| 75 |
(fun _ => Control.check_interrupt (); repeat0 t) (fun _ => ())). |
| 76 |
|
| 77 |
Ltac2 Abbreviation repeat := repeat0. |
| 78 |
|
| 79 |
Ltac2 dispatch0 t (head, tail) := |
| 80 |
match tail with |
| 81 |
| None => Control.enter (fun _ => t (); Control.dispatch head) |
| 82 |
| Some tacs => |
| 83 |
let (def, rem) := tacs in |
| 84 |
Control.enter (fun _ => t (); Control.extend head def rem) |
| 85 |
end. |
| 86 |
|
| 87 |
Ltac2 Notation t(thunk(self)) ">" "[" l(dispatch) "]" : 4 := dispatch0 t l. |
| 88 |
|
| 89 |
Ltac2 do0 n t := |
| 90 |
let rec aux n t := match Int.equal n 0 with |
| 91 |
| true => () |
| 92 |
| false => t (); aux (Int.sub n 1) t |
| 93 |
end in |
| 94 |
aux (n ()) t. |
| 95 |
|
| 96 |
Ltac2 Abbreviation do := do0. |
| 97 |
|
| 98 |
Ltac2 Abbreviation once := Control.once. |
| 99 |
|
| 100 |
Ltac2 Abbreviation unshelve := Control.unshelve. |
| 101 |
|
| 102 |
Ltac2 cycle := Control.cycle. |
| 103 |
|
| 104 |
Ltac2 progress0 tac := Control.enter (fun _ => Control.progress tac). |
| 105 |
|
| 106 |
Ltac2 Abbreviation progress := progress0. |
| 107 |
|
| 108 |
Ltac2 rec first0 tacs := |
| 109 |
match tacs with |
| 110 |
| [] => Control.zero (Tactic_failure None) |
| 111 |
| tac :: tacs => Control.enter (fun _ => orelse tac (fun _ => first0 tacs)) |
| 112 |
end. |
| 113 |
|
| 114 |
Ltac2 Notation "first" "[" tacs(list0(thunk(tactic(6)), "|")) "]" := first0 tacs. |
| 115 |
|
| 116 |
Ltac2 complete tac := |
| 117 |
let ans := tac () in |
| 118 |
Control.enter (fun () => Control.zero (Tactic_failure None)); |
| 119 |
ans. |
| 120 |
|
| 121 |
Ltac2 rec solve0 tacs := |
| 122 |
match tacs with |
| 123 |
| [] => Control.zero (Tactic_failure None) |
| 124 |
| tac :: tacs => |
| 125 |
Control.enter (fun _ => orelse (fun _ => complete tac) (fun _ => solve0 tacs)) |
| 126 |
end. |
| 127 |
|
| 128 |
Ltac2 Notation "solve" "[" tacs(list0(thunk(tactic(6)), "|")) "]" := solve0 tacs. |
| 129 |
|
| 130 |
Ltac2 time0 tac := Control.time None tac. |
| 131 |
|
| 132 |
Ltac2 Abbreviation time := time0. |
| 133 |
|
| 134 |
Ltac2 abstract0 tac := Control.abstract None tac. |
| 135 |
|
| 136 |
Ltac2 Abbreviation abstract := abstract0. |
| 137 |
|
| 138 |
(** Base tactics *) |
| 139 |
|
| 140 |
(** Note that we redeclare notations that can be parsed as mere identifiers |
| 141 |
as abbreviations, so that it allows to parse them as function arguments |
| 142 |
without having to write them within parentheses. *) |
| 143 |
|
| 144 |
(** Enter and check evar resolution *) |
| 145 |
Ltac2 enter_h ev f arg := |
| 146 |
match ev with |
| 147 |
| true => Control.enter (fun () => f ev (arg ())) |
| 148 |
| false => |
| 149 |
Control.enter (fun () => |
| 150 |
Control.with_holes arg (fun x => f ev x)) |
| 151 |
end. |
| 152 |
|
| 153 |
Ltac2 intros0 ev p := |
| 154 |
Control.enter (fun () => Std.intros ev p). |
| 155 |
|
| 156 |
Ltac2 Notation "intros" p(intropatterns) := intros0 false p. |
| 157 |
Ltac2 Abbreviation intros := intros. |
| 158 |
|
| 159 |
Ltac2 Notation "eintros" p(intropatterns) := intros0 true p. |
| 160 |
Ltac2 Abbreviation eintros := eintros. |
| 161 |
|
| 162 |
Ltac2 split0 ev bnd := |
| 163 |
enter_h ev Std.split bnd. |
| 164 |
|
| 165 |
Ltac2 Notation "split" bnd(thunk(with_bindings)) := split0 false bnd. |
| 166 |
Ltac2 Abbreviation split := split. |
| 167 |
|
| 168 |
Ltac2 Notation "esplit" bnd(thunk(with_bindings)) := split0 true bnd. |
| 169 |
Ltac2 Abbreviation esplit := esplit. |
| 170 |
|
| 171 |
Ltac2 exists0 ev bnds := match bnds with |
| 172 |
| [] => split0 ev (fun () => Std.NoBindings) |
| 173 |
| _ => |
| 174 |
let rec aux bnds := match bnds with |
| 175 |
| [] => () |
| 176 |
| bnd :: bnds => split0 ev bnd; aux bnds |
| 177 |
end in |
| 178 |
aux bnds |
| 179 |
end. |
| 180 |
|
| 181 |
Ltac2 Notation "exists" bnd(list0(thunk(bindings), ",")) := exists0 false bnd. |
| 182 |
(* Ltac2 Abbreviation exists := exists. *) |
| 183 |
|
| 184 |
Ltac2 Notation "eexists" bnd(list0(thunk(bindings), ",")) := exists0 true bnd. |
| 185 |
Ltac2 Abbreviation eexists := eexists. |
| 186 |
|
| 187 |
Ltac2 left0 ev bnd := enter_h ev Std.left bnd. |
| 188 |
|
| 189 |
Ltac2 Notation "left" bnd(thunk(with_bindings)) := left0 false bnd. |
| 190 |
Ltac2 Abbreviation left := left. |
| 191 |
|
| 192 |
Ltac2 Notation "eleft" bnd(thunk(with_bindings)) := left0 true bnd. |
| 193 |
Ltac2 Abbreviation eleft := eleft. |
| 194 |
|
| 195 |
Ltac2 right0 ev bnd := enter_h ev Std.right bnd. |
| 196 |
|
| 197 |
Ltac2 Notation "right" bnd(thunk(with_bindings)) := right0 false bnd. |
| 198 |
Ltac2 Abbreviation right := right. |
| 199 |
|
| 200 |
Ltac2 Notation "eright" bnd(thunk(with_bindings)) := right0 true bnd. |
| 201 |
Ltac2 Abbreviation eright := eright. |
| 202 |
|
| 203 |
Ltac2 constructor0 ev n bnd := |
| 204 |
enter_h ev (fun ev bnd => Std.constructor_n ev n bnd) bnd. |
| 205 |
|
| 206 |
Local Ltac2 constructor1 ev x := |
| 207 |
match x with |
| 208 |
| None => Control.enter (fun () => Std.constructor ev) |
| 209 |
| Some (tac, bnd) => constructor0 ev tac bnd |
| 210 |
end. |
| 211 |
|
| 212 |
Ltac2 Abbreviation constructor := constructor1 false None. |
| 213 |
Ltac2 Notation "constructor" x(opt(seq(tactic,thunk(with_bindings)))) := constructor1 false x. |
| 214 |
|
| 215 |
Ltac2 Abbreviation econstructor := constructor1 true None. |
| 216 |
Ltac2 Notation "econstructor" x(opt(seq(tactic,thunk(with_bindings)))) := constructor1 true x. |
| 217 |
|
| 218 |
Ltac2 specialize0 c pat := |
| 219 |
enter_h false (fun _ c => Std.specialize c pat) c. |
| 220 |
|
| 221 |
Ltac2 Notation "specialize" c(thunk(seq(constr, with_bindings))) ipat(opt(seq("as", intropattern))) := |
| 222 |
specialize0 c ipat. |
| 223 |
|
| 224 |
Ltac2 elim0 ev c bnd use := |
| 225 |
let f ev (c, bnd, use) := Std.elim ev (c, bnd) use in |
| 226 |
enter_h ev f (fun () => c (), bnd (), use ()). |
| 227 |
|
| 228 |
Ltac2 Notation "elim" c(thunk(constr)) bnd(thunk(with_bindings)) |
| 229 |
use(thunk(opt(seq("using", constr, with_bindings)))) := |
| 230 |
elim0 false c bnd use. |
| 231 |
|
| 232 |
Ltac2 Notation "eelim" c(thunk(constr)) bnd(thunk(with_bindings)) |
| 233 |
use(thunk(opt(seq("using", constr, with_bindings)))) := |
| 234 |
elim0 true c bnd use. |
| 235 |
|
| 236 |
Ltac2 apply0 adv ev cb cl := |
| 237 |
Std.apply adv ev cb cl. |
| 238 |
|
| 239 |
Ltac2 Notation "eapply" |
| 240 |
cb(list1(thunk(seq(open_constr, with_bindings)), ",")) |
| 241 |
cl(opt(seq("in", ident, opt(seq("as", intropattern))))) := |
| 242 |
apply0 true true cb cl. |
| 243 |
|
| 244 |
Ltac2 Notation "apply" |
| 245 |
cb(list1(thunk(seq(open_constr, with_bindings)), ",")) |
| 246 |
cl(opt(seq("in", ident, opt(seq("as", intropattern))))) := |
| 247 |
apply0 true false cb cl. |
| 248 |
|
| 249 |
Ltac2 default_on_concl cl := |
| 250 |
match cl with |
| 251 |
| None => { Std.on_hyps := Some []; Std.on_concl := Std.AllOccurrences } |
| 252 |
| Some cl => cl |
| 253 |
end. |
| 254 |
|
| 255 |
Ltac2 pose0 ev p := |
| 256 |
enter_h ev (fun _ (na, p) => Std.pose na p) p. |
| 257 |
|
| 258 |
Ltac2 Notation "pose" p(thunk(pose)) := |
| 259 |
pose0 false p. |
| 260 |
|
| 261 |
Ltac2 Notation "epose" p(thunk(pose)) := |
| 262 |
pose0 true p. |
| 263 |
|
| 264 |
Ltac2 Notation "set" p(thunk(pose)) cl(opt(clause)) := |
| 265 |
Std.set false p (default_on_concl cl). |
| 266 |
|
| 267 |
Ltac2 Notation "eset" p(thunk(pose)) cl(opt(clause)) := |
| 268 |
Std.set true p (default_on_concl cl). |
| 269 |
|
| 270 |
Ltac2 assert0 ev ast := |
| 271 |
enter_h ev (fun _ ast => Std.assert ast) ast. |
| 272 |
|
| 273 |
Ltac2 Notation "assert" ast(thunk(assert)) := assert0 false ast. |
| 274 |
|
| 275 |
Ltac2 Notation "eassert" ast(thunk(assert)) := assert0 true ast. |
| 276 |
|
| 277 |
Ltac2 enough_from_assertion(a : Std.assertion) := |
| 278 |
match a with |
| 279 |
| Std.AssertType ip_opt term tac_opt => Std.enough term (Some tac_opt) ip_opt |
| 280 |
| Std.AssertValue ident constr => Std.pose (Some ident) constr |
| 281 |
end. |
| 282 |
|
| 283 |
Ltac2 enough0 ev ast := |
| 284 |
enter_h ev (fun _ ast => enough_from_assertion ast) ast. |
| 285 |
|
| 286 |
Ltac2 Notation "enough" ast(thunk(assert)) := enough0 false ast. |
| 287 |
|
| 288 |
Ltac2 Notation "eenough" ast(thunk(assert)) := enough0 true ast. |
| 289 |
|
| 290 |
Ltac2 default_everywhere cl := |
| 291 |
match cl with |
| 292 |
| None => { Std.on_hyps := None; Std.on_concl := Std.AllOccurrences } |
| 293 |
| Some cl => cl |
| 294 |
end. |
| 295 |
|
| 296 |
Ltac2 Notation "remember" |
| 297 |
c(thunk(open_constr)) |
| 298 |
na(opt(seq("as", ident))) |
| 299 |
pat(opt(seq("eqn", ":", intropattern))) |
| 300 |
cl(opt(clause)) := |
| 301 |
Std.remember false na c pat (default_everywhere cl). |
| 302 |
|
| 303 |
Ltac2 Notation "eremember" |
| 304 |
c(thunk(open_constr)) |
| 305 |
na(opt(seq("as", ident))) |
| 306 |
pat(opt(seq("eqn", ":", intropattern))) |
| 307 |
cl(opt(clause)) := |
| 308 |
Std.remember true na c pat (default_everywhere cl). |
| 309 |
|
| 310 |
Ltac2 induction0 ev ic use := |
| 311 |
let f ev use := Std.induction ev ic use in |
| 312 |
enter_h ev f use. |
| 313 |
|
| 314 |
Ltac2 Notation "induction" |
| 315 |
ic(list1(induction_clause, ",")) |
| 316 |
use(thunk(opt(seq("using", constr, with_bindings)))) := |
| 317 |
induction0 false ic use. |
| 318 |
|
| 319 |
Ltac2 Notation "einduction" |
| 320 |
ic(list1(induction_clause, ",")) |
| 321 |
use(thunk(opt(seq("using", constr, with_bindings)))) := |
| 322 |
induction0 true ic use. |
| 323 |
|
| 324 |
Ltac2 generalize0 gen := |
| 325 |
enter_h false (fun _ gen => Std.generalize gen) gen. |
| 326 |
|
| 327 |
Ltac2 Notation "generalize" |
| 328 |
gen(thunk(list1(seq (open_constr, occurrences, opt(seq("as", ident))), ","))) := |
| 329 |
generalize0 gen. |
| 330 |
|
| 331 |
Ltac2 destruct0 ev ic use := |
| 332 |
let f ev use := Std.destruct ev ic use in |
| 333 |
enter_h ev f use. |
| 334 |
|
| 335 |
Ltac2 Notation "destruct" |
| 336 |
ic(list1(induction_clause, ",")) |
| 337 |
use(thunk(opt(seq("using", constr, with_bindings)))) := |
| 338 |
destruct0 false ic use. |
| 339 |
|
| 340 |
Ltac2 Notation "edestruct" |
| 341 |
ic(list1(induction_clause, ",")) |
| 342 |
use(thunk(opt(seq("using", constr, with_bindings)))) := |
| 343 |
destruct0 true ic use. |
| 344 |
|
| 345 |
Ltac2 Notation "simple" "inversion" |
| 346 |
arg(destruction_arg) |
| 347 |
pat(opt(seq("as", intropattern))) |
| 348 |
ids(opt(seq("in", list1(ident)))) := |
| 349 |
Std.inversion Std.SimpleInversion arg pat ids. |
| 350 |
|
| 351 |
Ltac2 Notation "inversion" |
| 352 |
arg(destruction_arg) |
| 353 |
pat(opt(seq("as", intropattern))) |
| 354 |
ids(opt(seq("in", list1(ident)))) := |
| 355 |
Std.inversion Std.FullInversion arg pat ids. |
| 356 |
|
| 357 |
Ltac2 Notation "inversion_clear" |
| 358 |
arg(destruction_arg) |
| 359 |
pat(opt(seq("as", intropattern))) |
| 360 |
ids(opt(seq("in", list1(ident)))) := |
| 361 |
Std.inversion Std.FullInversionClear arg pat ids. |
| 362 |
|
| 363 |
Ltac2 Abbreviation exfalso := Std.exfalso (). |
| 364 |
|
| 365 |
Ltac2 Notation "red" cl(opt(clause)) := |
| 366 |
Std.red (default_on_concl cl). |
| 367 |
Ltac2 Abbreviation red := red. |
| 368 |
|
| 369 |
Ltac2 Notation "hnf" cl(opt(clause)) := |
| 370 |
Std.hnf (default_on_concl cl). |
| 371 |
Ltac2 Abbreviation hnf := hnf. |
| 372 |
|
| 373 |
Ltac2 Notation "simpl" s(strategy) pl(opt(seq(pattern, occurrences))) cl(opt(clause)) := |
| 374 |
Std.simpl s pl (default_on_concl cl). |
| 375 |
Ltac2 Abbreviation simpl := simpl. |
| 376 |
|
| 377 |
Ltac2 Notation "cbv" s(strategy) cl(opt(clause)) := |
| 378 |
Std.cbv s (default_on_concl cl). |
| 379 |
Ltac2 Abbreviation cbv := cbv. |
| 380 |
|
| 381 |
Ltac2 Notation "cbn" s(strategy) cl(opt(clause)) := |
| 382 |
Std.cbn s (default_on_concl cl). |
| 383 |
Ltac2 Abbreviation cbn := cbn. |
| 384 |
|
| 385 |
Ltac2 Notation "lazy" s(strategy) cl(opt(clause)) := |
| 386 |
Std.lazy s (default_on_concl cl). |
| 387 |
Ltac2 Abbreviation lazy := lazy. |
| 388 |
|
| 389 |
Ltac2 Notation "unfold" pl(list1(seq(reference, occurrences), ",")) cl(opt(clause)) := |
| 390 |
Std.unfold pl (default_on_concl cl). |
| 391 |
|
| 392 |
Ltac2 fold0 pl cl := |
| 393 |
let cl := default_on_concl cl in |
| 394 |
Control.enter (fun () => Control.with_holes pl (fun pl => Std.fold pl cl)). |
| 395 |
|
| 396 |
Ltac2 Notation "fold" pl(thunk(list1(open_constr))) cl(opt(clause)) := |
| 397 |
fold0 pl cl. |
| 398 |
|
| 399 |
Ltac2 Notation "pattern" pl(list1(seq(constr, occurrences), ",")) cl(opt(clause)) := |
| 400 |
Std.pattern pl (default_on_concl cl). |
| 401 |
|
| 402 |
Ltac2 Notation "vm_compute" pl(opt(seq(pattern, occurrences))) cl(opt(clause)) := |
| 403 |
Std.vm pl (default_on_concl cl). |
| 404 |
Ltac2 Abbreviation vm_compute := vm_compute. |
| 405 |
|
| 406 |
Ltac2 Notation "native_compute" pl(opt(seq(pattern, occurrences))) cl(opt(clause)) := |
| 407 |
Std.native pl (default_on_concl cl). |
| 408 |
Ltac2 Abbreviation native_compute := native_compute. |
| 409 |
|
| 410 |
Ltac2 Notation "eval" "red" "in" c(constr) := |
| 411 |
Std.eval_red c. |
| 412 |
|
| 413 |
Ltac2 Notation "eval" "hnf" "in" c(constr) := |
| 414 |
Std.eval_hnf c. |
| 415 |
|
| 416 |
Ltac2 Notation "eval" "simpl" s(strategy) pl(opt(seq(pattern, occurrences))) "in" c(constr) := |
| 417 |
Std.eval_simpl s pl c. |
| 418 |
|
| 419 |
Ltac2 Notation "eval" "cbv" s(strategy) "in" c(constr) := |
| 420 |
Std.eval_cbv s c. |
| 421 |
|
| 422 |
Ltac2 Notation "eval" "cbn" s(strategy) "in" c(constr) := |
| 423 |
Std.eval_cbn s c. |
| 424 |
|
| 425 |
Ltac2 Notation "eval" "lazy" s(strategy) "in" c(constr) := |
| 426 |
Std.eval_lazy s c. |
| 427 |
|
| 428 |
Ltac2 Notation "eval" "unfold" pl(list1(seq(reference, occurrences), ",")) "in" c(constr) := |
| 429 |
Std.eval_unfold pl c. |
| 430 |
|
| 431 |
Ltac2 Notation "eval" "fold" pl(thunk(list1(open_constr))) "in" c(constr) := |
| 432 |
Std.eval_fold (pl ()) c. |
| 433 |
|
| 434 |
Ltac2 Notation "eval" "pattern" pl(list1(seq(constr, occurrences), ",")) "in" c(constr) := |
| 435 |
Std.eval_pattern pl c. |
| 436 |
|
| 437 |
Ltac2 Notation "eval" "vm_compute" pl(opt(seq(pattern, occurrences))) "in" c(constr) := |
| 438 |
Std.eval_vm pl c. |
| 439 |
|
| 440 |
Ltac2 Notation "eval" "native_compute" pl(opt(seq(pattern, occurrences))) "in" c(constr) := |
| 441 |
Std.eval_native pl c. |
| 442 |
|
| 443 |
Ltac2 change0 p cl := |
| 444 |
let (pat, c) := p in |
| 445 |
Std.change pat c (default_on_concl cl). |
| 446 |
|
| 447 |
Ltac2 Notation "change" c(conversion) cl(opt(clause)) := change0 c cl. |
| 448 |
|
| 449 |
Ltac2 rewrite0 ev rw cl tac := |
| 450 |
let cl := default_on_concl cl in |
| 451 |
Std.rewrite ev rw cl tac. |
| 452 |
|
| 453 |
Ltac2 Notation "rewrite" |
| 454 |
rw(list1(rewriting, ",")) |
| 455 |
cl(opt(clause)) |
| 456 |
tac(opt(seq("by", thunk(tactic)))) := |
| 457 |
rewrite0 false rw cl tac. |
| 458 |
|
| 459 |
Ltac2 Notation "setoid_rewrite" |
| 460 |
ori(orient) |
| 461 |
c(thunk(seq(open_constr, with_bindings))) |
| 462 |
occs(occurrences) |
| 463 |
id(opt(seq("in", ident))) := |
| 464 |
Std.setoid_rewrite (Option.default Std.LTR ori) c occs id. |
| 465 |
|
| 466 |
Ltac2 Notation "erewrite" |
| 467 |
rw(list1(rewriting, ",")) |
| 468 |
cl(opt(clause)) |
| 469 |
tac(opt(seq("by", thunk(tactic)))) := |
| 470 |
rewrite0 true rw cl tac. |
| 471 |
|
| 472 |
(** coretactics *) |
| 473 |
|
| 474 |
(** Provided for backwards compat *) |
| 475 |
#[deprecated(since="8.19")] |
| 476 |
Ltac2 exact0 ev c := |
| 477 |
Control.enter (fun _ => |
| 478 |
match ev with |
| 479 |
| true => |
| 480 |
let c := c () in |
| 481 |
Control.refine (fun _ => c) |
| 482 |
| false => |
| 483 |
Control.with_holes c (fun c => Control.refine (fun _ => c)) |
| 484 |
end |
| 485 |
). |
| 486 |
|
| 487 |
Ltac2 exact1 ev c := |
| 488 |
Control.enter (fun () => |
| 489 |
let c := |
| 490 |
Constr.Pretype.pretype |
| 491 |
(if ev then Constr.Pretype.Flags.open_constr_flags_with_tc else Constr.Pretype.Flags.constr_flags) |
| 492 |
(Constr.Pretype.expected_oftype (Control.goal())) |
| 493 |
c |
| 494 |
in |
| 495 |
Std.exact_no_check c). |
| 496 |
|
| 497 |
Ltac2 Notation "exact" c(preterm) := exact1 false c. |
| 498 |
|
| 499 |
Ltac2 Notation "eexact" c(preterm) := exact1 true c. |
| 500 |
(** Like [refine] but new evars are shelved instead of becoming subgoals. *) |
| 501 |
|
| 502 |
Ltac2 Notation "intro" id(opt(ident)) mv(opt(move_location)) := Std.intro id mv. |
| 503 |
Ltac2 Abbreviation intro := intro. |
| 504 |
|
| 505 |
Ltac2 Notation "move" id(ident) mv(move_location) := Std.move id mv. |
| 506 |
|
| 507 |
Ltac2 Abbreviation reflexivity := Std.reflexivity (). |
| 508 |
|
| 509 |
Ltac2 symmetry0 cl := |
| 510 |
Std.symmetry (default_on_concl cl). |
| 511 |
|
| 512 |
Ltac2 Notation "symmetry" cl(opt(clause)) := symmetry0 cl. |
| 513 |
Ltac2 Abbreviation symmetry := symmetry. |
| 514 |
|
| 515 |
Ltac2 Notation "revert" ids(list1(ident)) := Std.revert ids. |
| 516 |
|
| 517 |
Ltac2 Abbreviation assumption := Std.assumption (). |
| 518 |
|
| 519 |
Ltac2 Abbreviation eassumption := Std.eassumption (). |
| 520 |
|
| 521 |
Ltac2 Abbreviation etransitivity := Std.etransitivity (). |
| 522 |
|
| 523 |
Ltac2 Abbreviation admit := Std.admit (). |
| 524 |
|
| 525 |
Ltac2 clear0 ids := match ids with |
| 526 |
| [] => Std.keep [] |
| 527 |
| _ => Std.clear ids |
| 528 |
end. |
| 529 |
|
| 530 |
Ltac2 Notation "clear" ids(list0(ident)) := clear0 ids. |
| 531 |
Ltac2 Notation "clear" "-" ids(list1(ident)) := Std.keep ids. |
| 532 |
Ltac2 Abbreviation clear := clear. |
| 533 |
|
| 534 |
Ltac2 Abbreviation refine := Control.refine. |
| 535 |
|
| 536 |
(** extratactics *) |
| 537 |
|
| 538 |
Ltac2 absurd0 c := Control.enter (fun _ => Std.absurd (c ())). |
| 539 |
|
| 540 |
Ltac2 Notation "absurd" c(thunk(open_constr)) := absurd0 c. |
| 541 |
|
| 542 |
Ltac2 subst0 ids := match ids with |
| 543 |
| [] => Std.subst_all () |
| 544 |
| _ => Std.subst ids |
| 545 |
end. |
| 546 |
|
| 547 |
Ltac2 Notation "subst" ids(list0(ident)) := subst0 ids. |
| 548 |
Ltac2 Abbreviation subst := subst. |
| 549 |
|
| 550 |
Ltac2 Notation "discriminate" arg(opt(destruction_arg)) := |
| 551 |
Std.discriminate false arg. |
| 552 |
Ltac2 Abbreviation discriminate := discriminate. |
| 553 |
|
| 554 |
Ltac2 Notation "ediscriminate" arg(opt(destruction_arg)) := |
| 555 |
Std.discriminate true arg. |
| 556 |
Ltac2 Abbreviation ediscriminate := ediscriminate. |
| 557 |
|
| 558 |
Ltac2 Notation "injection" arg(opt(destruction_arg)) ipat(opt(seq("as", intropatterns))):= |
| 559 |
Std.injection false ipat arg. |
| 560 |
|
| 561 |
Ltac2 Notation "einjection" arg(opt(destruction_arg)) ipat(opt(seq("as", intropatterns))):= |
| 562 |
Std.injection true ipat arg. |
| 563 |
|
| 564 |
(** Auto *) |
| 565 |
|
| 566 |
Ltac2 default_db dbs := match dbs with |
| 567 |
| None => Some [] |
| 568 |
| Some dbs => |
| 569 |
match dbs with |
| 570 |
| None => None |
| 571 |
| Some l => Some l |
| 572 |
end |
| 573 |
end. |
| 574 |
|
| 575 |
Ltac2 default_list use := match use with |
| 576 |
| None => [] |
| 577 |
| Some use => use |
| 578 |
end. |
| 579 |
|
| 580 |
Ltac2 trivial0 use dbs := |
| 581 |
let dbs := default_db dbs in |
| 582 |
let use := default_list use in |
| 583 |
Std.trivial Std.Off use dbs. |
| 584 |
|
| 585 |
Ltac2 Notation "trivial" |
| 586 |
use(opt(seq("using", list1(reference, ",")))) |
| 587 |
dbs(opt(seq("with", hintdb))) := trivial0 use dbs. |
| 588 |
|
| 589 |
Ltac2 Abbreviation trivial := trivial. |
| 590 |
|
| 591 |
Ltac2 auto0 n use dbs := |
| 592 |
let dbs := default_db dbs in |
| 593 |
let use := default_list use in |
| 594 |
Std.auto Std.Off n use dbs. |
| 595 |
|
| 596 |
Ltac2 Notation "auto" n(opt(tactic(0))) |
| 597 |
use(opt(seq("using", list1(reference, ",")))) |
| 598 |
dbs(opt(seq("with", hintdb))) := auto0 n use dbs. |
| 599 |
|
| 600 |
Ltac2 Abbreviation auto := auto. |
| 601 |
|
| 602 |
Ltac2 eauto0 n use dbs := |
| 603 |
let dbs := default_db dbs in |
| 604 |
let use := default_list use in |
| 605 |
Std.eauto Std.Off n use dbs. |
| 606 |
|
| 607 |
Ltac2 Notation "eauto" n(opt(tactic(0))) |
| 608 |
use(opt(seq("using", list1(reference, ",")))) |
| 609 |
dbs(opt(seq("with", hintdb))) := eauto0 n use dbs. |
| 610 |
|
| 611 |
Ltac2 Abbreviation eauto := eauto. |
| 612 |
|
| 613 |
Ltac2 Notation "typeclasses_eauto" n(opt(tactic(0))) |
| 614 |
dbs(opt(seq("with", list1(ident)))) := Std.typeclasses_eauto None n dbs. |
| 615 |
|
| 616 |
Ltac2 Notation "typeclasses_eauto" "bfs" n(opt(tactic(0))) |
| 617 |
dbs(opt(seq("with", list1(ident)))) := Std.typeclasses_eauto (Some Std.BFS) n dbs. |
| 618 |
|
| 619 |
Ltac2 Abbreviation typeclasses_eauto := typeclasses_eauto. |
| 620 |
|
| 621 |
Ltac2 Notation "unify" x(constr) y(constr) := Std.unify x y. |
| 622 |
|
| 623 |
(** Congruence *) |
| 624 |
|
| 625 |
Ltac2 Notation "congruence" n(opt(tactic(0))) l(opt(seq("with", list1(constr)))) := Std.congruence n l. |
| 626 |
|
| 627 |
Ltac2 Notation "simple" "congruence" n(opt(tactic(0))) l(opt(seq("with", list1(constr)))) := Std.simple_congruence n l. |
| 628 |
|
| 629 |
#[deprecated(since="9.1", note="Use Std.f_equal instead.")] |
| 630 |
Ltac2 f_equal0 := Std.f_equal. |
| 631 |
Ltac2 Abbreviation f_equal := Std.f_equal (). |
| 632 |
|
| 633 |
(** now *) |
| 634 |
|
| 635 |
Ltac2 now0 t := t (); ltac1:(easy_forward_decl). |
| 636 |
Ltac2 Notation "now" t(thunk(tactic(6))) := now0 t. |
| 637 |
|
| 638 |
(** profiling *) |
| 639 |
|
| 640 |
Ltac2 start_profiling () := ltac1:(start ltac profiling). |
| 641 |
Ltac2 stop_profiling () := ltac1:(stop ltac profiling). |
| 642 |
Ltac2 show_profile () := ltac1:(show ltac profile). |