| 1 |
(* Checks syntax of Hints commands *) |
| 2 |
(* Old-style syntax *) |
| 3 |
#[export] Hint Resolve eq_refl eq_sym. |
| 4 |
#[export] Hint Resolve eq_refl eq_sym: foo. |
| 5 |
#[export] Hint Immediate eq_refl eq_sym. |
| 6 |
#[export] Hint Immediate eq_refl eq_sym: foo. |
| 7 |
#[export] Hint Unfold fst eq_sym. |
| 8 |
#[export] Hint Unfold fst eq_sym: foo. |
| 9 |
|
| 10 |
(* Checks that qualified names are accepted *) |
| 11 |
|
| 12 |
(* New-style syntax *) |
| 13 |
#[export] Hint Resolve eq_refl: core arith. |
| 14 |
#[export] Hint Immediate eq_trans. |
| 15 |
#[export] Hint Unfold eq_sym: core. |
| 16 |
#[export] Hint Constructors eq: foo bar. |
| 17 |
#[export] Hint Extern 3 (_ = _) => apply eq_refl: foo bar. |
| 18 |
|
| 19 |
(* Extended new syntax with patterns *) |
| 20 |
#[export] Hint Resolve eq_refl | 4 (_ = _) : baz. |
| 21 |
#[export] Hint Resolve eq_sym eq_trans : baz. |
| 22 |
#[export] Hint Extern 3 (_ = _) => apply eq_sym : baz. |
| 23 |
|
| 24 |
Parameter pred : nat -> Prop. |
| 25 |
Parameter pred0 : pred 0. |
| 26 |
Parameter f : nat -> nat. |
| 27 |
Parameter predf : forall n, pred n -> pred (f n). |
| 28 |
|
| 29 |
(* No conversion on let-bound variables and constants in pred (the default) *) |
| 30 |
#[export] Hint Resolve pred0 | 1 (pred _) : pred. |
| 31 |
#[export] Hint Resolve predf | 0 : pred. |
| 32 |
|
| 33 |
(* Allow full conversion on let-bound variables and constants *) |
| 34 |
Create HintDb predconv discriminated. |
| 35 |
#[export] Hint Resolve pred0 | 1 (pred _) : predconv. |
| 36 |
#[export] Hint Resolve predf | 0 : predconv. |
| 37 |
|
| 38 |
Parameter predconv : forall n, pred n -> pred (0 + S n). |
| 39 |
|
| 40 |
(* The inferred pattern contains 0 + ?n, syntactic match will fail to see convertible |
| 41 |
terms *) |
| 42 |
#[export] Hint Resolve pred0 : pred2. |
| 43 |
#[export] Hint Resolve predconv : pred2. |
| 44 |
|
| 45 |
(** In this database we allow predconv to apply to pred (S _) goals, more generally |
| 46 |
than the inferred pattern (pred (0 + S _)). *) |
| 47 |
Create HintDb pred2conv discriminated. |
| 48 |
#[export] Hint Resolve pred0 : pred2conv. |
| 49 |
#[export] Hint Resolve predconv | 1 (pred (S _)) : pred2conv. |
| 50 |
|
| 51 |
Goal pred 3. |
| 52 |
Fail typeclasses eauto with pred2. |
| 53 |
typeclasses eauto with pred2conv. |
| 54 |
Abort. |
| 55 |
|
| 56 |
Set Typeclasses Debug Verbosity 2. |
| 57 |
#[export] Hint Resolve predconv | 1 (pred _) : pred. |
| 58 |
#[export] Hint Resolve predconv | 1 (pred (S _)) : predconv. |
| 59 |
Test Typeclasses Limit Intros. |
| 60 |
Goal pred 3. |
| 61 |
(* predf is not tried as it doesn't match the goal *) |
| 62 |
(* predconv is tried but fails as the transparent state doesn't allow |
| 63 |
unfolding + *) |
| 64 |
Fail typeclasses eauto with pred. |
| 65 |
(* Here predconv succeeds as it matches (pred (S _)) and then |
| 66 |
full unification is allowed *) |
| 67 |
typeclasses eauto with predconv. |
| 68 |
Qed. |
| 69 |
|
| 70 |
(* Checks that local names are accepted *) |
| 71 |
Section A. |
| 72 |
Remark Refl : forall (A : Set) (x : A), x = x. |
| 73 |
Proof. exact @eq_refl. Defined. |
| 74 |
Definition Sym := eq_sym. |
| 75 |
Let Trans := eq_trans. |
| 76 |
|
| 77 |
Hint Resolve Refl: foo. |
| 78 |
Hint Resolve Sym: bar. |
| 79 |
Hint Resolve Trans: foo2. |
| 80 |
|
| 81 |
Hint Immediate Refl. |
| 82 |
Hint Immediate Sym. |
| 83 |
Hint Immediate Trans. |
| 84 |
|
| 85 |
Hint Unfold Refl. |
| 86 |
Hint Unfold Sym. |
| 87 |
Hint Unfold Trans. |
| 88 |
|
| 89 |
Hint Resolve Sym Trans Refl. |
| 90 |
Hint Immediate Sym Trans Refl. |
| 91 |
Hint Unfold Sym Trans Refl. |
| 92 |
|
| 93 |
End A. |
| 94 |
|
| 95 |
Axiom a : forall n, n=0 <-> n<=0. |
| 96 |
|
| 97 |
#[export] Hint Resolve -> a. |
| 98 |
Goal forall n, n=0 -> n<=0. |
| 99 |
auto. |
| 100 |
Qed. |
| 101 |
|
| 102 |
|
| 103 |
(* This example comes from Chlipala's ltamer *) |
| 104 |
(* It used to fail from r12902 to r13112 since type_of started to call *) |
| 105 |
(* e_cumul (instead of conv_leq) which was not able to unify "?id" and *) |
| 106 |
(* "(fun x => x) ?id" *) |
| 107 |
|
| 108 |
Notation "e :? pf" := (eq_rect _ (fun X : Set => X) e _ pf) |
| 109 |
(no associativity, at level 90). |
| 110 |
|
| 111 |
Axiom cast_coalesce : |
| 112 |
forall (T1 T2 T3 : Set) (e : T1) (pf1 : T1 = T2) (pf2 : T2 = T3), |
| 113 |
((e :? pf1) :? pf2) = (e :? trans_eq pf1 pf2). |
| 114 |
|
| 115 |
#[export] Hint Rewrite cast_coalesce : ltamer. |
| 116 |
|
| 117 |
Definition id := fun {A : Type} (x : A) => x. |
| 118 |
|
| 119 |
Definition compose := |
| 120 |
fun {A B C : Type} (g : B -> C) (f : A -> B) (x : A) => g (f x). |
| 121 |
|
| 122 |
Notation "g ∘ f " := (compose g f) (at level 10). |
| 123 |
|
| 124 |
Module HintCut. |
| 125 |
Class A (f : nat -> nat) := a : True. |
| 126 |
Class B (f : nat -> nat) := b : True. |
| 127 |
Class C (f : nat -> nat) := c : True. |
| 128 |
Class D (f : nat -> nat) := d : True. |
| 129 |
Class E (f : nat -> nat) := e : True. |
| 130 |
|
| 131 |
#[export] Instance a_is_b f : A f -> B f. |
| 132 |
Proof. easy. Qed. |
| 133 |
#[export] Instance b_is_c f : B f -> C f. |
| 134 |
Proof. easy. Qed. |
| 135 |
#[export] Instance c_is_d f : C f -> D f. |
| 136 |
Proof. easy. Qed. |
| 137 |
#[export] Instance d_is_e f : D f -> E f. |
| 138 |
Proof. easy. Qed. |
| 139 |
|
| 140 |
#[export] Instance a_compose f g : A f -> A g -> A (compose f g). |
| 141 |
Proof. easy. Qed. |
| 142 |
#[export] Instance b_compose f g : B f -> B g -> B (compose f g). |
| 143 |
Proof. easy. Qed. |
| 144 |
#[export] Instance c_compose f g : C f -> C g -> C (compose f g). |
| 145 |
Proof. easy. Qed. |
| 146 |
#[export] Instance d_compose f g : D f -> D g -> D (compose f g). |
| 147 |
Proof. easy. Qed. |
| 148 |
#[export] Instance e_compose f g : E f -> E g -> E (compose f g). |
| 149 |
Proof. easy. Qed. |
| 150 |
|
| 151 |
#[export] Instance a_id : A id. |
| 152 |
Proof. easy. Qed. |
| 153 |
|
| 154 |
#[export] Instance foo f : |
| 155 |
E (id ∘ id ∘ id ∘ id ∘ id ∘ id ∘ id ∘ id ∘ id ∘ id ∘ id ∘ id ∘ id ∘ id ∘ id ∘ |
| 156 |
id ∘ id ∘ id ∘ id ∘ id ∘ f ∘ id ∘ id ∘ id ∘ id ∘ id ∘ id ∘ id). |
| 157 |
Proof. |
| 158 |
#[export] Hint Cut [_* (a_is_b | b_is_c | c_is_d | d_is_e) |
| 159 |
(a_compose | b_compose | c_compose | d_compose | e_compose)] : typeclass_instances. |
| 160 |
|
| 161 |
Timeout 1 Fail apply _. (* 0.06s *) |
| 162 |
Abort. |
| 163 |
End HintCut. |
| 164 |
|
| 165 |
|
| 166 |
(* Check that auto-like tactics do not prefer "eq_refl" over more complex solutions, *) |
| 167 |
(* e.g. those tactics when considering a goal with existential variables *) |
| 168 |
(* like "m = ?n" won't pick "plus_n_O" hint over "eq_refl" hint. *) |
| 169 |
(* See this Coq club post for more detail: *) |
| 170 |
(* https://sympa.inria.fr/sympa/arc/coq-club/2017-12/msg00103.html *) |
| 171 |
|
| 172 |
Goal forall (m : nat), exists n, m = n /\ m = n. |
| 173 |
intros m; eexists; split; [trivial | reflexivity]. |
| 174 |
Qed. |
| 175 |
|
| 176 |
Section HintTransparent. |
| 177 |
|
| 178 |
Definition fn (x : nat) := S x. |
| 179 |
|
| 180 |
Create HintDb trans. |
| 181 |
|
| 182 |
Hint Resolve eq_refl | (_ = _) : trans. |
| 183 |
|
| 184 |
(* No reduction *) |
| 185 |
Hint Variables Opaque : trans. Hint Constants Opaque : trans. |
| 186 |
|
| 187 |
Goal forall x : nat, fn x = S x. |
| 188 |
Proof. |
| 189 |
intros. |
| 190 |
Fail typeclasses eauto with trans. |
| 191 |
unfold fn. |
| 192 |
typeclasses eauto with trans. |
| 193 |
Qed. |
| 194 |
|
| 195 |
(** Now allow unfolding fn *) |
| 196 |
Hint Constants Transparent : trans. |
| 197 |
|
| 198 |
Goal forall x : nat, fn x = S x. |
| 199 |
Proof. |
| 200 |
intros. |
| 201 |
typeclasses eauto with trans. |
| 202 |
Qed. |
| 203 |
|
| 204 |
End HintTransparent. |
| 205 |
|
| 206 |
Module RepeatCreat. |
| 207 |
Axiom T : Type. |
| 208 |
Axiom v : T. |
| 209 |
|
| 210 |
Set Warnings "+mismatched-hint-db". |
| 211 |
|
| 212 |
(* if this fails it means the db already exists as a discriminated db *) |
| 213 |
Succeed Create HintDb repeated. |
| 214 |
|
| 215 |
Create HintDb repeated discriminated. |
| 216 |
|
| 217 |
Fail Definition foo : T := ltac:(eauto with foo). |
| 218 |
|
| 219 |
Hint Resolve v : foo. |
| 220 |
Definition foo : T := ltac:(eauto with foo). |
| 221 |
|
| 222 |
Create HintDb repeated discriminated. |
| 223 |
(* hint is still there *) |
| 224 |
Definition foo' : T := ltac:(eauto with foo). |
| 225 |
|
| 226 |
Fail Create HintDb repeated. |
| 227 |
|
| 228 |
(* implicit hint db *) |
| 229 |
Fail Create HintDb foo discriminated. |
| 230 |
End RepeatCreat. |