Debian Codegraph @

test-suite/success/Template.v

raw
1 Set Printing Universes.
2
3 Module AutoYes.
4 Inductive Box (A:Type) : Type := box : A -> Box A.
5
6 About Box.
7
8 (* This checks that Box is template poly, see module No for how it fails *)
9 Universe i j. Constraint i < j.
10 Definition j_lebox (A:Type@{j}) := Box A.
11 Definition box_lti A := Box A : Type@{i}.
12
13 End AutoYes.
14
15 Module AutoNo.
16 Unset Auto Template Polymorphism.
17 Inductive Box (A:Type) : Type := box : A -> Box A.
18
19 About Box.
20
21 Universe i j. Constraint i < j.
22 Definition j_lebox (A:Type@{j}) := Box A.
23 Fail Definition box_lti A := Box A : Type@{i}.
24
25 End AutoNo.
26
27 Module Yes.
28 #[universes(template)]
29 Inductive Box@{i} (A:Type@{i}) : Type@{i} := box : A -> Box A.
30
31 About Box.
32
33 Universe i j. Constraint i < j.
34 Definition j_lebox (A:Type@{j}) := Box A.
35 Definition box_lti A := Box A : Type@{i}.
36
37 End Yes.
38
39 Module No.
40 #[universes(template=no)]
41 Inductive Box (A:Type) : Type := box : A -> Box A.
42
43 About Box.
44
45 Universe i j. Constraint i < j.
46 Definition j_lebox (A:Type@{j}) := Box A.
47 Fail Definition box_lti A := Box A : Type@{i}.
48 End No.
49
50 Module ExplicitTemplate.
51 #[universes(template)]
52 Inductive identity@{i} (A : Type@{i}) (a : A) : A -> Type@{i} := id_refl (_:A) : identity A a a.
53
54 (* There used to be a weird interaction of template polymorphism and inductive
55 types which fall in Prop due to kernel sort inference. This inductive is
56 template polymorphic, but the universe annotation Type@{i} was ignored by
57 the kernel which infered it lived in any universe and thus put it in Prop.
58 This is not the case anymore since return sort inference has been removed
59 from the kernel. Now the universe annotation is respected by the kernel. *)
60 Fail Check (identity Type nat nat : Prop).
61 Check (identity True I I : Prop).
62 Check identity nat 0 0 : Set.
63 Fail Check identity Type nat nat : Set.
64 Check identity Type nat nat : Type.
65 End ExplicitTemplate.
66
67 Module ExplicitTemplate2.
68 #[universes(template)]
69 Inductive identity@{i} (A : Type@{i}) (a : A) : A -> Type@{i} := id_refl : identity A a a.
70 (* we generate fresh qualities for A and the conclusion, and they end up unrelated
71 therefore the conclusion quality has no binders,
72 we can't make it a template poly quality and instead collapse to Type *)
73
74 Fail Check (identity Type nat nat : Prop).
75 Fail Check (identity True I I : Prop).
76 Check identity nat 0 0 : Set.
77 Fail Check identity Type nat nat : Set.
78 Check identity Type nat nat : Type.
79 End ExplicitTemplate2.
80
81 Polymorphic Definition f@{i} : Type@{i} := nat.
82 Polymorphic Definition baz@{i} : Type@{i} -> Type@{i} := fun x => x.
83
84 Section Foo.
85 Universe u.
86 Context (A : Type@{u}).
87
88 Inductive Bar :=
89 | bar : A -> Bar.
90
91 Set Universe Minimization ToSet.
92 Inductive Baz :=
93 | cbaz : A -> baz Baz -> Baz.
94
95 Inductive Baz' :=
96 | cbaz' : A -> baz@{Set} nat -> Baz'.
97
98 (* 2 constructors, at least in Set *)
99 Inductive Bazset@{v} :=
100 | cbaz1 : A -> baz@{v} Bazset -> Bazset
101 | cbaz2 : Bazset.
102
103 Eval compute in ltac:(let T := type of A in exact T).
104
105 Inductive Foo : Type :=
106 | foo : A -> f -> Foo.
107
108 End Foo.
109
110 Set Printing Universes.
111 (* Cannot fall back to Prop or Set anymore as baz is no longer template-polymorphic *)
112 Fail Check Bar True : Prop.
113 Fail Check Bar nat : Set.
114 About Baz.
115
116 Check cbaz True I.
117
118 (** Neither can it be Set *)
119 Fail Check Baz nat : Set.
120
121 (** No longer possible for Baz' which contains a type in Set *)
122 Fail Check Baz' True : Prop.
123 Fail Check Baz' nat : Set.
124
125 Fail Check Bazset True : Prop.
126 Fail Check Bazset True : Set.
127
128 (** We can force the universe instantiated in [baz Bazset] to be [u], so Bazset lives in max(Set, u). *)
129 Constraint u = Bazset.v.
130 (** As u is global it is already > Set, so: *)
131 Definition bazsetex@{i | i < u} : Type@{u} := Bazset Type@{i}.
132
133 (* Bazset is closed for universes u = u0, cannot be instantiated with Prop *)
134 Definition bazseetpar (X : Type@{u}) : Type@{u} := Bazset X.
135
136 (** Would otherwise break singleton elimination and extraction. *)
137 Fail Check Foo True : Prop.
138 Fail Check Foo True : Set.
139
140 Definition foo_proj {A} (f : Foo A) : nat :=
141 match f with foo _ _ n => n end.
142
143 Definition ex : Foo True := foo _ I 0.
144 Check foo_proj ex.
145
146 (** See failure/Template.v for a test of the unsafe Unset Template Check usage *)
147
148 Module AutoTemplateTest.
149 Set Warnings "+auto-template".
150 Section Foo.
151 Universe u'.
152 Context (A : Type@{u'}).
153
154 (* Not failing as Bar cannot be made template polymorphic at all *)
155 Inductive Bar :=
156 | bar : A -> Bar.
157 End Foo.
158 End AutoTemplateTest.
159
160 Module TestTemplateAttribute.
161 Section Foo.
162 Universe u.
163 Context (A : Type@{u}).
164
165 Set Warnings "+no-template-universe".
166
167 (* Failing as Bar cannot be made template polymorphic at all *)
168 Fail #[universes(template)] Inductive Bar :=
169 | bar : A -> Bar.
170
171 End Foo.
172 End TestTemplateAttribute.
173
174 Module SharingWithoutSection.
175 Inductive Foo A (S:= fun _ => Set : ltac:(let ty := type of A in exact ty))
176 := foo : S A -> Foo A.
177 Fail Check Foo True : Prop.
178 End SharingWithoutSection.
179
180 Module OkNotCovered.
181 (* Here it happens that box is safe but we don't see it *)
182 Section S.
183 Universe u.
184 Variable A : Type@{u}.
185 Inductive box (A:Type@{u}) := Box : A -> box A.
186 Definition B := Set : Type@{u}.
187 End S.
188 Fail Check box True : Prop.
189 End OkNotCovered.
190
191 Module BoxBox.
192
193 Inductive Box (A:Type) := box (_:A).
194 Inductive Box' (A:Type) := box' (_:Box A).
195 Check Box' True : Prop.
196
197 End BoxBox.
198
199 Module TemplateUnit.
200
201 Set Warnings "-no-template-universe".
202
203 (* This is marked as template without any actual template universe. *)
204 #[universes(template)] Inductive foo := Foo.
205
206 Check (foo : Prop).
207
208 End TemplateUnit.
209
210 Module TemplateParamUnit.
211
212 (* template where the univ doesn't appear in the conclusion (here Prop) *)
213 Set Warnings "+no-template-universe".
214 Inductive foo (A : Type) := Foo.
215
216 Polymorphic Definition foo'@{u|} (A:Type@{u}) : Prop := foo A.
217
218 Check (foo unit : Prop).
219
220 End TemplateParamUnit.
221
222 Module TemplateAlg.
223
224 Inductive foo (A:Type) (B :Type) := C (_:A).
225
226 Check foo True nat : Prop.
227
228 Check fun A => foo A nat : Prop.
229 Fail Check fun A:Set => foo A nat : Prop.
230
231 Goal Prop.
232 let c := constr:(forall A, prod A A) in
233 exact c.
234 Defined.
235
236 Universes u v.
237
238 Axiom U : Type@{u}.
239 Axiom V : Type@{v}.
240
241 Check foo (U * V) True : Type@{max(u,v)}.
242
243 End TemplateAlg.
244
245 Module TemplateNoExtraCsts.
246
247 Polymorphic Definition opt'@{u|} (A:Type@{u}) := option A.
248 Polymorphic Definition some@{u|} (A:Type@{u}) (x:A) : opt' A := Some x.
249
250 End TemplateNoExtraCsts.
251
252 Module BoundedQuality.
253 Inductive dumb' (b:bool) (B : Type) := cons' : B -> (b = true -> dumb' false nat) -> dumb' b B.
254
255 (* dumb' true _ contains a nat *)
256 Fail Check dumb' true True : Prop.
257
258 Check dumb' true nat : Set.
259 Fail Check dumb' true Set : Set.
260 Check dumb' true Set.
261 End BoundedQuality.
262
263 Module BoundedQuality2.
264 Inductive dumb' (A:Type) (b:bool) (B : Type) := cons' : A -> (b = true -> dumb' A false nat) -> dumb' A b B.
265
266 Check dumb' True true Set : Prop.
267 Fail Check dumb' nat true Set : Prop.
268 Check dumb' nat true Set : Set.
269 Fail Check dumb' Set true Set : Set.
270 Check dumb' Set true Set.
271 End BoundedQuality2.
272
273 Module UnminimizedOption.
274 Unset Universe Minimization ToSet.
275 Inductive option A := None | Some (_:A).
276
277 Fail Check option True : Prop.
278 Check option nat : Set.
279 Fail Check option Set : Set.
280 Check option Set : Type.
281 End UnminimizedOption.
282
283 Module UnminimizedFunction.
284 Unset Universe Minimization ToSet.
285 Inductive Foo (T:Type) := foo (_:nat -> T).
286
287 Check Foo True : Prop.
288 Fail Check Foo nat : Prop.
289 Check Foo nat : Set.
290 Fail Check Foo Set : Set.
291 Check Foo Set : Type.
292 End UnminimizedFunction.
293
294 Module ExplicitOption.
295 Inductive option@{u} (A:Type@{u}) : Type@{u} := None | Some (_:A).
296
297 Fail Check option True : Prop.
298 Check option nat : Set.
299 Fail Check option Set : Set.
300 Check option Set : Type.
301 End ExplicitOption.
302
303 Module QvarInCtor.
304 (* this could be sort polymorphic:
305 Record Foo@{q|u v|} (A:Type@{q|u}) : Type@{q|max(u,v+1)}
306 := { foo1 : A; foo2 : forall P : Type@{q|v}, P }.
307
308 but qvar "q" (and univ "v") cannot be template poly due to appearing in the constructor
309 (even if we generalized template poly to allow conversion-irrelevant appearances,
310 this one isn't irrelevant)
311
312 so we need to collapse q := Type and can be template poly on u *)
313 Record Foo A := { foo1 : A ; foo2 : forall P, P }.
314
315 Fail Check Foo True : Prop.
316 Fail Check Foo nat : Set.
317 Polymorphic Definition test@{|} : Type@{Foo.u1+1} := Foo nat.
318 Polymorphic Definition test'@{u|} (A:Type@{u}) : Type@{max(u,Foo.u1+1)} := Foo A.
319 End QvarInCtor.
320
321 Module SemiPoly.
322 Universe u.
323
324 (* u cannot be template poly (it's global) but we could be template sort polymorphic *)
325 Inductive foo (A:Type@{u}) (B:Type@{u}) C := pair (_:A) (_:B) (_:C).
326
327 Fail Check foo True True True : Prop. (* maybe will be allowed someday *)
328 Fail Check foo nat nat nat : Set. (* must not be allowed *)
329 End SemiPoly.