| 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 |
(** ** Tests of visibility attributes in a section inside a module *) |
| 28 |
|
| 29 |
(** We only test [Definition], [Coercion], [Canonical] and [Set], the other |
| 30 |
commands only support the [local] attribute in sections, which is also |
| 31 |
the default visibility, making them unavailable outside the section. *) |
| 32 |
|
| 33 |
(** *** Without attribute (default) *) |
| 34 |
|
| 35 |
Module InSectionDefault. |
| 36 |
|
| 37 |
Module M. |
| 38 |
Section Bar. |
| 39 |
(* A definition: *) |
| 40 |
Definition foo := 42. |
| 41 |
(* A Coercion: *) |
| 42 |
Coercion to_nat (b : bool) := if b then 1 else 0. |
| 43 |
(* A Canonical Structure: *) |
| 44 |
Canonical natPointed : PointedType := {| Carrier := nat; point := 42 |}. |
| 45 |
(* A Setting: *) |
| 46 |
Set Universe Polymorphism. |
| 47 |
End Bar. |
| 48 |
End M. |
| 49 |
|
| 50 |
Module M_not_imported. |
| 51 |
(** First, we do not import M. *) |
| 52 |
(* Availability of the definition *) |
| 53 |
Fail Check foo. (* not imported *) |
| 54 |
(* Availability of the coercion *) |
| 55 |
Fail Check (true + 2). (* not imported *) |
| 56 |
(* Availability of the canonical structure *) |
| 57 |
Fail Check (point nat). (* not imported *) |
| 58 |
(* Availability of [Set Universe Polymorphism] *) |
| 59 |
Definition foo_i@{u} := nat. |
| 60 |
Fail Check foo_i@{_}. |
| 61 |
End M_not_imported. |
| 62 |
|
| 63 |
Module M_imported. |
| 64 |
(** Now we import M. *) |
| 65 |
Import M. |
| 66 |
(* Availability of the definition *) |
| 67 |
Check foo. |
| 68 |
(* Availability of the coercion *) |
| 69 |
Check (true + 2). |
| 70 |
(* Availability of the canonical structure *) |
| 71 |
Check (point nat). |
| 72 |
(* Availability of [Set Universe Polymorphism] *) |
| 73 |
Definition foo_i@{u} := nat. |
| 74 |
Fail Check foo_i@{_}. |
| 75 |
End M_imported. |
| 76 |
|
| 77 |
End InSectionDefault. |
| 78 |
|
| 79 |
(** *** With the [local] attribute *) |
| 80 |
(** We only need to test a definition, we know the other commands have no effect |
| 81 |
outside the section (hence outside the module containing the section). *) |
| 82 |
Module InSectionLocal. |
| 83 |
|
| 84 |
Module M. |
| 85 |
Section Bar. |
| 86 |
(* A definition: *) |
| 87 |
#[local] |
| 88 |
Definition foo := 42. |
| 89 |
End Bar. |
| 90 |
End M. |
| 91 |
|
| 92 |
Module M_not_imported. |
| 93 |
(** First, we do not import M. *) |
| 94 |
(* Availability of the definition *) |
| 95 |
Fail Check foo. (* not imported *) |
| 96 |
Check M.foo. |
| 97 |
End M_not_imported. |
| 98 |
|
| 99 |
Module M_imported. |
| 100 |
(** Now we import M. *) |
| 101 |
Import M. |
| 102 |
(* Availability of the definition *) |
| 103 |
Fail Check foo. |
| 104 |
(* /!\ notice the local attribute has been passed to the module! *) |
| 105 |
Check M.foo. |
| 106 |
End M_imported. |
| 107 |
|
| 108 |
End InSectionLocal. |
| 109 |
|
| 110 |
(** *** With the [export] attribute *) |
| 111 |
(** We only need to test a setting, it is the only command for which [export] |
| 112 |
is supported inside a [Section]. *) |
| 113 |
Module InSectionExport. |
| 114 |
|
| 115 |
Module M. |
| 116 |
Section Bar. |
| 117 |
(* A Setting *) |
| 118 |
#[export] |
| 119 |
Set Universe Polymorphism. |
| 120 |
End Bar. |
| 121 |
End M. |
| 122 |
|
| 123 |
Module M_not_imported. |
| 124 |
(** **** Without importing: *) |
| 125 |
(* Availability of [Set Universe Polymorphism] *) |
| 126 |
Definition foo_ni@{u} := nat. |
| 127 |
Fail Check foo_ni@{_}. |
| 128 |
End M_not_imported. |
| 129 |
|
| 130 |
Module M_imported. |
| 131 |
Import M. |
| 132 |
(* Availability of [Set Universe Polymorphism] *) |
| 133 |
Definition foo_ni@{u} := nat. |
| 134 |
Check foo_ni@{_}. |
| 135 |
End M_imported. |
| 136 |
End InSectionExport. |
| 137 |
|
| 138 |
(** *** With the [export] attribute *) |
| 139 |
(** We only need to test [Coercion], [Canonical] and [Set]. *) |
| 140 |
|
| 141 |
Module InSectionGlobal. |
| 142 |
|
| 143 |
Module M. |
| 144 |
Section Bar. |
| 145 |
(* A Coercion: *) |
| 146 |
#[global] |
| 147 |
Coercion to_nat (b : bool) := if b then 1 else 0. |
| 148 |
(* A Canonical Structure: *) |
| 149 |
#[global] |
| 150 |
Canonical natPointed : PointedType := {| Carrier := nat; point := 42 |}. |
| 151 |
(* A Setting: *) |
| 152 |
#[global] |
| 153 |
Set Universe Polymorphism. |
| 154 |
End Bar. |
| 155 |
End M. |
| 156 |
|
| 157 |
Module M_not_imported. |
| 158 |
(** First, we do not import M. *) |
| 159 |
(* Availability of the coercion *) |
| 160 |
Fail Check (true + 2). (* not imported *) |
| 161 |
(* Availability of the canonical structure *) |
| 162 |
Fail Check (point nat). (* not imported *) |
| 163 |
(* Availability of [Set Universe Polymorphism] *) |
| 164 |
Definition foo_i@{u} := nat. |
| 165 |
Check foo_i@{_}. (* available *) |
| 166 |
(* /!\ global for [Set] in a section is passed to the module! *) |
| 167 |
End M_not_imported. |
| 168 |
|
| 169 |
Module M_imported. |
| 170 |
(** Now we import M. *) |
| 171 |
Import M. |
| 172 |
(* Availability of the coercion *) |
| 173 |
Check (true + 2). |
| 174 |
(* Availability of the canonical structure *) |
| 175 |
Check (point nat). |
| 176 |
(* Availability of [Set Universe Polymorphism] *) |
| 177 |
Definition foo_i@{u} := nat. |
| 178 |
Check foo_i@{_}. |
| 179 |
End M_imported. |
| 180 |
|
| 181 |
End InSectionGlobal. |