Debian Codegraph @

test-suite/success/primitiveproj.v

raw
1 Set Primitive Projections.
2 Set Nonrecursive Elimination Schemes.
3 Module Prim.
4
5 Record F := { a : nat; b : a = a }.
6 Record G (A : Type) := { c : A; d : F }.
7
8 Check c.
9 End Prim.
10 Module Univ.
11 Set Universe Polymorphism.
12 Set Implicit Arguments.
13 Record Foo (A : Type) := { foo : A }.
14
15 Record G (A : Type) := { c : A; d : c = c; e : Foo A }.
16
17 Definition Foon : Foo nat := {| foo := 0 |}.
18
19 Definition Foonp : nat := Foon.(foo).
20
21 Definition Gt : G nat := {| c:= 0; d:=eq_refl; e:= Foon |}.
22
23 Check (Gt.(e)).
24
25 Section bla.
26
27 Record bar := { baz : nat; def := 0; baz' : forall x, x = baz \/ x = def }.
28 End bla.
29
30 End Univ.
31
32 Set Primitive Projections.
33 Unset Elimination Schemes.
34 Set Implicit Arguments.
35
36 Check nat.
37
38 Inductive X (U:Type) := { k : nat; a: k = k -> X U; b : let x := a eq_refl in X U }.
39
40 Parameter x:X nat.
41 Check (a x : forall _ : @eq nat (k x) (k x), X nat).
42 Check (b x : X nat).
43
44 Inductive Y := { next : option Y }.
45
46 Check _.(next) : option Y.
47 Lemma eta_ind (y : Y) : y = Build_Y y.(next).
48 Proof. Fail reflexivity. Abort.
49
50 Inductive Fdef := { Fa : nat ; Fb := Fa; Fc : Fdef }.
51
52 Fail Scheme Fdef_rec := Induction for Fdef Sort Prop.
53
54 (*
55 Rules for parsing and printing of primitive projections and their eta expansions.
56 If r : R A where R is a primitive record with implicit parameter A.
57 If p : forall {A} (r : R A) {A : Set}, list (A * B).
58 *)
59
60 Record R {A : Type} := { p : forall {X : Set}, A * X }.
61 Arguments R : clear implicits.
62
63 Record R' {A : Type} := { p' : forall X : Set, A * X }.
64 Arguments R' : clear implicits.
65
66 Unset Printing All.
67
68 Parameter r : R nat.
69
70 Check (r.(p)).
71 Set Printing Projections.
72 Check (r.(p)).
73 Unset Printing Projections.
74 Set Printing All.
75 Check (r.(p)).
76 Unset Printing All.
77
78 (* Check (r.(p)).
79 Elaborates to a primitive application, X arg implicit.
80 Of type nat * ?ex
81 No Printing All: p r
82 Set Printing Projections.: r.(p)
83 Printing All: r.(@p) ?ex
84 *)
85
86 Check p r.
87 Set Printing Projections.
88 Check p r.
89 Unset Printing Projections.
90 Set Printing All.
91 Check p r.
92 Unset Printing All.
93
94 Check p r (X:=nat).
95 Set Printing Projections.
96 Check p r (X:=nat).
97 Unset Printing Projections.
98 Set Printing All.
99 Check p r (X:=nat).
100 Unset Printing All.
101
102 (* Same elaboration, printing for p r *)
103
104 (** Explicit version of the primitive projection, under applied w.r.t implicit arguments
105 can be printed only using projection notation. r.(@p) *)
106 Check r.(@p _).
107 Set Printing Projections.
108 Check r.(@p _).
109 Unset Printing Projections.
110 Set Printing All.
111 Check r.(@p _).
112 Unset Printing All.
113
114 (** Explicit version of the primitive projection, applied to its implicit arguments
115 can be printed using application notation r.(p), r.(@p) in fully explicit form *)
116 Check r.(@p _) nat.
117 Set Printing Projections.
118 Check r.(@p _) nat.
119 Unset Printing Projections.
120 Set Printing All.
121 Check r.(@p _) nat.
122 Unset Printing All.
123
124 Parameter r' : R' nat.
125
126 Check (r'.(p')).
127 Set Printing Projections.
128 Check (r'.(p')).
129 Unset Printing Projections.
130 Set Printing All.
131 Check (r'.(p')).
132 Unset Printing All.
133
134 (* Check (r'.(p')).
135 Elaborates to a primitive application, X arg explicit.
136 Of type forall X : Set, nat * X
137 No Printing All: p' r'
138 Set Printing Projections.: r'.(p')
139 Printing All: r'.(@p')
140 *)
141
142 Check p' r'.
143 Set Printing Projections.
144 Check p' r'.
145 Unset Printing Projections.
146 Set Printing All.
147 Check p' r'.
148 Unset Printing All.
149
150 (* Same elaboration, printing for p r *)
151
152 (** Explicit version of the primitive projection, under applied w.r.t implicit arguments
153 can be printed only using projection notation. r.(@p) *)
154 Check r'.(@p' _).
155 Set Printing Projections.
156 Check r'.(@p' _).
157 Unset Printing Projections.
158 Set Printing All.
159 Check r'.(@p' _).
160 Unset Printing All.
161
162 (** Explicit version of the primitive projection, applied to its implicit arguments
163 can be printed only using projection notation r.(p), r.(@p) in fully explicit form *)
164 Check p' r' nat.
165 Set Printing Projections.
166 Check p' r' nat.
167 Unset Printing Projections.
168 Set Printing All.
169 Check p' r' nat.
170 Unset Printing All.
171
172 Check (@p' nat).
173 Check p'.
174 Set Printing All.
175
176 Check (@p' nat).
177 Check p'.
178 Unset Printing All.
179
180 Record wrap (A : Type) := { unwrap : A; unwrap2 : A }.
181
182 Definition term (x : wrap nat) := x.(unwrap).
183 Definition term' (x : wrap nat) := let f := (@unwrap2 nat) in f x.
184
185 Require Corelib.extraction.Extraction.
186 Recursive Extraction term term'.
187 Extraction TestCompile term term'.
188 (*Unset Printing Primitive Projection Parameters.*)
189
190 (* Primitive projections in the presence of let-ins (was not failing in beta3)*)
191
192 Set Primitive Projections.
193 Record s (x:nat) (y:=S x) := {c:=x; d:x=c}.
194 Lemma f : 0=1.
195 Proof.
196 Fail apply d.
197 (*
198 split.
199 reflexivity.
200 Qed.
201 *)
202 Abort.
203
204 (* Primitive projection match compilation *)
205
206 Set Primitive Projections.
207
208 Record prod (A B : Type) := pair { fst : A ; snd : B }.
209 Arguments pair {_ _} _ _.
210
211 Definition snd' := @snd.
212
213 (* a match which is just a projection doesn't produce a bunch of letins *)
214 Goal True.
215 assert (v : prod nat bool) by admit.
216
217 let unfolded_snd := eval cbv beta delta [snd' snd] in (snd' v) in
218 let matched_snd := constr:(let 'pair _ x := v in x) in
219 constr_eq unfolded_snd matched_snd.
220
221 Abort.
222
223 Fixpoint split_at {A} (l : list A) (n : nat) : prod (list A) (list A) :=
224 match n with
225 | 0 => pair nil l
226 | S n =>
227 match l with
228 | nil => pair nil nil
229 | cons x l => let 'pair l1 l2 := split_at l n in pair (cons x l1) l2
230 end
231 end.
232
233 Section Repeat.
234
235 Variable A : Type.
236 Fixpoint repeat (x : A) (n: nat ) :=
237 match n with
238 | O => nil
239 | S k => cons x (repeat x k)
240 end.
241
242 End Repeat.
243
244 Time Eval vm_compute in split_at (repeat 0 20) 10. (* Takes 0s *)
245 Time Eval vm_compute in split_at (repeat 0 40) 20. (* Takes 0.001s *)
246 Timeout 1 Time Eval vm_compute in split_at (repeat 0 60) 30. (* Used to take 60s, now takes 0.001s *)
247
248 Check (@eq_refl _ 0 <: 0 = fst (pair 0 1)).
249 Fail Check (@eq_refl _ 0 <: 0 = snd (pair 0 1)).
250
251 Check (@eq_refl _ 0 <<: 0 = fst (pair 0 1)).
252 Fail Check (@eq_refl _ 0 <<: 0 = snd (pair 0 1)).
253
254 (* [unfold] tactic *)
255 Module Unfold.
256 Record rec (P: Prop) := REC { v: unit }.
257 Set Printing All.
258 Set Printing Unfolded Projection As Match.
259
260 (* Testing that [unfold] can unfold compatibility constants. *)
261 Goal forall r: rec True, @v True r = tt.
262 Proof.
263 intros.
264 lazymatch goal with
265 | |- context C [@v _ ?r] =>
266 (* Carefully construct a term that definitely contains the compatibility constant. *)
267 let t := constr:(@v True) in
268 let g := context C [t r] in
269 change g
270 end.
271 progress unfold v.
272 Abort.
273 End Unfold.