Debian Codegraph @

src/Bedrock/Field/Common/Arrays/MakeListLengths.v

raw
1 From Coq Require Import ZArith.
2 From Coq Require Import List.
3 Require Import Crypto.AbstractInterpretation.AbstractInterpretation.
4 Require Import Crypto.Bedrock.Field.Common.Types.
5 Require Import Crypto.Language.API.
6 Require Import Crypto.Util.Option.
7
8 Import Language.API.Compilers AbstractInterpretation.Compilers.
9 Import Types.Notations.
10 #[global]
11 Existing Instances rep.Z rep.listZ_mem.
12
13 Section with_parameters.
14 Context
15 {width BW word mem locals ext_spec varname_gen error}
16 `{parameters_sentinel : @parameters width BW word mem locals ext_spec varname_gen error}.
17
18 Fixpoint list_lengths_repeat_base (n : nat) t : base_listonly nat t :=
19 match t as t0 return base_listonly nat t0 with
20 | base.type.prod a b =>
21 (list_lengths_repeat_base n a, list_lengths_repeat_base n b)
22 | base_listZ => n
23 | _ => tt
24 end.
25 Fixpoint list_lengths_repeat_args (n : nat) t
26 : type.for_each_lhs_of_arrow list_lengths t :=
27 match t as t0 return type.for_each_lhs_of_arrow list_lengths t0 with
28 | type.base b => tt
29 | type.arrow (type.base s) d =>
30 (list_lengths_repeat_base n s, list_lengths_repeat_args n d)
31 | type.arrow s d => (tt, list_lengths_repeat_args n d)
32 end.
33
34 (* mostly a duplicate of list_lengths_from_value, just with ZRange interp *)
35 Fixpoint list_lengths_from_bounds {t}
36 : ZRange.type.base.option.interp t -> option (base_listonly nat t) :=
37 match t as t0 return
38 ZRange.type.base.option.interp t0 -> option (base_listonly nat t0) with
39 | base.type.prod a b =>
40 fun x =>
41 (x1 <- list_lengths_from_bounds (fst x);
42 x2 <- list_lengths_from_bounds (snd x);
43 Some (x1, x2))%option
44 | base_listZ =>
45 fun x : option (list _) => option_map (@List.length _) x
46 | _ => fun _ => Some tt
47 end.
48 Fixpoint list_lengths_from_argbounds {t}
49 : type.for_each_lhs_of_arrow ZRange.type.option.interp t ->
50 option (type.for_each_lhs_of_arrow list_lengths t) :=
51 match t as t0 return
52 type.for_each_lhs_of_arrow _ t0 ->
53 option (type.for_each_lhs_of_arrow _ t0) with
54 | type.base b => fun _ => Some tt
55 | type.arrow (type.base a) b =>
56 fun x =>
57 (x1 <- list_lengths_from_bounds (fst x);
58 x2 <- list_lengths_from_argbounds (snd x);
59 Some (x1, x2))%option
60 | type.arrow a b => fun _ => None
61 end.
62 End with_parameters.