Debian Codegraph @

src/Util/Tactics/InHypUnderBindersDo.v

raw
1 Require Import Crypto.Util.Tactics.SpecializeBy.
2 Require Import Crypto.Util.Tactics.GeneralizeOverHoles.
3 Require Import Crypto.Util.Tactics.UniquePose.
4
5 Ltac guarded_in_hyp_term_under_binders_do' guard_tac H tac :=
6 let is_transparent := match goal with
7 | _ => let __ := (eval cbv delta [H] in H) in
8 constr:(true)
9 | _ => constr:(false)
10 end in
11 let __ := lazymatch goal with _ => guard_tac H end in
12 match goal with
13 | _ => let __ := lazymatch goal with _ => progress tac H end in
14 H
15 | _ => let __ := lazymatch is_transparent with
16 | true => let H' := fresh in
17 rename H into H';
18 let v := open_constr:(_) in
19 pose (H' v) as H;
20 subst H'
21 | false
22 => (* kludge for old Coq *)
23 (*let v := open_constr:(_) in*)
24 let t := open_constr:(_) in
25 let v := fresh in
26 evar (v : t);
27 specialize (H v);
28 subst v
29 end in
30 guarded_in_hyp_term_under_binders_do' guard_tac H tac
31 end.
32
33 Ltac guarded_in_hyp_term_under_binders_do guard_tac H tac :=
34 generalize_over_holes ltac:(fun _ => guarded_in_hyp_term_under_binders_do' guard_tac H tac).
35
36 Ltac guarded_in_hyp_gen_hyp_under_binders_do all_ways guard_tac H tac :=
37 idtac;
38 let is_transparent := match goal with
39 | _ => let __ := (eval cbv delta [H] in H) in
40 constr:(true)
41 | _ => constr:(false)
42 end in
43 lazymatch constr:((all_ways, is_transparent)) with
44 | (false, true)
45 => let H' := fresh in
46 rename H into H';
47 let H'' := guarded_in_hyp_term_under_binders_do guard_tac H' tac in
48 pose H'' as H;
49 subst H'
50 | (true, true)
51 => let H := guarded_in_hyp_term_under_binders_do guard_tac H tac in
52 unique pose H
53 | (false, false)
54 => let H' := fresh in
55 rename H into H';
56 let H'' := guarded_in_hyp_term_under_binders_do guard_tac H' tac in
57 pose proof H'' as H;
58 clear H'
59 | (true, false)
60 => let H := guarded_in_hyp_term_under_binders_do guard_tac H tac in
61 unique pose proof H
62 end.
63
64 Ltac guarded_in_hyp_hyp_under_binders_do guard_tac H tac :=
65 guarded_in_hyp_gen_hyp_under_binders_do false guard_tac H tac.
66 Ltac guarded_in_hyp_hyp_all_ways_under_binders_do guard_tac H tac :=
67 guarded_in_hyp_gen_hyp_under_binders_do true guard_tac H tac.
68
69 Ltac guard_noop H := idtac.
70
71 Ltac guarded_in_hyp_gen_under_binders_do' all_ways tac guard_tac :=
72 idtac;
73 match goal with
74 | [ H : _ |- _ ]
75 => guard_tac H;
76 guarded_in_hyp_gen_hyp_under_binders_do all_ways guard_noop H tac
77 end.
78
79 Ltac guarded_in_hyp_under_binders_do' tac guard_tac :=
80 guarded_in_hyp_gen_under_binders_do' false tac guard_tac.
81
82 Ltac in_hyp_gen_under_binders_do' all_ways tac := guarded_in_hyp_gen_under_binders_do' all_ways tac ltac:(fun _ => idtac).
83
84 Ltac in_hyp_under_binders_do' tac := in_hyp_gen_under_binders_do' false tac.
85
86 Ltac guarded_in_hyp_gen_under_binders_do all_ways tac guard_tac := repeat guarded_in_hyp_gen_under_binders_do' all_ways tac guard_tac.
87
88 Ltac guarded_in_hyp_under_binders_do tac guard_tac := guarded_in_hyp_gen_under_binders_do false tac guard_tac.
89
90 Ltac guarded_in_hyp_all_ways_under_binders_do tac guard_tac := guarded_in_hyp_gen_under_binders_do true tac guard_tac.
91
92 Ltac in_hyp_gen_under_binders_do all_ways tac := repeat in_hyp_gen_under_binders_do' all_ways tac.
93
94 Ltac in_hyp_under_binders_do tac := in_hyp_gen_under_binders_do false tac.
95
96 Ltac in_hyp_all_ways_under_binders_do tac := in_hyp_gen_under_binders_do true tac.
97
98 (** [in_hyp_under_binders_do auto] should not mean [in_hyp_under_binders_do ( auto
99 with * )]!!!!!!! (see
100 https://coq.inria.fr/bugs/show_bug.cgi?id=4966) We fix this design
101 flaw. *)
102 Tactic Notation "in_hyp_under_binders_do" tactic3(tac) := in_hyp_under_binders_do tac.
103
104 Tactic Notation "in_hyp_all_ways_under_binders_do" tactic3(tac) := in_hyp_all_ways_under_binders_do tac.