Debian Codegraph @

src/Util/Tactics/SpecializeBy.v

raw
1 Require Export Crypto.Util.FixCoqMistakes.
2
3 Ltac transparent_specialize_one H arg :=
4 first [ let test := eval unfold H in H in idtac;
5 let H' := fresh in rename H into H'; pose (H' arg) as H; subst H'
6 | specialize (H arg) ].
7
8 (** try to specialize all non-dependent hypotheses using [tac], maintaining transparency *)
9 Ltac guarded_specialize_by' tac guard_tac :=
10 idtac;
11 match goal with
12 | [ H : ?A -> ?B |- _ ]
13 => guard_tac H;
14 let H' := fresh in
15 assert (H' : A) by tac;
16 transparent_specialize_one H H';
17 try clear H' (* if [H] was transparent, [H'] will remain *)
18 end.
19 Ltac specialize_by' tac := guarded_specialize_by' tac ltac:(fun _ => idtac).
20
21 Ltac specialize_by tac := repeat specialize_by' tac.
22
23 (** [specialize_by auto] should not mean [specialize_by ( auto
24 with * )]!!!!!!! (see
25 https://coq.inria.fr/bugs/show_bug.cgi?id=4966) We fix this design
26 flaw. *)
27 Tactic Notation "specialize_by" tactic3(tac) := specialize_by tac.
28
29 (** A marginally faster version of [specialize_by assumption] *)
30 Ltac specialize_by_assumption :=
31 repeat match goal with
32 | [ H : ?T, H' : (?T -> ?U)%type |- _ ]
33 => lazymatch goal with
34 | [ _ : context[H'] |- _ ] => fail
35 | [ |- context[H'] ] => fail
36 | _ => specialize (H' H)
37 end
38 end.