| 1 |
From elpi Require Export elpi. |
| 2 |
|
| 3 |
Elpi Tactic clear. |
| 4 |
Elpi Accumulate lp:{{ |
| 5 |
pred not-hyp i:term, i:prop, o:term. |
| 6 |
not-hyp X (decl Y _ Ty) Y :- not (occurs X Ty), not (X = Y). |
| 7 |
not-hyp X (def Y _ Ty Bo) Y :- not (occurs X Ty ; occurs X Bo), not (X = Y). |
| 8 |
|
| 9 |
solve (goal Ctx R T E [trm X]) [seal (goal Ctx R T E [])] :- name X, !, std.do! [ |
| 10 |
std.map-filter Ctx (not-hyp X) VisibleRev, |
| 11 |
prune E1 {std.rev VisibleRev}, % preserve the order |
| 12 |
std.assert-ok! (coq.typecheck E1 T) "cannot clear", |
| 13 |
E = E1 |
| 14 |
]. |
| 15 |
solve (goal _ _ _ _ Args) _ :- coq.error "clear expects 1 name, you passed:" Args. |
| 16 |
}}. |
| 17 |
|
| 18 |
Tactic Notation "eltac.clear" hyp(V) := elpi clear ltac_term:(V). |
| 19 |
|
| 20 |
Elpi Tactic clearbody. |
| 21 |
Elpi Accumulate lp:{{ |
| 22 |
pred drop-body i:list argument, i:prop, o:prop. |
| 23 |
drop-body ToBeCleared (def V Name Ty _Bo) (decl V Name Ty) :- std.mem ToBeCleared (trm V), !. |
| 24 |
drop-body _ (decl _ _ _ as X) X. |
| 25 |
drop-body _ (def _ _ _ _ as X) X. |
| 26 |
|
| 27 |
msolve [nabla G] [nabla G1] :- pi x\ msolve [G x] [G1 x]. |
| 28 |
msolve [seal (goal Ctx _ T E ToBeCleared)] [seal (goal Ctx1 _ T E1 [])] :- |
| 29 |
std.map Ctx (drop-body ToBeCleared) Ctx1, |
| 30 |
(@ltacfail! 0 ==> % this failure can be catch by ltac |
| 31 |
Ctx1 ==> % in the new context, do... |
| 32 |
std.assert-ok! (coq.typecheck-ty T _) "cannot clear since the goal does not typecheck in the new context"), |
| 33 |
(Ctx1 ==> std.assert-ok! (coq.typecheck E1 T) "should not happen"), % E1 see all the proof variables (the pi x in the nabla case) and T is OK in Ctx1 |
| 34 |
E = {{ lp:E1 : lp:T }}. % we make progress by saying that the old goal/evar is solved by the new one (which has the same type thanks to the line above) |
| 35 |
% note that E = E1 would be "unstable" since elpi could decide to |
| 36 |
% actually do E1 := E, while E = (let `x` T E1 x\x) forces elpi |
| 37 |
% to go the other way around |
| 38 |
}}. |
| 39 |
|
| 40 |
Tactic Notation "eltac.clearbody" hyp_list(V) := elpi clearbody ltac_term_list:(V). |