| 1 |
(** This file tests how locality attributes affect usual vernacular commands. |
| 2 |
PLEASE, when this file fails to compute following a voluntary change in |
| 3 |
Coq's behaviour, modify accordingly the tables in [sections.rst] and |
| 4 |
[modules.rst] in [doc/sphinx/language/core]. |
| 5 |
|
| 6 |
Also look at the corresponding discussions about locality attributes in the |
| 7 |
refman (directory doc/sphinx) |
| 8 |
- For Definition, Lemma, ..., look at language/core/definitions.rst |
| 9 |
- For Axiom, Conjecture, ..., look at language/core/assumptions.rst |
| 10 |
- For abbreviations, look at user-extensions/syntax-extensions.rst |
| 11 |
- For Notations, look at user-extensions/syntax-extensions.rst |
| 12 |
- For Tactic Notations, look at user-extensions/syntax-extensions.rst |
| 13 |
- For Ltac, look at proof-engine/ltac.rst |
| 14 |
- For Canonical Structures, look at language/extensions/canonical.rst |
| 15 |
- For Hints, look at proofs/automatic-tactics/auto.rst |
| 16 |
- For Coercions, look at addendum/implicit-coercions.rst |
| 17 |
- For Ltac2, look at proof-engine/ltac2.rst |
| 18 |
- For Ltac2 Notations, look at proof-engine/ltac2.rst |
| 19 |
- For Set, look at language/core/basic.rst |
| 20 |
*) |
| 21 |
|
| 22 |
|
| 23 |
(** This structure is used to test availability or not of a |
| 24 |
[Canonical Structure]. *) |
| 25 |
Structure PointedType : Type := { Carrier :> Set; point : Carrier }. |
| 26 |
|
| 27 |
(** This HintDb is used to test availability or not of a [Hint] command. *) |
| 28 |
Create HintDb plop. |
| 29 |
|
| 30 |
(** ** Tests for sections and visibility attributes *) |
| 31 |
|
| 32 |
(** *** Without attribute (default) *) |
| 33 |
|
| 34 |
Module InSectionDefault. |
| 35 |
|
| 36 |
Section Bar. |
| 37 |
(* A parameter: *) |
| 38 |
Parameter (secret : nat). |
| 39 |
(* An axiom: *) |
| 40 |
Axiom secret_is_42 : secret = 42. |
| 41 |
(* A custom tactic: *) |
| 42 |
Ltac find_secret := rewrite secret_is_42. |
| 43 |
(* An abbreviation: *) |
| 44 |
Notation add_42 := (Nat.add 42). |
| 45 |
(* A tactic notation: *) |
| 46 |
Tactic Notation "rfl" := reflexivity. |
| 47 |
(* A notation: *) |
| 48 |
Infix "+p" := Nat.add (only parsing, at level 30, right associativity) : nat_scope. |
| 49 |
(* A lemma: *) |
| 50 |
Lemma secret_42 : secret = 42. |
| 51 |
Proof. find_secret. rfl. Qed. |
| 52 |
(* A Canonical Structure: *) |
| 53 |
Canonical natPointed : PointedType := {| Carrier := nat; point := 42 |}. |
| 54 |
(* A Coercion: *) |
| 55 |
Coercion to_nat (b : bool) := if b then 1 else 0. |
| 56 |
(* A Setting: *) |
| 57 |
Set Universe Polymorphism. |
| 58 |
(* A Hint: *) |
| 59 |
Hint Resolve secret_42 : plop. |
| 60 |
End Bar. |
| 61 |
|
| 62 |
(* Availability of the parameter *) |
| 63 |
Check secret. |
| 64 |
(* Availability of the axiom *) |
| 65 |
Check secret_is_42. |
| 66 |
(* Availability of the tactic *) |
| 67 |
Fail Print find_secret. |
| 68 |
(* Availability of the abbreviation *) |
| 69 |
Fail Check add_42. |
| 70 |
(* Availability of the tactic notation *) |
| 71 |
Lemma plop_i : 2 + 2 = 4. |
| 72 |
Proof. Fail rfl. Admitted. |
| 73 |
(* Availability of the notation *) |
| 74 |
Fail Check (2 +p 3). |
| 75 |
(* Availability of the canonical structure *) |
| 76 |
Check (point nat). |
| 77 |
(* Availability of the coercion *) |
| 78 |
Check (true + 2). |
| 79 |
(* Availability of [Set Universe Polymorphism] *) |
| 80 |
Definition foo_i@{u} := nat. |
| 81 |
Check foo_i@{_}. |
| 82 |
(* Availability of the [Hint] *) |
| 83 |
Lemma hop_i : secret = 42. |
| 84 |
Proof. |
| 85 |
Fail solve [auto with plop]. |
| 86 |
Admitted. |
| 87 |
|
| 88 |
End InSectionDefault. |
| 89 |
|
| 90 |
Module InSectionLocal. |
| 91 |
|
| 92 |
Section Bar. |
| 93 |
(* A parameter: *) |
| 94 |
#[local] |
| 95 |
Parameter (secret : nat). |
| 96 |
(* An axiom: *) |
| 97 |
#[local] |
| 98 |
Axiom secret_is_42 : secret = 42. |
| 99 |
(* A custom tactic: *) |
| 100 |
#[local] |
| 101 |
Ltac find_secret := rewrite secret_is_42. |
| 102 |
(* An abbreviation: *) |
| 103 |
#[local] |
| 104 |
Notation add_42 := (Nat.add 42). |
| 105 |
(* A tactic notation: *) |
| 106 |
#[local] |
| 107 |
Tactic Notation "rfl" := reflexivity. |
| 108 |
(* A notation: *) |
| 109 |
#[local] |
| 110 |
Infix "+p" := Nat.add (only parsing, at level 30, right associativity) : nat_scope. |
| 111 |
(* A lemma: *) |
| 112 |
#[local] |
| 113 |
Lemma secret_42 : secret = 42. |
| 114 |
Proof. find_secret. rfl. Qed. |
| 115 |
(* A Canonical Structure *) |
| 116 |
#[local] |
| 117 |
Canonical natPointed : PointedType := {| Carrier := nat; point := 42 |}. |
| 118 |
(* A Coercion *) |
| 119 |
#[local] |
| 120 |
Coercion to_nat (b : bool) := if b then 1 else 0. |
| 121 |
(* A Setting *) |
| 122 |
#[local] |
| 123 |
Set Universe Polymorphism. |
| 124 |
(* A Hint *) |
| 125 |
#[local] |
| 126 |
Hint Resolve secret_42 : plop. |
| 127 |
End Bar. |
| 128 |
|
| 129 |
(** **** Without importing: *) |
| 130 |
|
| 131 |
(* Availability of the parameter *) |
| 132 |
Check secret. |
| 133 |
(* Availability of the axiom *) |
| 134 |
Check secret_is_42. |
| 135 |
(* Availability of the tactic *) |
| 136 |
Fail Print find_secret. |
| 137 |
(* Availability of the abbreviation *) |
| 138 |
Fail Check add_42. |
| 139 |
(* Availability of the tactic notation *) |
| 140 |
Lemma plop_ni : 2 + 2 = 4. |
| 141 |
Proof. Fail rfl. Admitted. |
| 142 |
(* Availability of the notation *) |
| 143 |
Fail Check (2 +p 3). |
| 144 |
(* Availability of the canonical structure *) |
| 145 |
Fail Check (point nat). |
| 146 |
(* Availability of the coercion *) |
| 147 |
Fail Check (true + 2). |
| 148 |
(* Availability of [Set Universe Polymorphism] *) |
| 149 |
Definition foo_ni@{u} := nat. |
| 150 |
Fail Check foo_ni@{_}. |
| 151 |
(* Availability of the [Hint] *) |
| 152 |
Lemma hop_ni : secret = 42. |
| 153 |
Proof. |
| 154 |
Fail solve [auto with plop]. |
| 155 |
Admitted. |
| 156 |
End InSectionLocal. |
| 157 |
|
| 158 |
Module InSectionExport. |
| 159 |
|
| 160 |
Section Bar. |
| 161 |
(* A parameter: *) |
| 162 |
Fail #[export] |
| 163 |
Parameter (secret : nat). |
| 164 |
(* An axiom: *) |
| 165 |
Fail #[export] |
| 166 |
Axiom plop : 0 = 0. |
| 167 |
(* A custom tactic: *) |
| 168 |
Fail #[export] |
| 169 |
Ltac find_secret := reflexivity. |
| 170 |
(* An abbreviation: *) |
| 171 |
Fail #[export] |
| 172 |
Notation add_42 := (Nat.add 42). |
| 173 |
(* A tactic notation: *) |
| 174 |
Fail #[export] |
| 175 |
Tactic Notation "rfl" := reflexivity. |
| 176 |
(* A notation: *) |
| 177 |
Fail #[export] |
| 178 |
Infix "+p" := Nat.add (only parsing, at level 30, right associativity) : nat_scope. |
| 179 |
(* A lemma: *) |
| 180 |
Fail #[export] |
| 181 |
Lemma secret_42 : secret = 42. |
| 182 |
(* A Canonical Structure *) |
| 183 |
Fail #[export] |
| 184 |
Canonical natPointed : PointedType := {| Carrier := nat; point := 42 |}. |
| 185 |
(* A Coercion *) |
| 186 |
Fail#[export] |
| 187 |
Coercion to_nat (b : bool) := if b then 1 else 0. |
| 188 |
(* A Setting *) |
| 189 |
#[export] |
| 190 |
Set Universe Polymorphism. |
| 191 |
(* A Hint *) |
| 192 |
Parameter (secret : nat). |
| 193 |
Axiom secret_42 : secret = 42. |
| 194 |
Fail #[export] |
| 195 |
Hint Resolve secret_42 : plop. |
| 196 |
End Bar. |
| 197 |
|
| 198 |
(* Availability of [Set Universe Polymorphism] *) |
| 199 |
Definition foo_ni@{u} := nat. |
| 200 |
Check foo_ni@{_}. |
| 201 |
|
| 202 |
End InSectionExport. |
| 203 |
|
| 204 |
Module InSectionGlobal. |
| 205 |
Section Bar. |
| 206 |
(* A parameter: *) |
| 207 |
#[global] |
| 208 |
Parameter (secret : nat). |
| 209 |
(* An axiom: *) |
| 210 |
#[global] |
| 211 |
Axiom secret_is_42 : secret = 42. |
| 212 |
(* A custom tactic: *) |
| 213 |
Fail #[global] |
| 214 |
Ltac find_secret := rewrite secret_is_42. |
| 215 |
(* An abbreviation: *) |
| 216 |
Fail #[global] |
| 217 |
Notation add_42 := (Nat.add 42). |
| 218 |
(* A tactic notation: *) |
| 219 |
Fail #[global] |
| 220 |
Tactic Notation "rfl" := reflexivity. |
| 221 |
(* A notation: *) |
| 222 |
Fail #[global] |
| 223 |
Infix "+p" := Nat.add (only parsing, at level 30, right associativity) : nat_scope. |
| 224 |
(* A Canonical Structure *) |
| 225 |
#[global] |
| 226 |
Canonical natPointed : PointedType := {| Carrier := nat; point := 42 |}. |
| 227 |
(* A Coercion *) |
| 228 |
#[global] |
| 229 |
Coercion to_nat (b : bool) := if b then 1 else 0. |
| 230 |
(* A Setting *) |
| 231 |
#[global] |
| 232 |
Set Universe Polymorphism. |
| 233 |
(* A Hint *) |
| 234 |
Fail #[global] |
| 235 |
Hint Resolve secret_is_42 : plop. |
| 236 |
End Bar. |
| 237 |
|
| 238 |
(** **** Without importing: *) |
| 239 |
|
| 240 |
(* Availability of the parameter *) |
| 241 |
Check secret. |
| 242 |
(* Availability of the axiom *) |
| 243 |
Check secret_is_42. |
| 244 |
(* Availability of the canonical structure *) |
| 245 |
Check (point nat). |
| 246 |
(* Availability of the coercion *) |
| 247 |
Check (true + 2). |
| 248 |
(* Availability of [Set Universe Polymorphism] *) |
| 249 |
Definition foo_ni@{u} := nat. |
| 250 |
Check foo_ni@{_}. |
| 251 |
|
| 252 |
End InSectionGlobal. |