Debian Codegraph @

test-suite/success/with_strategy.v

raw
1 Notation aid := (@id) (only parsing).
2 Notation idn := id (only parsing).
3 Ltac unfold_id := unfold id.
4
5 Fixpoint fact (n : nat)
6 := match n with
7 | 0 => 1
8 | S n => (S n) * fact n
9 end.
10
11 Opaque id.
12 Goal id 0 = 0.
13 with_strategy
14 opaque [id]
15 (with_strategy
16 opaque [id id]
17 (assert_fails unfold_id;
18 with_strategy
19 transparent [id]
20 (assert_succeeds unfold_id;
21 with_strategy
22 opaque [id]
23 (with_strategy
24 0 [id]
25 (assert_succeeds unfold_id;
26 with_strategy
27 1 [id]
28 (assert_succeeds unfold_id;
29 with_strategy
30 -1 [id]
31 (assert_succeeds unfold_id;
32 with_strategy
33 opaque [id]
34 (assert_fails unfold_id;
35 with_strategy
36 transparent [id]
37 (assert_succeeds unfold_id;
38 with_strategy
39 opaque [id]
40 (with_strategy
41 expand [id]
42 (assert_succeeds unfold_id;
43 let l := strategy_level:(expand) in
44 with_strategy
45 l [id]
46 (let idx := smart_global:(id) in
47 cbv [idx];
48 (* This should succeed, but doesn't, basically due to https://github.com/rocq-prover/rocq/issues/11202 *)
49 assert_fails
50 (let idx := smart_global:(id) in
51 with_strategy
52 expand [idx]
53 idtac);
54 reflexivity)))))))))))).
55 Qed.
56 Goal id 0 = 0.
57 with_strategy
58 opaque [aid]
59 (assert_fails unfold_id;
60 with_strategy
61 transparent [aid]
62 (assert_succeeds unfold_id;
63 with_strategy
64 opaque [aid]
65 (with_strategy
66 0 [aid]
67 (assert_succeeds unfold_id;
68 with_strategy
69 1 [aid]
70 (assert_succeeds unfold_id;
71 with_strategy
72 -1 [aid]
73 (assert_succeeds unfold_id;
74 with_strategy
75 opaque [aid]
76 (assert_fails unfold_id;
77 with_strategy
78 transparent [aid]
79 (assert_succeeds unfold_id;
80 with_strategy
81 opaque [aid]
82 (with_strategy
83 expand [aid]
84 (assert_succeeds unfold_id;
85 reflexivity)))))))))).
86 Qed.
87 Goal id 0 = 0.
88 with_strategy
89 opaque [idn]
90 (assert_fails unfold_id;
91 with_strategy
92 transparent [idn]
93 (assert_succeeds unfold_id;
94 with_strategy
95 opaque [idn]
96 (with_strategy
97 0 [idn]
98 (assert_succeeds unfold_id;
99 with_strategy
100 1 [idn]
101 (assert_succeeds unfold_id;
102 with_strategy
103 -1 [idn]
104 (assert_succeeds unfold_id;
105 with_strategy
106 opaque [idn]
107 (assert_fails unfold_id;
108 with_strategy
109 transparent [idn]
110 (assert_succeeds unfold_id;
111 with_strategy
112 opaque [idn]
113 (with_strategy
114 expand [idn]
115 (assert_succeeds unfold_id;
116 reflexivity)))))))))).
117 Qed.
118
119 (* test that strategy tactic does not persist after the execution of the tactic *)
120 Opaque id.
121 Goal id 0 = 0.
122 assert_fails unfold_id;
123 (with_strategy transparent [id] assert_succeeds unfold_id);
124 assert_fails unfold_id.
125 assert_fails unfold_id.
126 with_strategy transparent [id] assert_succeeds unfold_id.
127 assert_fails unfold_id.
128 reflexivity.
129 Qed.
130
131 (* test that the strategy tactic does persist through abstract *)
132 Opaque id.
133 Goal id 0 = 0.
134 Time Timeout 5
135 with_strategy
136 expand [id]
137 assert (id (fact 100) = fact 100) by abstract reflexivity.
138 reflexivity.
139 Time Timeout 5 Defined.
140
141 (* test that it works even with [Qed] *)
142 Goal id 0 = 0.
143 Proof using Type.
144 Time Timeout 5
145 abstract
146 (with_strategy
147 expand [id]
148 assert (id (fact 100) = fact 100) by abstract reflexivity;
149 reflexivity).
150 Time Timeout 5 Qed.
151
152 (* test that the strategy is correctly reverted after closing the goal completely *)
153 Goal id 0 = 0.
154 assert (id 0 = 0) by with_strategy expand [id] reflexivity.
155 Fail unfold id.
156 reflexivity.
157 Qed.
158
159 (* test that the strategy is correctly reverted after failure *)
160 Goal id 0 = 0.
161 let id' := id in
162 (try with_strategy expand [id] fail); assert_fails unfold id'.
163 Fail unfold id.
164 (* a more complicated test involving a success and then a failure after backtracking *)
165 let id' := id in
166 ((with_strategy expand [id] (unfold id' + fail)) + idtac);
167 lazymatch goal with |- id 0 = 0 => idtac end;
168 assert_fails unfold id'.
169 Fail unfold id.
170 reflexivity.
171 Qed.
172
173 (* test multi-success *)
174 Goal id (fact 100) = fact 100.
175 Timeout 1
176 (with_strategy -1 [id] (((idtac + (abstract reflexivity))); fail)).
177 Undo.
178 Timeout 1
179 let id' := id in
180 (with_strategy -1 [id] (((idtac + (unfold id'; reflexivity))); fail)).
181 Undo.
182 Timeout 1
183 (with_strategy -1 [id] (idtac + (abstract reflexivity))); fail. (* should not time out *)
184 Undo.
185 with_strategy -1 [id] abstract reflexivity.
186 Defined.
187
188 (* check that module substitutions happen correctly *)
189 Module F.
190 Definition id {T} := @id T.
191 Opaque id.
192 Ltac with_transparent_id tac := with_strategy transparent [id] tac.
193 End F.
194 Opaque F.id.
195
196 Goal F.id 0 = F.id 0.
197 Fail unfold F.id.
198 F.with_transparent_id ltac:(progress unfold F.id).
199 Undo.
200 F.with_transparent_id ltac:(let x := constr:(@F.id) in progress unfold x).
201 Abort.
202
203 Module Type Empty. End Empty.
204 Module E. End E.
205 Module F2F (E : Empty).
206 Definition id {T} := @id T.
207 Opaque id.
208 Ltac with_transparent_id tac := with_strategy transparent [id] tac.
209 End F2F.
210 Module F2 := F2F E.
211 Opaque F2.id.
212
213 Goal F2.id 0 = F2.id 0.
214 Fail unfold F2.id.
215 F2.with_transparent_id ltac:(progress unfold F2.id).
216 Undo.
217 F2.with_transparent_id ltac:(let x := constr:(@F2.id) in progress unfold x).
218 Abort.
219
220 (* test the tactic notation entries *)
221 Tactic Notation "with_strategy0" strategy_level(l) "[" ne_smart_global_list(v) "]" tactic3(tac) := with_strategy l [ v ] tac.
222 Tactic Notation "with_strategy1" strategy_level_or_var(l) "[" ne_smart_global_list(v) "]" tactic3(tac) := with_strategy l [ v ] tac.
223 Tactic Notation "with_strategy2" strategy_level(l) "[" constr(v) "]" tactic3(tac) := with_strategy l [ v ] tac.
224 Tactic Notation "with_strategy3" strategy_level_or_var(l) "[" constr(v) "]" tactic3(tac) := with_strategy l [ v ] tac.
225
226 (* [with_strategy0] should work, but it doesn't, due to a combination of https://github.com/rocq-prover/rocq/issues/11202 and https://github.com/rocq-prover/rocq/issues/11209 *)
227 Opaque id.
228 Goal id 0 = 0.
229 Fail (* should work, not Fail *) with_strategy0 opaque [id] idtac.
230 Fail (* should work, not Fail *) with_strategy0 opaque [id id] idtac.
231 assert_fails unfold_id.
232 Fail (* should work, not Fail *) with_strategy0 transparent [id] idtac.
233 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
234 Fail (* should work, not Fail *) with_strategy0 opaque [id] idtac.
235 Fail (* should work, not Fail *) with_strategy0 0 [id] idtac.
236 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
237 Fail (* should work, not Fail *) with_strategy0 1 [id] idtac.
238 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
239 Fail (* should work, not Fail *) with_strategy0 -1 [id] idtac.
240 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
241 Fail (* should work, not Fail *) with_strategy0 opaque [id] idtac.
242 assert_fails unfold_id.
243 Fail (* should work, not Fail *) with_strategy0 transparent [id] idtac.
244 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
245 Fail (* should work, not Fail *) with_strategy0 opaque [id] idtac.
246 Fail (* should work, not Fail *) with_strategy0 expand [id] idtac.
247 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
248 (* This should succeed, but doesn't, basically due to https://github.com/rocq-prover/rocq/issues/11202 *)
249 Fail let idx := smart_global:(id) in
250 with_strategy0 expand [idx] idtac.
251 reflexivity.
252 Qed.
253 Goal id 0 = 0.
254 Fail (* should work, not Fail *) with_strategy0 opaque [aid] idtac.
255 assert_fails unfold_id.
256 Fail (* should work, not Fail *) with_strategy0 transparent [aid] idtac.
257 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
258 Fail (* should work, not Fail *) with_strategy0 opaque [aid] idtac.
259 Fail (* should work, not Fail *) with_strategy0 0 [aid] idtac.
260 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
261 Fail (* should work, not Fail *) with_strategy0 1 [aid] idtac.
262 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
263 Fail (* should work, not Fail *) with_strategy0 -1 [aid] idtac.
264 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
265 Fail (* should work, not Fail *) with_strategy0 opaque [aid] idtac.
266 assert_fails unfold_id.
267 Fail (* should work, not Fail *) with_strategy0 transparent [aid] idtac.
268 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
269 Fail (* should work, not Fail *) with_strategy0 opaque [aid] idtac.
270 Fail (* should work, not Fail *) with_strategy0 expand [aid] idtac.
271 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
272 reflexivity.
273 Qed.
274 Goal id 0 = 0.
275 Fail (* should work, not Fail *) with_strategy0 opaque [idn] idtac.
276 assert_fails unfold_id.
277 Fail (* should work, not Fail *) with_strategy0 transparent [idn] idtac.
278 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
279 Fail (* should work, not Fail *) with_strategy0 opaque [idn] idtac.
280 Fail (* should work, not Fail *) with_strategy0 0 [idn] idtac.
281 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
282 Fail (* should work, not Fail *) with_strategy0 1 [idn] idtac.
283 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
284 Fail (* should work, not Fail *) with_strategy0 -1 [idn] idtac.
285 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
286 Fail (* should work, not Fail *) with_strategy0 opaque [idn] idtac.
287 assert_fails unfold_id.
288 Fail (* should work, not Fail *) with_strategy0 transparent [idn] idtac.
289 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
290 Fail (* should work, not Fail *) with_strategy0 opaque [idn] idtac.
291 Fail (* should work, not Fail *) with_strategy0 expand [idn] idtac.
292 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
293 reflexivity.
294 Qed.
295
296 (* [with_strategy1] should work, but it doesn't, due to a combination of https://github.com/rocq-prover/rocq/issues/11202 and https://github.com/rocq-prover/rocq/issues/11209 *)
297 Opaque id.
298 Goal id 0 = 0.
299 Fail (* should work, not Fail *) with_strategy1 opaque [id] idtac.
300 Fail (* should work, not Fail *) with_strategy1 opaque [id id] idtac.
301 assert_fails unfold_id.
302 Fail (* should work, not Fail *) with_strategy1 transparent [id] idtac.
303 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
304 Fail (* should work, not Fail *) with_strategy1 opaque [id] idtac.
305 Fail (* should work, not Fail *) with_strategy1 0 [id] idtac.
306 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
307 Fail (* should work, not Fail *) with_strategy1 1 [id] idtac.
308 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
309 Fail (* should work, not Fail *) with_strategy1 -1 [id] idtac.
310 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
311 Fail (* should work, not Fail *) with_strategy1 opaque [id] idtac.
312 assert_fails unfold_id.
313 Fail (* should work, not Fail *) with_strategy1 transparent [id] idtac.
314 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
315 Fail (* should work, not Fail *) with_strategy1 opaque [id] idtac.
316 Fail (* should work, not Fail *) with_strategy1 expand [id] idtac.
317 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
318 Fail (* should work, not Fail *) let l := strategy_level:(expand) in
319 with_strategy1 l [id] idtac.
320 (* This should succeed, but doesn't, basically due to https://github idtac.com/coq/coq/issues/11202 *)
321 Fail let idx := smart_global:(id) in
322 with_strategy1 expand [idx] idtac.
323 reflexivity.
324 Qed.
325 Goal id 0 = 0.
326 Fail (* should work, not Fail *) with_strategy1 opaque [aid] idtac.
327 assert_fails unfold_id.
328 Fail (* should work, not Fail *) with_strategy1 transparent [aid] idtac.
329 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
330 Fail (* should work, not Fail *) with_strategy1 opaque [aid] idtac.
331 Fail (* should work, not Fail *) with_strategy1 0 [aid] idtac.
332 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
333 Fail (* should work, not Fail *) with_strategy1 1 [aid] idtac.
334 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
335 Fail (* should work, not Fail *) with_strategy1 -1 [aid] idtac.
336 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
337 Fail (* should work, not Fail *) with_strategy1 opaque [aid] idtac.
338 assert_fails unfold_id.
339 Fail (* should work, not Fail *) with_strategy1 transparent [aid] idtac.
340 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
341 Fail (* should work, not Fail *) with_strategy1 opaque [aid] idtac.
342 Fail (* should work, not Fail *) with_strategy1 expand [aid] idtac.
343 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
344 reflexivity.
345 Qed.
346 Goal id 0 = 0.
347 Fail (* should work, not Fail *) with_strategy1 opaque [idn] idtac.
348 assert_fails unfold_id.
349 Fail (* should work, not Fail *) with_strategy1 transparent [idn] idtac.
350 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
351 Fail (* should work, not Fail *) with_strategy1 opaque [idn] idtac.
352 Fail (* should work, not Fail *) with_strategy1 0 [idn] idtac.
353 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
354 Fail (* should work, not Fail *) with_strategy1 1 [idn] idtac.
355 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
356 Fail (* should work, not Fail *) with_strategy1 -1 [idn] idtac.
357 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
358 Fail (* should work, not Fail *) with_strategy1 opaque [idn] idtac.
359 assert_fails unfold_id.
360 Fail (* should work, not Fail *) with_strategy1 transparent [idn] idtac.
361 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
362 Fail (* should work, not Fail *) with_strategy1 opaque [idn] idtac.
363 Fail (* should work, not Fail *) with_strategy1 expand [idn] idtac.
364 Fail (* should work, not Fail *) assert_succeeds unfold_id idtac.
365 reflexivity.
366 Qed.
367
368 Opaque id.
369 Goal id 0 = 0.
370 with_strategy2
371 opaque [id]
372 (with_strategy2
373 opaque [id]
374 (assert_fails unfold_id;
375 with_strategy2
376 transparent [id]
377 (assert_succeeds unfold_id;
378 with_strategy2
379 opaque [id]
380 (with_strategy2
381 0 [id]
382 (assert_succeeds unfold_id;
383 with_strategy2
384 1 [id]
385 (assert_succeeds unfold_id;
386 with_strategy2
387 -1 [id]
388 (assert_succeeds unfold_id;
389 with_strategy2
390 opaque [id]
391 (assert_fails unfold_id;
392 with_strategy2
393 transparent [id]
394 (assert_succeeds unfold_id;
395 with_strategy2
396 opaque [id]
397 (with_strategy2
398 expand [id]
399 (assert_succeeds unfold_id))))))))))).
400 (* This should succeed, but doesn't, basically due to https://github.com/rocq-prover/rocq/issues/11202 *)
401 Fail let idx := smart_global:(id) in
402 with_strategy2 expand [idx] idtac.
403 reflexivity.
404 Qed.
405 Goal id 0 = 0.
406 with_strategy2
407 opaque [aid]
408 (with_strategy2
409 opaque [aid]
410 (assert_fails unfold_id;
411 with_strategy2
412 transparent [aid]
413 (assert_succeeds unfold_id;
414 with_strategy2
415 opaque [aid]
416 (with_strategy2
417 0 [aid]
418 (assert_succeeds unfold_id;
419 with_strategy2
420 1 [aid]
421 (assert_succeeds unfold_id;
422 with_strategy2
423 -1 [aid]
424 (assert_succeeds unfold_id;
425 with_strategy2
426 opaque [aid]
427 (assert_fails unfold_id;
428 with_strategy2
429 transparent [aid]
430 (assert_succeeds unfold_id;
431 with_strategy2
432 opaque [aid]
433 (with_strategy2
434 expand [aid]
435 (assert_succeeds unfold_id))))))))))).
436 reflexivity.
437 Qed.
438 Goal id 0 = 0.
439 with_strategy2
440 opaque [idn]
441 (with_strategy2
442 opaque [idn]
443 (assert_fails unfold_id;
444 with_strategy2
445 transparent [idn]
446 (assert_succeeds unfold_id;
447 with_strategy2
448 opaque [idn]
449 (with_strategy2
450 0 [idn]
451 (assert_succeeds unfold_id;
452 with_strategy2
453 1 [idn]
454 (assert_succeeds unfold_id;
455 with_strategy2
456 -1 [idn]
457 (assert_succeeds unfold_id;
458 with_strategy2
459 opaque [idn]
460 (assert_fails unfold_id;
461 with_strategy2
462 transparent [idn]
463 (assert_succeeds unfold_id;
464 with_strategy2
465 opaque [idn]
466 (with_strategy2
467 expand [idn]
468 (assert_succeeds unfold_id))))))))))).
469 reflexivity.
470 Qed.
471
472 Opaque id.
473 Goal id 0 = 0.
474 with_strategy3
475 opaque [id]
476 (with_strategy3
477 opaque [id]
478 (assert_fails unfold_id;
479 with_strategy3
480 transparent [id]
481 (assert_succeeds unfold_id;
482 with_strategy3
483 opaque [id]
484 (with_strategy3
485 0 [id]
486 (assert_succeeds unfold_id;
487 with_strategy3
488 1 [id]
489 (assert_succeeds unfold_id;
490 with_strategy3
491 -1 [id]
492 (assert_succeeds unfold_id;
493 with_strategy3
494 opaque [id]
495 (assert_fails unfold_id;
496 with_strategy3
497 transparent [id]
498 (assert_succeeds unfold_id;
499 with_strategy3
500 opaque [id]
501 (with_strategy3
502 expand [id]
503 (assert_succeeds unfold_id))))))))))).
504 (* This should succeed, but doesn't, basically due to https://github.com/rocq-prover/rocq/issues/11202 *)
505 Fail let idx := smart_global:(id) in
506 with_strategy3 expand [idx] idtac.
507 reflexivity.
508 Qed.
509 Goal id 0 = 0.
510 with_strategy3
511 opaque [aid]
512 (with_strategy3
513 opaque [aid]
514 (assert_fails unfold_id;
515 with_strategy3
516 transparent [aid]
517 (assert_succeeds unfold_id;
518 with_strategy3
519 opaque [aid]
520 (with_strategy3
521 0 [aid]
522 (assert_succeeds unfold_id;
523 with_strategy3
524 1 [aid]
525 (assert_succeeds unfold_id;
526 with_strategy3
527 -1 [aid]
528 (assert_succeeds unfold_id;
529 with_strategy3
530 opaque [aid]
531 (assert_fails unfold_id;
532 with_strategy3
533 transparent [aid]
534 (assert_succeeds unfold_id;
535 with_strategy3
536 opaque [aid]
537 (with_strategy3
538 expand [aid]
539 (assert_succeeds unfold_id))))))))))).
540 reflexivity.
541 Qed.
542 Goal id 0 = 0.
543 with_strategy3
544 opaque [idn]
545 (with_strategy3
546 opaque [idn]
547 (assert_fails unfold_id;
548 with_strategy3
549 transparent [idn]
550 (assert_succeeds unfold_id;
551 with_strategy3
552 opaque [idn]
553 (with_strategy3
554 0 [idn]
555 (assert_succeeds unfold_id;
556 with_strategy3
557 1 [idn]
558 (assert_succeeds unfold_id;
559 with_strategy3
560 -1 [idn]
561 (assert_succeeds unfold_id;
562 with_strategy3
563 opaque [idn]
564 (assert_fails unfold_id;
565 with_strategy3
566 transparent [idn]
567 (assert_succeeds unfold_id;
568 with_strategy3
569 opaque [idn]
570 (with_strategy3
571 expand [idn]
572 (assert_succeeds unfold_id))))))))))).
573 reflexivity.
574 Qed.
575
576 (* Fake out coqchk to work around what is essentially COQBUG(https://github.com/rocq-prover/rocq/issues/12200) *)
577 Reset Initial.