Debian Codegraph @

test-suite/success/locality_attributes_modules.v

raw
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 (** This structure is used to test availability or not of a
23 [Canonical Structure]. *)
24 Structure PointedType : Type := { Carrier :> Set; point : Carrier }.
25
26 (** This HintDb is used to test availability or not of a [Hint] command. *)
27 Create HintDb plop.
28
29 (** ** Tests for modules and visibility attributes *)
30
31 (** *** Without attribute (default) *)
32
33 Module InModuleDefault.
34
35 Module Bar.
36 (* A parameter: *)
37 Parameter (secret : nat).
38 (* An axiom: *)
39 Axiom secret_is_42 : secret = 42.
40 (* A custom tactic: *)
41 Ltac find_secret := rewrite secret_is_42.
42 (* An abbreviation: *)
43 Notation add_42 := (Nat.add 42).
44 (* A tactic notation: *)
45 Tactic Notation "rfl" := reflexivity.
46 (* A notation: *)
47 Infix "+p" := Nat.add (only parsing, at level 30, right associativity) : nat_scope.
48 (* A lemma: *)
49 Lemma secret_42 : secret = 42.
50 Proof. find_secret. rfl. Qed.
51 (* A Canonical Structure: *)
52 Canonical natPointed : PointedType := {| Carrier := nat; point := 42 |}.
53 (* A Coercion: *)
54 Coercion to_nat (b : bool) := if b then 1 else 0.
55 (* A Setting: *)
56 Set Universe Polymorphism.
57 (* A Hint: *)
58 Hint Resolve secret_42 : plop.
59 End Bar.
60
61 (** **** Without importing: *)
62
63 (* Availability of the parameter *)
64 Check Bar.secret.
65 Fail Check secret.
66 (* Availability of the axiom *)
67 Check Bar.secret_is_42.
68 Fail Check secret_is_42.
69 (* Availability of the tactic *)
70 Fail Print find_secret.
71 Print Bar.find_secret.
72 (* Availability of the abbreviation *)
73 Fail Check add_42.
74 Check Bar.add_42.
75 (* Availability of the tactic notation *)
76 Lemma plop_ni : 2 + 2 = 4.
77 Proof. Fail rfl. Admitted.
78 (* Availability of the notation *)
79 Fail Check (2 +p 3).
80 (* Availability of the canonical structure *)
81 Fail Check (point nat).
82 (* Availability of the coercion *)
83 Fail Check (true + 2).
84 (* Availability of [Set Universe Polymorphism] *)
85 Definition foo_ni@{u} := nat.
86 Fail Check foo_ni@{_}.
87 (* Availability of the [Hint] *)
88 Lemma hop_ni : Bar.secret = 42.
89 Proof.
90 Fail solve [auto with plop].
91 Admitted.
92
93 (** **** After importing: *)
94
95 Import Bar.
96 (* Availability of the parameter *)
97 Check Bar.secret.
98 Check secret.
99 (* Availability of the axiom *)
100 Check Bar.secret_is_42.
101 Check secret_is_42.
102 (* Availability of the tactic *)
103 Print find_secret.
104 Print Bar.find_secret.
105 (* Availability of the abbreviation *)
106 Check add_42.
107 Check Bar.add_42.
108 (* Availability of the tactic notation *)
109 Lemma plop_i : 2 + 2 = 4.
110 Proof. rfl. Qed.
111 (* Availability of the notation *)
112 Check (2 +p 3).
113 (* Availability of the canonical structure *)
114 Check (point nat).
115 (* Availability of the coercion *)
116 Check (true + 2).
117 (* Availability of [Set Universe Polymorphism] *)
118 Definition foo_i@{u} := nat.
119 Fail Check foo_i@{_}.
120 (* Availability of the [Hint] *)
121 Lemma hop_i : Bar.secret = 42.
122 Proof.
123 solve [auto with plop].
124 Qed.
125
126 End InModuleDefault.
127
128 Module InModuleLocal.
129 Module Bar.
130 (* A parameter: *)
131 #[local]
132 Parameter (secret : nat).
133 (* An axiom: *)
134 #[local]
135 Axiom secret_is_42 : secret = 42.
136 (* A custom tactic: *)
137 #[local]
138 Ltac find_secret := rewrite secret_is_42.
139 (* An abbreviation: *)
140 #[local]
141 Notation add_42 := (Nat.add 42).
142 (* A tactic notation: *)
143 #[local]
144 Tactic Notation "rfl" := reflexivity.
145 (* A notation: *)
146 #[local]
147 Infix "+p" := Nat.add (only parsing, at level 30, right associativity) : nat_scope.
148 (* A lemma: *)
149 #[local]
150 Lemma secret_42 : secret = 42.
151 Proof. find_secret. rfl. Qed.
152 (* A Canonical Structure *)
153 #[local]
154 Canonical natPointed : PointedType := {| Carrier := nat; point := 42 |}.
155 (* A Coercion *)
156 #[local]
157 Coercion to_nat (b : bool) := if b then 1 else 0.
158 (* A Setting *)
159 #[local]
160 Set Universe Polymorphism.
161 (* A Hint *)
162 #[local]
163 Hint Resolve secret_42 : plop.
164 End Bar.
165
166 (** **** Without importing: *)
167
168 (* Availability of the parameter *)
169 Check Bar.secret.
170 Fail Check secret.
171 (* Availability of the axiom *)
172 Check Bar.secret_is_42.
173 Fail Check secret_is_42.
174 (* Availability of the tactic *)
175 Fail Print find_secret.
176 Fail Print Bar.find_secret.
177 (* Availability of the abbreviation *)
178 Fail Check add_42.
179 Fail Check Bar.add_42.
180 (* Availability of the tactic notation *)
181 Lemma plop_ni : 2 + 2 = 4.
182 Proof. Fail rfl. Admitted.
183 (* Availability of the notation *)
184 Fail Check (2 +p 3).
185 (* Availability of the canonical structure *)
186 Fail Check (point nat).
187 (* Availability of the coercion *)
188 Fail Check (true + 2).
189 (* Availability of [Set Universe Polymorphism] *)
190 Definition foo_ni@{u} := nat.
191 Fail Check foo_ni@{_}.
192 (* Availability of the [Hint] *)
193 Lemma hop_ni : Bar.secret = 42.
194 Proof.
195 Fail solve [auto with plop].
196 Admitted.
197
198 (** **** After importing: *)
199
200 Import Bar.
201 (* Availability of the parameter *)
202 Check Bar.secret.
203 Fail Check secret.
204 (* Availability of the axiom *)
205 Check Bar.secret_is_42.
206 Fail Check secret_is_42.
207 (* Availability of the tactic *)
208 Fail Print find_secret.
209 Fail Print Bar.find_secret.
210 (* Availability of the abbreviation *)
211 Fail Check add_42.
212 Fail Check Bar.add_42.
213 (* Availability of the tactic notation *)
214 Lemma plop_i : 2 + 2 = 4.
215 Proof. Fail rfl. Admitted.
216 (* Availability of the notation *)
217 Fail Check (2 +p 3).
218 (* Availability of the canonical structure *)
219 Check (point nat).
220 (* Availability of the coercion *)
221 Fail Check (true + 2).
222 (* Availability of [Set Universe Polymorphism] *)
223 Definition foo_i@{u} := nat.
224 Fail Check foo_i@{_}.
225 (* Availability of the [Hint] *)
226 Lemma hop_i : Bar.secret = 42.
227 Proof.
228 Fail solve [auto with plop].
229 Admitted.
230
231 End InModuleLocal.
232
233 Module InModuleExport.
234 Module Bar.
235 (* A parameter: *)
236 Fail #[export]
237 Parameter (secret : nat).
238 (* An axiom: *)
239 Fail #[export]
240 Axiom plop : 0 = 0.
241 (* A custom tactic: *)
242 Fail #[export]
243 Ltac find_secret := reflexivity.
244 (* An abbreviation: *)
245 #[export]
246 Notation add_42 := (Nat.add 42).
247 (* A tactic notation: *)
248 Fail #[export]
249 Tactic Notation "rfl" := reflexivity.
250 (* A notation: *)
251 Fail #[export]
252 Infix "+p" := Nat.add (only parsing, at level 30, right associativity) : nat_scope.
253 (* A lemma: *)
254 Fail #[export]
255 Lemma secret_42 : secret = 42.
256 (* A Canonical Structure *)
257 Fail #[export]
258 Canonical natPointed : PointedType := {| Carrier := nat; point := 42 |}.
259 (* A Coercion *)
260 Fail#[export]
261 Coercion to_nat (b : bool) := if b then 1 else 0.
262 (* A Setting *)
263 #[export]
264 Set Universe Polymorphism.
265 (* A Hint *)
266 Parameter (secret : nat).
267 Axiom secret_42 : secret = 42.
268 #[export]
269 Hint Resolve secret_42 : plop.
270 End Bar.
271
272 (** **** Without importing: *)
273
274 (* Availability of [Set Universe Polymorphism] *)
275 Definition foo_ni@{u} := nat.
276 Fail Check foo_ni@{_}.
277 (* Availability of the [Hint] *)
278 Lemma hop_ni : Bar.secret = 42.
279 Proof.
280 Fail solve [auto with plop].
281 Admitted.
282
283 (** **** After importing: *)
284
285 Import Bar.
286 (* Availability of [Set Universe Polymorphism] *)
287 Definition foo_i@{u} := nat.
288 Check foo_i@{_}.
289 (* Availability of the [Hint] *)
290 Lemma hop_i : Bar.secret = 42.
291 Proof.
292 solve [auto with plop].
293 Qed.
294
295 End InModuleExport.
296
297 Module InModuleGlobal.
298 Module Bar.
299 (* A parameter: *)
300 #[global]
301 Parameter (secret : nat).
302 (* An axiom: *)
303 #[global]
304 Axiom secret_is_42 : secret = 42.
305 (* A custom tactic: *)
306 #[global]
307 Ltac find_secret := rewrite secret_is_42.
308 (* An abbreviation: *)
309 #[global]
310 Notation add_42 := (Nat.add 42).
311 (* A tactic notation: *)
312 #[global]
313 Tactic Notation "rfl" := reflexivity.
314 (* A notation: *)
315 #[global]
316 Infix "+p" := Nat.add (only parsing, at level 30, right associativity) : nat_scope.
317 (* A lemma: *)
318 #[global]
319 Lemma secret_42 : secret = 42.
320 Proof. find_secret. rfl. Qed.
321 (* A Canonical Structure *)
322 #[global]
323 Canonical natPointed : PointedType := {| Carrier := nat; point := 42 |}.
324 (* A Coercion *)
325 #[global]
326 Coercion to_nat (b : bool) := if b then 1 else 0.
327 (* A Setting *)
328 #[global]
329 Set Universe Polymorphism.
330 (* A Hint *)
331 #[global]
332 Hint Resolve secret_42 : plop.
333 End Bar.
334
335 (** **** Without importing: *)
336
337 (* Availability of the parameter *)
338 Check Bar.secret.
339 Fail Check secret.
340 (* Availability of the axiom *)
341 Check Bar.secret_is_42.
342 Fail Check secret_is_42.
343 (* Availability of the tactic *)
344 Fail Print find_secret.
345 Print Bar.find_secret.
346 (* Availability of the abbreviation *)
347 Fail Check add_42.
348 Check Bar.add_42.
349 (* Availability of the tactic notation *)
350 Lemma plop_ni : 2 + 2 = 4.
351 Proof. Fail rfl. Admitted.
352 (* Availability of the notation *)
353 Fail Check (2 +p 3).
354 (* Availability of the canonical structure *)
355 Fail Check (point nat).
356 (* Availability of the coercion *)
357 Fail Check (true + 2).
358 (* Availability of [Set Universe Polymorphism] *)
359 Definition foo_ni@{u} := nat.
360 Check foo_ni@{_}.
361 (* Availability of the [Hint] *)
362 Lemma hop_ni : Bar.secret = 42.
363 Proof.
364 solve [auto with plop].
365 Admitted.
366
367 (** **** After importing: *)
368
369 Import Bar.
370 (* Availability of the parameter *)
371 Check Bar.secret.
372 Check secret.
373 (* Availability of the axiom *)
374 Check Bar.secret_is_42.
375 Check secret_is_42.
376 (* Availability of the tactic *)
377 Print find_secret.
378 Print Bar.find_secret.
379 (* Availability of the abbreviation *)
380 Check add_42.
381 Check Bar.add_42.
382 (* Availability of the tactic notation *)
383 Lemma plop_i : 2 + 2 = 4.
384 Proof. rfl. Qed.
385 (* Availability of the notation *)
386 Check (2 +p 3).
387 (* Availability of the canonical structure *)
388 Check (point nat).
389 (* Availability of the coercion *)
390 Check (true + 2).
391 (* Availability of [Set Universe Polymorphism] *)
392 Definition foo_i@{u} := nat.
393 Check foo_i@{_}.
394 (* Availability of the [Hint] *)
395 Lemma hop_i : Bar.secret = 42.
396 Proof.
397 solve [auto with plop].
398 Qed.
399
400 End InModuleGlobal.
401 (** Since I have some global Hints and Settings, the corresponding tests
402 for Sections are in the file locality_attributes_sections.v *)