Debian Codegraph @

src/Language/APINotations.v

raw
1 From Coq Require Import ZArith.
2 From Coq Require Import FMapPositive.
3 From Coq Require Import Bool.
4 From Coq Require Import Morphisms.
5 From Coq Require Import Relation_Definitions.
6 Require Import Ltac2.Ltac2.
7 Require Import Ltac2.Printf.
8 Require Import Crypto.Language.PreExtra.
9 Require Import Rewriter.Language.Language.
10 Require Import Rewriter.Language.Reify.
11 Require Import Crypto.Language.IdentifiersBasicGENERATED.
12 Require Import Crypto.Util.Tuple Crypto.Util.Prod Crypto.Util.LetIn.
13 Require Import Crypto.Util.ListUtil Coq.Lists.List Crypto.Util.NatUtil.
14 Require Import Crypto.Util.Option.
15 Require Import Crypto.Util.Prod.
16 Require Import Crypto.Util.ZRange.
17 Require Import Crypto.Util.ZRange.Operations.
18 Require Import Crypto.Util.ZUtil.Definitions.
19 Require Import Crypto.Util.ZUtil.Notations.
20 Require Import Crypto.Util.CPSNotations.
21 Require Import Crypto.Util.Bool.Reflect.
22 Require Import Crypto.Util.Notations.
23 Require Import Crypto.Util.Tactics.RunTacticAsConstr.
24 Require Import Crypto.Util.Tactics.DebugPrint.
25 Require Import Crypto.Util.Tactics.ConstrFail.
26 Require Import Crypto.Util.Tactics.Head.
27 Import Coq.Lists.List ListNotations. Local Open Scope bool_scope. Local Open Scope Z_scope.
28 Export Language.Pre.
29 Export Language.
30 Export IdentifiersBasicGENERATED.
31
32 Import EqNotations.
33 Module Compilers.
34 Export Language.Pre.
35 Export Language.Compilers.
36 Export Reify.Compilers.
37 Import IdentifiersBasicLibrary.Compilers.
38 Import IdentifiersBasicLibrary.Compilers.Basic.
39 Import IdentifiersBasicGenerate.Compilers.Basic.Tactic.
40 Import IdentifiersBasicGENERATED.Compilers.
41
42 Definition exprInfo : Classes.ExprInfoT := Eval hnf in GoalType.exprInfo package.
43 Definition exprExtraInfo : @Classes.ExprExtraInfoT exprInfo := Eval hnf in GoalType.exprExtraInfo package.
44
45 Global Existing Instances
46 baseHasNat
47 baseHasNatCorrect
48 try_make_base_transport_cps_correct
49 buildEagerIdent
50 buildInterpEagerIdentCorrect
51 toRestrictedIdent
52 toFromRestrictedIdent
53 buildInterpIdentCorrect
54 invertIdent
55 buildInvertIdentCorrect
56 base_default
57 exprInfo
58 .
59 Global Existing Instance reflect_base_beq | 10.
60 Global Existing Instance reflect_base_interp_beq | 10.
61 Global Existing Instance try_make_base_transport_cps | 5.
62 Global Existing Instance buildIdent | 5.
63 Global Existing Instance eqv_Reflexive_Proper | 1.
64 Global Existing Instance ident_interp_Proper | 1.
65
66 Bind Scope etype_scope with base.
67
68 Global Arguments ident_Literal {_} _ : assert.
69 Global Arguments ident_comment {_} : assert.
70 Global Arguments ident_comment_no_keep {_} : assert.
71 Global Arguments ident_value_barrier : assert.
72 Global Arguments ident_nil {_} : assert.
73 Global Arguments ident_cons {_} : assert.
74 Global Arguments ident_pair {_ _} : assert.
75 Global Arguments ident_fst {_ _} : assert.
76 Global Arguments ident_snd {_ _} : assert.
77 Global Arguments ident_prod_rect {_ _ _} : assert.
78 Global Arguments ident_bool_rect {_} : assert.
79 Global Arguments ident_bool_rect_nodep {_} : assert.
80 Global Arguments ident_nat_rect {_} : assert.
81 Global Arguments ident_nat_rect_arrow {_ _} : assert.
82 Global Arguments ident_eager_nat_rect {_} : assert.
83 Global Arguments ident_eager_nat_rect_arrow {_ _} : assert.
84 Global Arguments ident_nat_rect_fbb_b {_ _ _} : assert.
85 Global Arguments ident_nat_rect_fbb_b_b {_ _ _ _} : assert.
86 Global Arguments ident_list_rect {_ _} : assert.
87 Global Arguments ident_eager_list_rect {_ _} : assert.
88 Global Arguments ident_eager_list_rect_arrow {_ _ _} : assert.
89 Global Arguments ident_list_rect_arrow {_ _ _} : assert.
90 Global Arguments ident_list_rect_fbb_b {_ _ _ _} : assert.
91 Global Arguments ident_list_rect_fbb_b_b {_ _ _ _ _} : assert.
92 Global Arguments ident_list_rect_fbb_b_b_b {_ _ _ _ _ _} : assert.
93 Global Arguments ident_list_rect_fbb_b_b_b_b {_ _ _ _ _ _ _} : assert.
94 Global Arguments ident_list_rect_fbb_b_b_b_b_b {_ _ _ _ _ _ _ _} : assert.
95 Global Arguments ident_list_case {_ _} : assert.
96 Global Arguments ident_List_length {_} : assert.
97 Global Arguments ident_List_firstn {_} : assert.
98 Global Arguments ident_List_skipn {_} : assert.
99 Global Arguments ident_List_repeat {_} : assert.
100 Global Arguments ident_List_combine {_ _} : assert.
101 Global Arguments ident_List_map {_ _} : assert.
102 Global Arguments ident_List_app {_} : assert.
103 Global Arguments ident_List_rev {_} : assert.
104 Global Arguments ident_List_flat_map {_ _} : assert.
105 Global Arguments ident_List_partition {_} : assert.
106 Global Arguments ident_List_filter {_} : assert.
107 Global Arguments ident_List_fold_right {_ _} : assert.
108 Global Arguments ident_List_update_nth {_} : assert.
109 Global Arguments ident_List_nth_default {_} : assert.
110 Global Arguments ident_eager_List_nth_default {_} : assert.
111 Global Arguments ident_Some {_} : assert.
112 Global Arguments ident_None {_} : assert.
113 Global Arguments ident_option_rect {_ _} : assert.
114 Global Arguments ident_zrange_rect {_} : assert.
115 Global Arguments eta_base_cps {_} _ _ : assert.
116 Global Arguments ident_interp {_} _ : assert.
117 Global Arguments base_interp_beq {_ _} _ _ : assert.
118 Global Arguments reflect_base_interp_beq {_}.
119 Global Arguments ident_is_var_like {_} _ : assert.
120 Global Arguments eqv_Reflexive_Proper {_} _.
121 Global Arguments ident_interp_Proper {_}.
122
123 Ltac2 mk_reify_base () :=
124 let package := reify_package_of_package 'package in
125 reify_base_via_reify_package package.
126 Ltac2 mk_reify_base_type () :=
127 let package := reify_package_of_package 'package in
128 reify_base_type_via_reify_package package.
129 Ltac2 mk_reify_type () :=
130 let package := reify_package_of_package 'package in
131 reify_type_via_reify_package package.
132 Ltac2 mk_reify_ident_opt () :=
133 let package := reify_package_of_package 'package in
134 reify_ident_via_reify_package_opt package.
135 Ltac2 reify_base (ty : constr) : constr := mk_reify_base () ty.
136 Ltac2 reify_base_type (ty : constr) : constr := mk_reify_base_type () ty.
137 Ltac2 reify_type (ty : constr) : constr := mk_reify_type () ty.
138 Ltac2 reify_ident_opt (ctx_tys : binder list) (idc : constr) : constr option := mk_reify_ident_opt () ctx_tys idc.
139
140 #[deprecated(since="8.15",note="Use Ltac2 instead.")]
141 Ltac reify_base term :=
142 let f := ltac2:(term
143 |- Control.refine (fun () => reify_base (Option.get (Ltac1.to_constr term)))) in
144 constr:(ltac:(f term)).
145 #[deprecated(since="8.15",note="Use Ltac2 instead.")]
146 Ltac reify_base_type term :=
147 let f := ltac2:(term
148 |- Control.refine (fun () => reify_base_type (Option.get (Ltac1.to_constr term)))) in
149 constr:(ltac:(f term)).
150 #[deprecated(since="8.15",note="Use Ltac2 instead.")]
151 Ltac reify_type term :=
152 let f := ltac2:(term
153 |- Control.refine (fun () => reify_type (Option.get (Ltac1.to_constr term)))) in
154 constr:(ltac:(f term)).
155 #[deprecated(since="8.15",note="Use Ltac2 instead.")]
156 Ltac reify_ident term then_tac else_tac :=
157 let f := ltac2:(term
158 |- match reify_ident_opt [] (Option.get (Ltac1.to_constr term)) with
159 | Some v => Control.refine (fun () => '(@Datatypes.Some _ $v))
160 | None => Control.refine (fun () => '(@Datatypes.None Datatypes.unit))
161 end) in
162 match f term with
163 | Datatypes.Some ?v => then_tac v
164 | Datatypes.None => else_tac ()
165 end.
166
167 (** This file defines some convenience notations and definitions. *)
168 Module base.
169 Export Language.Compilers.base.
170
171 Module type.
172 Import IdentifiersBasicGENERATED.Compilers.
173 Notation base := base (only parsing).
174 Notation Z := Z (only parsing).
175 Notation positive := positive (only parsing).
176 Notation nat := nat (only parsing).
177 Notation zrange := zrange (only parsing).
178 Notation bool := bool (only parsing).
179 Notation base_beq := Compilers.base_beq (only parsing).
180 Notation string := string (only parsing).
181
182 Export Language.Compilers.base.type.
183 Notation type := (@type base) (only parsing).
184
185 Notation baseHasNat := Compilers.baseHasNat (only parsing).
186 Notation eta_base_cps_gen := Compilers.eta_base_cps_gen (only parsing).
187 Notation eta_base_cps := Compilers.eta_base_cps (only parsing).
188 End type.
189 Notation type := (@base.type base) (only parsing).
190 Notation base_interp := Compilers.base_interp (only parsing).
191 Notation interp := (base.interp Compilers.base_interp) (only parsing).
192 Notation reflect_base_beq := Compilers.reflect_base_beq (only parsing).
193 Notation base_interp_beq := Compilers.base_interp_beq (only parsing).
194 Notation baseHasNatCorrect := Compilers.baseHasNatCorrect (only parsing).
195 Notation reflect_base_interp_eq := Compilers.reflect_base_interp_beq (only parsing).
196 Notation try_make_base_transport_cps := Compilers.try_make_base_transport_cps (only parsing).
197 Notation try_make_base_transport_cps_correct := Compilers.try_make_base_transport_cps_correct (only parsing).
198
199 (* Avoid COQBUG(https://github.com/coq/coq/issues/16425)
200 Notation reify_base t := (ltac2:(let rt := reify_base (Constr.pretype t) in exact $rt)) (only parsing).
201 Notation reify t := (ltac2:(let rt := reify_base_type (Constr.pretype t) in exact $rt)) (only parsing).
202 Notation reify_norm_base t := (ltac2:(let t' := Constr.pretype t in let t' := eval cbv in $t' in let rt := reify_base t' in exact $rt)) (only parsing).
203 Notation reify_norm t := (ltac2:(let t' := Constr.pretype t in let t' := eval cbv in $t' in let rt := reify_base_type t' in exact $rt)) (only parsing).
204 *)
205 Notation reify_base t := (ltac:(let rt := reify_base t in exact rt)) (only parsing).
206 Notation reify t := (ltac:(let rt := reify_base_type t in exact rt)) (only parsing).
207 Notation reify_norm_base t := (ltac:(let t' := eval cbv in t in let rt := reify_base t' in exact rt)) (only parsing).
208 Notation reify_norm t := (ltac:(let t' := eval cbv in t in let rt := reify_base_type t' in exact rt)) (only parsing).
209 Notation reify_base_type_of e := (reify_base ((fun t (_ : t) => t) _ e)) (only parsing).
210 Notation reify_type_of e := (reify ((fun t (_ : t) => t) _ e)) (only parsing).
211 Notation reify_norm_base_type_of e := (reify_norm_base ((fun t (_ : t) => t) _ e)) (only parsing).
212 Notation reify_norm_type_of e := (reify_norm ((fun t (_ : t) => t) _ e)) (only parsing).
213
214 Ltac2 mk_reify_base := Compilers.mk_reify_base.
215 Ltac2 mk_reify := Compilers.mk_reify_base_type.
216 Ltac2 mk_reify_type := Compilers.mk_reify_type.
217 Ltac2 reify_base := Compilers.reify_base.
218 Ltac2 reify := Compilers.reify_base_type.
219 Ltac2 reify_type := Compilers.reify_type.
220 #[deprecated(since="8.15",note="Use Ltac2 instead.")]
221 Ltac reify_base ty := Compilers.reify_base ty.
222 #[deprecated(since="8.15",note="Use Ltac2 instead.")]
223 Ltac reify ty := Compilers.reify_base_type ty.
224 #[deprecated(since="8.15",note="Use Ltac2 instead.")]
225 Ltac reify_type ty := Compilers.reify_type ty.
226 End base.
227
228 Module ident.
229 Export Language.Compilers.ident.
230 Notation ident := Compilers.ident (only parsing).
231
232 Notation Literal := Compilers.ident_Literal (only parsing).
233 Notation comment := Compilers.ident_comment (only parsing).
234 Notation comment_no_keep := Compilers.ident_comment_no_keep (only parsing).
235 Notation value_barrier := Compilers.ident_value_barrier (only parsing).
236 Notation Nat_succ := Compilers.ident_Nat_succ (only parsing).
237 Notation Nat_pred := Compilers.ident_Nat_pred (only parsing).
238 Notation Nat_max := Compilers.ident_Nat_max (only parsing).
239 Notation Nat_mul := Compilers.ident_Nat_mul (only parsing).
240 Notation Nat_add := Compilers.ident_Nat_add (only parsing).
241 Notation Nat_sub := Compilers.ident_Nat_sub (only parsing).
242 Notation Nat_eqb := Compilers.ident_Nat_eqb (only parsing).
243 Notation nil := Compilers.ident_nil (only parsing).
244 Notation cons := Compilers.ident_cons (only parsing).
245 Notation tt := Compilers.ident_tt (only parsing).
246 Notation pair := Compilers.ident_pair (only parsing).
247 Notation fst := Compilers.ident_fst (only parsing).
248 Notation snd := Compilers.ident_snd (only parsing).
249 Notation prod_rect := Compilers.ident_prod_rect (only parsing).
250 Notation bool_rect := Compilers.ident_bool_rect (only parsing).
251 Notation bool_rect_nodep := Compilers.ident_bool_rect_nodep (only parsing).
252 Notation nat_rect := Compilers.ident_nat_rect (only parsing).
253 Notation nat_rect_arrow := Compilers.ident_nat_rect_arrow (only parsing).
254 Notation eager_nat_rect := Compilers.ident_eager_nat_rect (only parsing).
255 Notation eager_nat_rect_arrow := Compilers.ident_eager_nat_rect_arrow (only parsing).
256 Notation nat_rect_fbb_b := Compilers.ident_nat_rect_fbb_b (only parsing).
257 Notation nat_rect_fbb_b_b := Compilers.ident_nat_rect_fbb_b_b (only parsing).
258 Notation list_rect := Compilers.ident_list_rect (only parsing).
259 Notation list_rect_arrow := Compilers.ident_list_rect_arrow (only parsing).
260 Notation eager_list_rect := Compilers.ident_eager_list_rect (only parsing).
261 Notation eager_list_rect_arrow := Compilers.ident_eager_list_rect_arrow (only parsing).
262 Notation list_rect_fbb_b := Compilers.ident_list_rect_fbb_b (only parsing).
263 Notation list_rect_fbb_b_b := Compilers.ident_list_rect_fbb_b_b (only parsing).
264 Notation list_rect_fbb_b_b_b := Compilers.ident_list_rect_fbb_b_b_b (only parsing).
265 Notation list_rect_fbb_b_b_b_b := Compilers.ident_list_rect_fbb_b_b_b_b (only parsing).
266 Notation list_rect_fbb_b_b_b_b_b := Compilers.ident_list_rect_fbb_b_b_b_b_b (only parsing).
267 Notation list_case := Compilers.ident_list_case (only parsing).
268 Notation List_length := Compilers.ident_List_length (only parsing).
269 Notation List_seq := Compilers.ident_List_seq (only parsing).
270 Notation List_firstn := Compilers.ident_List_firstn (only parsing).
271 Notation List_skipn := Compilers.ident_List_skipn (only parsing).
272 Notation List_repeat := Compilers.ident_List_repeat (only parsing).
273 Notation List_combine := Compilers.ident_List_combine (only parsing).
274 Notation List_map := Compilers.ident_List_map (only parsing).
275 Notation List_app := Compilers.ident_List_app (only parsing).
276 Notation List_rev := Compilers.ident_List_rev (only parsing).
277 Notation List_flat_map := Compilers.ident_List_flat_map (only parsing).
278 Notation List_partition := Compilers.ident_List_partition (only parsing).
279 Notation List_filter := Compilers.ident_List_filter (only parsing).
280 Notation List_fold_right := Compilers.ident_List_fold_right (only parsing).
281 Notation List_update_nth := Compilers.ident_List_update_nth (only parsing).
282 Notation List_nth_default := Compilers.ident_List_nth_default (only parsing).
283 Notation eager_List_nth_default := Compilers.ident_eager_List_nth_default (only parsing).
284 Notation Pos_add := Compilers.ident_Pos_add (only parsing).
285 Notation Pos_mul := Compilers.ident_Pos_mul (only parsing).
286 Notation Z_add := Compilers.ident_Z_add (only parsing).
287 Notation Z_mul := Compilers.ident_Z_mul (only parsing).
288 Notation Z_pow := Compilers.ident_Z_pow (only parsing).
289 Notation Z_sub := Compilers.ident_Z_sub (only parsing).
290 Notation Z_opp := Compilers.ident_Z_opp (only parsing).
291 Notation Z_div := Compilers.ident_Z_div (only parsing).
292 Notation Z_modulo := Compilers.ident_Z_modulo (only parsing).
293 Notation Z_log2 := Compilers.ident_Z_log2 (only parsing).
294 Notation Z_log2_up := Compilers.ident_Z_log2_up (only parsing).
295 Notation Z_eqb := Compilers.ident_Z_eqb (only parsing).
296 Notation Z_leb := Compilers.ident_Z_leb (only parsing).
297 Notation Z_ltb := Compilers.ident_Z_ltb (only parsing).
298 Notation Z_geb := Compilers.ident_Z_geb (only parsing).
299 Notation Z_gtb := Compilers.ident_Z_gtb (only parsing).
300 Notation Z_of_nat := Compilers.ident_Z_of_nat (only parsing).
301 Notation Z_to_nat := Compilers.ident_Z_to_nat (only parsing).
302 Notation Z_pos := Compilers.ident_Z_pos (only parsing).
303 Notation Z_to_pos := Compilers.ident_Z_to_pos (only parsing).
304 Notation Z_shiftr := Compilers.ident_Z_shiftr (only parsing).
305 Notation Z_shiftl := Compilers.ident_Z_shiftl (only parsing).
306 Notation Z_land := Compilers.ident_Z_land (only parsing).
307 Notation Z_lor := Compilers.ident_Z_lor (only parsing).
308 Notation Z_min := Compilers.ident_Z_min (only parsing).
309 Notation Z_max := Compilers.ident_Z_max (only parsing).
310 Notation Z_abs := Compilers.ident_Z_abs (only parsing).
311 Notation Z_bneg := Compilers.ident_Z_bneg (only parsing).
312 Notation Z_lnot_modulo := Compilers.ident_Z_lnot_modulo (only parsing).
313 Notation Z_lxor := Compilers.ident_Z_lxor (only parsing).
314 Notation Z_truncating_shiftl := Compilers.ident_Z_truncating_shiftl (only parsing).
315 Notation Z_mul_split := Compilers.ident_Z_mul_split (only parsing).
316 Notation Z_mul_high := Compilers.ident_Z_mul_high (only parsing).
317 Notation Z_add_get_carry := Compilers.ident_Z_add_get_carry (only parsing).
318 Notation Z_add_with_carry := Compilers.ident_Z_add_with_carry (only parsing).
319 Notation Z_add_with_get_carry := Compilers.ident_Z_add_with_get_carry (only parsing).
320 Notation Z_sub_get_borrow := Compilers.ident_Z_sub_get_borrow (only parsing).
321 Notation Z_sub_with_get_borrow := Compilers.ident_Z_sub_with_get_borrow (only parsing).
322 Notation Z_ltz := Compilers.ident_Z_ltz (only parsing).
323 Notation Z_zselect := Compilers.ident_Z_zselect (only parsing).
324 Notation Z_add_modulo := Compilers.ident_Z_add_modulo (only parsing).
325 Notation Z_rshi := Compilers.ident_Z_rshi (only parsing).
326 Notation Z_cc_m := Compilers.ident_Z_cc_m (only parsing).
327 Notation Z_combine_at_bitwidth := Compilers.ident_Z_combine_at_bitwidth (only parsing).
328 Notation Z_cast := Compilers.ident_Z_cast (only parsing).
329 Notation Z_cast2 := Compilers.ident_Z_cast2 (only parsing).
330 Notation Some := Compilers.ident_Some (only parsing).
331 Notation None := Compilers.ident_None (only parsing).
332 Notation option_rect := Compilers.ident_option_rect (only parsing).
333 Notation Build_zrange := Compilers.ident_Build_zrange (only parsing).
334 Notation zrange_rect := Compilers.ident_zrange_rect (only parsing).
335 Notation fancy_add := Compilers.ident_fancy_add (only parsing).
336 Notation fancy_addc := Compilers.ident_fancy_addc (only parsing).
337 Notation fancy_sub := Compilers.ident_fancy_sub (only parsing).
338 Notation fancy_subb := Compilers.ident_fancy_subb (only parsing).
339 Notation fancy_mulll := Compilers.ident_fancy_mulll (only parsing).
340 Notation fancy_mullh := Compilers.ident_fancy_mullh (only parsing).
341 Notation fancy_mulhl := Compilers.ident_fancy_mulhl (only parsing).
342 Notation fancy_mulhh := Compilers.ident_fancy_mulhh (only parsing).
343 Notation fancy_rshi := Compilers.ident_fancy_rshi (only parsing).
344 Notation fancy_selc := Compilers.ident_fancy_selc (only parsing).
345 Notation fancy_selm := Compilers.ident_fancy_selm (only parsing).
346 Notation fancy_sell := Compilers.ident_fancy_sell (only parsing).
347 Notation fancy_addm := Compilers.ident_fancy_addm (only parsing).
348
349 Notation option_Some := Compilers.ident_Some (only parsing).
350 Notation option_None := Compilers.ident_None (only parsing).
351
352 Notation interp := Compilers.ident_interp (only parsing).
353
354 Notation buildEagerIdent := Compilers.buildEagerIdent (only parsing).
355 Notation buildInterpEagerIdentCorrect := Compilers.buildInterpEagerIdentCorrect (only parsing).
356 Notation toRestrictedIdent := Compilers.toRestrictedIdent (only parsing).
357 Notation toFromRestrictedIdent := Compilers.toFromRestrictedIdent (only parsing).
358
359 Ltac2 mk_reify_opt := Compilers.mk_reify_ident_opt.
360 Ltac2 reify_opt := Compilers.reify_ident_opt.
361 #[deprecated(since="8.15",note="Use Ltac2 instead.")]
362 Ltac reify := Compilers.reify_ident.
363
364 Notation buildIdent := Compilers.buildIdent (only parsing).
365 Notation is_var_like := Compilers.ident_is_var_like (only parsing).
366 Notation buildInterpIdentCorrect := Compilers.buildInterpIdentCorrect (only parsing).
367 Notation eqv_Reflexive_Proper := Compilers.eqv_Reflexive_Proper (only parsing).
368 Notation interp_Proper := Compilers.ident_interp_Proper (only parsing).
369
370 Definition is_comment t (idc : ident t) : Datatypes.bool
371 := match idc with
372 | comment _ => true
373 | comment_no_keep _ => true
374 | _ => false
375 end.
376
377 Module Export Notations.
378 Export Language.Compilers.ident.Notations.
379 Delimit Scope ident_scope with ident.
380 Bind Scope ident_scope with ident.
381 Notation interp := Compilers.ident_interp (only parsing).
382 Global Arguments expr.Ident {base_type%type ident%function var%function t%etype} idc%ident.
383 Notation "## x" := (Compilers.ident_Literal x) (only printing) : ident_scope.
384 Notation "## x" := (Compilers.ident_Literal (t:=base.reify_base_type_of x) x) (only parsing) : ident_scope.
385 Notation "## x" := (expr.Ident (Compilers.ident_Literal x)) (only printing) : expr_scope.
386 Notation "## x" := (smart_Literal (base_interp:=base_interp) (t:=base.reify_type_of x) x) (only parsing) : expr_scope.
387 Notation "# x" := (expr.Ident x) (only parsing) : expr_pat_scope.
388 Notation "# x" := (@expr.Ident base.type _ _ _ x) : expr_scope.
389 Notation "x @ y" := (expr.App x%expr_pat y%expr_pat) (only parsing) : expr_pat_scope.
390 Notation "( x , y , .. , z )" := (expr.App (expr.App (#Compilers.ident_pair) .. (expr.App (expr.App (#Compilers.ident_pair) x%expr) y%expr) .. ) z%expr) : expr_scope.
391 Notation "( x , y , .. , z )" := (expr.App (expr.App (#Compilers.ident_pair)%expr_pat .. (expr.App (expr.App (#Compilers.ident_pair)%expr_pat x%expr_pat) y%expr_pat) .. ) z%expr_pat) (only parsing) : expr_pat_scope.
392 Notation "x :: y" := (#Compilers.ident_cons @ x @ y)%expr : expr_scope.
393 Notation "[ ]" := (#Compilers.ident_nil)%expr : expr_scope.
394 Notation "x :: y" := (#Compilers.ident_cons @ x @ y)%expr_pat (only parsing) : expr_pat_scope.
395 Notation "[ ]" := (#Compilers.ident_nil)%expr_pat (only parsing) : expr_pat_scope.
396 Notation "[ x ]" := (x :: [])%expr : expr_scope.
397 Notation "[ x ; y ; .. ; z ]" := (#Compilers.ident_cons @ x @ (#Compilers.ident_cons @ y @ .. (#Compilers.ident_cons @ z @ #Compilers.ident_nil) ..))%expr : expr_scope.
398 Notation "ls [[ n ]]"
399 := ((#(Compilers.ident_List_nth_default) @ _ @ ls @ #(Compilers.ident_Literal n%nat))%expr)
400 : expr_scope.
401 Notation "xs ++ ys" := (#Compilers.ident_List_app @ xs @ ys)%expr : expr_scope.
402 Notation "x - y" := (#Compilers.ident_Z_sub @ x @ y)%expr : expr_scope.
403 Notation "x + y" := (#Compilers.ident_Z_add @ x @ y)%expr : expr_scope.
404 Notation "x / y" := (#Compilers.ident_Z_div @ x @ y)%expr : expr_scope.
405 Notation "x * y" := (#Compilers.ident_Z_mul @ x @ y)%expr : expr_scope.
406 Notation "x >> y" := (#Compilers.ident_Z_shiftr @ x @ y)%expr : expr_scope.
407 Notation "x << y" := (#Compilers.ident_Z_shiftl @ x @ y)%expr : expr_scope.
408 Notation "x &' y" := (#Compilers.ident_Z_land @ x @ y)%expr : expr_scope.
409 Notation "x || y" := (#Compilers.ident_Z_lor @ x @ y)%expr : expr_scope.
410 Notation "x 'mod' y" := (#Compilers.ident_Z_modulo @ x @ y)%expr : expr_scope.
411 Notation "- x" := (#Compilers.ident_Z_opp @ x)%expr : expr_scope.
412 Global Arguments ident_interp _ !_.
413 End Notations.
414 End ident.
415 Export ident.Notations.
416 Notation ident := IdentifiersBasicGENERATED.Compilers.ident (only parsing).
417
418 Ltac2 reify (var : constr) (term : constr) : constr :=
419 let reify_base_type := mk_reify_base_type () in
420 let reify_ident_opt := mk_reify_ident_opt () in
421 expr.reify 'base.type 'ident reify_base_type reify_ident_opt var term None.
422 Ltac2 _Reify (term : constr) : constr :=
423 let reify_base_type := mk_reify_base_type () in
424 let reify_ident_opt := mk_reify_ident_opt () in
425 expr._Reify 'base.type 'ident reify_base_type reify_ident_opt term.
426 Ltac2 _Reify_rhs () : unit :=
427 let reify_base_type := mk_reify_base_type () in
428 let reify_ident_opt := mk_reify_ident_opt () in
429 expr._Reify_rhs 'base.type 'ident reify_base_type reify_ident_opt '@base.interp '@ident_interp ().
430 Ltac2 Type exn ::= [ Not_a_constr (string, string, Ltac1.t) ].
431 Ltac reify var term :=
432 let f := ltac2:(var term
433 |- let get_to_constr name x
434 := match Ltac1.to_constr x with
435 | Some x => x
436 | None => Control.zero (Not_a_constr "APINotations.Compilers.reify" name x)
437 end in
438 let v := reify (get_to_constr "var" var) (get_to_constr "term" term) in
439 Control.refine (fun () => v)) in
440 constr:(ltac:(f constr:(var) term)).
441 Ltac Reify term :=
442 let f := ltac2:(term
443 |- let get_to_constr name x
444 := match Ltac1.to_constr x with
445 | Some x => x
446 | None => Control.zero (Not_a_constr "APINotations.Compilers.Reify" name x)
447 end in
448 let v := _Reify (get_to_constr "term" term) in
449 Control.refine (fun () => v)) in
450 constr:(ltac:(f term)).
451 Ltac Reify_rhs _ :=
452 ltac2:(_Reify_rhs ()).
453
454 Local Set Default Proof Mode "Classic".
455 Global Hint Extern 1 (@expr.Reified_of _ _ _ _ ?t ?v ?rv)
456 => cbv [expr.Reified_of]; Reify_rhs (); reflexivity : typeclass_instances.
457
458 Module Import invert_expr.
459 Export Language.Compilers.invert_expr.
460
461 Module ident.
462 Notation invertIdent := Compilers.invertIdent (only parsing).
463 Notation buildInvertIdentCorrect := Compilers.buildInvertIdentCorrect (only parsing).
464 End ident.
465
466 Section with_var.
467 Context {var : type base.type -> Type}.
468 Local Notation expr := (@expr base.type ident var).
469 Local Notation try_transportP P := (@type.try_transport _ _ P _ _).
470 Local Notation try_transport := (try_transportP _).
471 Let type_base (x : base) : base.type := base.type.type_base x.
472 Let base {bt} (x : Language.Compilers.base.type bt) : type.type _ := type.base x.
473 Local Coercion base : base.type >-> type.type.
474 Local Coercion type_base : Compilers.base >-> base.type.
475 Local Notation tZ := (base.type.type_base Z).
476 Local Notation tzrange := (base.type.type_base zrange).
477
478 Definition invert_Z_cast {t} (e : expr t)
479 : option ZRange.zrange
480 := match invert_AppIdent e with
481 | Some (existT (type.base tzrange) (idc, r))
482 => r <- reflect_smart_Literal r;
483 if match idc with ident.Z_cast => true | _ => false end
484 then Some r
485 else None
486 | _ => None
487 end%option.
488
489 Definition invert_Z_cast2 {t} (e : expr t)
490 : option (ZRange.zrange * ZRange.zrange)
491 := match invert_AppIdent e with
492 | Some (existT (type.base (tzrange * tzrange))
493 (idc, r))
494 => r <- reflect_smart_Literal r;
495 if match idc with ident.Z_cast2 => true | _ => false end
496 then Some r
497 else None
498 | _ => None
499 end%option.
500
501 Definition invert_App_Z_cast (e : expr tZ)
502 : option (ZRange.zrange * expr Z)
503 := match invert_App e with
504 | Some (existT (type.base tZ) (idc, v))
505 => r <- invert_Z_cast idc;
506 Some (r, v)
507 | _ => None
508 end.
509
510 Definition invert_App_Z_cast2 (e : expr (tZ * tZ))
511 : option ((ZRange.zrange * ZRange.zrange) * expr (Z * Z))
512 := match invert_App e with
513 | Some (existT (type.base (tZ * tZ)) (idc, v))
514 => r <- invert_Z_cast2 idc;
515 Some (r, v)
516 | _ => None
517 end.
518
519 Definition invert_App_cast {t} (e : expr t)
520 : option ((type.interp (Language.Compilers.base.interp (fun _ => ZRange.zrange)) t) * expr t)
521 := match t return expr t -> option (type.interp _ t * expr t) with
522 | type.base tZ => invert_App_Z_cast
523 | type.base (tZ * tZ) => invert_App_Z_cast2
524 | _ => fun _ => None
525 end e.
526
527 Definition invert_Literal_through_cast {t} (e : expr t)
528 : option (option (type.interp (Language.Compilers.base.interp (fun _ => ZRange.zrange)) t) * type.interp base.interp t)
529 := match invert_Literal e, invert_App_cast e with
530 | Some v, _ => Some (None, v)
531 | None, Some (r, e) => (v <- invert_Literal e; Some (Some r, v))%option
532 | None, None => None
533 end.
534 End with_var.
535 End invert_expr.
536
537 Module DefaultValue.
538 Export Language.Compilers.DefaultValue.
539 Module type.
540 Export Language.Compilers.DefaultValue.type.
541 Module base.
542 Export Language.Compilers.DefaultValue.type.base.
543 Notation base_default := Compilers.base_default (only parsing).
544 End base.
545 End type.
546 End DefaultValue.
547
548 Module Classes.
549 Export Language.Compilers.Classes.
550 Notation exprInfo := Compilers.exprInfo (only parsing).
551 Notation exprExtraInfo := Compilers.exprExtraInfo (only parsing).
552 End Classes.
553
554 Module Coercions.
555 Coercion type_base (x : base) : base.type := base.type.type_base x.
556 Coercion base {bt} (x : Language.Compilers.base.type bt) : type.type _ := type.base x.
557 Global Arguments base {_} _ / .
558 Global Arguments type_base _ / .
559 End Coercions.
560 End Compilers.