effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Tot | val destr_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ())) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f () | val destr_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
let destr_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ())) = | false | null | false | fun u u_if f x -> f () | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.BitStop",
"FStar.Ghost.erased",
"LowParse.Spec.BitSum.if_combinator_weak",
"FStar.Ghost.reveal",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.synth_bitsum'",
"LowParse.Spec.BitSum.destr_bitsum'_t"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val destr_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ())) | [] | LowParse.Spec.BitSum.destr_bitsum'_bitstop | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | cl: LowParse.BitFields.uint_t tot t
-> LowParse.Spec.BitSum.destr_bitsum'_t (LowParse.Spec.BitSum.BitStop ()) | {
"end_col": 6,
"end_line": 1302,
"start_col": 2,
"start_line": 1301
} |
Prims.Tot | val bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x | val bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload)) = | false | null | false | x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.BitSum'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload)) | [] | LowParse.Spec.BitSum.bitsum'_type_intro_BitSum' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
x: LowParse.Spec.BitSum.bitsum'_type_bitsum' cl bitsum'_size key key_size e payload
-> LowParse.Spec.BitSum.bitsum'_type (LowParse.Spec.BitSum.BitSum' key key_size e payload) | {
"end_col": 3,
"end_line": 109,
"start_col": 2,
"start_line": 109
} |
Prims.Tot | val parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b | val parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b)) = | false | null | false | synth_bitsum'_injective b;
(p `parse_filter` (filter_bitsum' b)) `parse_synth` (synth_bitsum' b) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.BitSum.synth_bitsum'",
"Prims.unit",
"LowParse.Spec.BitSum.synth_bitsum'_injective"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b)) | [] | LowParse.Spec.BitSum.parse_bitsum' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl tot -> p: LowParse.Spec.Base.parser k t
-> LowParse.Spec.Base.parser (LowParse.Spec.Combinators.parse_filter_kind k)
(LowParse.Spec.BitSum.bitsum'_type b) | {
"end_col": 67,
"end_line": 372,
"start_col": 2,
"start_line": 371
} |
Prims.Tot | val synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b) (decreases (bitsum'_size)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p | val synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b) (decreases (bitsum'_size))
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b) (decreases (bitsum'_size)) = | false | null | false | match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl
bitsum'_size
sz
rest
(cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f:bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k:enum_key e = enum_key_of_repr e f in
let z:bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p:(k': enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total",
""
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.bitsum'_type_intro_BitField",
"FStar.Pervasives.Native.Mktuple2",
"LowParse.BitFields.bitfield",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"LowParse.Spec.BitSum.synth_bitsum'",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'_type_intro_BitSum'",
"Prims.dtuple2",
"Prims.Mkdtuple2",
"LowParse.Spec.Enum.enum_key_of_repr"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b) (decreases (bitsum'_size)) | [
"recursion"
] | LowParse.Spec.BitSum.synth_bitsum' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
x: LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitSum.filter_bitsum' b)
-> Prims.Tot (LowParse.Spec.BitSum.bitsum'_type b) | {
"end_col": 71,
"end_line": 259,
"start_col": 2,
"start_line": 250
} |
Prims.Tot | val bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x | val bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest)) = | false | null | false | x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.BitField"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest)) | [] | LowParse.Spec.BitSum.bitsum'_type_intro_BitField | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
sz: Prims.nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot} ->
rest: LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - sz) ->
x: LowParse.Spec.BitSum.bitsum'_type_bitfield bitsum'_size sz rest
-> LowParse.Spec.BitSum.bitsum'_type (LowParse.Spec.BitSum.BitField sz rest) | {
"end_col": 3,
"end_line": 135,
"start_col": 2,
"start_line": 135
} |
Prims.Tot | val filter_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ())) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true | val filter_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
let filter_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ())) = | false | null | false | fun _ -> true | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.bool",
"Prims.eq2",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.BitStop",
"LowParse.Spec.BitSum.filter_bitsum'_t"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val filter_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ())) | [] | LowParse.Spec.BitSum.filter_bitsum'_bitstop | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | cl: LowParse.BitFields.uint_t tot t
-> LowParse.Spec.BitSum.filter_bitsum'_t (LowParse.Spec.BitSum.BitStop ()) | {
"end_col": 15,
"end_line": 1089,
"start_col": 2,
"start_line": 1089
} |
Prims.Tot | val bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x | val bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest) = | false | null | false | coerce (bitsum'_key_type rest) x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.BitField",
"LowParse.Spec.BitSum.coerce"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest) | [] | LowParse.Spec.BitSum.bitsum'_key_type_elim_BitField | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
sz: Prims.nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot} ->
rest: LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - sz) ->
x: LowParse.Spec.BitSum.bitsum'_key_type (LowParse.Spec.BitSum.BitField sz rest)
-> LowParse.Spec.BitSum.bitsum'_key_type rest | {
"end_col": 34,
"end_line": 218,
"start_col": 2,
"start_line": 218
} |
Prims.Tot | val bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x | val bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest)) = | false | null | false | coerce (bitsum'_key_type (BitField sz rest)) x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.coerce",
"LowParse.Spec.BitSum.BitField"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest)) | [] | LowParse.Spec.BitSum.bitsum'_key_type_intro_BitField | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
sz: Prims.nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot} ->
rest: LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - sz) ->
x: LowParse.Spec.BitSum.bitsum'_key_type rest
-> LowParse.Spec.BitSum.bitsum'_key_type (LowParse.Spec.BitSum.BitField sz rest) | {
"end_col": 48,
"end_line": 205,
"start_col": 2,
"start_line": 205
} |
FStar.Pervasives.Lemma | val synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot)
: Lemma (synth_injective (synth_bitsum' b)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
) | val synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot)
: Lemma (synth_injective (synth_bitsum' b))
let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot)
: Lemma (synth_injective (synth_bitsum' b)) = | false | null | true | synth_injective_intro' (synth_bitsum' b)
(fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.Combinators.synth_injective_intro'",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.synth_bitsum'",
"Prims._assert",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"Prims.unit",
"LowParse.BitFields.get_bitfield_full",
"LowParse.Spec.BitSum.synth_bitsum'_injective'",
"Prims.l_True",
"Prims.squash",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Spec.Combinators.parse_filter_refine",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot)
: Lemma (synth_injective (synth_bitsum' b)) | [] | LowParse.Spec.BitSum.synth_bitsum'_injective | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl tot
-> FStar.Pervasives.Lemma
(ensures LowParse.Spec.Combinators.synth_injective (LowParse.Spec.BitSum.synth_bitsum' b)) | {
"end_col": 3,
"end_line": 313,
"start_col": 2,
"start_line": 308
} |
FStar.Pervasives.Lemma | val synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl | val synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size)) = | false | null | true | match b with
| BitStop _ -> ()
| BitField sz rest ->
let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl))
(bitsum'_size - sz)
(bitsum'_size)
(cl.v hd)
0
(bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k , tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl))
(bitsum'_size - key_size)
(bitsum'_size)
(cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl))
(bitsum'_size - key_size)
(bitsum'_size)
(cl.v (enum_repr_of_key e k))
0
(bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x)
(bitsum'_size - key_size)
(bitsum'_size))) ==
cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.BitFields.bitfield",
"LowParse.Spec.BitSum.synth_bitsum'_recip'_prop",
"Prims.unit",
"LowParse.Spec.BitSum.filter_bitsum'_ext",
"LowParse.Spec.BitSum.synth_bitsum'_recip'",
"LowParse.BitFields.get_bitfield_set_bitfield_other",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Enum.enum_key_of_repr_of_key",
"Prims._assert",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"LowParse.Spec.Enum.enum_repr_of_key",
"LowParse.BitFields.get_bitfield_set_bitfield_same",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'",
"Prims.l_True",
"Prims.bool",
"LowParse.Spec.BitSum.filter_bitsum'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size)) | [
"recursion"
] | LowParse.Spec.BitSum.synth_bitsum'_recip'_prop | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.BitSum.bitsum'_type b
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.BitSum.filter_bitsum' b (LowParse.Spec.BitSum.synth_bitsum'_recip' b x) ==
true) (decreases bitsum'_size) | {
"end_col": 44,
"end_line": 485,
"start_col": 2,
"start_line": 471
} |
FStar.Pervasives.Lemma | val synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma (s.g k (s.f k x) == x) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x | val synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma (s.g k (s.f k x) == x)
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma (s.g k (s.f k x) == x) = | false | null | true | s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f_inj",
"LowParse.Spec.BitSum.__proj__SynthCase__item__g",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f",
"Prims.unit",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f_g_eq",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma (s.g k (s.f k x) == x) | [] | LowParse.Spec.BitSum.synth_case_g_f_eq | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
k: LowParse.Spec.BitSum.bitsum'_type b ->
x: type_of_tag (LowParse.Spec.BitSum.bitsum'_key_of_t b k)
-> FStar.Pervasives.Lemma (ensures SynthCase?.g s k (SynthCase?.f s k x) == x) | {
"end_col": 31,
"end_line": 676,
"start_col": 2,
"start_line": 675
} |
Prims.Tot | val synth_bitsum'_recip_BitStop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ())) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0 | val synth_bitsum'_recip_BitStop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
let synth_bitsum'_recip_BitStop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ())) = | false | null | false | fun _ -> cl.uint_to_t 0 | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.BitStop",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"Prims.eq2",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"LowParse.Spec.BitSum.synth_bitsum'_recip_t"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_recip_BitStop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ())) | [] | LowParse.Spec.BitSum.synth_bitsum'_recip_BitStop | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | cl: LowParse.BitFields.uint_t tot t
-> LowParse.Spec.BitSum.synth_bitsum'_recip_t (LowParse.Spec.BitSum.BitStop ()) | {
"end_col": 25,
"end_line": 1561,
"start_col": 2,
"start_line": 1561
} |
FStar.Pervasives.Lemma | val get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat{bitsum'_size <= lo /\ lo <= hi /\ hi <= tot})
: Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi | val get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat{bitsum'_size <= lo /\ lo <= hi /\ hi <= tot})
: Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat{bitsum'_size <= lo /\ lo <= hi /\ hi <= tot})
: Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size)) = | false | null | true | match b with
| BitStop h -> BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl))
(bitsum'_size - sz)
bitsum'_size
(cl.v hd)
lo
hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k , tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl))
(bitsum'_size - key_size)
bitsum'_size
(cl.v (enum_repr_of_key e k))
lo
hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"LowParse.BitFields.get_bitfield_zero",
"Prims.op_GreaterThan",
"Prims.op_Subtraction",
"LowParse.BitFields.bitfield",
"LowParse.Spec.BitSum.get_bitfield_synth_bitsum'_recip'_other",
"Prims.unit",
"LowParse.BitFields.get_bitfield_set_bitfield_other",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.Spec.BitSum.synth_bitsum'_recip'",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Enum.enum_repr_of_key",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'",
"Prims.l_True",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat{bitsum'_size <= lo /\ lo <= hi /\ hi <= tot})
: Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size)) | [
"recursion"
] | LowParse.Spec.BitSum.get_bitfield_synth_bitsum'_recip'_other | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
x: LowParse.Spec.BitSum.bitsum'_type b ->
lo: Prims.nat ->
hi: Prims.nat{bitsum'_size <= lo /\ lo <= hi /\ hi <= tot}
-> FStar.Pervasives.Lemma
(ensures
Mkuint_t?.v cl
(Mkuint_t?.get_bitfield cl (LowParse.Spec.BitSum.synth_bitsum'_recip' b x) lo hi) ==
0) (decreases bitsum'_size) | {
"end_col": 64,
"end_line": 418,
"start_col": 2,
"start_line": 408
} |
Prims.Tot | val weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
: Tot (k: parser_kind{forall (x: bitsum'_key_type b). k `is_weaker_than` (dfst (f x))}) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k | val weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
: Tot (k: parser_kind{forall (x: bitsum'_key_type b). k `is_weaker_than` (dfst (f x))})
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
: Tot (k: parser_kind{forall (x: bitsum'_key_type b). k `is_weaker_than` (dfst (f x))}) = | false | null | false | let (| k , phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_key_type",
"Prims.dtuple2",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"LowParse.Spec.Base.is_weaker_than",
"FStar.Pervasives.dfst",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Classical.forall_intro",
"Prims.l_Forall",
"LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
: Tot (k: parser_kind{forall (x: bitsum'_key_type b). k `is_weaker_than` (dfst (f x))}) | [] | LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
f:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k -> LowParse.Spec.Base.parser k (type_of_tag x)))
-> k:
LowParse.Spec.Base.parser_kind
{ forall (x: LowParse.Spec.BitSum.bitsum'_key_type b).
LowParse.Spec.Base.is_weaker_than k (FStar.Pervasives.dfst (f x)) } | {
"end_col": 3,
"end_line": 725,
"start_col": 1,
"start_line": 723
} |
FStar.Pervasives.Lemma | val synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl | val synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size)
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = | false | null | true | match b with
| BitStop _ -> ()
| BitField sz rest ->
let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) ==
cl.uint_to_t (cl.v hd));
BF.get_bitfield_set_bitfield_other (cl.v y1)
(bitsum'_size - sz)
(bitsum'_size)
(cl.v hd)
0
(bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k , tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
BF.get_bitfield_set_bitfield_same (cl.v y1)
(bitsum'_size - key_size)
(bitsum'_size)
(cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) ==
cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
BF.get_bitfield_set_bitfield_other (cl.v y1)
(bitsum'_size - key_size)
bitsum'_size
(cl.v (enum_repr_of_key e k))
0
(bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1;
synth_bitsum'_recip_inverse' (payload k) tl | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.BitFields.bitfield",
"LowParse.Spec.BitSum.synth_bitsum'_recip_inverse'",
"Prims.unit",
"LowParse.Spec.BitSum.synth_bitsum'_ext",
"LowParse.Spec.BitSum.filter_bitsum'_ext",
"LowParse.BitFields.get_bitfield_set_bitfield_other",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"Prims._assert",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"LowParse.BitFields.get_bitfield_set_bitfield_same",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Enum.enum_repr_of_key",
"LowParse.Spec.Enum.enum_key_of_repr_of_key",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'",
"Prims.l_True",
"LowParse.Spec.BitSum.synth_bitsum'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) | [
"recursion"
] | LowParse.Spec.BitSum.synth_bitsum'_recip_inverse' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.BitSum.bitsum'_type b
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.BitSum.synth_bitsum' b (LowParse.Spec.BitSum.synth_bitsum'_recip b x) == x)
(decreases bitsum'_size) | {
"end_col": 47,
"end_line": 537,
"start_col": 2,
"start_line": 511
} |
FStar.Pervasives.Lemma | val synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma (synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
) | val synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma (synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))]
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma (synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] = | false | null | true | synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y -> synth_case.f_g_eq x y) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"LowParse.Spec.Combinators.synth_inverse_intro'",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f",
"LowParse.Spec.BitSum.__proj__SynthCase__item__g",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f_g_eq",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"LowParse.Spec.Combinators.synth_inverse",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma (synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] | [] | LowParse.Spec.BitSum.synth_bitsum_case_recip_inverse | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
x: LowParse.Spec.BitSum.bitsum'_type b
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Combinators.synth_inverse (SynthCase?.f synth_case x)
(SynthCase?.g synth_case x))
[
SMTPat (LowParse.Spec.Combinators.synth_inverse (SynthCase?.f synth_case x)
(SynthCase?.g synth_case x))
] | {
"end_col": 3,
"end_line": 892,
"start_col": 2,
"start_line": 890
} |
FStar.Pervasives.Lemma | val synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma (synth_injective (synth_case.f x)) [SMTPat (synth_injective (synth_case.f x))] | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
) | val synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma (synth_injective (synth_case.f x)) [SMTPat (synth_injective (synth_case.f x))]
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma (synth_injective (synth_case.f x)) [SMTPat (synth_injective (synth_case.f x))] = | false | null | true | synth_injective_intro' (synth_case.f x) (fun y z -> synth_case.f_inj x y z) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"LowParse.Spec.Combinators.synth_injective_intro'",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f_inj",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"LowParse.Spec.Combinators.synth_injective",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma (synth_injective (synth_case.f x)) [SMTPat (synth_injective (synth_case.f x))] | [] | LowParse.Spec.BitSum.synth_bitsum_case_injective | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
x: LowParse.Spec.BitSum.bitsum'_type b
-> FStar.Pervasives.Lemma
(ensures LowParse.Spec.Combinators.synth_injective (SynthCase?.f synth_case x))
[SMTPat (LowParse.Spec.Combinators.synth_injective (SynthCase?.f synth_case x))] | {
"end_col": 3,
"end_line": 742,
"start_col": 2,
"start_line": 740
} |
Prims.GTot | val serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload | val serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes = | false | null | false | let k = bitsum'_key_of_t b tg in
(serialize s (synth_bitsum'_recip b tg)) `Seq.append` (serialize (g k) payload) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"sometrivial"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.dtuple2",
"Prims.__proj__Mkdtuple2__item___1",
"FStar.Pervasives.dsnd",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"FStar.Seq.Base.append",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"LowParse.Bytes.bytes"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes | [] | LowParse.Spec.BitSum.serialize_bitsum_alt_2 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind kt ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } ->
g:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) ->
tg: LowParse.Spec.BitSum.bitsum'_type b ->
payload: type_of_tag (LowParse.Spec.BitSum.bitsum'_key_of_t b tg)
-> Prims.GTot LowParse.Bytes.bytes | {
"end_col": 77,
"end_line": 1046,
"start_col": 1,
"start_line": 1045
} |
FStar.Pervasives.Lemma | val serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x ==
serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x | val serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x ==
serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x ==
serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x) = | false | null | true | serialize_tagged_union_eq #(parse_filter_kind kt) #(bitsum'_type b) #(parse_bitsum' b p)
(serialize_bitsum' b s) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g) x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _ , p |) = f k in
serialize_synth_eq #_ #(type_of_tag k) p (synth_case.f tg) (g k) (synth_case.g tg) () x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.dtuple2",
"Prims.__proj__Mkdtuple2__item___1",
"FStar.Pervasives.dsnd",
"LowParse.Spec.Combinators.serialize_synth_eq",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f",
"LowParse.Spec.BitSum.__proj__SynthCase__item__g",
"Prims.unit",
"LowParse.Spec.BitSum.serialize_bitsum'_eq",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.Spec.Combinators.serialize_tagged_union_eq",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.BitSum.parse_bitsum'",
"LowParse.Spec.BitSum.serialize_bitsum'",
"LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind",
"LowParse.Spec.BitSum.parse_bitsum_cases",
"LowParse.Spec.BitSum.serialize_bitsum_cases",
"Prims.l_True",
"Prims.squash",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.BitSum.parse_bitsum_kind",
"LowParse.Spec.BitSum.parse_bitsum",
"LowParse.Spec.BitSum.serialize_bitsum",
"LowParse.Spec.BitSum.serialize_bitsum_alt",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x ==
serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x) | [] | LowParse.Spec.BitSum.serialize_bitsum_eq | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind kt ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } ->
g:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) ->
x: data
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Base.serialize (LowParse.Spec.BitSum.serialize_bitsum b
tag_of_data
type_of_tag
synth_case
s
g)
x ==
LowParse.Spec.BitSum.serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x) | {
"end_col": 5,
"end_line": 1007,
"start_col": 2,
"start_line": 984
} |
Prims.GTot | val is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool
= match b with
| BitStop _ -> false
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then true
else is_valid_bitfield rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield (payload k') r' low high | val is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool
let rec is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool = | false | null | false | match b with
| BitStop _ -> false
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then true
else is_valid_bitfield rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k' , r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield (payload k') r' low high | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_key_type",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.op_Addition",
"Prims.bool",
"LowParse.Spec.BitSum.is_valid_bitfield",
"LowParse.Spec.BitSum.bitsum'_key_type_elim_BitField",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"Prims.dtuple2",
"LowParse.Spec.BitSum.bitsum'_key_type_elim_BitSum'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl
inline_for_extraction
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim ()
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
if k' = k
then begin
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
end else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
in
destr_tail (k' <: key) rest
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` ((k, r) :: []) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` []
})
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: []))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let]
let _ : squash (k' = k) =
if (k' = k)
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
end
in
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
[@filter_bitsum'_t_attr]
noextract
let rec mk_synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (synth_bitsum'_recip_t b)
(decreases %[b;1;()])
= match b with
| BitStop _ -> synth_bitsum'_recip_BitStop cl
| BitField sz rest -> synth_bitsum'_recip_BitField cl bitsum'_size sz rest (mk_synth_bitsum'_recip rest)
| BitSum' key key_size e payload ->
synth_bitsum'_recip_BitSum_intro cl bitsum'_size key key_size e payload (mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload [] e)
and mk_synth_bitsum'_recip_BitSum
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
synth_bitsum'_recip_BitSum_nil cl bitsum'_size key key_size e payload l1
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
synth_bitsum'_recip_BitSum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_synth_bitsum'_recip (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
synth_bitsum'_recip_BitSum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_synth_bitsum'_recip (payload k))
(mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Mutating a bitfield within a bitsum value *)
let rec is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool | [
"recursion"
] | LowParse.Spec.BitSum.is_valid_bitfield | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
k: LowParse.Spec.BitSum.bitsum'_key_type b ->
low: Prims.nat ->
high: Prims.nat
-> Prims.GTot Prims.bool | {
"end_col": 46,
"end_line": 1804,
"start_col": 2,
"start_line": 1796
} |
Prims.Tot | val filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e []) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false) | val filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e []) = | false | null | false | (fun x xr -> false) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"Prims.squash",
"Prims.eq2",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.List.Tot.Base.append",
"Prims.Nil",
"Prims.l_not",
"LowParse.Spec.Enum.list_mem",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"LowParse.Spec.Enum.list_map",
"FStar.Pervasives.Native.snd",
"LowParse.BitFields.__proj__Mkuint_t__item__bitfield_eq_lhs",
"Prims.bool",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.BitSum'",
"LowParse.Spec.BitSum.filter_bitsum'_bitsum'_t"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` [])) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e []) | [] | LowParse.Spec.BitSum.filter_bitsum'_bitsum'_nil | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
h: Prims.squash (e == e @ [])
-> LowParse.Spec.BitSum.filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [] | {
"end_col": 21,
"end_line": 1171,
"start_col": 2,
"start_line": 1171
} |
Prims.Tot | val synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd | val synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest)) = | false | null | false | fun x ->
[@@ inline_let ]let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.synth_bitsum'_recip_t",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.BitField",
"LowParse.BitFields.bitfield",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield",
"Prims.eq2",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest)) | [] | LowParse.Spec.BitSum.synth_bitsum'_recip_BitField | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
sz: Prims.nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot} ->
rest: LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - sz) ->
ih: LowParse.Spec.BitSum.synth_bitsum'_recip_t rest
-> LowParse.Spec.BitSum.synth_bitsum'_recip_t (LowParse.Spec.BitSum.BitField sz rest) | {
"end_col": 63,
"end_line": 1576,
"start_col": 2,
"start_line": 1573
} |
FStar.Pervasives.Lemma | val is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma (requires (is_valid_bitfield b k low high))
(ensures (low <= high /\ high <= bitsum'_size))
[SMTPat (is_valid_bitfield b k low high)] | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma
(requires (is_valid_bitfield b k low high))
(ensures (
low <= high /\ high <= bitsum'_size
))
[SMTPat (is_valid_bitfield b k low high)]
= match b with
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then ()
else is_valid_bitfield_prop rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield_prop (payload k') r' low high | val is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma (requires (is_valid_bitfield b k low high))
(ensures (low <= high /\ high <= bitsum'_size))
[SMTPat (is_valid_bitfield b k low high)]
let rec is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma (requires (is_valid_bitfield b k low high))
(ensures (low <= high /\ high <= bitsum'_size))
[SMTPat (is_valid_bitfield b k low high)] = | false | null | true | match b with
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then ()
else
is_valid_bitfield_prop rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k' , r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield_prop (payload k') r' low high | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_key_type",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Prims.bool",
"LowParse.Spec.BitSum.is_valid_bitfield_prop",
"LowParse.Spec.BitSum.bitsum'_key_type_elim_BitField",
"Prims.unit",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"Prims.dtuple2",
"LowParse.Spec.BitSum.bitsum'_key_type_elim_BitSum'",
"LowParse.Spec.BitSum.is_valid_bitfield",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl
inline_for_extraction
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim ()
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
if k' = k
then begin
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
end else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
in
destr_tail (k' <: key) rest
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` ((k, r) :: []) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` []
})
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: []))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let]
let _ : squash (k' = k) =
if (k' = k)
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
end
in
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
[@filter_bitsum'_t_attr]
noextract
let rec mk_synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (synth_bitsum'_recip_t b)
(decreases %[b;1;()])
= match b with
| BitStop _ -> synth_bitsum'_recip_BitStop cl
| BitField sz rest -> synth_bitsum'_recip_BitField cl bitsum'_size sz rest (mk_synth_bitsum'_recip rest)
| BitSum' key key_size e payload ->
synth_bitsum'_recip_BitSum_intro cl bitsum'_size key key_size e payload (mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload [] e)
and mk_synth_bitsum'_recip_BitSum
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
synth_bitsum'_recip_BitSum_nil cl bitsum'_size key key_size e payload l1
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
synth_bitsum'_recip_BitSum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_synth_bitsum'_recip (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
synth_bitsum'_recip_BitSum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_synth_bitsum'_recip (payload k))
(mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Mutating a bitfield within a bitsum value *)
let rec is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool
= match b with
| BitStop _ -> false
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then true
else is_valid_bitfield rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield (payload k') r' low high
let rec is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma
(requires (is_valid_bitfield b k low high))
(ensures (
low <= high /\ high <= bitsum'_size
)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma (requires (is_valid_bitfield b k low high))
(ensures (low <= high /\ high <= bitsum'_size))
[SMTPat (is_valid_bitfield b k low high)] | [
"recursion"
] | LowParse.Spec.BitSum.is_valid_bitfield_prop | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
k: LowParse.Spec.BitSum.bitsum'_key_type b ->
low: Prims.nat ->
high: Prims.nat
-> FStar.Pervasives.Lemma (requires LowParse.Spec.BitSum.is_valid_bitfield b k low high)
(ensures low <= high /\ high <= bitsum'_size)
[SMTPat (LowParse.Spec.BitSum.is_valid_bitfield b k low high)] | {
"end_col": 51,
"end_line": 1827,
"start_col": 2,
"start_line": 1820
} |
FStar.Pervasives.Lemma | val filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)
) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else () | val filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)
) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size))
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)
) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = | false | null | true | match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f:bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g:bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) ==
BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.filter_bitsum'_ext",
"Prims.unit",
"LowParse.BitFields.get_bitfield_get_bitfield",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Enum.list_mem",
"LowParse.Spec.Enum.list_map",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.snd",
"LowParse.Spec.Enum.enum_key_of_repr",
"Prims.bool",
"Prims._assert",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"FStar.UInt.uint_t",
"LowParse.BitFields.get_bitfield",
"LowParse.BitFields.ubitfield",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"LowParse.Spec.BitSum.filter_bitsum'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 64,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)
) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) | [
"recursion"
] | LowParse.Spec.BitSum.filter_bitsum'_ext | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: t -> y: t
-> FStar.Pervasives.Lemma
(requires
LowParse.BitFields.get_bitfield (Mkuint_t?.v cl x) 0 bitsum'_size ==
LowParse.BitFields.get_bitfield (Mkuint_t?.v cl y) 0 bitsum'_size)
(ensures LowParse.Spec.BitSum.filter_bitsum' b x == LowParse.Spec.BitSum.filter_bitsum' b y)
(decreases bitsum'_size) | {
"end_col": 15,
"end_line": 457,
"start_col": 2,
"start_line": 435
} |
Prims.Tot | val synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(repr_of: (k: enum_key e -> Tot (r: enum_repr e {r == enum_repr_of_key e k})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: (k: enum_key e -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k) | val synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(repr_of: (k: enum_key e -> Tot (r: enum_repr e {r == enum_repr_of_key e k})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: (k: enum_key e -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(repr_of: (k: enum_key e -> Tot (r: enum_repr e {r == enum_repr_of_key e k})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: (k: enum_key e -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload)) = | false | null | false | fun x ->
[@@ inline_let ]let (| k , pl |) =
bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x
in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Enum.enum_repr",
"Prims.eq2",
"LowParse.Spec.Enum.enum_repr_of_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.synth_bitsum'_recip_t",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.BitSum'",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k)))) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(repr_of: (k: enum_key e -> Tot (r: enum_repr e {r == enum_repr_of_key e k})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: (k: enum_key e -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload)) | [] | LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_gen | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
repr_of:
(k: LowParse.Spec.Enum.enum_key e
-> r: LowParse.Spec.Enum.enum_repr e {r == LowParse.Spec.Enum.enum_repr_of_key e k}) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
synth_payload:
(k: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.synth_bitsum'_recip_t (payload k))
-> LowParse.Spec.BitSum.synth_bitsum'_recip_t (LowParse.Spec.BitSum.BitSum' key key_size e payload
) | {
"end_col": 91,
"end_line": 1597,
"start_col": 2,
"start_line": 1594
} |
Prims.Tot | val serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x)) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
()) | val serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x)) = | false | null | false | let tg = bitsum'_key_of_t b x in
let (| _ , p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x;
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x;
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth p (synth_case.f x) (g tg) (synth_case.g x) ()) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"Prims.dtuple2",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.__proj__Mkdtuple2__item___1",
"FStar.Pervasives.dsnd",
"LowParse.Spec.Combinators.serialize_weaken",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f",
"LowParse.Spec.Combinators.serialize_synth",
"LowParse.Spec.BitSum.__proj__SynthCase__item__g",
"Prims.unit",
"LowParse.Spec.BitSum.synth_bitsum_case_recip_inverse",
"LowParse.Spec.BitSum.synth_bitsum_case_injective",
"LowParse.Spec.BitSum.parse_bitsum_cases",
"LowParse.Spec.BitSum.bitsum'_key_of_t"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x)) | [] | LowParse.Spec.BitSum.serialize_bitsum_cases | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
g:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) ->
x: LowParse.Spec.BitSum.bitsum'_type b
-> LowParse.Spec.Base.serializer (LowParse.Spec.BitSum.parse_bitsum_cases b
tag_of_data
type_of_tag
synth_case
f
x) | {
"end_col": 9,
"end_line": 917,
"start_col": 1,
"start_line": 907
} |
Prims.Tot | val destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) {e == l1 `L.append` l2})
: Tot (Type u#(a + 1)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x)) | val destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) {e == l1 `L.append` l2})
: Tot (Type u#(a + 1))
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) {e == l1 `L.append` l2})
: Tot (Type u#(a + 1)) = | false | null | false |
u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a)) ->
u_if:
(x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))
-> Tot (if_combinator_weak (u (Ghost.reveal x)))) ->
f: (x: bitsum'_type (BitSum' key key_size e payload) -> Tot (u x)) ->
x:
parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload))
{ ~(list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size
<:
bitfield cl key_size)
(list_map snd l1)) }
-> Tot (u (synth_bitsum' (BitSum' key key_size e payload) x)) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.eq2",
"FStar.List.Tot.Base.append",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.BitSum'",
"FStar.Ghost.erased",
"LowParse.Spec.BitSum.if_combinator_weak",
"FStar.Ghost.reveal",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'",
"Prims.l_not",
"LowParse.Spec.Enum.list_mem",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"LowParse.Spec.Enum.list_map",
"FStar.Pervasives.Native.snd",
"LowParse.Spec.BitSum.synth_bitsum'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) {e == l1 `L.append` l2})
: Tot (Type u#(a + 1)) | [] | LowParse.Spec.BitSum.destr_bitsum'_bitsum_t | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
l1: Prims.list (key * LowParse.BitFields.bitfield cl key_size) ->
l2: Prims.list (key * LowParse.BitFields.bitfield cl key_size) {e == l1 @ l2}
-> Type | {
"end_col": 60,
"end_line": 1370,
"start_col": 2,
"start_line": 1366
} |
FStar.Pervasives.Lemma | val synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma (requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | val synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma (requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma (requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size)) = | false | null | true | match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) ==
cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) ==
cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) ==
cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) ==
cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f:bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g:bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) ==
cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims._assert",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"Prims.unit",
"LowParse.BitFields.get_bitfield_empty",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.BitFields.get_bitfield_partition",
"Prims.Cons",
"Prims.Nil",
"FStar.UInt.uint_t",
"LowParse.Spec.BitSum.synth_bitsum'_injective'",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Enum.enum_repr_of_key_of_repr",
"LowParse.Spec.Enum.enum_key_of_repr",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.synth_bitsum'",
"Prims.l_or",
"LowParse.BitFields.get_bitfield",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma (requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size)) | [
"recursion"
] | LowParse.Spec.BitSum.synth_bitsum'_injective' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
x: LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitSum.filter_bitsum' b) ->
y: LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitSum.filter_bitsum' b)
-> FStar.Pervasives.Lemma
(requires LowParse.Spec.BitSum.synth_bitsum' b x == LowParse.Spec.BitSum.synth_bitsum' b y)
(ensures
Mkuint_t?.get_bitfield cl x 0 bitsum'_size == Mkuint_t?.get_bitfield cl y 0 bitsum'_size)
(decreases bitsum'_size) | {
"end_col": 125,
"end_line": 296,
"start_col": 2,
"start_line": 276
} |
Prims.Tot | val synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x | val synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b)) = | false | null | false | synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.synth_bitsum'_recip'",
"Prims.unit",
"LowParse.Spec.BitSum.synth_bitsum'_recip'_prop",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b)) | [] | LowParse.Spec.BitSum.synth_bitsum'_recip | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.BitSum.bitsum'_type b
-> LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitSum.filter_bitsum' b) | {
"end_col": 26,
"end_line": 497,
"start_col": 2,
"start_line": 496
} |
FStar.Pervasives.Lemma | val parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x ==
(match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2)
else None)) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x | val parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x ==
(match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2)
else None))
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x ==
(match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2)
else None)) = | false | null | true | parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` (filter_bitsum' b)) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"LowParse.Spec.Base.parser",
"Prims.dtuple2",
"LowParse.Bytes.bytes",
"LowParse.Spec.Combinators.parse_filter_eq",
"LowParse.Spec.BitSum.filter_bitsum'",
"Prims.unit",
"LowParse.Spec.Combinators.parse_synth_eq",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.BitSum.synth_bitsum'",
"LowParse.Spec.BitSum.synth_bitsum'_injective",
"LowParse.Spec.BitSum.parse_bitsum_eq",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowParse.Spec.BitSum.parse_bitsum",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.dsnd",
"FStar.Seq.Base.slice",
"LowParse.Bytes.byte",
"FStar.Seq.Base.length",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f",
"Prims.op_Addition",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"Prims.bool",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x ==
(match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2)
else None)) | [] | LowParse.Spec.BitSum.parse_bitsum_eq' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
p: LowParse.Spec.Base.parser kt t ->
f:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k -> LowParse.Spec.Base.parser k (type_of_tag x))) ->
x: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Base.parse (LowParse.Spec.BitSum.parse_bitsum b
tag_of_data
type_of_tag
synth_case
p
f)
x ==
(match LowParse.Spec.Base.parse p x with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ tg' consumed1) ->
(match LowParse.Spec.BitSum.filter_bitsum' b tg' with
| true ->
let tg = LowParse.Spec.BitSum.synth_bitsum' b tg' in
let k = LowParse.Spec.BitSum.bitsum'_key_of_t b tg in
(match
LowParse.Spec.Base.parse (FStar.Pervasives.dsnd (f k))
(FStar.Seq.Base.slice x consumed1 (FStar.Seq.Base.length x))
with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some
#_
(FStar.Pervasives.Native.Mktuple2 #_ #_ y consumed2) ->
FStar.Pervasives.Native.Some (SynthCase?.f synth_case tg y, consumed1 + consumed2)
)
<:
FStar.Pervasives.Native.option (data * LowParse.Spec.Base.consumed_length x)
| _ -> FStar.Pervasives.Native.None)
<:
FStar.Pervasives.Native.option (data * LowParse.Spec.Base.consumed_length x))) | {
"end_col": 40,
"end_line": 875,
"start_col": 2,
"start_line": 872
} |
FStar.Pervasives.Lemma | val synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
) | val synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) = | false | null | true | synth_inverse_intro' (synth_bitsum' b)
(synth_bitsum'_recip b)
(fun x -> synth_bitsum'_recip_inverse' b x) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.Combinators.synth_inverse_intro'",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.synth_bitsum'",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"LowParse.Spec.BitSum.synth_bitsum'_recip_inverse'",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"LowParse.Spec.Combinators.synth_inverse",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) | [] | LowParse.Spec.BitSum.synth_bitsum'_recip_inverse | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Combinators.synth_inverse (LowParse.Spec.BitSum.synth_bitsum' b)
(LowParse.Spec.BitSum.synth_bitsum'_recip b)) | {
"end_col": 3,
"end_line": 552,
"start_col": 2,
"start_line": 550
} |
FStar.Pervasives.Lemma | val parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x ==
(match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2))) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x)) | val parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x ==
(match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2)))
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x ==
(match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2))) = | false | null | true | parse_tagged_union_eq #(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq (dsnd (f k)) (synth_case.f tg) (Seq.slice x consumed1 (Seq.length x)) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"LowParse.Spec.Base.parser",
"Prims.dtuple2",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse",
"LowParse.Spec.BitSum.parse_bitsum'",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Combinators.parse_synth_eq",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.refine_with_tag",
"FStar.Pervasives.dsnd",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f",
"FStar.Seq.Base.slice",
"LowParse.Bytes.byte",
"FStar.Seq.Base.length",
"Prims.unit",
"LowParse.Spec.BitSum.synth_bitsum_case_injective",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.Spec.Combinators.parse_tagged_union_eq",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind",
"LowParse.Spec.BitSum.parse_bitsum_cases",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.BitSum.parse_bitsum",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Addition",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x ==
(match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2))) | [] | LowParse.Spec.BitSum.parse_bitsum_eq | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
p: LowParse.Spec.Base.parser kt t ->
f:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k -> LowParse.Spec.Base.parser k (type_of_tag x))) ->
x: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Base.parse (LowParse.Spec.BitSum.parse_bitsum b
tag_of_data
type_of_tag
synth_case
p
f)
x ==
(match LowParse.Spec.Base.parse (LowParse.Spec.BitSum.parse_bitsum' b p) x with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ tg consumed1) ->
let k = LowParse.Spec.BitSum.bitsum'_key_of_t b tg in
(match
LowParse.Spec.Base.parse (FStar.Pervasives.dsnd (f k))
(FStar.Seq.Base.slice x consumed1 (FStar.Seq.Base.length x))
with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ y consumed2) ->
FStar.Pervasives.Native.Some (SynthCase?.f synth_case tg y, consumed1 + consumed2))
<:
FStar.Pervasives.Native.option (data * LowParse.Spec.Base.consumed_length x))) | {
"end_col": 44,
"end_line": 839,
"start_col": 2,
"start_line": 822
} |
Prims.Tot | val weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b -> Tot parser_kind))
: Tot (k': parser_kind & (x: bitsum'_key_type b -> Lemma (k' `is_weaker_than` (f x))))
(decreases (bitsum'_size)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |) | val weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b -> Tot parser_kind))
: Tot (k': parser_kind & (x: bitsum'_key_type b -> Lemma (k' `is_weaker_than` (f x))))
(decreases (bitsum'_size))
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b -> Tot parser_kind))
: Tot (k': parser_kind & (x: bitsum'_key_type b -> Lemma (k' `is_weaker_than` (f x))))
(decreases (bitsum'_size)) = | false | null | false | match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g , phi |) =
weaken_parse_bitsum_cases_kind' rest
(fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x))
in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys:list key = List.Tot.map fst e in
let phi (x: key)
: Tot
(k: parser_kind &
(y: bitsum'_key_type b
-> Lemma
(requires
(dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) ==
x)) (ensures (k `is_weaker_than` (f y))))) =
if List.Tot.mem x keys
then
let (| k , g |) =
weaken_parse_bitsum_cases_kind' (payload x)
(fun z ->
f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |)))
in
(|
k,
(fun y ->
let (| y1 , y2 |) =
bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y
in
assert (y1 == x);
g y2)
|)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(|
k,
(fun y ->
let (| y1 , y2 |) =
bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y
in
dsnd (phi y1) y)
|) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total",
""
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.Base.parser_kind",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.Mkdtuple2",
"Prims.unit",
"Prims.l_True",
"LowParse.Spec.Base.is_weaker_than",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.bitsum'_key_type_intro_BitField",
"LowParse.Spec.BitSum.BitField",
"LowParse.Spec.BitSum.bitsum'_key_type_elim_BitField",
"Prims.dtuple2",
"LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind'",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.BitSum'",
"FStar.Pervasives.dsnd",
"FStar.Pervasives.dfst",
"LowParse.Spec.BitSum.bitsum'_key_type_elim_BitSum'",
"LowParse.Spec.Base.glb_list_of",
"FStar.List.Tot.Base.mem",
"LowParse.Spec.BitSum.bitsum'_key_type_intro_BitSum'",
"Prims._assert",
"Prims.bool",
"LowParse.Spec.Base.default_parser_kind",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x))) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b -> Tot parser_kind))
: Tot (k': parser_kind & (x: bitsum'_key_type b -> Lemma (k' `is_weaker_than` (f x))))
(decreases (bitsum'_size)) | [
"recursion"
] | LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
f: (x: LowParse.Spec.BitSum.bitsum'_key_type b -> LowParse.Spec.Base.parser_kind)
-> Prims.Tot
(Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k' ->
x: LowParse.Spec.BitSum.bitsum'_key_type b
-> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.is_weaker_than k' (f x)))) | {
"end_col": 8,
"end_line": 713,
"start_col": 2,
"start_line": 689
} |
Prims.Tot | val id (#t: Type) (x: t) : Tot t | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let id
(#t: Type)
(x: t)
: Tot t
= x | val id (#t: Type) (x: t) : Tot t
let id (#t: Type) (x: t) : Tot t = | false | null | false | x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val id (#t: Type) (x: t) : Tot t | [] | LowParse.Spec.BitSum.id | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | x: t -> t | {
"end_col": 3,
"end_line": 621,
"start_col": 2,
"start_line": 621
} |
Prims.Tot | val bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype (decreases (bitsum'_size)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key)) | val bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype (decreases (bitsum'_size))
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype (decreases (bitsum'_size)) = | false | null | false | match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total",
""
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"Prims.dtuple2"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype (decreases (bitsum'_size)) | [
"recursion"
] | LowParse.Spec.BitSum.bitsum'_key_type | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> Prims.Tot Prims.eqtype | {
"end_col": 54,
"end_line": 150,
"start_col": 2,
"start_line": 146
} |
Prims.Tot | val bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x | val bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest) = | false | null | false | x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.BitField",
"LowParse.Spec.BitSum.bitsum'_type_bitfield"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest) | [] | LowParse.Spec.BitSum.bitsum'_type_elim_BitField | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
sz: Prims.nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot} ->
rest: LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - sz) ->
x: LowParse.Spec.BitSum.bitsum'_type (LowParse.Spec.BitSum.BitField sz rest)
-> LowParse.Spec.BitSum.bitsum'_type_bitfield bitsum'_size sz rest | {
"end_col": 3,
"end_line": 122,
"start_col": 2,
"start_line": 122
} |
Prims.Tot | val bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x | val bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = | false | null | false | x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.BitSum'",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) | [] | LowParse.Spec.BitSum.bitsum'_type_elim_BitSum' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
x: LowParse.Spec.BitSum.bitsum'_type (LowParse.Spec.BitSum.BitSum' key key_size e payload)
-> LowParse.Spec.BitSum.bitsum'_type_bitsum' cl bitsum'_size key key_size e payload | {
"end_col": 3,
"end_line": 94,
"start_col": 2,
"start_line": 94
} |
Prims.Tot | val get_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
: Tot (bitfield cl (high - low)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec get_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Tot (bitfield cl (high - low))
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then hd
else get_valid_bitfield rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield (payload k') r' low high | val get_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
: Tot (bitfield cl (high - low))
let rec get_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
: Tot (bitfield cl (high - low)) = | false | null | false | match b with
| BitField sz rest ->
let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size then hd else get_valid_bitfield rest tl low high
| BitSum' key key_size e payload ->
let (| k' , r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield (payload k') r' low high | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.b2t",
"LowParse.Spec.BitSum.is_valid_bitfield",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"Prims.l_and",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.BitFields.bitfield",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Prims.bool",
"LowParse.Spec.BitSum.get_valid_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl
inline_for_extraction
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim ()
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
if k' = k
then begin
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
end else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
in
destr_tail (k' <: key) rest
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` ((k, r) :: []) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` []
})
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: []))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let]
let _ : squash (k' = k) =
if (k' = k)
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
end
in
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
[@filter_bitsum'_t_attr]
noextract
let rec mk_synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (synth_bitsum'_recip_t b)
(decreases %[b;1;()])
= match b with
| BitStop _ -> synth_bitsum'_recip_BitStop cl
| BitField sz rest -> synth_bitsum'_recip_BitField cl bitsum'_size sz rest (mk_synth_bitsum'_recip rest)
| BitSum' key key_size e payload ->
synth_bitsum'_recip_BitSum_intro cl bitsum'_size key key_size e payload (mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload [] e)
and mk_synth_bitsum'_recip_BitSum
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
synth_bitsum'_recip_BitSum_nil cl bitsum'_size key key_size e payload l1
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
synth_bitsum'_recip_BitSum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_synth_bitsum'_recip (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
synth_bitsum'_recip_BitSum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_synth_bitsum'_recip (payload k))
(mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Mutating a bitfield within a bitsum value *)
let rec is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool
= match b with
| BitStop _ -> false
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then true
else is_valid_bitfield rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield (payload k') r' low high
let rec is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma
(requires (is_valid_bitfield b k low high))
(ensures (
low <= high /\ high <= bitsum'_size
))
[SMTPat (is_valid_bitfield b k low high)]
= match b with
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then ()
else is_valid_bitfield_prop rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield_prop (payload k') r' low high
let rec get_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high }) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
: Tot (bitfield cl (high - low)) | [
"recursion"
] | LowParse.Spec.BitSum.get_valid_bitfield | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
k: LowParse.Spec.BitSum.bitsum'_type b ->
low: Prims.nat ->
high:
Prims.nat
{ LowParse.Spec.BitSum.is_valid_bitfield b
(LowParse.Spec.BitSum.bitsum'_key_of_t b k)
low
high }
-> LowParse.BitFields.bitfield cl (high - low) | {
"end_col": 47,
"end_line": 1847,
"start_col": 2,
"start_line": 1839
} |
Prims.Pure | val coerce (t2 #t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2) | val coerce (t2 #t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True))
let coerce (t2 #t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = | false | null | false | (x <: t2) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [] | [
"Prims.eq2",
"Prims.l_True"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val coerce (t2 #t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) | [] | LowParse.Spec.BitSum.coerce | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | t2: Type -> x: t1 -> Prims.Pure t2 | {
"end_col": 11,
"end_line": 192,
"start_col": 2,
"start_line": 192
} |
Prims.Tot | val bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x | val bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload)) = | false | null | false | x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"Prims.dtuple2",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.BitSum'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k'))) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload)) | [] | LowParse.Spec.BitSum.bitsum'_key_type_intro_BitSum' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
x:
Prims.dtuple2 (LowParse.Spec.Enum.enum_key e)
(fun k' -> LowParse.Spec.BitSum.bitsum'_key_type (payload k'))
-> LowParse.Spec.BitSum.bitsum'_key_type (LowParse.Spec.BitSum.BitSum' key key_size e payload) | {
"end_col": 3,
"end_line": 180,
"start_col": 2,
"start_line": 180
} |
Prims.Tot | val set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Tot (bitsum'_type b) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Tot (bitsum'_type b)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
bitsum'_type_intro_BitField cl bitsum'_size sz rest
begin if low + sz = high && high = bitsum'_size
then (v, tl)
else (hd, set_valid_bitfield rest tl low high v)
end
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k' , set_valid_bitfield (payload k') r' low high v |) | val set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Tot (bitsum'_type b)
let rec set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Tot (bitsum'_type b) = | false | null | false | match b with
| BitField sz rest ->
let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
bitsum'_type_intro_BitField cl
bitsum'_size
sz
rest
(if low + sz = high && high = bitsum'_size
then (v, tl)
else (hd, set_valid_bitfield rest tl low high v))
| BitSum' key key_size e payload ->
let (| k' , r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
bitsum'_type_intro_BitSum' cl
bitsum'_size
key
key_size
e
payload
(| k', set_valid_bitfield (payload k') r' low high v |) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.b2t",
"LowParse.Spec.BitSum.is_valid_bitfield",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.BitFields.bitfield",
"Prims.op_Subtraction",
"Prims.l_and",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.BitSum.bitsum'_type_intro_BitField",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"LowParse.Spec.BitSum.set_valid_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'_type_intro_BitSum'",
"Prims.Mkdtuple2",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl
inline_for_extraction
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim ()
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
if k' = k
then begin
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
end else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
in
destr_tail (k' <: key) rest
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` ((k, r) :: []) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` []
})
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: []))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let]
let _ : squash (k' = k) =
if (k' = k)
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
end
in
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
[@filter_bitsum'_t_attr]
noextract
let rec mk_synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (synth_bitsum'_recip_t b)
(decreases %[b;1;()])
= match b with
| BitStop _ -> synth_bitsum'_recip_BitStop cl
| BitField sz rest -> synth_bitsum'_recip_BitField cl bitsum'_size sz rest (mk_synth_bitsum'_recip rest)
| BitSum' key key_size e payload ->
synth_bitsum'_recip_BitSum_intro cl bitsum'_size key key_size e payload (mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload [] e)
and mk_synth_bitsum'_recip_BitSum
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
synth_bitsum'_recip_BitSum_nil cl bitsum'_size key key_size e payload l1
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
synth_bitsum'_recip_BitSum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_synth_bitsum'_recip (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
synth_bitsum'_recip_BitSum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_synth_bitsum'_recip (payload k))
(mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Mutating a bitfield within a bitsum value *)
let rec is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool
= match b with
| BitStop _ -> false
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then true
else is_valid_bitfield rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield (payload k') r' low high
let rec is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma
(requires (is_valid_bitfield b k low high))
(ensures (
low <= high /\ high <= bitsum'_size
))
[SMTPat (is_valid_bitfield b k low high)]
= match b with
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then ()
else is_valid_bitfield_prop rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield_prop (payload k') r' low high
let rec get_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Tot (bitfield cl (high - low))
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then hd
else get_valid_bitfield rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield (payload k') r' low high
let rec get_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Lemma
(get_valid_bitfield b k low high == cl.get_bitfield (synth_bitsum'_recip b k) low high)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_correct rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_correct (payload k') r' low high
let rec set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Tot (bitsum'_type b) | [
"recursion"
] | LowParse.Spec.BitSum.set_valid_bitfield | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
k: LowParse.Spec.BitSum.bitsum'_type b ->
low: Prims.nat ->
high:
Prims.nat
{ LowParse.Spec.BitSum.is_valid_bitfield b
(LowParse.Spec.BitSum.bitsum'_key_of_t b k)
low
high } ->
v: LowParse.BitFields.bitfield cl (high - low)
-> LowParse.Spec.BitSum.bitsum'_type b | {
"end_col": 126,
"end_line": 1891,
"start_col": 2,
"start_line": 1881
} |
Prims.Tot | val filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2:
list (key & bitfield cl key_size)
{ e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 })
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail:
filter_bitsum'_bitsum'_t cl
bitsum'_size
key
key_size
e
payload
(l1 `L.append` [(k, r)])
l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr | val filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2:
list (key & bitfield cl key_size)
{ e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 })
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail:
filter_bitsum'_bitsum'_t cl
bitsum'_size
key
key_size
e
payload
(l1 `L.append` [(k, r)])
l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2:
list (key & bitfield cl key_size)
{ e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 })
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail:
filter_bitsum'_bitsum'_t cl
bitsum'_size
key
key_size
e
payload
(l1 `L.append` [(k, r)])
l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) = | false | null | false | fun x xr ->
[@@ inline_let ]let _ = enum_repr_of_key_append_cons e l1 (k, r) l2 in
[@@ inline_let ]let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@@ inline_let ]let cond = (xr <: t) = yr in
[@@ inline_let ]let _ =
assert (cond == true <==>
(cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then destr_payload x
else
[@@ inline_let ]let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1)
(L.map snd [(k, r)])
(cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.eq2",
"FStar.List.Tot.Base.append",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"LowParse.Spec.Enum.list_mem",
"LowParse.Spec.Enum.list_map",
"FStar.Pervasives.Native.fst",
"LowParse.Spec.Enum.enum_repr_of_key",
"Prims.Nil",
"LowParse.Spec.BitSum.filter_bitsum'_t",
"LowParse.Spec.BitSum.filter_bitsum'_bitsum'_t",
"Prims.l_not",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"FStar.Pervasives.Native.snd",
"LowParse.BitFields.__proj__Mkuint_t__item__bitfield_eq_lhs",
"Prims.bool",
"Prims.unit",
"FStar.List.Tot.Properties.append_mem",
"FStar.List.Tot.Base.map",
"FStar.List.Tot.Properties.map_append",
"FStar.List.Tot.Properties.append_assoc",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.BitSum'",
"Prims._assert",
"Prims.l_iff",
"Prims.op_Equality",
"LowParse.BitFields.__proj__Mkuint_t__item__bitfield_eq_rhs",
"LowParse.Spec.Enum.enum_repr_of_key_append_cons"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2:
list (key & bitfield cl key_size)
{ e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 })
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail:
filter_bitsum'_bitsum'_t cl
bitsum'_size
key
key_size
e
payload
(l1 `L.append` [(k, r)])
l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) | [] | LowParse.Spec.BitSum.filter_bitsum'_bitsum'_cons | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
l1: Prims.list (key * LowParse.BitFields.bitfield cl key_size) ->
k: key ->
r: LowParse.BitFields.bitfield cl key_size ->
l2:
Prims.list (key * LowParse.BitFields.bitfield cl key_size)
{ e == l1 @ FStar.Pervasives.Native.Mktuple2 k r :: l2 /\
LowParse.Spec.Enum.list_mem k (LowParse.Spec.Enum.list_map FStar.Pervasives.Native.fst e) /\
LowParse.Spec.Enum.enum_repr_of_key e k == r /\ e == (l1 @ [k, r]) @ l2 } ->
destr_payload: LowParse.Spec.BitSum.filter_bitsum'_t (payload k) ->
destr_tail:
LowParse.Spec.BitSum.filter_bitsum'_bitsum'_t cl
bitsum'_size
key
key_size
e
payload
(l1 @ [k, r])
l2
-> LowParse.Spec.BitSum.filter_bitsum'_bitsum'_t cl
bitsum'_size
key
key_size
e
payload
l1
(FStar.Pervasives.Native.Mktuple2 k r :: l2) | {
"end_col": 28,
"end_line": 1213,
"start_col": 2,
"start_line": 1195
} |
FStar.Pervasives.Lemma | val get_valid_bitfield_set_valid_bitfield_same
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Lemma
(let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low high /\ get_valid_bitfield b k' low high == v) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec get_valid_bitfield_set_valid_bitfield_same
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Lemma
(
let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low high /\
get_valid_bitfield b k' low high == v
)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_set_valid_bitfield_same rest tl low high v
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_set_valid_bitfield_same (payload k') r' low high v | val get_valid_bitfield_set_valid_bitfield_same
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Lemma
(let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low high /\ get_valid_bitfield b k' low high == v)
let rec get_valid_bitfield_set_valid_bitfield_same
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Lemma
(let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low high /\ get_valid_bitfield b k' low high == v) = | false | null | true | match b with
| BitField sz rest ->
let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_set_valid_bitfield_same rest tl low high v
| BitSum' key key_size e payload ->
let (| k' , r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_set_valid_bitfield_same (payload k') r' low high v | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.b2t",
"LowParse.Spec.BitSum.is_valid_bitfield",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.BitFields.bitfield",
"Prims.op_Subtraction",
"Prims.l_and",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Prims.bool",
"LowParse.Spec.BitSum.get_valid_bitfield_set_valid_bitfield_same",
"Prims.unit",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"LowParse.Spec.BitSum.get_valid_bitfield",
"LowParse.Spec.BitSum.set_valid_bitfield",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl
inline_for_extraction
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim ()
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
if k' = k
then begin
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
end else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
in
destr_tail (k' <: key) rest
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` ((k, r) :: []) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` []
})
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: []))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let]
let _ : squash (k' = k) =
if (k' = k)
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
end
in
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
[@filter_bitsum'_t_attr]
noextract
let rec mk_synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (synth_bitsum'_recip_t b)
(decreases %[b;1;()])
= match b with
| BitStop _ -> synth_bitsum'_recip_BitStop cl
| BitField sz rest -> synth_bitsum'_recip_BitField cl bitsum'_size sz rest (mk_synth_bitsum'_recip rest)
| BitSum' key key_size e payload ->
synth_bitsum'_recip_BitSum_intro cl bitsum'_size key key_size e payload (mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload [] e)
and mk_synth_bitsum'_recip_BitSum
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
synth_bitsum'_recip_BitSum_nil cl bitsum'_size key key_size e payload l1
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
synth_bitsum'_recip_BitSum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_synth_bitsum'_recip (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
synth_bitsum'_recip_BitSum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_synth_bitsum'_recip (payload k))
(mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Mutating a bitfield within a bitsum value *)
let rec is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool
= match b with
| BitStop _ -> false
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then true
else is_valid_bitfield rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield (payload k') r' low high
let rec is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma
(requires (is_valid_bitfield b k low high))
(ensures (
low <= high /\ high <= bitsum'_size
))
[SMTPat (is_valid_bitfield b k low high)]
= match b with
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then ()
else is_valid_bitfield_prop rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield_prop (payload k') r' low high
let rec get_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Tot (bitfield cl (high - low))
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then hd
else get_valid_bitfield rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield (payload k') r' low high
let rec get_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Lemma
(get_valid_bitfield b k low high == cl.get_bitfield (synth_bitsum'_recip b k) low high)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_correct rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_correct (payload k') r' low high
let rec set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Tot (bitsum'_type b)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
bitsum'_type_intro_BitField cl bitsum'_size sz rest
begin if low + sz = high && high = bitsum'_size
then (v, tl)
else (hd, set_valid_bitfield rest tl low high v)
end
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k' , set_valid_bitfield (payload k') r' low high v |)
let rec bitsum'_key_of_t_set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Lemma
(bitsum'_key_of_t b (set_valid_bitfield b k low high v) == bitsum'_key_of_t b k)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else bitsum'_key_of_t_set_valid_bitfield rest tl low high v
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
bitsum'_key_of_t_set_valid_bitfield (payload k') r' low high v
let rec get_valid_bitfield_set_valid_bitfield_same
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Lemma
(
let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low high /\
get_valid_bitfield b k' low high == v | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_valid_bitfield_set_valid_bitfield_same
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Lemma
(let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low high /\ get_valid_bitfield b k' low high == v) | [
"recursion"
] | LowParse.Spec.BitSum.get_valid_bitfield_set_valid_bitfield_same | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
k: LowParse.Spec.BitSum.bitsum'_type b ->
low: Prims.nat ->
high:
Prims.nat
{ LowParse.Spec.BitSum.is_valid_bitfield b
(LowParse.Spec.BitSum.bitsum'_key_of_t b k)
low
high } ->
v: LowParse.BitFields.bitfield cl (high - low)
-> FStar.Pervasives.Lemma
(ensures
(let k' = LowParse.Spec.BitSum.set_valid_bitfield b k low high v in
LowParse.Spec.BitSum.is_valid_bitfield b
(LowParse.Spec.BitSum.bitsum'_key_of_t b k')
low
high /\ LowParse.Spec.BitSum.get_valid_bitfield b k' low high == v)) | {
"end_col": 73,
"end_line": 1939,
"start_col": 2,
"start_line": 1931
} |
Prims.Tot | val bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k')) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x | val bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k')) = | false | null | false | x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.BitSum'",
"Prims.dtuple2"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k')) | [] | LowParse.Spec.BitSum.bitsum'_key_type_elim_BitSum' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
x: LowParse.Spec.BitSum.bitsum'_key_type (LowParse.Spec.BitSum.BitSum' key key_size e payload)
-> Prims.dtuple2 (LowParse.Spec.Enum.enum_key e)
(fun k' -> LowParse.Spec.BitSum.bitsum'_key_type (payload k')) | {
"end_col": 3,
"end_line": 165,
"start_col": 2,
"start_line": 165
} |
Prims.Tot | val destr_bitsum'_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from)
: Tot (Type u#(a + 1)) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x)) | val destr_bitsum'_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from)
: Tot (Type u#(a + 1))
let destr_bitsum'_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from)
: Tot (Type u#(a + 1)) = | false | null | false |
u: (bitsum'_type b -> Tot (Type u#a)) ->
u_if: (k: Ghost.erased (bitsum'_type b) -> Tot (if_combinator_weak (u (Ghost.reveal k)))) ->
f: (k: bitsum'_type b -> Tot (u k)) ->
x: parse_filter_refine (filter_bitsum' b)
-> Tot (u (synth_bitsum' b x)) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"FStar.Ghost.erased",
"LowParse.Spec.BitSum.if_combinator_weak",
"FStar.Ghost.reveal",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.synth_bitsum'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val destr_bitsum'_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from)
: Tot (Type u#(a + 1)) | [] | LowParse.Spec.BitSum.destr_bitsum'_t | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl from -> Type | {
"end_col": 29,
"end_line": 1293,
"start_col": 2,
"start_line": 1289
} |
Prims.Tot | val filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool (decreases (bitsum'_size)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false | val filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool (decreases (bitsum'_size))
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool (decreases (bitsum'_size)) = | false | null | false | match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f:bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else false | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total",
""
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Enum.list_mem",
"LowParse.Spec.Enum.list_map",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.snd",
"LowParse.Spec.Enum.enum_key_of_repr",
"Prims.bool",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool (decreases (bitsum'_size)) | [
"recursion"
] | LowParse.Spec.BitSum.filter_bitsum' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: t -> Prims.Tot Prims.bool | {
"end_col": 11,
"end_line": 239,
"start_col": 2,
"start_line": 229
} |
Prims.Tot | val synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r:
bitfield cl key_size
{ e == l1 `L.append` ([(k, r)]) /\ list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` [] })
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ([(k, r)])) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` ((k, r) :: []) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` []
})
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: []))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let]
let _ : squash (k' = k) =
if (k' = k)
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
end
in
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t) | val synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r:
bitfield cl key_size
{ e == l1 `L.append` ([(k, r)]) /\ list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` [] })
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ([(k, r)]))
let synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r:
bitfield cl key_size
{ e == l1 `L.append` ([(k, r)]) /\ list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` [] })
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ([(k, r)])) = | false | null | false | fun k' rest ->
[@@ inline_let ]let _ = enum_repr_of_key_append_cons e l1 (k, r) [] in
[@@ inline_let ]let _:squash (k' = k) =
if (k' = k)
then ()
else
(L.append_assoc l1 [(k, r)] [];
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key))
in
[@@ inline_let ]let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) ==
cl.set_bitfield (synth_bitsum'_recip (payload k') rest)
(bitsum'_size - key_size)
bitsum'_size
(enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.eq2",
"FStar.List.Tot.Base.append",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Nil",
"LowParse.Spec.Enum.list_mem",
"LowParse.Spec.Enum.list_map",
"FStar.Pervasives.Native.fst",
"LowParse.Spec.Enum.enum_repr_of_key",
"LowParse.Spec.BitSum.synth_bitsum'_recip_t",
"Prims.l_not",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.l_or",
"Prims.bool",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.BitSum'",
"FStar.UInt.uint_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.set_bitfield",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"Prims.Mkdtuple2",
"LowParse.Spec.BitSum.bitsum'_type'",
"Prims.squash",
"Prims.op_Equality",
"FStar.List.Tot.Properties.append_mem",
"FStar.List.Tot.Base.map",
"FStar.List.Tot.Properties.map_append",
"FStar.List.Tot.Properties.append_assoc",
"LowParse.Spec.Enum.enum_repr_of_key_append_cons",
"LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_t"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl
inline_for_extraction
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim ()
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
if k' = k
then begin
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
end else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
in
destr_tail (k' <: key) rest
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` ((k, r) :: []) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` []
})
(destr_payload: synth_bitsum'_recip_t (payload k)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r:
bitfield cl key_size
{ e == l1 `L.append` ([(k, r)]) /\ list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` [] })
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ([(k, r)])) | [] | LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_cons_nil | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
l1: Prims.list (key * LowParse.BitFields.bitfield cl key_size) ->
k: key ->
r:
LowParse.BitFields.bitfield cl key_size
{ e == l1 @ [k, r] /\
LowParse.Spec.Enum.list_mem k (LowParse.Spec.Enum.list_map FStar.Pervasives.Native.fst e) /\
LowParse.Spec.Enum.enum_repr_of_key e k == r /\ e == (l1 @ [k, r]) @ [] } ->
destr_payload: LowParse.Spec.BitSum.synth_bitsum'_recip_t (payload k)
-> LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_t cl
bitsum'_size
key
key_size
e
payload
l1
[k, r] | {
"end_col": 88,
"end_line": 1732,
"start_col": 2,
"start_line": 1713
} |
Prims.Tot | val bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b) (decreases (bitsum'_size)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end | val bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b) (decreases (bitsum'_size))
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b) (decreases (bitsum'_size)) = | false | null | false | match b with
| BitStop _ -> ()
| BitField sz rest ->
(match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| _, tl -> bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl))
| BitSum' key key_size e payload ->
match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k , pl |) ->
bitsum'_key_type_intro_BitSum' cl
bitsum'_size
key
key_size
e
payload
(| k, bitsum'_key_of_t (payload k) pl |) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total",
""
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField",
"LowParse.BitFields.bitfield",
"LowParse.Spec.BitSum.bitsum'_key_type_intro_BitField",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'",
"LowParse.Spec.BitSum.bitsum'_key_type_intro_BitSum'",
"Prims.Mkdtuple2"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b) (decreases (bitsum'_size)) | [
"recursion"
] | LowParse.Spec.BitSum.bitsum'_key_of_t | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.BitSum.bitsum'_type b
-> Prims.Tot (LowParse.Spec.BitSum.bitsum'_key_type b) | {
"end_col": 7,
"end_line": 613,
"start_col": 2,
"start_line": 602
} |
Prims.Tot | val synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t (decreases (bitsum'_size)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2 | val synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t (decreases (bitsum'_size))
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t (decreases (bitsum'_size)) = | false | null | false | match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k , tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2 | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total",
""
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.BitFields.bitfield",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield",
"LowParse.Spec.BitSum.synth_bitsum'_recip'",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"FStar.UInt.uint_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.set_bitfield",
"LowParse.Spec.Enum.enum_repr_of_key",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t (decreases (bitsum'_size)) | [
"recursion"
] | LowParse.Spec.BitSum.synth_bitsum'_recip' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.BitSum.bitsum'_type b
-> Prims.Tot t | {
"end_col": 6,
"end_line": 392,
"start_col": 2,
"start_line": 383
} |
Prims.Tot | val serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
() | val serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p)) = | false | null | false | synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth (p `parse_filter` (filter_bitsum' b))
(synth_bitsum' b)
(s `serialize_filter` (filter_bitsum' b))
(synth_bitsum'_recip b)
() | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.Combinators.serialize_synth",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.BitSum.synth_bitsum'",
"LowParse.Spec.Combinators.serialize_filter",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"Prims.unit",
"LowParse.Spec.BitSum.synth_bitsum'_recip_inverse",
"LowParse.Spec.BitSum.synth_bitsum'_injective",
"LowParse.Spec.BitSum.parse_bitsum'"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p)) | [] | LowParse.Spec.BitSum.serialize_bitsum' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | b: LowParse.Spec.BitSum.bitsum' cl tot -> s: LowParse.Spec.Base.serializer p
-> LowParse.Spec.Base.serializer (LowParse.Spec.BitSum.parse_bitsum' b p) | {
"end_col": 6,
"end_line": 570,
"start_col": 2,
"start_line": 563
} |
Prims.Tot | val parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f) | val parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data) = | false | null | false | parse_tagged_union #(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"LowParse.Spec.Base.parser",
"Prims.dtuple2",
"LowParse.Spec.Combinators.parse_tagged_union",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.BitSum.parse_bitsum'",
"LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind",
"LowParse.Spec.BitSum.parse_bitsum_cases",
"LowParse.Spec.BitSum.parse_bitsum_kind"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data) | [] | LowParse.Spec.BitSum.parse_bitsum | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
p: LowParse.Spec.Base.parser kt t ->
f:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k -> LowParse.Spec.Base.parser k (type_of_tag x)))
-> LowParse.Spec.Base.parser (LowParse.Spec.BitSum.parse_bitsum_kind kt b type_of_tag f) data | {
"end_col": 63,
"end_line": 792,
"start_col": 2,
"start_line": 785
} |
Prims.Tot | val parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
: Tot parser_kind | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f) | val parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
: Tot parser_kind
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
: Tot parser_kind = | false | null | false | and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_key_type",
"Prims.dtuple2",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
: Tot parser_kind | [] | LowParse.Spec.BitSum.parse_bitsum_kind | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
kt: LowParse.Spec.Base.parser_kind ->
b: LowParse.Spec.BitSum.bitsum' cl tot ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
f:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k -> LowParse.Spec.Base.parser k (type_of_tag x)))
-> LowParse.Spec.Base.parser_kind | {
"end_col": 87,
"end_line": 770,
"start_col": 2,
"start_line": 770
} |
FStar.Pervasives.Lemma | val serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x | val serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) = | false | null | true | synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq (p `parse_filter` (filter_bitsum' b))
(synth_bitsum' b)
(s `serialize_filter` (filter_bitsum' b))
(synth_bitsum'_recip b)
()
x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.Combinators.serialize_synth_eq",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.BitSum.synth_bitsum'",
"LowParse.Spec.Combinators.serialize_filter",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"Prims.unit",
"LowParse.Spec.BitSum.synth_bitsum'_recip_inverse",
"LowParse.Spec.BitSum.synth_bitsum'_injective",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.BitSum.parse_bitsum'",
"LowParse.Spec.BitSum.serialize_bitsum'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) | [] | LowParse.Spec.BitSum.serialize_bitsum'_eq | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
s: LowParse.Spec.Base.serializer p ->
x: LowParse.Spec.BitSum.bitsum'_type b
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Base.serialize (LowParse.Spec.BitSum.serialize_bitsum' b s) x ==
LowParse.Spec.Base.serialize s (LowParse.Spec.BitSum.synth_bitsum'_recip b x)) | {
"end_col": 5,
"end_line": 591,
"start_col": 2,
"start_line": 583
} |
Prims.Tot | val parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(x: bitsum'_type b)
: Tot
(parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x) | val parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(x: bitsum'_type b)
: Tot
(parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(x: bitsum'_type b)
: Tot
(parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x)) = | false | null | false | let tg:bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_ , p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` (synth_case.f x)) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"Prims.dtuple2",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.weaken",
"LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f",
"LowParse.Spec.BitSum.bitsum'_key_of_t"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(x: bitsum'_type b)
: Tot
(parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x)) | [] | LowParse.Spec.BitSum.parse_bitsum_cases | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
f:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k -> LowParse.Spec.Base.parser k (type_of_tag x))) ->
x: LowParse.Spec.BitSum.bitsum'_type b
-> LowParse.Spec.Base.parser (LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind b type_of_tag f)
(LowParse.Spec.Base.refine_with_tag tag_of_data x) | {
"end_col": 90,
"end_line": 758,
"start_col": 1,
"start_line": 756
} |
Prims.Tot | val serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f)) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g) | val serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f)) = | false | null | false | serialize_tagged_union #(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.dtuple2",
"Prims.__proj__Mkdtuple2__item___1",
"FStar.Pervasives.dsnd",
"LowParse.Spec.Combinators.serialize_tagged_union",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.BitSum.parse_bitsum'",
"LowParse.Spec.BitSum.serialize_bitsum'",
"LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind",
"LowParse.Spec.BitSum.parse_bitsum_cases",
"LowParse.Spec.BitSum.serialize_bitsum_cases",
"LowParse.Spec.BitSum.parse_bitsum_kind",
"LowParse.Spec.BitSum.parse_bitsum"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f)) | [] | LowParse.Spec.BitSum.serialize_bitsum | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind kt ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } ->
g:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x)))
-> LowParse.Spec.Base.serializer (LowParse.Spec.BitSum.parse_bitsum b
tag_of_data
type_of_tag
synth_case
p
f) | {
"end_col": 70,
"end_line": 943,
"start_col": 2,
"start_line": 934
} |
Prims.GTot | val serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: data)
: GTot bytes | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload | val serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: data)
: GTot bytes
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: data)
: GTot bytes = | false | null | false | let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
(serialize s (synth_bitsum'_recip b tg)) `Seq.append` (serialize (g k) payload) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"sometrivial"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.dtuple2",
"Prims.__proj__Mkdtuple2__item___1",
"FStar.Pervasives.dsnd",
"FStar.Seq.Base.append",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.Spec.BitSum.__proj__SynthCase__item__g",
"LowParse.Bytes.bytes"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: data)
: GTot bytes | [] | LowParse.Spec.BitSum.serialize_bitsum_alt | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind kt ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } ->
g:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) ->
x: data
-> Prims.GTot LowParse.Bytes.bytes | {
"end_col": 79,
"end_line": 965,
"start_col": 1,
"start_line": 961
} |
FStar.Pervasives.Lemma | val serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x ==
serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x | val serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x ==
serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x ==
serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x) = | false | null | true | serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.dtuple2",
"Prims.__proj__Mkdtuple2__item___1",
"FStar.Pervasives.dsnd",
"LowParse.Spec.BitSum.serialize_bitsum_eq",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"LowParse.Bytes.bytes",
"LowParse.Spec.BitSum.serialize_bitsum",
"LowParse.Spec.BitSum.serialize_bitsum_alt",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x ==
serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x) | [] | LowParse.Spec.BitSum.serialize_bitsum_eq' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind kt ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } ->
g:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) ->
x: data
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.BitSum.serialize_bitsum b tag_of_data type_of_tag synth_case s g x ==
LowParse.Spec.BitSum.serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x) | {
"end_col": 64,
"end_line": 1026,
"start_col": 2,
"start_line": 1026
} |
FStar.Pervasives.Lemma | val serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g
(synth_case.f tg payload) ==
serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg
payload) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload | val serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g
(synth_case.f tg payload) ==
serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg
payload)
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g
(synth_case.f tg payload) ==
serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg
payload) = | false | null | true | serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.synth_case_t",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.dtuple2",
"Prims.__proj__Mkdtuple2__item___1",
"FStar.Pervasives.dsnd",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.Spec.BitSum.synth_case_g_f_eq",
"Prims.unit",
"LowParse.Spec.BitSum.serialize_bitsum_eq",
"LowParse.Spec.BitSum.__proj__SynthCase__item__f",
"Prims.l_True",
"Prims.squash",
"LowParse.Bytes.bytes",
"LowParse.Spec.BitSum.serialize_bitsum",
"LowParse.Spec.BitSum.serialize_bitsum_alt_2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p {kt.parser_kind_subkind == Some ParserStrong})
(#f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x))))
(g: (x: bitsum'_key_type b -> Tot (serializer (dsnd (f x)))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g
(synth_case.f tg payload) ==
serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg
payload) | [] | LowParse.Spec.BitSum.serialize_bitsum_eq_2 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl tot ->
tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) ->
type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) ->
synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind kt ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } ->
g:
(x: LowParse.Spec.BitSum.bitsum'_key_type b
-> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) ->
tg: LowParse.Spec.BitSum.bitsum'_type b ->
payload: type_of_tag (LowParse.Spec.BitSum.bitsum'_key_of_t b tg)
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.BitSum.serialize_bitsum b
tag_of_data
type_of_tag
synth_case
s
g
(SynthCase?.f synth_case tg payload) ==
LowParse.Spec.BitSum.serialize_bitsum_alt_2 b
tag_of_data
type_of_tag
synth_case
s
g
tg
payload) | {
"end_col": 41,
"end_line": 1067,
"start_col": 2,
"start_line": 1066
} |
FStar.Pervasives.Lemma | val synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)
) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v) | val synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)
) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size))
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)
) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = | false | null | true | match b with
| BitStop _ -> ()
| BitField sz rest ->
let f:bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g:bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f:bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g:bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x ==
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y ==
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) ==
BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) ==
BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.synth_bitsum'_ext",
"Prims.unit",
"LowParse.BitFields.get_bitfield_get_bitfield",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"Prims._assert",
"LowParse.BitFields.bitfield",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.BitFields.ubitfield",
"LowParse.BitFields.get_bitfield",
"LowParse.Spec.BitSum.BitSum'",
"LowParse.Spec.BitSum.synth_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_intro_BitSum'",
"Prims.Mkdtuple2",
"LowParse.Spec.Enum.enum_key_of_repr",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y)) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 64,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)
) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) | [
"recursion"
] | LowParse.Spec.BitSum.synth_bitsum'_ext | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
x: LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitSum.filter_bitsum' b) ->
y: LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitSum.filter_bitsum' b)
-> FStar.Pervasives.Lemma
(requires
LowParse.BitFields.get_bitfield (Mkuint_t?.v cl x) 0 bitsum'_size ==
LowParse.BitFields.get_bitfield (Mkuint_t?.v cl y) 0 bitsum'_size)
(ensures LowParse.Spec.BitSum.synth_bitsum' b x == LowParse.Spec.BitSum.synth_bitsum' b y)
(decreases bitsum'_size) | {
"end_col": 19,
"end_line": 359,
"start_col": 2,
"start_line": 330
} |
Prims.Tot | val filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest)) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x | val filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest)) = | false | null | false | fun x -> phi x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.filter_bitsum'_t",
"Prims.bool",
"Prims.eq2",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.BitField"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot})
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest)) | [] | LowParse.Spec.BitSum.filter_bitsum'_bitfield | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
sz: Prims.nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot} ->
rest: LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - sz) ->
phi: LowParse.Spec.BitSum.filter_bitsum'_t rest
-> LowParse.Spec.BitSum.filter_bitsum'_t (LowParse.Spec.BitSum.BitField sz rest) | {
"end_col": 16,
"end_line": 1101,
"start_col": 2,
"start_line": 1101
} |
Prims.Tot | val filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload)) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr | val filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload)) = | false | null | false | fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.filter_bitsum'_bitsum'_t",
"Prims.Nil",
"FStar.Pervasives.Native.tuple2",
"LowParse.BitFields.__proj__Mkuint_t__item__bitfield_eq_lhs",
"Prims.bool",
"Prims.eq2",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.BitSum'",
"LowParse.Spec.BitSum.filter_bitsum'_t"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload)) | [] | LowParse.Spec.BitSum.filter_bitsum'_bitsum'_intro | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
phi: LowParse.Spec.BitSum.filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e
-> LowParse.Spec.BitSum.filter_bitsum'_t (LowParse.Spec.BitSum.BitSum' key key_size e payload) | {
"end_col": 12,
"end_line": 1157,
"start_col": 2,
"start_line": 1155
} |
Prims.Tot | val filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: (x: bitfield cl key_size -> Tot (y: bool{y == list_mem x (list_map snd e)})))
(key_of: (x: enum_repr e -> Tot (y: enum_key e {y == enum_key_of_repr e x})))
(destr_payload: (k: enum_key e -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload)) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x | val filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: (x: bitfield cl key_size -> Tot (y: bool{y == list_mem x (list_map snd e)})))
(key_of: (x: enum_repr e -> Tot (y: enum_key e {y == enum_key_of_repr e x})))
(destr_payload: (k: enum_key e -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: (x: bitfield cl key_size -> Tot (y: bool{y == list_mem x (list_map snd e)})))
(key_of: (x: enum_repr e -> Tot (y: enum_key e {y == enum_key_of_repr e x})))
(destr_payload: (k: enum_key e -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload)) = | false | null | false | fun x ->
let r:bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r) then false else destr_payload (key_of r) x | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"Prims.bool",
"Prims.eq2",
"LowParse.Spec.Enum.list_mem",
"LowParse.Spec.Enum.list_map",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.snd",
"LowParse.Spec.Enum.enum_repr",
"LowParse.Spec.Enum.enum_key_of_repr",
"LowParse.Spec.BitSum.filter_bitsum'_t",
"Prims.op_Negation",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.BitSum'",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k))) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: (x: bitfield cl key_size -> Tot (y: bool{y == list_mem x (list_map snd e)})))
(key_of: (x: enum_repr e -> Tot (y: enum_key e {y == enum_key_of_repr e x})))
(destr_payload: (k: enum_key e -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload)) | [] | LowParse.Spec.BitSum.filter_bitsum'_bitsum_gen | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
is_valid_repr:
(x: LowParse.BitFields.bitfield cl key_size
-> y:
Prims.bool
{ y ==
LowParse.Spec.Enum.list_mem x
(LowParse.Spec.Enum.list_map FStar.Pervasives.Native.snd e) }) ->
key_of:
(x: LowParse.Spec.Enum.enum_repr e
-> y: LowParse.Spec.Enum.enum_key e {y == LowParse.Spec.Enum.enum_key_of_repr e x}) ->
destr_payload:
(k: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.filter_bitsum'_t (payload k))
-> LowParse.Spec.BitSum.filter_bitsum'_t (LowParse.Spec.BitSum.BitSum' key key_size e payload) | {
"end_col": 32,
"end_line": 1123,
"start_col": 2,
"start_line": 1117
} |
Prims.Tot | val destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e []) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ()) | val destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e []) = | false | null | false | (fun u u_if f x ->
assert False;
false_elim ()) | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"Prims.squash",
"Prims.eq2",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.List.Tot.Base.append",
"Prims.Nil",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.BitSum'",
"FStar.Ghost.erased",
"LowParse.Spec.BitSum.if_combinator_weak",
"FStar.Ghost.reveal",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.BitSum.filter_bitsum'",
"Prims.l_not",
"LowParse.Spec.Enum.list_mem",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"LowParse.Spec.Enum.list_map",
"FStar.Pervasives.Native.snd",
"FStar.Pervasives.false_elim",
"LowParse.Spec.BitSum.synth_bitsum'",
"Prims.unit",
"Prims._assert",
"Prims.l_False",
"LowParse.Spec.BitSum.destr_bitsum'_bitsum_t"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` [])) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e []) | [] | LowParse.Spec.BitSum.destr_bitsum'_bitsum_nil | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
h: Prims.squash (e == e @ [])
-> LowParse.Spec.BitSum.destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [] | {
"end_col": 18,
"end_line": 1401,
"start_col": 2,
"start_line": 1399
} |
Prims.Tot | val synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl | val synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload)) = | false | null | false | fun x ->
[@@ inline_let ]let (| k , pl |) = x in
phi k pl | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_t",
"Prims.Nil",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.BitSum.bitsum'_type",
"LowParse.Spec.BitSum.BitSum'",
"LowParse.Spec.BitSum.bitsum'_type'",
"Prims.eq2",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"LowParse.Spec.BitSum.synth_bitsum'_recip_t"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload)) | [] | LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_intro | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
phi:
LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e
-> LowParse.Spec.BitSum.synth_bitsum'_recip_t (LowParse.Spec.BitSum.BitSum' key key_size e payload
) | {
"end_col": 10,
"end_line": 1632,
"start_col": 2,
"start_line": 1629
} |
Prims.Tot | val synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) {e == l1 `L.append` []})
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 []) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim () | val synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) {e == l1 `L.append` []})
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) {e == l1 `L.append` []})
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 []) = | false | null | false | fun k _ ->
[@@ inline_let ]let _ = L.append_l_nil l1 in
false_elim () | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.eq2",
"FStar.List.Tot.Base.append",
"Prims.Nil",
"Prims.l_not",
"LowParse.Spec.Enum.list_mem",
"LowParse.Spec.Enum.list_map",
"FStar.Pervasives.Native.fst",
"LowParse.Spec.BitSum.bitsum'_type",
"FStar.Pervasives.false_elim",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"LowParse.Spec.BitSum.BitSum'",
"Prims.Mkdtuple2",
"LowParse.Spec.BitSum.bitsum'_type'",
"Prims.unit",
"FStar.List.Tot.Properties.append_l_nil",
"LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_t"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl
inline_for_extraction
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } ) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) {e == l1 `L.append` []})
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 []) | [] | LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_nil | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
l1: Prims.list (key * LowParse.BitFields.bitfield cl key_size) {e == l1 @ []}
-> LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [] | {
"end_col": 15,
"end_line": 1649,
"start_col": 2,
"start_line": 1646
} |
FStar.Pervasives.Lemma | val bitsum'_key_of_t_set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Lemma (bitsum'_key_of_t b (set_valid_bitfield b k low high v) == bitsum'_key_of_t b k) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec bitsum'_key_of_t_set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Lemma
(bitsum'_key_of_t b (set_valid_bitfield b k low high v) == bitsum'_key_of_t b k)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else bitsum'_key_of_t_set_valid_bitfield rest tl low high v
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
bitsum'_key_of_t_set_valid_bitfield (payload k') r' low high v | val bitsum'_key_of_t_set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Lemma (bitsum'_key_of_t b (set_valid_bitfield b k low high v) == bitsum'_key_of_t b k)
let rec bitsum'_key_of_t_set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Lemma (bitsum'_key_of_t b (set_valid_bitfield b k low high v) == bitsum'_key_of_t b k) = | false | null | true | match b with
| BitField sz rest ->
let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else bitsum'_key_of_t_set_valid_bitfield rest tl low high v
| BitSum' key key_size e payload ->
let (| k' , r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
bitsum'_key_of_t_set_valid_bitfield (payload k') r' low high v | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.b2t",
"LowParse.Spec.BitSum.is_valid_bitfield",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.BitFields.bitfield",
"Prims.op_Subtraction",
"Prims.l_and",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Prims.bool",
"LowParse.Spec.BitSum.bitsum'_key_of_t_set_valid_bitfield",
"Prims.unit",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"LowParse.Spec.BitSum.bitsum'_key_type",
"LowParse.Spec.BitSum.set_valid_bitfield",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl
inline_for_extraction
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim ()
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
if k' = k
then begin
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
end else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
in
destr_tail (k' <: key) rest
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` ((k, r) :: []) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` []
})
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: []))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let]
let _ : squash (k' = k) =
if (k' = k)
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
end
in
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
[@filter_bitsum'_t_attr]
noextract
let rec mk_synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (synth_bitsum'_recip_t b)
(decreases %[b;1;()])
= match b with
| BitStop _ -> synth_bitsum'_recip_BitStop cl
| BitField sz rest -> synth_bitsum'_recip_BitField cl bitsum'_size sz rest (mk_synth_bitsum'_recip rest)
| BitSum' key key_size e payload ->
synth_bitsum'_recip_BitSum_intro cl bitsum'_size key key_size e payload (mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload [] e)
and mk_synth_bitsum'_recip_BitSum
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
synth_bitsum'_recip_BitSum_nil cl bitsum'_size key key_size e payload l1
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
synth_bitsum'_recip_BitSum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_synth_bitsum'_recip (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
synth_bitsum'_recip_BitSum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_synth_bitsum'_recip (payload k))
(mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Mutating a bitfield within a bitsum value *)
let rec is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool
= match b with
| BitStop _ -> false
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then true
else is_valid_bitfield rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield (payload k') r' low high
let rec is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma
(requires (is_valid_bitfield b k low high))
(ensures (
low <= high /\ high <= bitsum'_size
))
[SMTPat (is_valid_bitfield b k low high)]
= match b with
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then ()
else is_valid_bitfield_prop rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield_prop (payload k') r' low high
let rec get_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Tot (bitfield cl (high - low))
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then hd
else get_valid_bitfield rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield (payload k') r' low high
let rec get_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Lemma
(get_valid_bitfield b k low high == cl.get_bitfield (synth_bitsum'_recip b k) low high)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_correct rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_correct (payload k') r' low high
let rec set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Tot (bitsum'_type b)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
bitsum'_type_intro_BitField cl bitsum'_size sz rest
begin if low + sz = high && high = bitsum'_size
then (v, tl)
else (hd, set_valid_bitfield rest tl low high v)
end
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k' , set_valid_bitfield (payload k') r' low high v |)
let rec bitsum'_key_of_t_set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Lemma | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bitsum'_key_of_t_set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Lemma (bitsum'_key_of_t b (set_valid_bitfield b k low high v) == bitsum'_key_of_t b k) | [
"recursion"
] | LowParse.Spec.BitSum.bitsum'_key_of_t_set_valid_bitfield | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
k: LowParse.Spec.BitSum.bitsum'_type b ->
low: Prims.nat ->
high:
Prims.nat
{ LowParse.Spec.BitSum.is_valid_bitfield b
(LowParse.Spec.BitSum.bitsum'_key_of_t b k)
low
high } ->
v: LowParse.BitFields.bitfield cl (high - low)
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.BitSum.bitsum'_key_of_t b
(LowParse.Spec.BitSum.set_valid_bitfield b k low high v) ==
LowParse.Spec.BitSum.bitsum'_key_of_t b k) | {
"end_col": 66,
"end_line": 1913,
"start_col": 2,
"start_line": 1905
} |
Prims.Tot | val synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2:
list (key & bitfield cl key_size)
{ e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 })
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail:
synth_bitsum'_recip_BitSum_t cl
bitsum'_size
key
key_size
e
payload
(l1 `L.append` [(k, r)])
l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
if k' = k
then begin
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
end else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
in
destr_tail (k' <: key) rest | val synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2:
list (key & bitfield cl key_size)
{ e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 })
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail:
synth_bitsum'_recip_BitSum_t cl
bitsum'_size
key
key_size
e
payload
(l1 `L.append` [(k, r)])
l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2:
list (key & bitfield cl key_size)
{ e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 })
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail:
synth_bitsum'_recip_BitSum_t cl
bitsum'_size
key
key_size
e
payload
(l1 `L.append` [(k, r)])
l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) = | false | null | false | fun k' rest ->
[@@ inline_let ]let _ = enum_repr_of_key_append_cons e l1 (k, r) l2 in
if k' = k
then
[@@ inline_let ]let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) ==
cl.set_bitfield (synth_bitsum'_recip (payload k') rest)
(bitsum'_size - key_size)
bitsum'_size
(enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
else
[@@ inline_let ]let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
in
destr_tail (k' <: key) rest | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'",
"Prims.op_Subtraction",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.eq2",
"FStar.List.Tot.Base.append",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"LowParse.Spec.Enum.list_mem",
"LowParse.Spec.Enum.list_map",
"FStar.Pervasives.Native.fst",
"LowParse.Spec.Enum.enum_repr_of_key",
"Prims.Nil",
"LowParse.Spec.BitSum.synth_bitsum'_recip_t",
"LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_t",
"Prims.l_not",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.op_Equality",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.l_or",
"Prims.bool",
"LowParse.Spec.BitSum.filter_bitsum'",
"LowParse.Spec.BitSum.BitSum'",
"FStar.UInt.uint_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.set_bitfield",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"Prims.Mkdtuple2",
"LowParse.Spec.BitSum.bitsum'_type'",
"FStar.List.Tot.Properties.append_mem",
"FStar.List.Tot.Base.map",
"FStar.List.Tot.Properties.map_append",
"FStar.List.Tot.Properties.append_assoc",
"LowParse.Spec.Enum.enum_repr_of_key_append_cons"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl
inline_for_extraction
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim ()
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot})
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2:
list (key & bitfield cl key_size)
{ e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 })
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail:
synth_bitsum'_recip_BitSum_t cl
bitsum'_size
key
key_size
e
payload
(l1 `L.append` [(k, r)])
l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) | [] | LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_cons | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
cl: LowParse.BitFields.uint_t tot t ->
bitsum'_size: Prims.nat ->
key: Prims.eqtype ->
key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} ->
e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) ->
payload:
(_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size)
) ->
l1: Prims.list (key * LowParse.BitFields.bitfield cl key_size) ->
k: key ->
r: LowParse.BitFields.bitfield cl key_size ->
l2:
Prims.list (key * LowParse.BitFields.bitfield cl key_size)
{ e == l1 @ FStar.Pervasives.Native.Mktuple2 k r :: l2 /\
LowParse.Spec.Enum.list_mem k (LowParse.Spec.Enum.list_map FStar.Pervasives.Native.fst e) /\
LowParse.Spec.Enum.enum_repr_of_key e k == r /\ e == (l1 @ [k, r]) @ l2 } ->
destr_payload: LowParse.Spec.BitSum.synth_bitsum'_recip_t (payload k) ->
destr_tail:
LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_t cl
bitsum'_size
key
key_size
e
payload
(l1 @ [k, r])
l2
-> LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_t cl
bitsum'_size
key
key_size
e
payload
l1
(FStar.Pervasives.Native.Mktuple2 k r :: l2) | {
"end_col": 33,
"end_line": 1691,
"start_col": 2,
"start_line": 1673
} |
FStar.Pervasives.Lemma | val get_valid_bitfield_set_valid_bitfield_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
(low': nat)
(high':
nat
{ is_valid_bitfield b (bitsum'_key_of_t b k) low' high' /\
(high' <= low \/ high <= low') })
: Lemma
(let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low' high' /\
get_valid_bitfield b k' low' high' == get_valid_bitfield b k low' high') | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec get_valid_bitfield_set_valid_bitfield_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
(low': nat)
(high': nat { is_valid_bitfield b (bitsum'_key_of_t b k) low' high' /\ (high' <= low \/ high <= low') })
: Lemma
(
let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low' high' /\
get_valid_bitfield b k' low' high' == get_valid_bitfield b k low' high'
)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low' + sz = high' && high' = bitsum'_size
then ()
else if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_set_valid_bitfield_other rest tl low high v low' high'
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_set_valid_bitfield_other (payload k') r' low high v low' high' | val get_valid_bitfield_set_valid_bitfield_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
(low': nat)
(high':
nat
{ is_valid_bitfield b (bitsum'_key_of_t b k) low' high' /\
(high' <= low \/ high <= low') })
: Lemma
(let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low' high' /\
get_valid_bitfield b k' low' high' == get_valid_bitfield b k low' high')
let rec get_valid_bitfield_set_valid_bitfield_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
(low': nat)
(high':
nat
{ is_valid_bitfield b (bitsum'_key_of_t b k) low' high' /\
(high' <= low \/ high <= low') })
: Lemma
(let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low' high' /\
get_valid_bitfield b k' low' high' == get_valid_bitfield b k low' high') = | false | null | true | match b with
| BitField sz rest ->
let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low' + sz = high' && high' = bitsum'_size
then ()
else
if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_set_valid_bitfield_other rest tl low high v low' high'
| BitSum' key key_size e payload ->
let (| k' , r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_set_valid_bitfield_other (payload k') r' low high v low' high' | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.b2t",
"LowParse.Spec.BitSum.is_valid_bitfield",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.BitFields.bitfield",
"Prims.op_Subtraction",
"Prims.l_and",
"Prims.l_or",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Prims.bool",
"LowParse.Spec.BitSum.get_valid_bitfield_set_valid_bitfield_other",
"Prims.unit",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"LowParse.Spec.BitSum.get_valid_bitfield",
"LowParse.Spec.BitSum.set_valid_bitfield",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl
inline_for_extraction
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim ()
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
if k' = k
then begin
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
end else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
in
destr_tail (k' <: key) rest
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` ((k, r) :: []) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` []
})
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: []))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let]
let _ : squash (k' = k) =
if (k' = k)
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
end
in
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
[@filter_bitsum'_t_attr]
noextract
let rec mk_synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (synth_bitsum'_recip_t b)
(decreases %[b;1;()])
= match b with
| BitStop _ -> synth_bitsum'_recip_BitStop cl
| BitField sz rest -> synth_bitsum'_recip_BitField cl bitsum'_size sz rest (mk_synth_bitsum'_recip rest)
| BitSum' key key_size e payload ->
synth_bitsum'_recip_BitSum_intro cl bitsum'_size key key_size e payload (mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload [] e)
and mk_synth_bitsum'_recip_BitSum
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
synth_bitsum'_recip_BitSum_nil cl bitsum'_size key key_size e payload l1
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
synth_bitsum'_recip_BitSum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_synth_bitsum'_recip (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
synth_bitsum'_recip_BitSum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_synth_bitsum'_recip (payload k))
(mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Mutating a bitfield within a bitsum value *)
let rec is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool
= match b with
| BitStop _ -> false
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then true
else is_valid_bitfield rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield (payload k') r' low high
let rec is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma
(requires (is_valid_bitfield b k low high))
(ensures (
low <= high /\ high <= bitsum'_size
))
[SMTPat (is_valid_bitfield b k low high)]
= match b with
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then ()
else is_valid_bitfield_prop rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield_prop (payload k') r' low high
let rec get_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Tot (bitfield cl (high - low))
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then hd
else get_valid_bitfield rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield (payload k') r' low high
let rec get_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Lemma
(get_valid_bitfield b k low high == cl.get_bitfield (synth_bitsum'_recip b k) low high)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_correct rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_correct (payload k') r' low high
let rec set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Tot (bitsum'_type b)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
bitsum'_type_intro_BitField cl bitsum'_size sz rest
begin if low + sz = high && high = bitsum'_size
then (v, tl)
else (hd, set_valid_bitfield rest tl low high v)
end
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k' , set_valid_bitfield (payload k') r' low high v |)
let rec bitsum'_key_of_t_set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Lemma
(bitsum'_key_of_t b (set_valid_bitfield b k low high v) == bitsum'_key_of_t b k)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else bitsum'_key_of_t_set_valid_bitfield rest tl low high v
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
bitsum'_key_of_t_set_valid_bitfield (payload k') r' low high v
let rec get_valid_bitfield_set_valid_bitfield_same
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Lemma
(
let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low high /\
get_valid_bitfield b k' low high == v
)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_set_valid_bitfield_same rest tl low high v
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_set_valid_bitfield_same (payload k') r' low high v
let rec get_valid_bitfield_set_valid_bitfield_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
(low': nat)
(high': nat { is_valid_bitfield b (bitsum'_key_of_t b k) low' high' /\ (high' <= low \/ high <= low') })
: Lemma
(
let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low' high' /\
get_valid_bitfield b k' low' high' == get_valid_bitfield b k low' high' | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_valid_bitfield_set_valid_bitfield_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
(low': nat)
(high':
nat
{ is_valid_bitfield b (bitsum'_key_of_t b k) low' high' /\
(high' <= low \/ high <= low') })
: Lemma
(let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low' high' /\
get_valid_bitfield b k' low' high' == get_valid_bitfield b k low' high') | [
"recursion"
] | LowParse.Spec.BitSum.get_valid_bitfield_set_valid_bitfield_other | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
k: LowParse.Spec.BitSum.bitsum'_type b ->
low: Prims.nat ->
high:
Prims.nat
{ LowParse.Spec.BitSum.is_valid_bitfield b
(LowParse.Spec.BitSum.bitsum'_key_of_t b k)
low
high } ->
v: LowParse.BitFields.bitfield cl (high - low) ->
low': Prims.nat ->
high':
Prims.nat
{ LowParse.Spec.BitSum.is_valid_bitfield b
(LowParse.Spec.BitSum.bitsum'_key_of_t b k)
low'
high' /\ (high' <= low \/ high <= low') }
-> FStar.Pervasives.Lemma
(ensures
(let k' = LowParse.Spec.BitSum.set_valid_bitfield b k low high v in
LowParse.Spec.BitSum.is_valid_bitfield b
(LowParse.Spec.BitSum.bitsum'_key_of_t b k')
low'
high' /\
LowParse.Spec.BitSum.get_valid_bitfield b k' low' high' ==
LowParse.Spec.BitSum.get_valid_bitfield b k low' high')) | {
"end_col": 85,
"end_line": 1969,
"start_col": 2,
"start_line": 1959
} |
FStar.Pervasives.Lemma | val set_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Lemma
(synth_bitsum'_recip b (set_valid_bitfield b k low high v) ==
cl.set_bitfield (synth_bitsum'_recip b k) low high v) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec set_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Lemma
(synth_bitsum'_recip b (set_valid_bitfield b k low high v) == cl.set_bitfield (synth_bitsum'_recip b k) low high v)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then
BF.uint_set_bitfield_set_bitfield_same cl (synth_bitsum'_recip rest tl) low high hd v
else begin
BF.uint_set_bitfield_set_bitfield_other cl (synth_bitsum'_recip rest tl) (bitsum'_size - sz) bitsum'_size hd low high v;
set_valid_bitfield_correct rest tl low high v
end
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
BF.uint_set_bitfield_set_bitfield_other cl (synth_bitsum'_recip (payload k') r') (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k') low high v;
set_valid_bitfield_correct (payload k') r' low high v | val set_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Lemma
(synth_bitsum'_recip b (set_valid_bitfield b k low high v) ==
cl.set_bitfield (synth_bitsum'_recip b k) low high v)
let rec set_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Lemma
(synth_bitsum'_recip b (set_valid_bitfield b k low high v) ==
cl.set_bitfield (synth_bitsum'_recip b k) low high v) = | false | null | true | match b with
| BitField sz rest ->
let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then BF.uint_set_bitfield_set_bitfield_same cl (synth_bitsum'_recip rest tl) low high hd v
else
(BF.uint_set_bitfield_set_bitfield_other cl
(synth_bitsum'_recip rest tl)
(bitsum'_size - sz)
bitsum'_size
hd
low
high
v;
set_valid_bitfield_correct rest tl low high v)
| BitSum' key key_size e payload ->
let (| k' , r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
BF.uint_set_bitfield_set_bitfield_other cl
(synth_bitsum'_recip (payload k') r')
(bitsum'_size - key_size)
bitsum'_size
(enum_repr_of_key e k')
low
high
v;
set_valid_bitfield_correct (payload k') r' low high v | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.b2t",
"LowParse.Spec.BitSum.is_valid_bitfield",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"LowParse.BitFields.bitfield",
"Prims.op_Subtraction",
"Prims.l_and",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"LowParse.BitFields.uint_set_bitfield_set_bitfield_same",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"Prims.bool",
"LowParse.Spec.BitSum.set_valid_bitfield_correct",
"Prims.unit",
"LowParse.BitFields.uint_set_bitfield_set_bitfield_other",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Enum.enum_repr_of_key",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.l_or",
"LowParse.Spec.BitSum.filter_bitsum'",
"FStar.UInt.uint_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.set_bitfield",
"LowParse.Spec.BitSum.set_valid_bitfield",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl
inline_for_extraction
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim ()
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
if k' = k
then begin
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
end else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
in
destr_tail (k' <: key) rest
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` ((k, r) :: []) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` []
})
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: []))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let]
let _ : squash (k' = k) =
if (k' = k)
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
end
in
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
[@filter_bitsum'_t_attr]
noextract
let rec mk_synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (synth_bitsum'_recip_t b)
(decreases %[b;1;()])
= match b with
| BitStop _ -> synth_bitsum'_recip_BitStop cl
| BitField sz rest -> synth_bitsum'_recip_BitField cl bitsum'_size sz rest (mk_synth_bitsum'_recip rest)
| BitSum' key key_size e payload ->
synth_bitsum'_recip_BitSum_intro cl bitsum'_size key key_size e payload (mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload [] e)
and mk_synth_bitsum'_recip_BitSum
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
synth_bitsum'_recip_BitSum_nil cl bitsum'_size key key_size e payload l1
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
synth_bitsum'_recip_BitSum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_synth_bitsum'_recip (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
synth_bitsum'_recip_BitSum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_synth_bitsum'_recip (payload k))
(mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Mutating a bitfield within a bitsum value *)
let rec is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool
= match b with
| BitStop _ -> false
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then true
else is_valid_bitfield rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield (payload k') r' low high
let rec is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma
(requires (is_valid_bitfield b k low high))
(ensures (
low <= high /\ high <= bitsum'_size
))
[SMTPat (is_valid_bitfield b k low high)]
= match b with
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then ()
else is_valid_bitfield_prop rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield_prop (payload k') r' low high
let rec get_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Tot (bitfield cl (high - low))
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then hd
else get_valid_bitfield rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield (payload k') r' low high
let rec get_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Lemma
(get_valid_bitfield b k low high == cl.get_bitfield (synth_bitsum'_recip b k) low high)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_correct rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_correct (payload k') r' low high
let rec set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Tot (bitsum'_type b)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
bitsum'_type_intro_BitField cl bitsum'_size sz rest
begin if low + sz = high && high = bitsum'_size
then (v, tl)
else (hd, set_valid_bitfield rest tl low high v)
end
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k' , set_valid_bitfield (payload k') r' low high v |)
let rec bitsum'_key_of_t_set_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Lemma
(bitsum'_key_of_t b (set_valid_bitfield b k low high v) == bitsum'_key_of_t b k)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else bitsum'_key_of_t_set_valid_bitfield rest tl low high v
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
bitsum'_key_of_t_set_valid_bitfield (payload k') r' low high v
let rec get_valid_bitfield_set_valid_bitfield_same
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Lemma
(
let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low high /\
get_valid_bitfield b k' low high == v
)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_set_valid_bitfield_same rest tl low high v
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_set_valid_bitfield_same (payload k') r' low high v
let rec get_valid_bitfield_set_valid_bitfield_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
(low': nat)
(high': nat { is_valid_bitfield b (bitsum'_key_of_t b k) low' high' /\ (high' <= low \/ high <= low') })
: Lemma
(
let k' = set_valid_bitfield b k low high v in
is_valid_bitfield b (bitsum'_key_of_t b k') low' high' /\
get_valid_bitfield b k' low' high' == get_valid_bitfield b k low' high'
)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low' + sz = high' && high' = bitsum'_size
then ()
else if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_set_valid_bitfield_other rest tl low high v low' high'
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_set_valid_bitfield_other (payload k') r' low high v low' high'
let rec set_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
(v: bitfield cl (high - low))
: Lemma | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
(v: bitfield cl (high - low))
: Lemma
(synth_bitsum'_recip b (set_valid_bitfield b k low high v) ==
cl.set_bitfield (synth_bitsum'_recip b k) low high v) | [
"recursion"
] | LowParse.Spec.BitSum.set_valid_bitfield_correct | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
k: LowParse.Spec.BitSum.bitsum'_type b ->
low: Prims.nat ->
high:
Prims.nat
{ LowParse.Spec.BitSum.is_valid_bitfield b
(LowParse.Spec.BitSum.bitsum'_key_of_t b k)
low
high } ->
v: LowParse.BitFields.bitfield cl (high - low)
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.BitSum.synth_bitsum'_recip b
(LowParse.Spec.BitSum.set_valid_bitfield b k low high v) ==
Mkuint_t?.set_bitfield cl (LowParse.Spec.BitSum.synth_bitsum'_recip b k) low high v) | {
"end_col": 57,
"end_line": 1996,
"start_col": 2,
"start_line": 1983
} |
FStar.Pervasives.Lemma | val get_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
: Lemma (get_valid_bitfield b k low high == cl.get_bitfield (synth_bitsum'_recip b k) low high) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.BitFields",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec get_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Lemma
(get_valid_bitfield b k low high == cl.get_bitfield (synth_bitsum'_recip b k) low high)
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then ()
else get_valid_bitfield_correct rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_correct (payload k') r' low high | val get_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
: Lemma (get_valid_bitfield b k low high == cl.get_bitfield (synth_bitsum'_recip b k) low high)
let rec get_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
: Lemma (get_valid_bitfield b k low high == cl.get_bitfield (synth_bitsum'_recip b k) low high) = | false | null | true | match b with
| BitField sz rest ->
let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size then () else get_valid_bitfield_correct rest tl low high
| BitSum' key key_size e payload ->
let (| k' , r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield_correct (payload k') r' low high | {
"checked_file": "LowParse.Spec.BitSum.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.BitSum.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"LowParse.Spec.BitSum.bitsum'_type",
"Prims.b2t",
"LowParse.Spec.BitSum.is_valid_bitfield",
"LowParse.Spec.BitSum.bitsum'_key_of_t",
"Prims.l_and",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.BitFields.bitfield",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Prims.bool",
"LowParse.Spec.BitSum.get_valid_bitfield_correct",
"Prims.unit",
"LowParse.Spec.BitSum.bitsum'_type_bitfield",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitField",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.bitsum'_type_bitsum'",
"LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.l_or",
"Prims.op_LessThan",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"Prims.pow2",
"FStar.UInt.uint_t",
"LowParse.BitFields.get_bitfield",
"LowParse.Spec.BitSum.synth_bitsum'_recip",
"LowParse.Spec.BitSum.get_valid_bitfield",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.BitSum
include LowParse.Spec.Enum
include LowParse.BitFields
module L = FStar.List.Tot
// IMPORTANT: these bitfield operators are defined in a MOST
// significant bit (MSB) first fashion.
noeq
type bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
=
| BitStop of (squash (bitsum'_size == 0))
| BitField :
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) ->
(rest: bitsum' cl (bitsum'_size - sz)) ->
bitsum' cl bitsum'_size
| BitSum' :
(key: eqtype) ->
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment
(e: enum key (bitfield cl key_size)) ->
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) ->
bitsum' cl bitsum'_size
noextract
let rec bitsum'_type'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> (bitfield cl sz & bitsum'_type' rest)
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_type' (payload key))
noextract
let bitsum'_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= bitsum'_type' b
inline_for_extraction
let bitsum'_type_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
: Tot Type
= bitfield cl sz & bitsum'_type rest
let bitsum'_type_bitsum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
: Tot Type
= (k': enum_key e & bitsum'_type (payload k'))
noextract
noeq
type filter_bitsum'_t_attr =
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type (BitSum' key key_size e payload))
: Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
: Tot (bitsum'_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type (BitField sz rest))
: Tot (bitsum'_type_bitfield bitsum'_size sz rest)
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_type_bitfield bitsum'_size sz rest)
: Tot (bitsum'_type (BitField sz rest))
= x
noextract
let rec bitsum'_key_type
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot eqtype
(decreases (bitsum'_size))
= match b with
| BitStop _ -> unit
| BitField sz rest -> bitsum'_key_type rest
| BitSum' key key_size e payload ->
(key: enum_key e & bitsum'_key_type (payload key))
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: bitsum'_key_type (BitSum' key key_size e payload))
: Tot (k': enum_key e & bitsum'_key_type (payload k'))
= x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitSum'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(x: (k': enum_key e & bitsum'_key_type (payload k')))
: Tot (bitsum'_key_type (BitSum' key key_size e payload))
= x
[@filter_bitsum'_t_attr]
unfold
inline_for_extraction
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_intro_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type rest)
: Tot (bitsum'_key_type (BitField sz rest))
= coerce (bitsum'_key_type (BitField sz rest)) x
[@filter_bitsum'_t_attr]
inline_for_extraction
let bitsum'_key_type_elim_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(x: bitsum'_key_type (BitField sz rest))
: Tot (bitsum'_key_type rest)
= coerce (bitsum'_key_type rest) x
let rec filter_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: t)
: Tot bool
(decreases (bitsum'_size))
= match b with
| BitStop _ -> true
| BitField _ rest -> filter_bitsum' rest x
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if list_mem f (list_map snd e)
then
let k = enum_key_of_repr e f in
filter_bitsum' (payload k) x
else
false
let rec synth_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: parse_filter_refine (filter_bitsum' b))
: Tot (bitsum'_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x)
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
let k : enum_key e = enum_key_of_repr e f in
let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in
let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in
bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
let rec synth_bitsum'_injective'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (synth_bitsum' b x == synth_bitsum' b y))
(ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_empty (cl.v x) 0;
BF.get_bitfield_empty (cl.v y) 0;
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitField sz rest ->
assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size)));
synth_bitsum'_injective' rest x y;
assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz)));
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
let k = enum_key_of_repr e f in
enum_repr_of_key_of_repr e f;
enum_repr_of_key_of_repr e g;
assert (cl.v f == cl.v g);
synth_bitsum'_injective' (payload k) x y;
BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size];
assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
#pop-options
let synth_bitsum'_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
: Lemma
(synth_injective (synth_bitsum' b))
// [SMTPat (synth_injective (synth_bitsum' b))]
= synth_injective_intro' (synth_bitsum' b) (fun x y ->
synth_bitsum'_injective' b x y;
BF.get_bitfield_full (cl.v x);
BF.get_bitfield_full (cl.v y);
assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y))
)
// #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false"
#push-options "--z3rlimit 64"
let rec synth_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: parse_filter_refine (filter_bitsum' b))
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (synth_bitsum' b x == synth_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in
let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
synth_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
let k = enum_key_of_repr e f in
let u = synth_bitsum' (payload k) x in
let v = synth_bitsum' (payload k) y in
assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |));
assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |));
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size));
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size));
synth_bitsum'_ext (payload k) x y;
assert (u == v)
#pop-options
let parse_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(p: parser k t)
: Tot (parser (parse_filter_kind k) (bitsum'_type b))
= synth_bitsum'_injective b;
(p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
let rec synth_bitsum'_recip'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot t
(decreases (bitsum'_size))
= match b with
| BitStop _ -> cl.uint_to_t 0
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y1 = synth_bitsum'_recip' (payload k) tl in
let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in
y2
#push-options "--z3rlimit 16"
let rec get_bitfield_synth_bitsum'_recip'_other
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
(lo: nat)
(hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot })
: Lemma
(ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0))
(decreases (bitsum'_size))
= match b with
| BitStop h ->
BF.get_bitfield_zero tot lo hi
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi;
get_bitfield_synth_bitsum'_recip'_other rest tl lo hi
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi;
get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
#pop-options
#push-options "--z3rlimit 64"
let rec filter_bitsum'_ext
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x y: t)
: Lemma
(requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size))
(ensures (filter_bitsum' b x == filter_bitsum' b y))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz);
filter_bitsum'_ext rest x y
| BitSum' key key_size e payload ->
let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in
let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size;
assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size));
assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g));
assert (f == g);
if list_mem f (list_map snd e)
then begin
let k = enum_key_of_repr e f in
BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size);
BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) x y
end else ()
#pop-options
let rec synth_bitsum'_recip'_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl);
synth_bitsum'_recip'_prop rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t)));
enum_key_of_repr_of_key e k;
filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl);
synth_bitsum'_recip'_prop (payload k) tl
inline_for_extraction
let synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (parse_filter_refine (filter_bitsum' b))
= synth_bitsum'_recip'_prop b x;
synth_bitsum'_recip' b x
#push-options "--z3rlimit 16"
let rec synth_bitsum'_recip_inverse'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Lemma
(ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x))
(decreases bitsum'_size)
= match b with
| BitStop _ -> ()
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip rest tl in
(* Part 1/2: synth_bitfield cl 0 header_size header y == hd *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd);
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd));
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz);
filter_bitsum'_ext rest y y1;
synth_bitsum'_ext rest y y1 ;
synth_bitsum'_recip_inverse' rest tl
| BitSum' key key_size e payload ->
let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
let y = synth_bitsum'_recip b x in
let y1 = synth_bitsum'_recip (payload k) tl in
(* Part 1/2: k == enum_key_of_repr e f *)
BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k));
assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k)));
enum_key_of_repr_of_key e k;
(* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *)
BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size);
filter_bitsum'_ext (payload k) y y1;
synth_bitsum'_ext (payload k) y y1 ;
synth_bitsum'_recip_inverse' (payload k) tl
#pop-options
let synth_bitsum'_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Lemma
(synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
// [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))]
= synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x ->
synth_bitsum'_recip_inverse' b x
)
let serialize_bitsum'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bitsum' b p))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
let serialize_bitsum'_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#k: parser_kind)
(#p: parser k t)
(s: serializer p)
(x: bitsum'_type b)
: Lemma
(serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
= synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
serialize_synth_eq
(p `parse_filter` filter_bitsum' b)
(synth_bitsum' b)
(s `serialize_filter` filter_bitsum' b)
(synth_bitsum'_recip b)
()
x
let rec bitsum'_key_of_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(x: bitsum'_type b)
: Tot (bitsum'_key_type b)
(decreases (bitsum'_size))
= match b with
| BitStop _ -> ()
| BitField sz rest ->
begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with
| (_, tl) ->
bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)
end
| BitSum' key key_size e payload ->
begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with
| (| k, pl |) ->
bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
end
inline_for_extraction
noextract
let id
(#t: Type)
(x: t)
: Tot t
= x
inline_for_extraction
noextract
noeq
type synth_case_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
: Type
= | SynthCase:
(f: (
(k' : bitsum'_type b) ->
type_of_tag (bitsum'_key_of_t b k') ->
Tot (refine_with_tag (tag_of_data) k')
)) ->
(f_inj: (
(k' : bitsum'_type b) ->
(pl1: type_of_tag (bitsum'_key_of_t b k')) ->
(pl2: type_of_tag (bitsum'_key_of_t b k')) ->
Lemma
(requires (f k' pl1 == f k' pl2))
(ensures (pl1 == pl2))
)) ->
(g: (
(k' : bitsum'_type b) ->
refine_with_tag (tag_of_data) k' ->
Tot (type_of_tag (bitsum'_key_of_t b k'))
)) ->
(f_g_eq: (
(k: bitsum'_type b) ->
(x: refine_with_tag (tag_of_data) k) ->
Lemma
(f k (g k x) == x)
))
-> synth_case_t b data tag_of_data type_of_tag
let synth_case_g_f_eq
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#b: bitsum' cl tot)
(#data: Type)
(#tag_of_data: (data -> Tot (bitsum'_type b)))
(#type_of_tag: (bitsum'_key_type b -> Tot Type))
(s: synth_case_t b data tag_of_data type_of_tag)
(k: bitsum'_type b)
(x: type_of_tag (bitsum'_key_of_t b k))
: Lemma
(s.g k (s.f k x) == x)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x
#push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3"
let rec weaken_parse_bitsum_cases_kind'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(f: (x: bitsum'_key_type b) -> Tot parser_kind)
: Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x)))
(decreases (bitsum'_size))
= match b with
| BitStop _ -> (| f (), (fun y -> ()) |)
| BitField sz rest ->
let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in
(| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |)
| BitSum' key key_size e payload ->
let keys : list key = List.Tot.map fst e in
let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma
(requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x))
(ensures (k `is_weaker_than` f y)))) =
if List.Tot.mem x keys
then
let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
assert (y1 == x);
g y2
) |)
else (| default_parser_kind, (fun y -> ()) |)
in
let k = glb_list_of #key (fun x -> dfst (phi x)) keys in
(| k, (fun y ->
let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in
dsnd (phi y1) y
) |)
let weaken_parse_bitsum_cases_kind
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) })
= let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in
Classical.forall_intro phi;
k
let synth_bitsum_case_injective
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_injective (synth_case.f x))
[SMTPat (synth_injective (synth_case.f x))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
)
let parse_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bitsum'_type b)
: Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x))
= let tg : bitsum'_key_type b = bitsum'_key_of_t b x in
let (| k_, p |) = f tg in
weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
inline_for_extraction
let parse_bitsum_kind
(kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
let parse_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
: Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
= parse_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
module Seq = FStar.Seq
#push-options "--z3rlimit 16"
let parse_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with
| None -> None
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
))
= parse_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
(parse_bitsum' b p)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
x;
match parse (parse_bitsum' b p) x with
| None -> ()
| Some (tg, consumed1) ->
let k = bitsum'_key_of_t b tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg;
parse_synth_eq
(dsnd (f k))
(synth_case.f tg)
(Seq.slice x consumed1 (Seq.length x))
#pop-options
let parse_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(p: parser kt t)
(f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(x: bytes)
: Lemma
(parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with
| None -> None
| Some (tg', consumed1) ->
if filter_bitsum' b tg'
then
let tg = synth_bitsum' b tg' in
let k = bitsum'_key_of_t b tg in
begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with
| None -> None
| Some (y, consumed2) ->
Some ((synth_case.f tg y <: data), consumed1 + consumed2)
end
else
None
))
= parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x;
synth_bitsum'_injective b;
parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x;
parse_filter_eq p (filter_bitsum' b) x
let synth_bitsum_case_recip_inverse
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(x: bitsum'_type b)
: Lemma
(synth_inverse (synth_case.f x) (synth_case.g x))
[SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY?
= synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y ->
synth_case.f_g_eq x y
)
let serialize_bitsum_cases
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: bitsum'_type b)
: Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x))
= let tg = bitsum'_key_of_t b x in
let (| _, p |) = f tg in
synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger?
serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f)
(serialize_synth
p
(synth_case.f x)
(g tg)
(synth_case.g x)
())
let serialize_bitsum
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
: Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f))
= serialize_tagged_union
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
let serialize_bitsum_alt
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: GTot bytes
=
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
let payload = synth_case.g tg x in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x)
= serialize_tagged_union_eq
#(parse_filter_kind kt)
#(bitsum'_type b)
#(parse_bitsum' b p)
(serialize_bitsum' b s)
#(data)
(tag_of_data)
#(weaken_parse_bitsum_cases_kind b type_of_tag f)
#(parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
(serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g)
x;
let tg = tag_of_data x in
let k = bitsum'_key_of_t b tg in
serialize_bitsum'_eq b s tg;
let (| _, p |) = f k in
serialize_synth_eq
#_
#(type_of_tag k)
p
(synth_case.f tg)
(g k)
(synth_case.g tg)
()
x
let serialize_bitsum_eq'
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(x: data)
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x
let serialize_bitsum_alt_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: GTot bytes
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload
let serialize_bitsum_eq_2
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(tg: bitsum'_type b)
(payload: type_of_tag (bitsum'_key_of_t b tg))
: Lemma
(serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload);
synth_case_g_f_eq synth_case tg payload
(* Implementation of filter_bitsum' *)
inline_for_extraction
noextract
let filter_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: t) ->
Tot (y: bool { y == filter_bitsum' b x })
inline_for_extraction
let filter_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun _ -> true
inline_for_extraction
let filter_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: filter_bitsum'_t rest)
: Tot (filter_bitsum'_t (BitField sz rest))
= fun x -> phi x
inline_for_extraction
let filter_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) })))
(key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x })))
(destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k)))
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
if not (is_valid_repr r)
then
false
else
destr_payload (key_of r) x
inline_for_extraction
noextract
let filter_bitsum'_bitsum'_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
(xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) ->
Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x })
inline_for_extraction
let filter_bitsum'_bitsum'_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e)
: Tot (filter_bitsum'_t (BitSum' key key_size e payload))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr
inline_for_extraction
let filter_bitsum'_bitsum'_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e [])
= (fun x xr -> false)
inline_for_extraction
let filter_bitsum'_bitsum'_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: filter_bitsum'_t (payload k))
(destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun x xr ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in
[@inline_let] let cond = (xr <: t) = yr in
[@inline_let] let _ =
assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r)
in
if cond
then
destr_payload x
else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail (x <: t) xr
let bitsum_wellfoundedness
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b:bitsum' cl bitsum'_size { BitSum'? b })
: Lemma (let BitSum' key key_size e payload = b in
(forall (k:enum_key e). payload k << b))
= ()
[@filter_bitsum'_t_attr]
noextract
let rec mk_filter_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (filter_bitsum'_t b)
(decreases %[b; 1; ()])
= match b with
| BitStop _ -> filter_bitsum'_bitstop cl
| BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest)
| BitSum' key key_size e payload ->
filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e)
and mk_filter_bitsum'_bitsum'_t'
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload ()
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_filter_bitsum'_t' (payload k))
(mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Universal destructor *)
inline_for_extraction
let if_combinator_weak
(t: Type)
: Tot Type
= (cond: bool) ->
(sv_true: (cond_true cond -> Tot t)) ->
(sv_false: (cond_false cond -> Tot t)) ->
Tot (y: t)
inline_for_extraction
noextract
let destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#from: nat)
(b: bitsum' cl from)
: Tot (Type u#(a + 1))
= (u: (bitsum'_type b -> Tot (Type u#a))) ->
(u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) ->
(f: ((k: bitsum'_type b) -> Tot (u k))) ->
(x: parse_filter_refine (filter_bitsum' b)) ->
Tot (u (synth_bitsum' b x))
inline_for_extraction
let destr_bitsum'_bitstop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
= fun u u_if f x ->
f ()
inline_for_extraction
let destr_bitsum'_bitfield
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(phi: destr_bitsum'_t rest)
: Tot (destr_bitsum'_t (BitField sz rest))
= fun u u_if f x ->
phi
(fun z -> u (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
(fun z -> u_if (Ghost.hide (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, Ghost.reveal z)))
(fun z -> f (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, z))
x
inline_for_extraction
let destr_bitsum'_bitsum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(key_of: (
(x: enum_repr e) ->
Tot (y: enum_key e {
y == enum_key_of_repr e x
})))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(destr_payload: ((k: enum_key e) -> Tot (destr_bitsum'_t (payload k))))
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
[@inline_let]
let r : enum_repr e = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in
[@inline_let]
let k : enum_key e = key_of r in
destr_payload
k
(fun z -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
(fun z -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal z |))))
(fun z -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, z |)))
x
module L = FStar.List.Tot
inline_for_extraction
noextract
let destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (Type u#(a + 1))
= (u: (bitsum'_type (BitSum' key key_size e payload) -> Tot (Type u#a))) ->
(u_if: ((x: Ghost.erased (bitsum'_type (BitSum' key key_size e payload))) -> Tot (if_combinator_weak (u (Ghost.reveal x))))) ->
(f: ((x: bitsum'_type (BitSum' key key_size e payload)) -> Tot (u x))) ->
(x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) ->
Tot (u (synth_bitsum' (BitSum' key key_size e payload) x))
inline_for_extraction
let destr_bitsum'_bitsum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
: Tot (destr_bitsum'_t (BitSum' key key_size e payload))
= fun u u_if f x ->
phi u u_if f x
inline_for_extraction
let destr_bitsum'_bitsum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(h: squash (e == e `L.append` []))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload e [])
= (fun u u_if f x ->
assert False;
false_elim ())
#push-options "--z3rlimit 32"
inline_for_extraction
let destr_bitsum'_bitsum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: destr_bitsum'_t (payload k))
(destr_tail: destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
[@inline_let] let cond = ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r) in
u_if
(Ghost.hide (synth_bitsum' (BitSum' key key_size e payload) x))
cond
(fun cond_true ->
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
)
(fun cond_false ->
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
in
destr_tail u u_if f (x <: t)
)
inline_for_extraction
let destr_bitsum'_bitsum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` [(k, r)] /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r
})
(destr_payload: destr_bitsum'_t (payload k))
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 [(k, r)])
= fun u u_if f x ->
// [@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let] let _ : squash ((cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) =
if (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) = r
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append snd l1 [(k, r)];
L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size)
end
in
destr_payload
(fun x -> u (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
(fun x -> u_if (Ghost.hide (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, Ghost.reveal x |))))
(fun x -> f (bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)))
x
[@filter_bitsum'_t_attr]
noextract
let rec mk_destr_bitsum'_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (destr_bitsum'_t b <: Type u#1)
(decreases %[b;1;()])
= match b with
| BitStop _ -> destr_bitsum'_bitstop cl
| BitField sz rest -> destr_bitsum'_bitfield cl bitsum'_size sz rest (mk_destr_bitsum'_t rest)
| BitSum' key key_size e payload ->
destr_bitsum'_bitsum_intro cl bitsum'_size key key_size e payload (mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload [] e)
and mk_destr_bitsum'_bitsum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2 <: Type u#1)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
destr_bitsum'_bitsum_nil cl bitsum'_size key key_size e payload ()
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
destr_bitsum'_bitsum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_destr_bitsum'_t (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
destr_bitsum'_bitsum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_destr_bitsum'_t (payload k))
(mk_destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* from a bitsum key to its representation *)
inline_for_extraction
let synth_bitsum'_recip_t
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot Type
= (x: bitsum'_type b) ->
Tot (y: t { y == synth_bitsum'_recip b x })
inline_for_extraction
let synth_bitsum'_recip_BitStop
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ()))
= fun _ -> cl.uint_to_t 0
inline_for_extraction
let synth_bitsum'_recip_BitField
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot })
(rest: bitsum' cl (bitsum'_size - sz))
(ih: synth_bitsum'_recip_t rest)
: Tot (synth_bitsum'_recip_t (BitField sz rest))
= fun x ->
[@inline_let]
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in
cl.set_bitfield (ih tl) (bitsum'_size - sz) (bitsum'_size) hd
inline_for_extraction
let synth_bitsum'_recip_BitSum_gen
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(repr_of: (
(k: enum_key e) ->
Tot (r: enum_repr e { r == enum_repr_of_key e k })
))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(synth_payload: ((k: enum_key e) -> Tot (synth_bitsum'_recip_t (payload k))))
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in
cl.set_bitfield (synth_payload k pl) (bitsum'_size - key_size) bitsum'_size (repr_of k)
inline_for_extraction
noextract
let synth_bitsum'_recip_BitSum_t
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot Type
= (k: enum_key e { ~ (list_mem (k <: key) (list_map fst l1)) }) ->
(pl: bitsum'_type (payload k)) ->
Tot (y: t { y == synth_bitsum'_recip (BitSum' key key_size e payload) (| k, pl |) } )
inline_for_extraction
let synth_bitsum'_recip_BitSum_intro
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(phi: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload [] e)
: Tot (synth_bitsum'_recip_t (BitSum' key key_size e payload))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl
inline_for_extraction
let synth_bitsum'_recip_BitSum_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size) { e == l1 `L.append` [] } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim ()
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size)
(l2: list (key & bitfield cl key_size) {
e == l1 `L.append` ((k, r) :: l2) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` l2
})
(destr_payload: synth_bitsum'_recip_t (payload k))
(destr_tail: synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) l2
in
if k' = k
then begin
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
end else
[@inline_let] let _ =
L.append_assoc l1 [(k, r)] l2;
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
in
destr_tail (k' <: key) rest
inline_for_extraction
let synth_bitsum'_recip_BitSum_cons_nil
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(k: key)
(r: bitfield cl key_size {
e == l1 `L.append` ((k, r) :: []) /\
list_mem k (list_map fst e) /\
enum_repr_of_key e k == r /\
e == (l1 `L.append` [(k, r)]) `L.append` []
})
(destr_payload: synth_bitsum'_recip_t (payload k))
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 ((k, r) :: []))
= fun k' rest ->
[@inline_let]
let _ =
enum_repr_of_key_append_cons e l1 (k, r) []
in
[@inline_let]
let _ : squash (k' = k) =
if (k' = k)
then ()
else begin
L.append_assoc l1 [(k, r)] [];
L.map_append fst l1 [(k, r)];
L.append_mem (L.map fst l1) (L.map fst [(k, r)]) (k' <: key)
end
in
[@inline_let]
let _ =
assert_norm (synth_bitsum'_recip (BitSum' key key_size e payload) (| k', rest |) == cl.set_bitfield (synth_bitsum'_recip (payload k') rest) (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k'))
in
(cl.set_bitfield (destr_payload rest) (bitsum'_size - key_size) bitsum'_size r <: t)
[@filter_bitsum'_t_attr]
noextract
let rec mk_synth_bitsum'_recip
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
: Tot (synth_bitsum'_recip_t b)
(decreases %[b;1;()])
= match b with
| BitStop _ -> synth_bitsum'_recip_BitStop cl
| BitField sz rest -> synth_bitsum'_recip_BitField cl bitsum'_size sz rest (mk_synth_bitsum'_recip rest)
| BitSum' key key_size e payload ->
synth_bitsum'_recip_BitSum_intro cl bitsum'_size key key_size e payload (mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload [] e)
and mk_synth_bitsum'_recip_BitSum
(#tot: pos)
(#t: eqtype)
(cl: uint_t tot t)
(bitsum'_size: nat)
(key: eqtype)
(key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot })
(e: enum key (bitfield cl key_size))
(payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size))))
(l1: list (key & bitfield cl key_size))
(l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
: Tot (synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 l2)
(decreases %[BitSum' key key_size e payload; 0; l2])
= bitsum_wellfoundedness (BitSum' key key_size e payload);
match l2 with
| [] ->
[@inline_let] let _ =
L.append_l_nil l1
in
synth_bitsum'_recip_BitSum_nil cl bitsum'_size key key_size e payload l1
| [(k, r)] ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) [];
L.append_assoc l1 [(k, r)] []
in
synth_bitsum'_recip_BitSum_cons_nil cl bitsum'_size key key_size e payload l1 k r
(mk_synth_bitsum'_recip (payload k))
| (k, r) :: q ->
[@inline_let] let _ =
enum_repr_of_key_append_cons e l1 (k, r) q;
L.append_assoc l1 [(k, r)] q
in
synth_bitsum'_recip_BitSum_cons cl bitsum'_size key key_size e payload l1 k r q
(mk_synth_bitsum'_recip (payload k))
(mk_synth_bitsum'_recip_BitSum cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q)
(* Mutating a bitfield within a bitsum value *)
let rec is_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: GTot bool
= match b with
| BitStop _ -> false
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then true
else is_valid_bitfield rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield (payload k') r' low high
let rec is_valid_bitfield_prop
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_key_type b)
(low high: nat)
: Lemma
(requires (is_valid_bitfield b k low high))
(ensures (
low <= high /\ high <= bitsum'_size
))
[SMTPat (is_valid_bitfield b k low high)]
= match b with
| BitField sz rest ->
if low + sz = high && high = bitsum'_size
then ()
else is_valid_bitfield_prop rest (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest k) low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
is_valid_bitfield_prop (payload k') r' low high
let rec get_valid_bitfield
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Tot (bitfield cl (high - low))
= match b with
| BitField sz rest ->
let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest k in
if low + sz = high && high = bitsum'_size
then hd
else get_valid_bitfield rest tl low high
| BitSum' key key_size e payload ->
let (| k', r' |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload k in
get_valid_bitfield (payload k') r' low high
let rec get_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat { is_valid_bitfield b (bitsum'_key_of_t b k) low high })
: Lemma | false | false | LowParse.Spec.BitSum.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 8,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_valid_bitfield_correct
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(#bitsum'_size: nat)
(b: bitsum' cl bitsum'_size)
(k: bitsum'_type b)
(low: nat)
(high: nat{is_valid_bitfield b (bitsum'_key_of_t b k) low high})
: Lemma (get_valid_bitfield b k low high == cl.get_bitfield (synth_bitsum'_recip b k) low high) | [
"recursion"
] | LowParse.Spec.BitSum.get_valid_bitfield_correct | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size ->
k: LowParse.Spec.BitSum.bitsum'_type b ->
low: Prims.nat ->
high:
Prims.nat
{ LowParse.Spec.BitSum.is_valid_bitfield b
(LowParse.Spec.BitSum.bitsum'_key_of_t b k)
low
high }
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.BitSum.get_valid_bitfield b k low high ==
Mkuint_t?.get_bitfield cl (LowParse.Spec.BitSum.synth_bitsum'_recip b k) low high) | {
"end_col": 55,
"end_line": 1868,
"start_col": 3,
"start_line": 1860
} |
Prims.GTot | val disjoint (i j: rid) : GTot bool | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "Map"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "Set"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let disjoint (i:rid) (j:rid) :GTot bool = not (includes i j) && not (includes j i) | val disjoint (i j: rid) : GTot bool
let disjoint (i j: rid) : GTot bool = | false | null | false | not (includes i j) && not (includes j i) | {
"checked_file": "FStar.Monotonic.HyperHeap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Heap.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.HyperHeap.fsti"
} | [
"sometrivial"
] | [
"FStar.Monotonic.HyperHeap.rid",
"Prims.op_AmpAmp",
"Prims.op_Negation",
"FStar.Monotonic.HyperHeap.includes",
"Prims.bool"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi, and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.HyperHeap
module Set = FStar.Set
module Map = FStar.Map
open FStar.Monotonic.Heap
open FStar.Ghost
(*
* This module provides the map view of the memory and associated functions and lemmas
* The intention of this module is for it to be included in HyperStack
* Clients should not open/know about HyperHeap, they should work only with HyperStack
*)
(*
* AR: mark it must_erase_for_extraction temporarily until CMI comes in
*)
[@@must_erase_for_extraction]
val rid :eqtype
val reveal (r:rid) :GTot (list (int * int))
let rid_last_component (r:rid) :GTot int
= let open FStar.List.Tot in
let r = reveal r in
if length r = 0 then 0
else snd (hd r)
val color (x:rid) :GTot int
val rid_freeable (x:rid) : GTot bool
type hmap = Map.t rid heap
val root : r:rid{color r == 0 /\ not (rid_freeable r)}
val root_last_component (_:unit) : Lemma (rid_last_component root == 0)
let root_has_color_zero (u:unit) :Lemma (color root == 0) = ()
val root_is_not_freeable (_:unit) : Lemma (not (rid_freeable root))
private val rid_length (r:rid) :GTot nat
private val rid_tail (r:rid{rid_length r > 0}) :rid
val includes (r1:rid) (r2:rid) :GTot bool (decreases (reveal r2)) | false | false | FStar.Monotonic.HyperHeap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val disjoint (i j: rid) : GTot bool | [] | FStar.Monotonic.HyperHeap.disjoint | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | i: FStar.Monotonic.HyperHeap.rid -> j: FStar.Monotonic.HyperHeap.rid -> Prims.GTot Prims.bool | {
"end_col": 82,
"end_line": 64,
"start_col": 42,
"start_line": 64
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "Map"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "Set"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let modifies (s:Set.set rid) (m0:hmap) (m1:hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement (mod_set s)) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1) | let modifies (s: Set.set rid) (m0 m1: hmap) = | false | null | false | Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement (mod_set s)) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1) | {
"checked_file": "FStar.Monotonic.HyperHeap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Heap.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.HyperHeap.fsti"
} | [
"total"
] | [
"FStar.Set.set",
"FStar.Monotonic.HyperHeap.rid",
"FStar.Monotonic.HyperHeap.hmap",
"Prims.l_and",
"FStar.Map.equal",
"FStar.Monotonic.Heap.heap",
"FStar.Map.concat",
"FStar.Map.restrict",
"FStar.Set.complement",
"FStar.Monotonic.HyperHeap.mod_set",
"FStar.Set.subset",
"FStar.Map.domain",
"Prims.logical"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi, and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.HyperHeap
module Set = FStar.Set
module Map = FStar.Map
open FStar.Monotonic.Heap
open FStar.Ghost
(*
* This module provides the map view of the memory and associated functions and lemmas
* The intention of this module is for it to be included in HyperStack
* Clients should not open/know about HyperHeap, they should work only with HyperStack
*)
(*
* AR: mark it must_erase_for_extraction temporarily until CMI comes in
*)
[@@must_erase_for_extraction]
val rid :eqtype
val reveal (r:rid) :GTot (list (int * int))
let rid_last_component (r:rid) :GTot int
= let open FStar.List.Tot in
let r = reveal r in
if length r = 0 then 0
else snd (hd r)
val color (x:rid) :GTot int
val rid_freeable (x:rid) : GTot bool
type hmap = Map.t rid heap
val root : r:rid{color r == 0 /\ not (rid_freeable r)}
val root_last_component (_:unit) : Lemma (rid_last_component root == 0)
let root_has_color_zero (u:unit) :Lemma (color root == 0) = ()
val root_is_not_freeable (_:unit) : Lemma (not (rid_freeable root))
private val rid_length (r:rid) :GTot nat
private val rid_tail (r:rid{rid_length r > 0}) :rid
val includes (r1:rid) (r2:rid) :GTot bool (decreases (reveal r2))
let disjoint (i:rid) (j:rid) :GTot bool = not (includes i j) && not (includes j i)
val lemma_disjoint_includes (i:rid) (j:rid) (k:rid)
:Lemma (requires (disjoint i j /\ includes j k))
(ensures (disjoint i k))
(decreases (List.Tot.length (reveal k)))
[SMTPat (disjoint i j); SMTPat (includes j k)]
val extends (i:rid) (j:rid) :GTot bool
val parent (r:rid{r =!= root}) :rid
val lemma_includes_refl (i:rid)
:Lemma (includes i i)
[SMTPat (includes i i)]
val lemma_extends_includes (i:rid) (j:rid)
:Lemma (requires (extends j i))
(ensures (includes i j /\ not(includes j i)))
[SMTPat (extends j i)]
val lemma_includes_anti_symmetric (i:rid) (j:rid)
:Lemma (requires (includes i j /\ i =!= j))
(ensures (not (includes j i)))
[SMTPat (includes i j)]
val lemma_extends_disjoint (i:rid) (j:rid) (k:rid)
:Lemma (requires (extends j i /\ extends k i /\ j =!= k))
(ensures (disjoint j k))
val lemma_extends_parent (i:rid{i =!= root})
:Lemma (extends i (parent i))
[SMTPat (parent i)]
val lemma_extends_not_root (i:rid) (j:rid{extends j i})
:Lemma (j =!= root)
[SMTPat (extends j i)]
val lemma_extends_only_parent (i:rid) (j:rid{extends j i})
:Lemma (i == parent j)
[SMTPat (extends j i)]
val mod_set (s:Set.set rid) :(Set.set rid)
assume Mod_set_def: forall (x:rid) (s:Set.set rid). {:pattern Set.mem x (mod_set s)}
Set.mem x (mod_set s) <==> (exists (y:rid). Set.mem y s /\ includes y x) | false | true | FStar.Monotonic.HyperHeap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val modifies : s: FStar.Set.set FStar.Monotonic.HyperHeap.rid ->
m0: FStar.Monotonic.HyperHeap.hmap ->
m1: FStar.Monotonic.HyperHeap.hmap
-> Prims.logical | [] | FStar.Monotonic.HyperHeap.modifies | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Set.set FStar.Monotonic.HyperHeap.rid ->
m0: FStar.Monotonic.HyperHeap.hmap ->
m1: FStar.Monotonic.HyperHeap.hmap
-> Prims.logical | {
"end_col": 44,
"end_line": 112,
"start_col": 2,
"start_line": 111
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "Map"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "Set"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let modifies_just (s:Set.set rid) (m0:hmap) (m1:hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement s) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1) | let modifies_just (s: Set.set rid) (m0 m1: hmap) = | false | null | false | Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement s) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1) | {
"checked_file": "FStar.Monotonic.HyperHeap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Heap.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.HyperHeap.fsti"
} | [
"total"
] | [
"FStar.Set.set",
"FStar.Monotonic.HyperHeap.rid",
"FStar.Monotonic.HyperHeap.hmap",
"Prims.l_and",
"FStar.Map.equal",
"FStar.Monotonic.Heap.heap",
"FStar.Map.concat",
"FStar.Map.restrict",
"FStar.Set.complement",
"FStar.Set.subset",
"FStar.Map.domain",
"Prims.logical"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi, and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.HyperHeap
module Set = FStar.Set
module Map = FStar.Map
open FStar.Monotonic.Heap
open FStar.Ghost
(*
* This module provides the map view of the memory and associated functions and lemmas
* The intention of this module is for it to be included in HyperStack
* Clients should not open/know about HyperHeap, they should work only with HyperStack
*)
(*
* AR: mark it must_erase_for_extraction temporarily until CMI comes in
*)
[@@must_erase_for_extraction]
val rid :eqtype
val reveal (r:rid) :GTot (list (int * int))
let rid_last_component (r:rid) :GTot int
= let open FStar.List.Tot in
let r = reveal r in
if length r = 0 then 0
else snd (hd r)
val color (x:rid) :GTot int
val rid_freeable (x:rid) : GTot bool
type hmap = Map.t rid heap
val root : r:rid{color r == 0 /\ not (rid_freeable r)}
val root_last_component (_:unit) : Lemma (rid_last_component root == 0)
let root_has_color_zero (u:unit) :Lemma (color root == 0) = ()
val root_is_not_freeable (_:unit) : Lemma (not (rid_freeable root))
private val rid_length (r:rid) :GTot nat
private val rid_tail (r:rid{rid_length r > 0}) :rid
val includes (r1:rid) (r2:rid) :GTot bool (decreases (reveal r2))
let disjoint (i:rid) (j:rid) :GTot bool = not (includes i j) && not (includes j i)
val lemma_disjoint_includes (i:rid) (j:rid) (k:rid)
:Lemma (requires (disjoint i j /\ includes j k))
(ensures (disjoint i k))
(decreases (List.Tot.length (reveal k)))
[SMTPat (disjoint i j); SMTPat (includes j k)]
val extends (i:rid) (j:rid) :GTot bool
val parent (r:rid{r =!= root}) :rid
val lemma_includes_refl (i:rid)
:Lemma (includes i i)
[SMTPat (includes i i)]
val lemma_extends_includes (i:rid) (j:rid)
:Lemma (requires (extends j i))
(ensures (includes i j /\ not(includes j i)))
[SMTPat (extends j i)]
val lemma_includes_anti_symmetric (i:rid) (j:rid)
:Lemma (requires (includes i j /\ i =!= j))
(ensures (not (includes j i)))
[SMTPat (includes i j)]
val lemma_extends_disjoint (i:rid) (j:rid) (k:rid)
:Lemma (requires (extends j i /\ extends k i /\ j =!= k))
(ensures (disjoint j k))
val lemma_extends_parent (i:rid{i =!= root})
:Lemma (extends i (parent i))
[SMTPat (parent i)]
val lemma_extends_not_root (i:rid) (j:rid{extends j i})
:Lemma (j =!= root)
[SMTPat (extends j i)]
val lemma_extends_only_parent (i:rid) (j:rid{extends j i})
:Lemma (i == parent j)
[SMTPat (extends j i)]
val mod_set (s:Set.set rid) :(Set.set rid)
assume Mod_set_def: forall (x:rid) (s:Set.set rid). {:pattern Set.mem x (mod_set s)}
Set.mem x (mod_set s) <==> (exists (y:rid). Set.mem y s /\ includes y x)
let modifies (s:Set.set rid) (m0:hmap) (m1:hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement (mod_set s)) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1) | false | true | FStar.Monotonic.HyperHeap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val modifies_just : s: FStar.Set.set FStar.Monotonic.HyperHeap.rid ->
m0: FStar.Monotonic.HyperHeap.hmap ->
m1: FStar.Monotonic.HyperHeap.hmap
-> Prims.logical | [] | FStar.Monotonic.HyperHeap.modifies_just | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Set.set FStar.Monotonic.HyperHeap.rid ->
m0: FStar.Monotonic.HyperHeap.hmap ->
m1: FStar.Monotonic.HyperHeap.hmap
-> Prims.logical | {
"end_col": 44,
"end_line": 116,
"start_col": 2,
"start_line": 115
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "Map"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "Set"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let modifies_one (r:rid) (m0:hmap) (m1:hmap) = modifies_just (Set.singleton r) m0 m1 | let modifies_one (r: rid) (m0 m1: hmap) = | false | null | false | modifies_just (Set.singleton r) m0 m1 | {
"checked_file": "FStar.Monotonic.HyperHeap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Heap.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.HyperHeap.fsti"
} | [
"total"
] | [
"FStar.Monotonic.HyperHeap.rid",
"FStar.Monotonic.HyperHeap.hmap",
"FStar.Monotonic.HyperHeap.modifies_just",
"FStar.Set.singleton",
"Prims.logical"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi, and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.HyperHeap
module Set = FStar.Set
module Map = FStar.Map
open FStar.Monotonic.Heap
open FStar.Ghost
(*
* This module provides the map view of the memory and associated functions and lemmas
* The intention of this module is for it to be included in HyperStack
* Clients should not open/know about HyperHeap, they should work only with HyperStack
*)
(*
* AR: mark it must_erase_for_extraction temporarily until CMI comes in
*)
[@@must_erase_for_extraction]
val rid :eqtype
val reveal (r:rid) :GTot (list (int * int))
let rid_last_component (r:rid) :GTot int
= let open FStar.List.Tot in
let r = reveal r in
if length r = 0 then 0
else snd (hd r)
val color (x:rid) :GTot int
val rid_freeable (x:rid) : GTot bool
type hmap = Map.t rid heap
val root : r:rid{color r == 0 /\ not (rid_freeable r)}
val root_last_component (_:unit) : Lemma (rid_last_component root == 0)
let root_has_color_zero (u:unit) :Lemma (color root == 0) = ()
val root_is_not_freeable (_:unit) : Lemma (not (rid_freeable root))
private val rid_length (r:rid) :GTot nat
private val rid_tail (r:rid{rid_length r > 0}) :rid
val includes (r1:rid) (r2:rid) :GTot bool (decreases (reveal r2))
let disjoint (i:rid) (j:rid) :GTot bool = not (includes i j) && not (includes j i)
val lemma_disjoint_includes (i:rid) (j:rid) (k:rid)
:Lemma (requires (disjoint i j /\ includes j k))
(ensures (disjoint i k))
(decreases (List.Tot.length (reveal k)))
[SMTPat (disjoint i j); SMTPat (includes j k)]
val extends (i:rid) (j:rid) :GTot bool
val parent (r:rid{r =!= root}) :rid
val lemma_includes_refl (i:rid)
:Lemma (includes i i)
[SMTPat (includes i i)]
val lemma_extends_includes (i:rid) (j:rid)
:Lemma (requires (extends j i))
(ensures (includes i j /\ not(includes j i)))
[SMTPat (extends j i)]
val lemma_includes_anti_symmetric (i:rid) (j:rid)
:Lemma (requires (includes i j /\ i =!= j))
(ensures (not (includes j i)))
[SMTPat (includes i j)]
val lemma_extends_disjoint (i:rid) (j:rid) (k:rid)
:Lemma (requires (extends j i /\ extends k i /\ j =!= k))
(ensures (disjoint j k))
val lemma_extends_parent (i:rid{i =!= root})
:Lemma (extends i (parent i))
[SMTPat (parent i)]
val lemma_extends_not_root (i:rid) (j:rid{extends j i})
:Lemma (j =!= root)
[SMTPat (extends j i)]
val lemma_extends_only_parent (i:rid) (j:rid{extends j i})
:Lemma (i == parent j)
[SMTPat (extends j i)]
val mod_set (s:Set.set rid) :(Set.set rid)
assume Mod_set_def: forall (x:rid) (s:Set.set rid). {:pattern Set.mem x (mod_set s)}
Set.mem x (mod_set s) <==> (exists (y:rid). Set.mem y s /\ includes y x)
let modifies (s:Set.set rid) (m0:hmap) (m1:hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement (mod_set s)) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1)
let modifies_just (s:Set.set rid) (m0:hmap) (m1:hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement s) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1) | false | true | FStar.Monotonic.HyperHeap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val modifies_one : r: FStar.Monotonic.HyperHeap.rid ->
m0: FStar.Monotonic.HyperHeap.hmap ->
m1: FStar.Monotonic.HyperHeap.hmap
-> Prims.logical | [] | FStar.Monotonic.HyperHeap.modifies_one | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
r: FStar.Monotonic.HyperHeap.rid ->
m0: FStar.Monotonic.HyperHeap.hmap ->
m1: FStar.Monotonic.HyperHeap.hmap
-> Prims.logical | {
"end_col": 84,
"end_line": 118,
"start_col": 47,
"start_line": 118
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "Map"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "Set"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let disjoint_regions (s1:Set.set rid) (s2:Set.set rid) =
forall x y. {:pattern (Set.mem x s1); (Set.mem y s2)} (Set.mem x s1 /\ Set.mem y s2) ==> disjoint x y | let disjoint_regions (s1 s2: Set.set rid) = | false | null | false | forall x y. {:pattern (Set.mem x s1); (Set.mem y s2)}
(Set.mem x s1 /\ Set.mem y s2) ==> disjoint x y | {
"checked_file": "FStar.Monotonic.HyperHeap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Heap.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.HyperHeap.fsti"
} | [
"total"
] | [
"FStar.Set.set",
"FStar.Monotonic.HyperHeap.rid",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_and",
"Prims.b2t",
"FStar.Set.mem",
"FStar.Monotonic.HyperHeap.disjoint",
"Prims.logical"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi, and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.HyperHeap
module Set = FStar.Set
module Map = FStar.Map
open FStar.Monotonic.Heap
open FStar.Ghost
(*
* This module provides the map view of the memory and associated functions and lemmas
* The intention of this module is for it to be included in HyperStack
* Clients should not open/know about HyperHeap, they should work only with HyperStack
*)
(*
* AR: mark it must_erase_for_extraction temporarily until CMI comes in
*)
[@@must_erase_for_extraction]
val rid :eqtype
val reveal (r:rid) :GTot (list (int * int))
let rid_last_component (r:rid) :GTot int
= let open FStar.List.Tot in
let r = reveal r in
if length r = 0 then 0
else snd (hd r)
val color (x:rid) :GTot int
val rid_freeable (x:rid) : GTot bool
type hmap = Map.t rid heap
val root : r:rid{color r == 0 /\ not (rid_freeable r)}
val root_last_component (_:unit) : Lemma (rid_last_component root == 0)
let root_has_color_zero (u:unit) :Lemma (color root == 0) = ()
val root_is_not_freeable (_:unit) : Lemma (not (rid_freeable root))
private val rid_length (r:rid) :GTot nat
private val rid_tail (r:rid{rid_length r > 0}) :rid
val includes (r1:rid) (r2:rid) :GTot bool (decreases (reveal r2))
let disjoint (i:rid) (j:rid) :GTot bool = not (includes i j) && not (includes j i)
val lemma_disjoint_includes (i:rid) (j:rid) (k:rid)
:Lemma (requires (disjoint i j /\ includes j k))
(ensures (disjoint i k))
(decreases (List.Tot.length (reveal k)))
[SMTPat (disjoint i j); SMTPat (includes j k)]
val extends (i:rid) (j:rid) :GTot bool
val parent (r:rid{r =!= root}) :rid
val lemma_includes_refl (i:rid)
:Lemma (includes i i)
[SMTPat (includes i i)]
val lemma_extends_includes (i:rid) (j:rid)
:Lemma (requires (extends j i))
(ensures (includes i j /\ not(includes j i)))
[SMTPat (extends j i)]
val lemma_includes_anti_symmetric (i:rid) (j:rid)
:Lemma (requires (includes i j /\ i =!= j))
(ensures (not (includes j i)))
[SMTPat (includes i j)]
val lemma_extends_disjoint (i:rid) (j:rid) (k:rid)
:Lemma (requires (extends j i /\ extends k i /\ j =!= k))
(ensures (disjoint j k))
val lemma_extends_parent (i:rid{i =!= root})
:Lemma (extends i (parent i))
[SMTPat (parent i)]
val lemma_extends_not_root (i:rid) (j:rid{extends j i})
:Lemma (j =!= root)
[SMTPat (extends j i)]
val lemma_extends_only_parent (i:rid) (j:rid{extends j i})
:Lemma (i == parent j)
[SMTPat (extends j i)]
val mod_set (s:Set.set rid) :(Set.set rid)
assume Mod_set_def: forall (x:rid) (s:Set.set rid). {:pattern Set.mem x (mod_set s)}
Set.mem x (mod_set s) <==> (exists (y:rid). Set.mem y s /\ includes y x)
let modifies (s:Set.set rid) (m0:hmap) (m1:hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement (mod_set s)) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1)
let modifies_just (s:Set.set rid) (m0:hmap) (m1:hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement s) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1)
let modifies_one (r:rid) (m0:hmap) (m1:hmap) = modifies_just (Set.singleton r) m0 m1
let equal_on (s:Set.set rid) (m0:hmap) (m1:hmap) =
(forall (r:rid). {:pattern (Map.contains m0 r)} (Set.mem r (mod_set s) /\ Map.contains m0 r) ==> Map.contains m1 r) /\
Map.equal m1 (Map.concat m1 (Map.restrict (mod_set s) m0))
let lemma_modifies_just_trans (m1:hmap) (m2:hmap) (m3:hmap)
(s1:Set.set rid) (s2:Set.set rid)
:Lemma (requires (modifies_just s1 m1 m2 /\ modifies_just s2 m2 m3))
(ensures (modifies_just (Set.union s1 s2) m1 m3))
= ()
let lemma_modifies_trans (m1:hmap) (m2:hmap) (m3:hmap)
(s1:Set.set rid) (s2:Set.set rid)
:Lemma (requires (modifies s1 m1 m2 /\ modifies s2 m2 m3))
(ensures (modifies (Set.union s1 s2) m1 m3))
= ()
val lemma_includes_trans (i:rid) (j:rid) (k:rid)
:Lemma (requires (includes i j /\ includes j k))
(ensures (includes i k))
(decreases (reveal k))
[SMTPat (includes i j); SMTPat (includes j k)]
val lemma_modset (i:rid) (j:rid)
:Lemma (requires (includes j i))
(ensures (Set.subset (mod_set (Set.singleton i)) (mod_set (Set.singleton j))))
val lemma_modifies_includes (m1:hmap) (m2:hmap) (i:rid) (j:rid)
:Lemma (requires (modifies (Set.singleton i) m1 m2 /\ includes j i))
(ensures (modifies (Set.singleton j) m1 m2))
val lemma_modifies_includes2 (m1:hmap) (m2:hmap) (s1:Set.set rid) (s2:Set.set rid)
:Lemma (requires (modifies s1 m1 m2 /\ (forall x. Set.mem x s1 ==> (exists y. Set.mem y s2 /\ includes y x))))
(ensures (modifies s2 m1 m2))
val lemma_disjoint_parents (pr:rid) (r:rid) (ps:rid) (s:rid)
:Lemma (requires (r `extends` pr /\ s `extends` ps /\ disjoint pr ps))
(ensures (disjoint r s))
[SMTPat (extends r pr); SMTPat (extends s ps); SMTPat (disjoint pr ps)]
val lemma_include_cons (i:rid) (j:rid)
:Lemma (requires (i =!= j /\ includes i j))
(ensures (j =!= root)) | false | true | FStar.Monotonic.HyperHeap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val disjoint_regions : s1: FStar.Set.set FStar.Monotonic.HyperHeap.rid -> s2: FStar.Set.set FStar.Monotonic.HyperHeap.rid
-> Prims.logical | [] | FStar.Monotonic.HyperHeap.disjoint_regions | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Set.set FStar.Monotonic.HyperHeap.rid -> s2: FStar.Set.set FStar.Monotonic.HyperHeap.rid
-> Prims.logical | {
"end_col": 106,
"end_line": 164,
"start_col": 5,
"start_line": 164
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "Map"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "Set"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let equal_on (s:Set.set rid) (m0:hmap) (m1:hmap) =
(forall (r:rid). {:pattern (Map.contains m0 r)} (Set.mem r (mod_set s) /\ Map.contains m0 r) ==> Map.contains m1 r) /\
Map.equal m1 (Map.concat m1 (Map.restrict (mod_set s) m0)) | let equal_on (s: Set.set rid) (m0 m1: hmap) = | false | null | false | (forall (r: rid). {:pattern (Map.contains m0 r)}
(Set.mem r (mod_set s) /\ Map.contains m0 r) ==> Map.contains m1 r) /\
Map.equal m1 (Map.concat m1 (Map.restrict (mod_set s) m0)) | {
"checked_file": "FStar.Monotonic.HyperHeap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Heap.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.HyperHeap.fsti"
} | [
"total"
] | [
"FStar.Set.set",
"FStar.Monotonic.HyperHeap.rid",
"FStar.Monotonic.HyperHeap.hmap",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"FStar.Set.mem",
"FStar.Monotonic.HyperHeap.mod_set",
"FStar.Map.contains",
"FStar.Monotonic.Heap.heap",
"FStar.Map.equal",
"FStar.Map.concat",
"FStar.Map.restrict",
"Prims.logical"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi, and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.HyperHeap
module Set = FStar.Set
module Map = FStar.Map
open FStar.Monotonic.Heap
open FStar.Ghost
(*
* This module provides the map view of the memory and associated functions and lemmas
* The intention of this module is for it to be included in HyperStack
* Clients should not open/know about HyperHeap, they should work only with HyperStack
*)
(*
* AR: mark it must_erase_for_extraction temporarily until CMI comes in
*)
[@@must_erase_for_extraction]
val rid :eqtype
val reveal (r:rid) :GTot (list (int * int))
let rid_last_component (r:rid) :GTot int
= let open FStar.List.Tot in
let r = reveal r in
if length r = 0 then 0
else snd (hd r)
val color (x:rid) :GTot int
val rid_freeable (x:rid) : GTot bool
type hmap = Map.t rid heap
val root : r:rid{color r == 0 /\ not (rid_freeable r)}
val root_last_component (_:unit) : Lemma (rid_last_component root == 0)
let root_has_color_zero (u:unit) :Lemma (color root == 0) = ()
val root_is_not_freeable (_:unit) : Lemma (not (rid_freeable root))
private val rid_length (r:rid) :GTot nat
private val rid_tail (r:rid{rid_length r > 0}) :rid
val includes (r1:rid) (r2:rid) :GTot bool (decreases (reveal r2))
let disjoint (i:rid) (j:rid) :GTot bool = not (includes i j) && not (includes j i)
val lemma_disjoint_includes (i:rid) (j:rid) (k:rid)
:Lemma (requires (disjoint i j /\ includes j k))
(ensures (disjoint i k))
(decreases (List.Tot.length (reveal k)))
[SMTPat (disjoint i j); SMTPat (includes j k)]
val extends (i:rid) (j:rid) :GTot bool
val parent (r:rid{r =!= root}) :rid
val lemma_includes_refl (i:rid)
:Lemma (includes i i)
[SMTPat (includes i i)]
val lemma_extends_includes (i:rid) (j:rid)
:Lemma (requires (extends j i))
(ensures (includes i j /\ not(includes j i)))
[SMTPat (extends j i)]
val lemma_includes_anti_symmetric (i:rid) (j:rid)
:Lemma (requires (includes i j /\ i =!= j))
(ensures (not (includes j i)))
[SMTPat (includes i j)]
val lemma_extends_disjoint (i:rid) (j:rid) (k:rid)
:Lemma (requires (extends j i /\ extends k i /\ j =!= k))
(ensures (disjoint j k))
val lemma_extends_parent (i:rid{i =!= root})
:Lemma (extends i (parent i))
[SMTPat (parent i)]
val lemma_extends_not_root (i:rid) (j:rid{extends j i})
:Lemma (j =!= root)
[SMTPat (extends j i)]
val lemma_extends_only_parent (i:rid) (j:rid{extends j i})
:Lemma (i == parent j)
[SMTPat (extends j i)]
val mod_set (s:Set.set rid) :(Set.set rid)
assume Mod_set_def: forall (x:rid) (s:Set.set rid). {:pattern Set.mem x (mod_set s)}
Set.mem x (mod_set s) <==> (exists (y:rid). Set.mem y s /\ includes y x)
let modifies (s:Set.set rid) (m0:hmap) (m1:hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement (mod_set s)) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1)
let modifies_just (s:Set.set rid) (m0:hmap) (m1:hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement s) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1)
let modifies_one (r:rid) (m0:hmap) (m1:hmap) = modifies_just (Set.singleton r) m0 m1 | false | true | FStar.Monotonic.HyperHeap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val equal_on : s: FStar.Set.set FStar.Monotonic.HyperHeap.rid ->
m0: FStar.Monotonic.HyperHeap.hmap ->
m1: FStar.Monotonic.HyperHeap.hmap
-> Prims.logical | [] | FStar.Monotonic.HyperHeap.equal_on | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Set.set FStar.Monotonic.HyperHeap.rid ->
m0: FStar.Monotonic.HyperHeap.hmap ->
m1: FStar.Monotonic.HyperHeap.hmap
-> Prims.logical | {
"end_col": 59,
"end_line": 122,
"start_col": 1,
"start_line": 121
} |
|
Prims.GTot | val rid_last_component (r: rid) : GTot int | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "Map"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "Set"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rid_last_component (r:rid) :GTot int
= let open FStar.List.Tot in
let r = reveal r in
if length r = 0 then 0
else snd (hd r) | val rid_last_component (r: rid) : GTot int
let rid_last_component (r: rid) : GTot int = | false | null | false | let open FStar.List.Tot in
let r = reveal r in
if length r = 0 then 0 else snd (hd r) | {
"checked_file": "FStar.Monotonic.HyperHeap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Heap.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.HyperHeap.fsti"
} | [
"sometrivial"
] | [
"FStar.Monotonic.HyperHeap.rid",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"FStar.Pervasives.Native.tuple2",
"Prims.bool",
"FStar.Pervasives.Native.snd",
"FStar.List.Tot.Base.hd",
"Prims.list",
"FStar.Monotonic.HyperHeap.reveal"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi, and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.HyperHeap
module Set = FStar.Set
module Map = FStar.Map
open FStar.Monotonic.Heap
open FStar.Ghost
(*
* This module provides the map view of the memory and associated functions and lemmas
* The intention of this module is for it to be included in HyperStack
* Clients should not open/know about HyperHeap, they should work only with HyperStack
*)
(*
* AR: mark it must_erase_for_extraction temporarily until CMI comes in
*)
[@@must_erase_for_extraction]
val rid :eqtype
val reveal (r:rid) :GTot (list (int * int)) | false | false | FStar.Monotonic.HyperHeap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rid_last_component (r: rid) : GTot int | [] | FStar.Monotonic.HyperHeap.rid_last_component | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | r: FStar.Monotonic.HyperHeap.rid -> Prims.GTot Prims.int | {
"end_col": 19,
"end_line": 42,
"start_col": 4,
"start_line": 39
} |
Prims.Tot | val extend_post (r: rid) (n c: int) (freeable: bool) : pure_post rid | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "Map"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "Set"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let extend_post (r:rid) (n:int) (c:int) (freeable:bool) : pure_post rid =
fun s ->
s `extends` r /\
Cons? (reveal s) /\
Cons?.hd (reveal s) == (c, n) /\
color s == c /\
rid_freeable s == freeable | val extend_post (r: rid) (n c: int) (freeable: bool) : pure_post rid
let extend_post (r: rid) (n c: int) (freeable: bool) : pure_post rid = | false | null | false | fun s ->
s `extends` r /\ Cons? (reveal s) /\ Cons?.hd (reveal s) == (c, n) /\ color s == c /\
rid_freeable s == freeable | {
"checked_file": "FStar.Monotonic.HyperHeap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Heap.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.HyperHeap.fsti"
} | [
"total"
] | [
"FStar.Monotonic.HyperHeap.rid",
"Prims.int",
"Prims.bool",
"Prims.l_True",
"Prims.l_and",
"Prims.b2t",
"FStar.Monotonic.HyperHeap.extends",
"Prims.uu___is_Cons",
"FStar.Pervasives.Native.tuple2",
"FStar.Monotonic.HyperHeap.reveal",
"Prims.eq2",
"Prims.__proj__Cons__item__hd",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Monotonic.HyperHeap.color",
"FStar.Monotonic.HyperHeap.rid_freeable",
"Prims.pure_post"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi, and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.HyperHeap
module Set = FStar.Set
module Map = FStar.Map
open FStar.Monotonic.Heap
open FStar.Ghost
(*
* This module provides the map view of the memory and associated functions and lemmas
* The intention of this module is for it to be included in HyperStack
* Clients should not open/know about HyperHeap, they should work only with HyperStack
*)
(*
* AR: mark it must_erase_for_extraction temporarily until CMI comes in
*)
[@@must_erase_for_extraction]
val rid :eqtype
val reveal (r:rid) :GTot (list (int * int))
let rid_last_component (r:rid) :GTot int
= let open FStar.List.Tot in
let r = reveal r in
if length r = 0 then 0
else snd (hd r)
val color (x:rid) :GTot int
val rid_freeable (x:rid) : GTot bool
type hmap = Map.t rid heap
val root : r:rid{color r == 0 /\ not (rid_freeable r)}
val root_last_component (_:unit) : Lemma (rid_last_component root == 0)
let root_has_color_zero (u:unit) :Lemma (color root == 0) = ()
val root_is_not_freeable (_:unit) : Lemma (not (rid_freeable root))
private val rid_length (r:rid) :GTot nat
private val rid_tail (r:rid{rid_length r > 0}) :rid
val includes (r1:rid) (r2:rid) :GTot bool (decreases (reveal r2))
let disjoint (i:rid) (j:rid) :GTot bool = not (includes i j) && not (includes j i)
val lemma_disjoint_includes (i:rid) (j:rid) (k:rid)
:Lemma (requires (disjoint i j /\ includes j k))
(ensures (disjoint i k))
(decreases (List.Tot.length (reveal k)))
[SMTPat (disjoint i j); SMTPat (includes j k)]
val extends (i:rid) (j:rid) :GTot bool
val parent (r:rid{r =!= root}) :rid
val lemma_includes_refl (i:rid)
:Lemma (includes i i)
[SMTPat (includes i i)]
val lemma_extends_includes (i:rid) (j:rid)
:Lemma (requires (extends j i))
(ensures (includes i j /\ not(includes j i)))
[SMTPat (extends j i)]
val lemma_includes_anti_symmetric (i:rid) (j:rid)
:Lemma (requires (includes i j /\ i =!= j))
(ensures (not (includes j i)))
[SMTPat (includes i j)]
val lemma_extends_disjoint (i:rid) (j:rid) (k:rid)
:Lemma (requires (extends j i /\ extends k i /\ j =!= k))
(ensures (disjoint j k))
val lemma_extends_parent (i:rid{i =!= root})
:Lemma (extends i (parent i))
[SMTPat (parent i)]
val lemma_extends_not_root (i:rid) (j:rid{extends j i})
:Lemma (j =!= root)
[SMTPat (extends j i)]
val lemma_extends_only_parent (i:rid) (j:rid{extends j i})
:Lemma (i == parent j)
[SMTPat (extends j i)]
val mod_set (s:Set.set rid) :(Set.set rid)
assume Mod_set_def: forall (x:rid) (s:Set.set rid). {:pattern Set.mem x (mod_set s)}
Set.mem x (mod_set s) <==> (exists (y:rid). Set.mem y s /\ includes y x)
let modifies (s:Set.set rid) (m0:hmap) (m1:hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement (mod_set s)) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1)
let modifies_just (s:Set.set rid) (m0:hmap) (m1:hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement s) m0)) /\
Set.subset (Map.domain m0) (Map.domain m1)
let modifies_one (r:rid) (m0:hmap) (m1:hmap) = modifies_just (Set.singleton r) m0 m1
let equal_on (s:Set.set rid) (m0:hmap) (m1:hmap) =
(forall (r:rid). {:pattern (Map.contains m0 r)} (Set.mem r (mod_set s) /\ Map.contains m0 r) ==> Map.contains m1 r) /\
Map.equal m1 (Map.concat m1 (Map.restrict (mod_set s) m0))
let lemma_modifies_just_trans (m1:hmap) (m2:hmap) (m3:hmap)
(s1:Set.set rid) (s2:Set.set rid)
:Lemma (requires (modifies_just s1 m1 m2 /\ modifies_just s2 m2 m3))
(ensures (modifies_just (Set.union s1 s2) m1 m3))
= ()
let lemma_modifies_trans (m1:hmap) (m2:hmap) (m3:hmap)
(s1:Set.set rid) (s2:Set.set rid)
:Lemma (requires (modifies s1 m1 m2 /\ modifies s2 m2 m3))
(ensures (modifies (Set.union s1 s2) m1 m3))
= ()
val lemma_includes_trans (i:rid) (j:rid) (k:rid)
:Lemma (requires (includes i j /\ includes j k))
(ensures (includes i k))
(decreases (reveal k))
[SMTPat (includes i j); SMTPat (includes j k)]
val lemma_modset (i:rid) (j:rid)
:Lemma (requires (includes j i))
(ensures (Set.subset (mod_set (Set.singleton i)) (mod_set (Set.singleton j))))
val lemma_modifies_includes (m1:hmap) (m2:hmap) (i:rid) (j:rid)
:Lemma (requires (modifies (Set.singleton i) m1 m2 /\ includes j i))
(ensures (modifies (Set.singleton j) m1 m2))
val lemma_modifies_includes2 (m1:hmap) (m2:hmap) (s1:Set.set rid) (s2:Set.set rid)
:Lemma (requires (modifies s1 m1 m2 /\ (forall x. Set.mem x s1 ==> (exists y. Set.mem y s2 /\ includes y x))))
(ensures (modifies s2 m1 m2))
val lemma_disjoint_parents (pr:rid) (r:rid) (ps:rid) (s:rid)
:Lemma (requires (r `extends` pr /\ s `extends` ps /\ disjoint pr ps))
(ensures (disjoint r s))
[SMTPat (extends r pr); SMTPat (extends s ps); SMTPat (disjoint pr ps)]
val lemma_include_cons (i:rid) (j:rid)
:Lemma (requires (i =!= j /\ includes i j))
(ensures (j =!= root))
let disjoint_regions (s1:Set.set rid) (s2:Set.set rid) =
forall x y. {:pattern (Set.mem x s1); (Set.mem y s2)} (Set.mem x s1 /\ Set.mem y s2) ==> disjoint x y
val extends_parent (tip:rid{tip =!= root}) (r:rid)
:Lemma (extends r (parent tip) /\ r =!= tip ==> disjoint r tip \/ extends r tip)
[SMTPat (extends r (parent tip))]
val includes_child (tip:rid{tip =!= root}) (r:rid)
:Lemma (includes r tip ==> r == tip \/ includes r (parent tip))
[SMTPat (includes r (parent tip))]
val root_is_root (s:rid)
:Lemma (requires (includes s root))
(ensures (s == root))
[SMTPat (includes s root)]
unfold | false | true | FStar.Monotonic.HyperHeap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val extend_post (r: rid) (n c: int) (freeable: bool) : pure_post rid | [] | FStar.Monotonic.HyperHeap.extend_post | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | r: FStar.Monotonic.HyperHeap.rid -> n: Prims.int -> c: Prims.int -> freeable: Prims.bool
-> Prims.pure_post FStar.Monotonic.HyperHeap.rid | {
"end_col": 28,
"end_line": 186,
"start_col": 2,
"start_line": 181
} |
Prims.Tot | val no_static_asserts (sas: static_asserts) : Tot bool | [
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let no_static_asserts (sas: static_asserts) : Tot bool =
Nil? sas.includes &&
Nil? sas.sizeof_assertions | val no_static_asserts (sas: static_asserts) : Tot bool
let no_static_asserts (sas: static_asserts) : Tot bool = | false | null | false | Nil? sas.includes && Nil? sas.sizeof_assertions | {
"checked_file": "StaticAssertions.fst.checked",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"Options.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "StaticAssertions.fst"
} | [
"total"
] | [
"StaticAssertions.static_asserts",
"Prims.op_AmpAmp",
"Prims.uu___is_Nil",
"Prims.string",
"StaticAssertions.__proj__Mkstatic_asserts__item__includes",
"StaticAssertions.sizeof_assertion",
"StaticAssertions.__proj__Mkstatic_asserts__item__sizeof_assertions",
"Prims.bool"
] | [] | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain as copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module StaticAssertions
open FStar.All
open Ast
module B = Binding
noeq
type sizeof_assertion = {
type_name : ident;
size : int
}
noeq
type static_asserts = {
includes : list string;
sizeof_assertions : list sizeof_assertion
}
let empty_static_asserts = {
includes = [];
sizeof_assertions = []
}
let compute_static_asserts (benv:B.global_env)
(senv:TypeSizes.size_env)
(r:option type_refinement)
: ML static_asserts
= let env = B.mk_env benv, senv in
match r with
| None -> empty_static_asserts
| Some r ->
let sizeof_assertions =
r.type_map
|> List.map
(fun (i, jopt) ->
let j =
match jopt with
| None -> i
| Some j -> j
in
let t_j = with_dummy_range (Type_app j KindSpec []) in
match TypeSizes.size_of_typ env t_j with
| TypeSizes.Fixed n
| TypeSizes.WithVariableSuffix n ->
{ type_name = i;
size = n }
| _ ->
Ast.error
(Printf.sprintf
"Type %s is variable sized and cannot refine a C type %s"
(ident_to_string j) (ident_to_string i))
i.range)
in
{
includes = r.Ast.includes;
sizeof_assertions = sizeof_assertions
} | false | true | StaticAssertions.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val no_static_asserts (sas: static_asserts) : Tot bool | [] | StaticAssertions.no_static_asserts | {
"file_name": "src/3d/StaticAssertions.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | sas: StaticAssertions.static_asserts -> Prims.bool | {
"end_col": 28,
"end_line": 75,
"start_col": 2,
"start_line": 74
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let empty_static_asserts = {
includes = [];
sizeof_assertions = []
} | let empty_static_asserts = | false | null | false | { includes = []; sizeof_assertions = [] } | {
"checked_file": "StaticAssertions.fst.checked",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"Options.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "StaticAssertions.fst"
} | [
"total"
] | [
"StaticAssertions.Mkstatic_asserts",
"Prims.Nil",
"Prims.string",
"StaticAssertions.sizeof_assertion"
] | [] | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain as copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module StaticAssertions
open FStar.All
open Ast
module B = Binding
noeq
type sizeof_assertion = {
type_name : ident;
size : int
}
noeq
type static_asserts = {
includes : list string;
sizeof_assertions : list sizeof_assertion
} | false | true | StaticAssertions.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val empty_static_asserts : StaticAssertions.static_asserts | [] | StaticAssertions.empty_static_asserts | {
"file_name": "src/3d/StaticAssertions.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | StaticAssertions.static_asserts | {
"end_col": 24,
"end_line": 35,
"start_col": 2,
"start_line": 34
} |
|
Prims.Tot | val has_static_asserts (sas: static_asserts) : Tot bool | [
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let has_static_asserts (sas: static_asserts) : Tot bool =
not (no_static_asserts sas) | val has_static_asserts (sas: static_asserts) : Tot bool
let has_static_asserts (sas: static_asserts) : Tot bool = | false | null | false | not (no_static_asserts sas) | {
"checked_file": "StaticAssertions.fst.checked",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"Options.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "StaticAssertions.fst"
} | [
"total"
] | [
"StaticAssertions.static_asserts",
"Prims.op_Negation",
"StaticAssertions.no_static_asserts",
"Prims.bool"
] | [] | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain as copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module StaticAssertions
open FStar.All
open Ast
module B = Binding
noeq
type sizeof_assertion = {
type_name : ident;
size : int
}
noeq
type static_asserts = {
includes : list string;
sizeof_assertions : list sizeof_assertion
}
let empty_static_asserts = {
includes = [];
sizeof_assertions = []
}
let compute_static_asserts (benv:B.global_env)
(senv:TypeSizes.size_env)
(r:option type_refinement)
: ML static_asserts
= let env = B.mk_env benv, senv in
match r with
| None -> empty_static_asserts
| Some r ->
let sizeof_assertions =
r.type_map
|> List.map
(fun (i, jopt) ->
let j =
match jopt with
| None -> i
| Some j -> j
in
let t_j = with_dummy_range (Type_app j KindSpec []) in
match TypeSizes.size_of_typ env t_j with
| TypeSizes.Fixed n
| TypeSizes.WithVariableSuffix n ->
{ type_name = i;
size = n }
| _ ->
Ast.error
(Printf.sprintf
"Type %s is variable sized and cannot refine a C type %s"
(ident_to_string j) (ident_to_string i))
i.range)
in
{
includes = r.Ast.includes;
sizeof_assertions = sizeof_assertions
}
let no_static_asserts (sas: static_asserts) : Tot bool =
Nil? sas.includes &&
Nil? sas.sizeof_assertions | false | true | StaticAssertions.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val has_static_asserts (sas: static_asserts) : Tot bool | [] | StaticAssertions.has_static_asserts | {
"file_name": "src/3d/StaticAssertions.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | sas: StaticAssertions.static_asserts -> Prims.bool | {
"end_col": 29,
"end_line": 78,
"start_col": 2,
"start_line": 78
} |
FStar.All.ML | val print_static_asserts (sas: static_asserts) : ML string | [
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let print_static_asserts (sas:static_asserts)
: ML string
= let includes =
sas.includes
|> List.map (fun i -> Printf.sprintf "#include \"%s\"" i)
|> String.concat "\n"
in
let sizeof_assertions =
sas.sizeof_assertions
|> List.map (fun sa -> Printf.sprintf "C_ASSERT(sizeof(%s) == %d);" (ident_to_string sa.type_name) sa.size)
|> String.concat "\n"
in
Options.make_includes () ^
includes ^ "\n" ^ sizeof_assertions | val print_static_asserts (sas: static_asserts) : ML string
let print_static_asserts (sas: static_asserts) : ML string = | true | null | false | let includes =
sas.includes |> List.map (fun i -> Printf.sprintf "#include \"%s\"" i) |> String.concat "\n"
in
let sizeof_assertions =
sas.sizeof_assertions |>
List.map (fun sa ->
Printf.sprintf "C_ASSERT(sizeof(%s) == %d);" (ident_to_string sa.type_name) sa.size) |>
String.concat "\n"
in
Options.make_includes () ^ includes ^ "\n" ^ sizeof_assertions | {
"checked_file": "StaticAssertions.fst.checked",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"Options.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "StaticAssertions.fst"
} | [
"ml"
] | [
"StaticAssertions.static_asserts",
"Prims.op_Hat",
"Prims.string",
"Options.make_includes",
"FStar.All.op_Bar_Greater",
"Prims.list",
"FStar.String.concat",
"StaticAssertions.sizeof_assertion",
"StaticAssertions.__proj__Mkstatic_asserts__item__sizeof_assertions",
"FStar.List.map",
"FStar.Printf.sprintf",
"Ast.ident_to_string",
"StaticAssertions.__proj__Mksizeof_assertion__item__type_name",
"StaticAssertions.__proj__Mksizeof_assertion__item__size",
"StaticAssertions.__proj__Mkstatic_asserts__item__includes"
] | [] | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain as copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module StaticAssertions
open FStar.All
open Ast
module B = Binding
noeq
type sizeof_assertion = {
type_name : ident;
size : int
}
noeq
type static_asserts = {
includes : list string;
sizeof_assertions : list sizeof_assertion
}
let empty_static_asserts = {
includes = [];
sizeof_assertions = []
}
let compute_static_asserts (benv:B.global_env)
(senv:TypeSizes.size_env)
(r:option type_refinement)
: ML static_asserts
= let env = B.mk_env benv, senv in
match r with
| None -> empty_static_asserts
| Some r ->
let sizeof_assertions =
r.type_map
|> List.map
(fun (i, jopt) ->
let j =
match jopt with
| None -> i
| Some j -> j
in
let t_j = with_dummy_range (Type_app j KindSpec []) in
match TypeSizes.size_of_typ env t_j with
| TypeSizes.Fixed n
| TypeSizes.WithVariableSuffix n ->
{ type_name = i;
size = n }
| _ ->
Ast.error
(Printf.sprintf
"Type %s is variable sized and cannot refine a C type %s"
(ident_to_string j) (ident_to_string i))
i.range)
in
{
includes = r.Ast.includes;
sizeof_assertions = sizeof_assertions
}
let no_static_asserts (sas: static_asserts) : Tot bool =
Nil? sas.includes &&
Nil? sas.sizeof_assertions
let has_static_asserts (sas: static_asserts) : Tot bool =
not (no_static_asserts sas)
let print_static_asserts (sas:static_asserts) | false | false | StaticAssertions.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val print_static_asserts (sas: static_asserts) : ML string | [] | StaticAssertions.print_static_asserts | {
"file_name": "src/3d/StaticAssertions.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | sas: StaticAssertions.static_asserts -> FStar.All.ML Prims.string | {
"end_col": 39,
"end_line": 93,
"start_col": 3,
"start_line": 82
} |
FStar.All.ML | val compute_static_asserts
(benv: B.global_env)
(senv: TypeSizes.size_env)
(r: option type_refinement)
: ML static_asserts | [
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compute_static_asserts (benv:B.global_env)
(senv:TypeSizes.size_env)
(r:option type_refinement)
: ML static_asserts
= let env = B.mk_env benv, senv in
match r with
| None -> empty_static_asserts
| Some r ->
let sizeof_assertions =
r.type_map
|> List.map
(fun (i, jopt) ->
let j =
match jopt with
| None -> i
| Some j -> j
in
let t_j = with_dummy_range (Type_app j KindSpec []) in
match TypeSizes.size_of_typ env t_j with
| TypeSizes.Fixed n
| TypeSizes.WithVariableSuffix n ->
{ type_name = i;
size = n }
| _ ->
Ast.error
(Printf.sprintf
"Type %s is variable sized and cannot refine a C type %s"
(ident_to_string j) (ident_to_string i))
i.range)
in
{
includes = r.Ast.includes;
sizeof_assertions = sizeof_assertions
} | val compute_static_asserts
(benv: B.global_env)
(senv: TypeSizes.size_env)
(r: option type_refinement)
: ML static_asserts
let compute_static_asserts
(benv: B.global_env)
(senv: TypeSizes.size_env)
(r: option type_refinement)
: ML static_asserts = | true | null | false | let env = B.mk_env benv, senv in
match r with
| None -> empty_static_asserts
| Some r ->
let sizeof_assertions =
r.type_map |>
List.map (fun (i, jopt) ->
let j =
match jopt with
| None -> i
| Some j -> j
in
let t_j = with_dummy_range (Type_app j KindSpec []) in
match TypeSizes.size_of_typ env t_j with
| TypeSizes.Fixed n | TypeSizes.WithVariableSuffix n -> { type_name = i; size = n }
| _ ->
Ast.error (Printf.sprintf "Type %s is variable sized and cannot refine a C type %s"
(ident_to_string j)
(ident_to_string i))
i.range)
in
{ includes = r.Ast.includes; sizeof_assertions = sizeof_assertions } | {
"checked_file": "StaticAssertions.fst.checked",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"Options.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "StaticAssertions.fst"
} | [
"ml"
] | [
"GlobalEnv.global_env",
"TypeSizes.size_env",
"FStar.Pervasives.Native.option",
"Ast.type_refinement",
"StaticAssertions.empty_static_asserts",
"StaticAssertions.static_asserts",
"StaticAssertions.Mkstatic_asserts",
"Ast.__proj__Mktype_refinement__item__includes",
"Prims.list",
"StaticAssertions.sizeof_assertion",
"FStar.All.op_Bar_Greater",
"FStar.Pervasives.Native.tuple2",
"Ast.with_meta_t",
"Ast.ident'",
"Ast.__proj__Mktype_refinement__item__type_map",
"FStar.List.map",
"Prims.int",
"StaticAssertions.Mksizeof_assertion",
"TypeSizes.size",
"Ast.error",
"FStar.Printf.sprintf",
"Ast.ident_to_string",
"Ast.__proj__Mkwith_meta_t__item__range",
"TypeSizes.size_of_typ",
"Ast.typ'",
"Ast.with_dummy_range",
"Ast.Type_app",
"Ast.KindSpec",
"Prims.Nil",
"Ast.either",
"Ast.expr",
"Ast.out_expr",
"Binding.env",
"FStar.Pervasives.Native.Mktuple2",
"Binding.mk_env"
] | [] | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain as copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module StaticAssertions
open FStar.All
open Ast
module B = Binding
noeq
type sizeof_assertion = {
type_name : ident;
size : int
}
noeq
type static_asserts = {
includes : list string;
sizeof_assertions : list sizeof_assertion
}
let empty_static_asserts = {
includes = [];
sizeof_assertions = []
}
let compute_static_asserts (benv:B.global_env)
(senv:TypeSizes.size_env)
(r:option type_refinement) | false | false | StaticAssertions.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compute_static_asserts
(benv: B.global_env)
(senv: TypeSizes.size_env)
(r: option type_refinement)
: ML static_asserts | [] | StaticAssertions.compute_static_asserts | {
"file_name": "src/3d/StaticAssertions.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
benv: GlobalEnv.global_env ->
senv: TypeSizes.size_env ->
r: FStar.Pervasives.Native.option Ast.type_refinement
-> FStar.All.ML StaticAssertions.static_asserts | {
"end_col": 7,
"end_line": 71,
"start_col": 3,
"start_line": 42
} |
FStar.All.ML | val collect_and_sort_dependencies (files: list string) : ML (list string) | [
{
"abbrev": true,
"full_module": "Hashtable",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let collect_and_sort_dependencies (files:list string) : ML (list string) =
collect_and_sort_dependencies_from_graph (build_dep_graph_from_list files) files | val collect_and_sort_dependencies (files: list string) : ML (list string)
let collect_and_sort_dependencies (files: list string) : ML (list string) = | true | null | false | collect_and_sort_dependencies_from_graph (build_dep_graph_from_list files) files | {
"checked_file": "Deps.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.All.fst.checked",
"Config.fst.checked"
],
"interface_file": false,
"source_file": "Deps.fsti"
} | [
"ml"
] | [
"Prims.list",
"Prims.string",
"Deps.collect_and_sort_dependencies_from_graph",
"Deps.dep_graph",
"Deps.build_dep_graph_from_list"
] | [] | module Deps
open FStar.All
val dep_graph : Type0
val dependencies (graph: dep_graph) (modul: string) : Tot (list string)
val build_dep_graph_from_list (files: list string) : ML dep_graph
val collect_and_sort_dependencies_from_graph (g: dep_graph) (files:list string) : ML (list string) | false | false | Deps.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val collect_and_sort_dependencies (files: list string) : ML (list string) | [] | Deps.collect_and_sort_dependencies | {
"file_name": "src/3d/Deps.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | files: Prims.list Prims.string -> FStar.All.ML (Prims.list Prims.string) | {
"end_col": 82,
"end_line": 14,
"start_col": 2,
"start_line": 14
} |
Prims.Tot | val xor (x: uint8) (v: bytes) : lbytes (Seq.length v) | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let xor (x: uint8) (v: bytes) : lbytes (Seq.length v) =
Spec.Loops.seq_map (logxor x) v | val xor (x: uint8) (v: bytes) : lbytes (Seq.length v)
let xor (x: uint8) (v: bytes) : lbytes (Seq.length v) = | false | null | false | Spec.Loops.seq_map (logxor x) v | {
"checked_file": "Spec.Agile.HMAC.fst.checked",
"dependencies": [
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.Agile.HMAC.fst"
} | [
"total"
] | [
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.bytes",
"Spec.Loops.seq_map",
"Lib.IntTypes.logxor",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Spec.Agile.HMAC.lbytes",
"FStar.Seq.Base.length"
] | [] | module Spec.Agile.HMAC
open Spec.Hash.Definitions
open Lib.IntTypes
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
let wrap
(a: fixed_len_alg)
(key: bytes{Seq.length key `less_than_max_input_length` a})
: lbytes (block_length a)
=
let key0 = if Seq.length key <= block_length a then key else Spec.Agile.Hash.hash a key in
let paddingLength = block_length a - Seq.length key0 in
Seq.append key0 (Seq.create paddingLength (u8 0)) | false | false | Spec.Agile.HMAC.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val xor (x: uint8) (v: bytes) : lbytes (Seq.length v) | [] | Spec.Agile.HMAC.xor | {
"file_name": "specs/Spec.Agile.HMAC.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Lib.IntTypes.uint8 -> v: Spec.Hash.Definitions.bytes
-> Spec.Agile.HMAC.lbytes (FStar.Seq.Base.length v) | {
"end_col": 33,
"end_line": 18,
"start_col": 2,
"start_line": 18
} |
Prims.Pure | val hmac:
a: fixed_len_alg ->
key: bytes ->
data: bytes ->
Pure (lbytes (hash_length a))
(requires keysized a (Seq.length key) /\
(Seq.length data + block_length a) `less_than_max_input_length` a)
(ensures fun _ -> True) | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let hmac a key data =
assert_norm (pow2 32 < pow2 61);
assert_norm (pow2 32 < pow2 125);
let k = wrap a key in
let h1 = Spec.Agile.Hash.hash a (Seq.append (xor (u8 0x36) k) data) in
let h2 = Spec.Agile.Hash.hash a (Seq.append (xor (u8 0x5c) k) h1) in
h2 | val hmac:
a: fixed_len_alg ->
key: bytes ->
data: bytes ->
Pure (lbytes (hash_length a))
(requires keysized a (Seq.length key) /\
(Seq.length data + block_length a) `less_than_max_input_length` a)
(ensures fun _ -> True)
let hmac a key data = | false | null | false | assert_norm (pow2 32 < pow2 61);
assert_norm (pow2 32 < pow2 125);
let k = wrap a key in
let h1 = Spec.Agile.Hash.hash a (Seq.append (xor (u8 0x36) k) data) in
let h2 = Spec.Agile.Hash.hash a (Seq.append (xor (u8 0x5c) k) h1) in
h2 | {
"checked_file": "Spec.Agile.HMAC.fst.checked",
"dependencies": [
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.Agile.HMAC.fst"
} | [] | [
"Spec.Hash.Definitions.fixed_len_alg",
"Spec.Hash.Definitions.bytes",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Spec.Hash.Definitions.hash_length'",
"Spec.Agile.Hash.hash",
"FStar.Seq.Base.append",
"Lib.IntTypes.uint8",
"Spec.Agile.HMAC.xor",
"Lib.IntTypes.u8",
"Spec.Agile.HMAC.lbytes",
"Spec.Hash.Definitions.block_length",
"Spec.Agile.HMAC.wrap",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Spec.Hash.Definitions.hash_length"
] | [] | module Spec.Agile.HMAC
open Spec.Hash.Definitions
open Lib.IntTypes
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
let wrap
(a: fixed_len_alg)
(key: bytes{Seq.length key `less_than_max_input_length` a})
: lbytes (block_length a)
=
let key0 = if Seq.length key <= block_length a then key else Spec.Agile.Hash.hash a key in
let paddingLength = block_length a - Seq.length key0 in
Seq.append key0 (Seq.create paddingLength (u8 0))
let xor (x: uint8) (v: bytes) : lbytes (Seq.length v) =
Spec.Loops.seq_map (logxor x) v
#push-options "--max_fuel 1"
let rec xor_lemma (x: uint8) (v: bytes) : Lemma
(ensures xor x v == Spec.Loops.seq_map2 logxor (Seq.create (Seq.length v) x) v)
(decreases (Seq.length v))
=
let l = Seq.length v in
if l > 0 then (
let xs = Seq.create l x in
let xs' = Seq.create (l-1) x in
Seq.lemma_eq_intro (Seq.slice xs 1 l) xs';
xor_lemma x (Seq.slice v 1 l))
#pop-options | false | false | Spec.Agile.HMAC.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hmac:
a: fixed_len_alg ->
key: bytes ->
data: bytes ->
Pure (lbytes (hash_length a))
(requires keysized a (Seq.length key) /\
(Seq.length data + block_length a) `less_than_max_input_length` a)
(ensures fun _ -> True) | [] | Spec.Agile.HMAC.hmac | {
"file_name": "specs/Spec.Agile.HMAC.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Spec.Hash.Definitions.fixed_len_alg ->
key: Spec.Hash.Definitions.bytes ->
data: Spec.Hash.Definitions.bytes
-> Prims.Pure (Spec.Agile.HMAC.lbytes (Spec.Hash.Definitions.hash_length a)) | {
"end_col": 4,
"end_line": 41,
"start_col": 2,
"start_line": 36
} |
Prims.Tot | val wrap (a: fixed_len_alg) (key: bytes{(Seq.length key) `less_than_max_input_length` a})
: lbytes (block_length a) | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let wrap
(a: fixed_len_alg)
(key: bytes{Seq.length key `less_than_max_input_length` a})
: lbytes (block_length a)
=
let key0 = if Seq.length key <= block_length a then key else Spec.Agile.Hash.hash a key in
let paddingLength = block_length a - Seq.length key0 in
Seq.append key0 (Seq.create paddingLength (u8 0)) | val wrap (a: fixed_len_alg) (key: bytes{(Seq.length key) `less_than_max_input_length` a})
: lbytes (block_length a)
let wrap (a: fixed_len_alg) (key: bytes{(Seq.length key) `less_than_max_input_length` a})
: lbytes (block_length a) = | false | null | false | let key0 = if Seq.length key <= block_length a then key else Spec.Agile.Hash.hash a key in
let paddingLength = block_length a - Seq.length key0 in
Seq.append key0 (Seq.create paddingLength (u8 0)) | {
"checked_file": "Spec.Agile.HMAC.fst.checked",
"dependencies": [
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.Agile.HMAC.fst"
} | [
"total"
] | [
"Spec.Hash.Definitions.fixed_len_alg",
"Spec.Hash.Definitions.bytes",
"Prims.b2t",
"Spec.Hash.Definitions.less_than_max_input_length",
"FStar.Seq.Base.length",
"Lib.IntTypes.uint8",
"FStar.Seq.Base.append",
"FStar.Seq.Base.create",
"Lib.IntTypes.u8",
"Prims.int",
"Prims.op_Subtraction",
"Spec.Hash.Definitions.block_length",
"FStar.Seq.Base.seq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.op_LessThanOrEqual",
"Prims.bool",
"Spec.Agile.Hash.hash",
"Spec.Agile.HMAC.lbytes"
] | [] | module Spec.Agile.HMAC
open Spec.Hash.Definitions
open Lib.IntTypes
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
let wrap
(a: fixed_len_alg)
(key: bytes{Seq.length key `less_than_max_input_length` a}) | false | false | Spec.Agile.HMAC.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val wrap (a: fixed_len_alg) (key: bytes{(Seq.length key) `less_than_max_input_length` a})
: lbytes (block_length a) | [] | Spec.Agile.HMAC.wrap | {
"file_name": "specs/Spec.Agile.HMAC.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Spec.Hash.Definitions.fixed_len_alg ->
key:
Spec.Hash.Definitions.bytes
{Spec.Hash.Definitions.less_than_max_input_length (FStar.Seq.Base.length key) a}
-> Spec.Agile.HMAC.lbytes (Spec.Hash.Definitions.block_length a) | {
"end_col": 51,
"end_line": 15,
"start_col": 1,
"start_line": 12
} |
FStar.Pervasives.Lemma | val xor_lemma (x: uint8) (v: bytes)
: Lemma (ensures xor x v == Spec.Loops.seq_map2 logxor (Seq.create (Seq.length v) x) v)
(decreases (Seq.length v)) | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec xor_lemma (x: uint8) (v: bytes) : Lemma
(ensures xor x v == Spec.Loops.seq_map2 logxor (Seq.create (Seq.length v) x) v)
(decreases (Seq.length v))
=
let l = Seq.length v in
if l > 0 then (
let xs = Seq.create l x in
let xs' = Seq.create (l-1) x in
Seq.lemma_eq_intro (Seq.slice xs 1 l) xs';
xor_lemma x (Seq.slice v 1 l)) | val xor_lemma (x: uint8) (v: bytes)
: Lemma (ensures xor x v == Spec.Loops.seq_map2 logxor (Seq.create (Seq.length v) x) v)
(decreases (Seq.length v))
let rec xor_lemma (x: uint8) (v: bytes)
: Lemma (ensures xor x v == Spec.Loops.seq_map2 logxor (Seq.create (Seq.length v) x) v)
(decreases (Seq.length v)) = | false | null | true | let l = Seq.length v in
if l > 0
then
(let xs = Seq.create l x in
let xs' = Seq.create (l - 1) x in
Seq.lemma_eq_intro (Seq.slice xs 1 l) xs';
xor_lemma x (Seq.slice v 1 l)) | {
"checked_file": "Spec.Agile.HMAC.fst.checked",
"dependencies": [
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.Agile.HMAC.fst"
} | [
"lemma",
""
] | [
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.bytes",
"Prims.op_GreaterThan",
"Spec.Agile.HMAC.xor_lemma",
"FStar.Seq.Base.slice",
"Prims.unit",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Seq.Base.seq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.Seq.Base.create",
"Prims.op_Subtraction",
"Prims.bool",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.l_or",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Lib.IntTypes.logxor",
"Spec.Agile.HMAC.xor",
"Spec.Loops.seq_map2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Spec.Agile.HMAC
open Spec.Hash.Definitions
open Lib.IntTypes
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
let wrap
(a: fixed_len_alg)
(key: bytes{Seq.length key `less_than_max_input_length` a})
: lbytes (block_length a)
=
let key0 = if Seq.length key <= block_length a then key else Spec.Agile.Hash.hash a key in
let paddingLength = block_length a - Seq.length key0 in
Seq.append key0 (Seq.create paddingLength (u8 0))
let xor (x: uint8) (v: bytes) : lbytes (Seq.length v) =
Spec.Loops.seq_map (logxor x) v
#push-options "--max_fuel 1"
let rec xor_lemma (x: uint8) (v: bytes) : Lemma
(ensures xor x v == Spec.Loops.seq_map2 logxor (Seq.create (Seq.length v) x) v) | false | false | Spec.Agile.HMAC.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val xor_lemma (x: uint8) (v: bytes)
: Lemma (ensures xor x v == Spec.Loops.seq_map2 logxor (Seq.create (Seq.length v) x) v)
(decreases (Seq.length v)) | [
"recursion"
] | Spec.Agile.HMAC.xor_lemma | {
"file_name": "specs/Spec.Agile.HMAC.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Lib.IntTypes.uint8 -> v: Spec.Hash.Definitions.bytes
-> FStar.Pervasives.Lemma
(ensures
Spec.Agile.HMAC.xor x v ==
Spec.Loops.seq_map2 Lib.IntTypes.logxor
(FStar.Seq.Base.create (FStar.Seq.Base.length v) x)
v) (decreases FStar.Seq.Base.length v) | {
"end_col": 34,
"end_line": 31,
"start_col": 1,
"start_line": 25
} |
Steel.ST.Effect.Ghost.STGhost | val on_range_cons (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
((p i) `star` (on_range p j k))
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True) | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let on_range_cons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True)
= on_range_singleton_intro p i j;
on_range_join p i j k | val on_range_cons (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
((p i) `star` (on_range p j k))
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True)
let on_range_cons (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
((p i) `star` (on_range p j k))
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True) = | true | null | false | on_range_singleton_intro p i j;
on_range_join p i j k | {
"checked_file": "Steel.ST.OnRange.fsti.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.OnRange.fsti"
} | [] | [
"Steel.Memory.inames",
"Prims.nat",
"Steel.Effect.Common.vprop",
"Steel.ST.OnRange.on_range_join",
"Prims.unit",
"Steel.ST.OnRange.on_range_singleton_intro",
"Steel.Effect.Common.star",
"Steel.ST.OnRange.on_range",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Prims.l_True"
] | [] | module Steel.ST.OnRange
include Steel.ST.Util
val on_range (p: (nat -> vprop)) (i j: nat) : vprop
val on_range_le
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> on_range p i j)
True
(fun _ -> i <= j)
val on_range_empty
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
emp
(fun _ -> on_range p i j)
(i == j)
(fun _ -> True)
val on_range_singleton_intro
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
(p i)
(fun _ -> on_range p i j)
(j == i + 1)
(fun _ -> True)
val on_range_singleton_elim
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> p i)
(j == i + 1)
(fun _ -> True)
val on_range_split
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` on_range p j k)
(i <= j /\ j <= k)
(fun _ -> True)
val on_range_join
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhostT unit opened
(on_range p i j `star` on_range p j k)
(fun _ -> on_range p i k)
let on_range_cons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k)
(j == i + 1) | false | false | Steel.ST.OnRange.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val on_range_cons (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
((p i) `star` (on_range p j k))
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True) | [] | Steel.ST.OnRange.on_range_cons | {
"file_name": "lib/steel/Steel.ST.OnRange.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | p: (_: Prims.nat -> Steel.Effect.Common.vprop) -> i: Prims.nat -> j: Prims.nat -> k: Prims.nat
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | {
"end_col": 23,
"end_line": 76,
"start_col": 2,
"start_line": 75
} |
Steel.ST.Effect.Ghost.STGhost | val on_range_unsnoc (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
(on_range p i k)
(fun _ -> (on_range p i j) `star` (p j))
(i <= j /\ k == j + 1)
(fun _ -> True) | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let on_range_unsnoc
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` p j)
(i <= j /\ k == j + 1)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p j k | val on_range_unsnoc (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
(on_range p i k)
(fun _ -> (on_range p i j) `star` (p j))
(i <= j /\ k == j + 1)
(fun _ -> True)
let on_range_unsnoc (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
(on_range p i k)
(fun _ -> (on_range p i j) `star` (p j))
(i <= j /\ k == j + 1)
(fun _ -> True) = | true | null | false | on_range_split p i j k;
on_range_singleton_elim p j k | {
"checked_file": "Steel.ST.OnRange.fsti.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.OnRange.fsti"
} | [] | [
"Steel.Memory.inames",
"Prims.nat",
"Steel.Effect.Common.vprop",
"Steel.ST.OnRange.on_range_singleton_elim",
"Prims.unit",
"Steel.ST.OnRange.on_range_split",
"Steel.ST.OnRange.on_range",
"Steel.Effect.Common.star",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Prims.l_True"
] | [] | module Steel.ST.OnRange
include Steel.ST.Util
val on_range (p: (nat -> vprop)) (i j: nat) : vprop
val on_range_le
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> on_range p i j)
True
(fun _ -> i <= j)
val on_range_empty
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
emp
(fun _ -> on_range p i j)
(i == j)
(fun _ -> True)
val on_range_singleton_intro
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
(p i)
(fun _ -> on_range p i j)
(j == i + 1)
(fun _ -> True)
val on_range_singleton_elim
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> p i)
(j == i + 1)
(fun _ -> True)
val on_range_split
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` on_range p j k)
(i <= j /\ j <= k)
(fun _ -> True)
val on_range_join
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhostT unit opened
(on_range p i j `star` on_range p j k)
(fun _ -> on_range p i k)
let on_range_cons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True)
= on_range_singleton_intro p i j;
on_range_join p i j k
let on_range_uncons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p i `star` on_range p j k)
(j == i + 1 /\ j <= k)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p i j
let on_range_cons_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k `star`
(on_range p i k @==> (p i `star` on_range p j k))
)
(j == i + 1)
(fun _ -> True)
= on_range_le p j k;
on_range_cons p i j k;
intro_implies
(on_range p i k)
(p i `star` on_range p j k)
emp
(fun _ -> on_range_uncons p i j k)
let on_range_snoc
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1)
(fun _ -> True)
= rewrite (p j') (p j);
on_range_singleton_intro p j k;
on_range_join p i j k
let on_range_unsnoc
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` p j)
(i <= j /\ k == j + 1) | false | false | Steel.ST.OnRange.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val on_range_unsnoc (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
(on_range p i k)
(fun _ -> (on_range p i j) `star` (p j))
(i <= j /\ k == j + 1)
(fun _ -> True) | [] | Steel.ST.OnRange.on_range_unsnoc | {
"file_name": "lib/steel/Steel.ST.OnRange.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | p: (_: Prims.nat -> Steel.Effect.Common.vprop) -> i: Prims.nat -> j: Prims.nat -> k: Prims.nat
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | {
"end_col": 31,
"end_line": 132,
"start_col": 2,
"start_line": 131
} |
Steel.ST.Effect.Ghost.STGhost | val on_range_uncons (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
(on_range p i k)
(fun _ -> (p i) `star` (on_range p j k))
(j == i + 1 /\ j <= k)
(fun _ -> True) | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let on_range_uncons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p i `star` on_range p j k)
(j == i + 1 /\ j <= k)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p i j | val on_range_uncons (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
(on_range p i k)
(fun _ -> (p i) `star` (on_range p j k))
(j == i + 1 /\ j <= k)
(fun _ -> True)
let on_range_uncons (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
(on_range p i k)
(fun _ -> (p i) `star` (on_range p j k))
(j == i + 1 /\ j <= k)
(fun _ -> True) = | true | null | false | on_range_split p i j k;
on_range_singleton_elim p i j | {
"checked_file": "Steel.ST.OnRange.fsti.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.OnRange.fsti"
} | [] | [
"Steel.Memory.inames",
"Prims.nat",
"Steel.Effect.Common.vprop",
"Steel.ST.OnRange.on_range_singleton_elim",
"Prims.unit",
"Steel.ST.OnRange.on_range_split",
"Steel.ST.OnRange.on_range",
"Steel.Effect.Common.star",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.l_True"
] | [] | module Steel.ST.OnRange
include Steel.ST.Util
val on_range (p: (nat -> vprop)) (i j: nat) : vprop
val on_range_le
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> on_range p i j)
True
(fun _ -> i <= j)
val on_range_empty
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
emp
(fun _ -> on_range p i j)
(i == j)
(fun _ -> True)
val on_range_singleton_intro
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
(p i)
(fun _ -> on_range p i j)
(j == i + 1)
(fun _ -> True)
val on_range_singleton_elim
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> p i)
(j == i + 1)
(fun _ -> True)
val on_range_split
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` on_range p j k)
(i <= j /\ j <= k)
(fun _ -> True)
val on_range_join
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhostT unit opened
(on_range p i j `star` on_range p j k)
(fun _ -> on_range p i k)
let on_range_cons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True)
= on_range_singleton_intro p i j;
on_range_join p i j k
let on_range_uncons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p i `star` on_range p j k)
(j == i + 1 /\ j <= k) | false | false | Steel.ST.OnRange.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val on_range_uncons (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
(on_range p i k)
(fun _ -> (p i) `star` (on_range p j k))
(j == i + 1 /\ j <= k)
(fun _ -> True) | [] | Steel.ST.OnRange.on_range_uncons | {
"file_name": "lib/steel/Steel.ST.OnRange.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | p: (_: Prims.nat -> Steel.Effect.Common.vprop) -> i: Prims.nat -> j: Prims.nat -> k: Prims.nat
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | {
"end_col": 31,
"end_line": 88,
"start_col": 2,
"start_line": 87
} |
Steel.ST.Effect.Ghost.STGhost | val on_range_snoc (#opened: _) (p: (nat -> vprop)) (i j j' k: nat)
: STGhost unit
opened
((on_range p i j) `star` (p j'))
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1)
(fun _ -> True) | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let on_range_snoc
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1)
(fun _ -> True)
= rewrite (p j') (p j);
on_range_singleton_intro p j k;
on_range_join p i j k | val on_range_snoc (#opened: _) (p: (nat -> vprop)) (i j j' k: nat)
: STGhost unit
opened
((on_range p i j) `star` (p j'))
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1)
(fun _ -> True)
let on_range_snoc (#opened: _) (p: (nat -> vprop)) (i j j' k: nat)
: STGhost unit
opened
((on_range p i j) `star` (p j'))
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1)
(fun _ -> True) = | true | null | false | rewrite (p j') (p j);
on_range_singleton_intro p j k;
on_range_join p i j k | {
"checked_file": "Steel.ST.OnRange.fsti.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.OnRange.fsti"
} | [] | [
"Steel.Memory.inames",
"Prims.nat",
"Steel.Effect.Common.vprop",
"Steel.ST.OnRange.on_range_join",
"Prims.unit",
"Steel.ST.OnRange.on_range_singleton_intro",
"Steel.ST.Util.rewrite",
"Steel.Effect.Common.star",
"Steel.ST.OnRange.on_range",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Prims.l_True"
] | [] | module Steel.ST.OnRange
include Steel.ST.Util
val on_range (p: (nat -> vprop)) (i j: nat) : vprop
val on_range_le
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> on_range p i j)
True
(fun _ -> i <= j)
val on_range_empty
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
emp
(fun _ -> on_range p i j)
(i == j)
(fun _ -> True)
val on_range_singleton_intro
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
(p i)
(fun _ -> on_range p i j)
(j == i + 1)
(fun _ -> True)
val on_range_singleton_elim
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> p i)
(j == i + 1)
(fun _ -> True)
val on_range_split
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` on_range p j k)
(i <= j /\ j <= k)
(fun _ -> True)
val on_range_join
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhostT unit opened
(on_range p i j `star` on_range p j k)
(fun _ -> on_range p i k)
let on_range_cons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True)
= on_range_singleton_intro p i j;
on_range_join p i j k
let on_range_uncons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p i `star` on_range p j k)
(j == i + 1 /\ j <= k)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p i j
let on_range_cons_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k `star`
(on_range p i k @==> (p i `star` on_range p j k))
)
(j == i + 1)
(fun _ -> True)
= on_range_le p j k;
on_range_cons p i j k;
intro_implies
(on_range p i k)
(p i `star` on_range p j k)
emp
(fun _ -> on_range_uncons p i j k)
let on_range_snoc
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1) | false | false | Steel.ST.OnRange.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val on_range_snoc (#opened: _) (p: (nat -> vprop)) (i j j' k: nat)
: STGhost unit
opened
((on_range p i j) `star` (p j'))
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1)
(fun _ -> True) | [] | Steel.ST.OnRange.on_range_snoc | {
"file_name": "lib/steel/Steel.ST.OnRange.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
p: (_: Prims.nat -> Steel.Effect.Common.vprop) ->
i: Prims.nat ->
j: Prims.nat ->
j': Prims.nat ->
k: Prims.nat
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | {
"end_col": 23,
"end_line": 120,
"start_col": 2,
"start_line": 118
} |
Steel.ST.Effect.Ghost.STGhost | val on_range_get (#opened: _) (p: (nat -> vprop)) (i j k l: nat)
: STGhost unit
opened
(on_range p i l)
(fun _ -> ((on_range p i j) `star` (p j)) `star` (on_range p k l))
(i <= j /\ j + 1 == k /\ k <= l)
(fun _ -> True) | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let on_range_get
(#opened: _)
(p: (nat -> vprop))
(i j k l: nat)
: STGhost unit opened
(on_range p i l)
(fun _ -> on_range p i j `star` p j `star` on_range p k l)
(i <= j /\ j + 1 == k /\ k <= l)
(fun _ -> True)
= on_range_split p i j l;
on_range_split p j k l;
on_range_singleton_elim p j k | val on_range_get (#opened: _) (p: (nat -> vprop)) (i j k l: nat)
: STGhost unit
opened
(on_range p i l)
(fun _ -> ((on_range p i j) `star` (p j)) `star` (on_range p k l))
(i <= j /\ j + 1 == k /\ k <= l)
(fun _ -> True)
let on_range_get (#opened: _) (p: (nat -> vprop)) (i j k l: nat)
: STGhost unit
opened
(on_range p i l)
(fun _ -> ((on_range p i j) `star` (p j)) `star` (on_range p k l))
(i <= j /\ j + 1 == k /\ k <= l)
(fun _ -> True) = | true | null | false | on_range_split p i j l;
on_range_split p j k l;
on_range_singleton_elim p j k | {
"checked_file": "Steel.ST.OnRange.fsti.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.OnRange.fsti"
} | [] | [
"Steel.Memory.inames",
"Prims.nat",
"Steel.Effect.Common.vprop",
"Steel.ST.OnRange.on_range_singleton_elim",
"Prims.unit",
"Steel.ST.OnRange.on_range_split",
"Steel.ST.OnRange.on_range",
"Steel.Effect.Common.star",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Prims.l_True"
] | [] | module Steel.ST.OnRange
include Steel.ST.Util
val on_range (p: (nat -> vprop)) (i j: nat) : vprop
val on_range_le
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> on_range p i j)
True
(fun _ -> i <= j)
val on_range_empty
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
emp
(fun _ -> on_range p i j)
(i == j)
(fun _ -> True)
val on_range_singleton_intro
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
(p i)
(fun _ -> on_range p i j)
(j == i + 1)
(fun _ -> True)
val on_range_singleton_elim
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> p i)
(j == i + 1)
(fun _ -> True)
val on_range_split
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` on_range p j k)
(i <= j /\ j <= k)
(fun _ -> True)
val on_range_join
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhostT unit opened
(on_range p i j `star` on_range p j k)
(fun _ -> on_range p i k)
let on_range_cons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True)
= on_range_singleton_intro p i j;
on_range_join p i j k
let on_range_uncons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p i `star` on_range p j k)
(j == i + 1 /\ j <= k)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p i j
let on_range_cons_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k `star`
(on_range p i k @==> (p i `star` on_range p j k))
)
(j == i + 1)
(fun _ -> True)
= on_range_le p j k;
on_range_cons p i j k;
intro_implies
(on_range p i k)
(p i `star` on_range p j k)
emp
(fun _ -> on_range_uncons p i j k)
let on_range_snoc
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1)
(fun _ -> True)
= rewrite (p j') (p j);
on_range_singleton_intro p j k;
on_range_join p i j k
let on_range_unsnoc
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` p j)
(i <= j /\ k == j + 1)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p j k
let on_range_snoc_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k `star` (on_range p i k `implies_` (on_range p i j `star` p j')))
(j' == j /\ k == j + 1)
(fun _ -> True)
= on_range_le p i j;
on_range_snoc p i j j' k;
intro_implies
(on_range p i k)
(on_range p i j `star` p j')
emp
(fun _ ->
on_range_unsnoc p i j k;
rewrite (p j) (p j')
)
let on_range_get
(#opened: _)
(p: (nat -> vprop))
(i j k l: nat)
: STGhost unit opened
(on_range p i l)
(fun _ -> on_range p i j `star` p j `star` on_range p k l)
(i <= j /\ j + 1 == k /\ k <= l) | false | false | Steel.ST.OnRange.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val on_range_get (#opened: _) (p: (nat -> vprop)) (i j k l: nat)
: STGhost unit
opened
(on_range p i l)
(fun _ -> ((on_range p i j) `star` (p j)) `star` (on_range p k l))
(i <= j /\ j + 1 == k /\ k <= l)
(fun _ -> True) | [] | Steel.ST.OnRange.on_range_get | {
"file_name": "lib/steel/Steel.ST.OnRange.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
p: (_: Prims.nat -> Steel.Effect.Common.vprop) ->
i: Prims.nat ->
j: Prims.nat ->
k: Prims.nat ->
l: Prims.nat
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | {
"end_col": 31,
"end_line": 165,
"start_col": 2,
"start_line": 163
} |
Steel.ST.Effect.Ghost.STGhostT | val on_range_weaken
(#opened: _)
(p p': (nat -> vprop))
(i j: nat)
(phi: (k: nat{i <= k /\ k < j} -> STGhostT unit opened (p k) (fun _ -> p' k)))
: STGhostT unit opened (on_range p i j) (fun _ -> on_range p' i j) | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let on_range_weaken
(#opened: _)
(p p': (nat -> vprop))
(i: nat)
(j: nat)
(phi: (k: nat { i <= k /\ k < j }) -> STGhostT unit opened (p k) (fun _ -> p' k))
: STGhostT unit opened
(on_range p i j)
(fun _ -> on_range p' i j)
= on_range_weaken_and_shift
p p'
0
i j
(fun k -> phi k; rewrite (p' k) (p' (k + 0)))
i j | val on_range_weaken
(#opened: _)
(p p': (nat -> vprop))
(i j: nat)
(phi: (k: nat{i <= k /\ k < j} -> STGhostT unit opened (p k) (fun _ -> p' k)))
: STGhostT unit opened (on_range p i j) (fun _ -> on_range p' i j)
let on_range_weaken
(#opened: _)
(p p': (nat -> vprop))
(i j: nat)
(phi: (k: nat{i <= k /\ k < j} -> STGhostT unit opened (p k) (fun _ -> p' k)))
: STGhostT unit opened (on_range p i j) (fun _ -> on_range p' i j) = | true | null | false | on_range_weaken_and_shift p
p'
0
i
j
(fun k ->
phi k;
rewrite (p' k) (p' (k + 0)))
i
j | {
"checked_file": "Steel.ST.OnRange.fsti.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.OnRange.fsti"
} | [] | [
"Steel.Memory.inames",
"Prims.nat",
"Steel.Effect.Common.vprop",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.unit",
"Steel.ST.OnRange.on_range_weaken_and_shift",
"Steel.ST.Util.rewrite",
"Prims.op_Addition",
"Steel.ST.OnRange.on_range"
] | [] | module Steel.ST.OnRange
include Steel.ST.Util
val on_range (p: (nat -> vprop)) (i j: nat) : vprop
val on_range_le
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> on_range p i j)
True
(fun _ -> i <= j)
val on_range_empty
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
emp
(fun _ -> on_range p i j)
(i == j)
(fun _ -> True)
val on_range_singleton_intro
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
(p i)
(fun _ -> on_range p i j)
(j == i + 1)
(fun _ -> True)
val on_range_singleton_elim
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> p i)
(j == i + 1)
(fun _ -> True)
val on_range_split
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` on_range p j k)
(i <= j /\ j <= k)
(fun _ -> True)
val on_range_join
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhostT unit opened
(on_range p i j `star` on_range p j k)
(fun _ -> on_range p i k)
let on_range_cons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True)
= on_range_singleton_intro p i j;
on_range_join p i j k
let on_range_uncons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p i `star` on_range p j k)
(j == i + 1 /\ j <= k)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p i j
let on_range_cons_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k `star`
(on_range p i k @==> (p i `star` on_range p j k))
)
(j == i + 1)
(fun _ -> True)
= on_range_le p j k;
on_range_cons p i j k;
intro_implies
(on_range p i k)
(p i `star` on_range p j k)
emp
(fun _ -> on_range_uncons p i j k)
let on_range_snoc
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1)
(fun _ -> True)
= rewrite (p j') (p j);
on_range_singleton_intro p j k;
on_range_join p i j k
let on_range_unsnoc
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` p j)
(i <= j /\ k == j + 1)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p j k
let on_range_snoc_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k `star` (on_range p i k `implies_` (on_range p i j `star` p j')))
(j' == j /\ k == j + 1)
(fun _ -> True)
= on_range_le p i j;
on_range_snoc p i j j' k;
intro_implies
(on_range p i k)
(on_range p i j `star` p j')
emp
(fun _ ->
on_range_unsnoc p i j k;
rewrite (p j) (p j')
)
let on_range_get
(#opened: _)
(p: (nat -> vprop))
(i j k l: nat)
: STGhost unit opened
(on_range p i l)
(fun _ -> on_range p i j `star` p j `star` on_range p k l)
(i <= j /\ j + 1 == k /\ k <= l)
(fun _ -> True)
= on_range_split p i j l;
on_range_split p j k l;
on_range_singleton_elim p j k
let on_range_put
(#opened: _)
(p: (nat -> vprop))
(i j k l m: nat)
: STGhost unit opened
(on_range p i j `star` p k `star` on_range p l m)
(fun _ -> on_range p i m)
(j == k /\ k + 1 == l)
(fun _ -> True)
= rewrite (p k) (p j);
on_range_singleton_intro p j l;
on_range_join p i j l;
on_range_join p i l m
let on_range_focus
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p j `star` (p j `implies_` on_range p i k))
(i <= j /\ j < k)
(fun _ -> True)
= on_range_get p i j (j + 1) k;
intro_implies
(p j)
(on_range p i k)
(on_range p i j `star` on_range p (j + 1) k)
(fun _ ->
on_range_put p i j j (j + 1) k
)
let rec on_range_weaken_and_shift
(#opened: _)
(p p': (nat -> vprop))
(delta: int)
(i: nat { i + delta >= 0 })
(j: nat)
(phi: (k: nat { i <= k /\ k < j }) -> STGhostT unit opened (p k) (fun _ -> p' (k + delta)))
(i': nat { i' == i + delta })
(j': nat { j' == j + delta })
: STGhostT unit opened
(on_range p i j)
(fun _ -> on_range p' i' j')
(decreases (if j >= i then j - i else 0))
= on_range_le p i j;
if j <= i
then begin
drop (on_range p i j);
on_range_empty p' i' j'
end else begin
on_range_split p i (i + 1) j;
on_range_singleton_elim p i (i + 1);
phi i;
rewrite (p' _) (p' i');
on_range_singleton_intro p' i' (i' + 1);
on_range_weaken_and_shift p p' delta (i + 1) j phi (i' + 1) j';
on_range_join p' i' (i' + 1) j'
end
let on_range_weaken
(#opened: _)
(p p': (nat -> vprop))
(i: nat)
(j: nat)
(phi: (k: nat { i <= k /\ k < j }) -> STGhostT unit opened (p k) (fun _ -> p' k))
: STGhostT unit opened
(on_range p i j) | false | false | Steel.ST.OnRange.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val on_range_weaken
(#opened: _)
(p p': (nat -> vprop))
(i j: nat)
(phi: (k: nat{i <= k /\ k < j} -> STGhostT unit opened (p k) (fun _ -> p' k)))
: STGhostT unit opened (on_range p i j) (fun _ -> on_range p' i j) | [] | Steel.ST.OnRange.on_range_weaken | {
"file_name": "lib/steel/Steel.ST.OnRange.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
p: (_: Prims.nat -> Steel.Effect.Common.vprop) ->
p': (_: Prims.nat -> Steel.Effect.Common.vprop) ->
i: Prims.nat ->
j: Prims.nat ->
phi: (k: Prims.nat{i <= k /\ k < j} -> Steel.ST.Effect.Ghost.STGhostT Prims.unit)
-> Steel.ST.Effect.Ghost.STGhostT Prims.unit | {
"end_col": 7,
"end_line": 241,
"start_col": 2,
"start_line": 236
} |
Steel.ST.Effect.Ghost.STGhost | val on_range_focus (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
(on_range p i k)
(fun _ -> (p j) `star` ((p j) `implies_` (on_range p i k)))
(i <= j /\ j < k)
(fun _ -> True) | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let on_range_focus
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p j `star` (p j `implies_` on_range p i k))
(i <= j /\ j < k)
(fun _ -> True)
= on_range_get p i j (j + 1) k;
intro_implies
(p j)
(on_range p i k)
(on_range p i j `star` on_range p (j + 1) k)
(fun _ ->
on_range_put p i j j (j + 1) k
) | val on_range_focus (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
(on_range p i k)
(fun _ -> (p j) `star` ((p j) `implies_` (on_range p i k)))
(i <= j /\ j < k)
(fun _ -> True)
let on_range_focus (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
(on_range p i k)
(fun _ -> (p j) `star` ((p j) `implies_` (on_range p i k)))
(i <= j /\ j < k)
(fun _ -> True) = | true | null | false | on_range_get p i j (j + 1) k;
intro_implies (p j)
(on_range p i k)
((on_range p i j) `star` (on_range p (j + 1) k))
(fun _ -> on_range_put p i j j (j + 1) k) | {
"checked_file": "Steel.ST.OnRange.fsti.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.OnRange.fsti"
} | [] | [
"Steel.Memory.inames",
"Prims.nat",
"Steel.Effect.Common.vprop",
"Steel.ST.Util.intro_implies",
"Steel.ST.OnRange.on_range",
"Steel.Effect.Common.star",
"Prims.op_Addition",
"Steel.ST.OnRange.on_range_put",
"Prims.unit",
"Steel.ST.OnRange.on_range_get",
"Steel.ST.Util.implies_",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.l_True"
] | [] | module Steel.ST.OnRange
include Steel.ST.Util
val on_range (p: (nat -> vprop)) (i j: nat) : vprop
val on_range_le
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> on_range p i j)
True
(fun _ -> i <= j)
val on_range_empty
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
emp
(fun _ -> on_range p i j)
(i == j)
(fun _ -> True)
val on_range_singleton_intro
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
(p i)
(fun _ -> on_range p i j)
(j == i + 1)
(fun _ -> True)
val on_range_singleton_elim
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> p i)
(j == i + 1)
(fun _ -> True)
val on_range_split
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` on_range p j k)
(i <= j /\ j <= k)
(fun _ -> True)
val on_range_join
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhostT unit opened
(on_range p i j `star` on_range p j k)
(fun _ -> on_range p i k)
let on_range_cons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True)
= on_range_singleton_intro p i j;
on_range_join p i j k
let on_range_uncons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p i `star` on_range p j k)
(j == i + 1 /\ j <= k)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p i j
let on_range_cons_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k `star`
(on_range p i k @==> (p i `star` on_range p j k))
)
(j == i + 1)
(fun _ -> True)
= on_range_le p j k;
on_range_cons p i j k;
intro_implies
(on_range p i k)
(p i `star` on_range p j k)
emp
(fun _ -> on_range_uncons p i j k)
let on_range_snoc
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1)
(fun _ -> True)
= rewrite (p j') (p j);
on_range_singleton_intro p j k;
on_range_join p i j k
let on_range_unsnoc
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` p j)
(i <= j /\ k == j + 1)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p j k
let on_range_snoc_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k `star` (on_range p i k `implies_` (on_range p i j `star` p j')))
(j' == j /\ k == j + 1)
(fun _ -> True)
= on_range_le p i j;
on_range_snoc p i j j' k;
intro_implies
(on_range p i k)
(on_range p i j `star` p j')
emp
(fun _ ->
on_range_unsnoc p i j k;
rewrite (p j) (p j')
)
let on_range_get
(#opened: _)
(p: (nat -> vprop))
(i j k l: nat)
: STGhost unit opened
(on_range p i l)
(fun _ -> on_range p i j `star` p j `star` on_range p k l)
(i <= j /\ j + 1 == k /\ k <= l)
(fun _ -> True)
= on_range_split p i j l;
on_range_split p j k l;
on_range_singleton_elim p j k
let on_range_put
(#opened: _)
(p: (nat -> vprop))
(i j k l m: nat)
: STGhost unit opened
(on_range p i j `star` p k `star` on_range p l m)
(fun _ -> on_range p i m)
(j == k /\ k + 1 == l)
(fun _ -> True)
= rewrite (p k) (p j);
on_range_singleton_intro p j l;
on_range_join p i j l;
on_range_join p i l m
let on_range_focus
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p j `star` (p j `implies_` on_range p i k))
(i <= j /\ j < k) | false | false | Steel.ST.OnRange.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val on_range_focus (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
(on_range p i k)
(fun _ -> (p j) `star` ((p j) `implies_` (on_range p i k)))
(i <= j /\ j < k)
(fun _ -> True) | [] | Steel.ST.OnRange.on_range_focus | {
"file_name": "lib/steel/Steel.ST.OnRange.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | p: (_: Prims.nat -> Steel.Effect.Common.vprop) -> i: Prims.nat -> j: Prims.nat -> k: Prims.nat
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | {
"end_col": 5,
"end_line": 197,
"start_col": 2,
"start_line": 190
} |
Steel.ST.Effect.Ghost.STGhost | val on_range_put (#opened: _) (p: (nat -> vprop)) (i j k l m: nat)
: STGhost unit
opened
(((on_range p i j) `star` (p k)) `star` (on_range p l m))
(fun _ -> on_range p i m)
(j == k /\ k + 1 == l)
(fun _ -> True) | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let on_range_put
(#opened: _)
(p: (nat -> vprop))
(i j k l m: nat)
: STGhost unit opened
(on_range p i j `star` p k `star` on_range p l m)
(fun _ -> on_range p i m)
(j == k /\ k + 1 == l)
(fun _ -> True)
= rewrite (p k) (p j);
on_range_singleton_intro p j l;
on_range_join p i j l;
on_range_join p i l m | val on_range_put (#opened: _) (p: (nat -> vprop)) (i j k l m: nat)
: STGhost unit
opened
(((on_range p i j) `star` (p k)) `star` (on_range p l m))
(fun _ -> on_range p i m)
(j == k /\ k + 1 == l)
(fun _ -> True)
let on_range_put (#opened: _) (p: (nat -> vprop)) (i j k l m: nat)
: STGhost unit
opened
(((on_range p i j) `star` (p k)) `star` (on_range p l m))
(fun _ -> on_range p i m)
(j == k /\ k + 1 == l)
(fun _ -> True) = | true | null | false | rewrite (p k) (p j);
on_range_singleton_intro p j l;
on_range_join p i j l;
on_range_join p i l m | {
"checked_file": "Steel.ST.OnRange.fsti.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.OnRange.fsti"
} | [] | [
"Steel.Memory.inames",
"Prims.nat",
"Steel.Effect.Common.vprop",
"Steel.ST.OnRange.on_range_join",
"Prims.unit",
"Steel.ST.OnRange.on_range_singleton_intro",
"Steel.ST.Util.rewrite",
"Steel.Effect.Common.star",
"Steel.ST.OnRange.on_range",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Prims.l_True"
] | [] | module Steel.ST.OnRange
include Steel.ST.Util
val on_range (p: (nat -> vprop)) (i j: nat) : vprop
val on_range_le
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> on_range p i j)
True
(fun _ -> i <= j)
val on_range_empty
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
emp
(fun _ -> on_range p i j)
(i == j)
(fun _ -> True)
val on_range_singleton_intro
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
(p i)
(fun _ -> on_range p i j)
(j == i + 1)
(fun _ -> True)
val on_range_singleton_elim
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> p i)
(j == i + 1)
(fun _ -> True)
val on_range_split
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` on_range p j k)
(i <= j /\ j <= k)
(fun _ -> True)
val on_range_join
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhostT unit opened
(on_range p i j `star` on_range p j k)
(fun _ -> on_range p i k)
let on_range_cons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True)
= on_range_singleton_intro p i j;
on_range_join p i j k
let on_range_uncons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p i `star` on_range p j k)
(j == i + 1 /\ j <= k)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p i j
let on_range_cons_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k `star`
(on_range p i k @==> (p i `star` on_range p j k))
)
(j == i + 1)
(fun _ -> True)
= on_range_le p j k;
on_range_cons p i j k;
intro_implies
(on_range p i k)
(p i `star` on_range p j k)
emp
(fun _ -> on_range_uncons p i j k)
let on_range_snoc
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1)
(fun _ -> True)
= rewrite (p j') (p j);
on_range_singleton_intro p j k;
on_range_join p i j k
let on_range_unsnoc
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` p j)
(i <= j /\ k == j + 1)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p j k
let on_range_snoc_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k `star` (on_range p i k `implies_` (on_range p i j `star` p j')))
(j' == j /\ k == j + 1)
(fun _ -> True)
= on_range_le p i j;
on_range_snoc p i j j' k;
intro_implies
(on_range p i k)
(on_range p i j `star` p j')
emp
(fun _ ->
on_range_unsnoc p i j k;
rewrite (p j) (p j')
)
let on_range_get
(#opened: _)
(p: (nat -> vprop))
(i j k l: nat)
: STGhost unit opened
(on_range p i l)
(fun _ -> on_range p i j `star` p j `star` on_range p k l)
(i <= j /\ j + 1 == k /\ k <= l)
(fun _ -> True)
= on_range_split p i j l;
on_range_split p j k l;
on_range_singleton_elim p j k
let on_range_put
(#opened: _)
(p: (nat -> vprop))
(i j k l m: nat)
: STGhost unit opened
(on_range p i j `star` p k `star` on_range p l m)
(fun _ -> on_range p i m)
(j == k /\ k + 1 == l) | false | false | Steel.ST.OnRange.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val on_range_put (#opened: _) (p: (nat -> vprop)) (i j k l m: nat)
: STGhost unit
opened
(((on_range p i j) `star` (p k)) `star` (on_range p l m))
(fun _ -> on_range p i m)
(j == k /\ k + 1 == l)
(fun _ -> True) | [] | Steel.ST.OnRange.on_range_put | {
"file_name": "lib/steel/Steel.ST.OnRange.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
p: (_: Prims.nat -> Steel.Effect.Common.vprop) ->
i: Prims.nat ->
j: Prims.nat ->
k: Prims.nat ->
l: Prims.nat ->
m: Prims.nat
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | {
"end_col": 23,
"end_line": 179,
"start_col": 2,
"start_line": 176
} |
Steel.ST.Effect.Ghost.STGhost | val on_range_cons_with_implies (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
((p i) `star` (on_range p j k))
(fun _ -> (on_range p i k) `star` (on_range p i k @==> ((p i) `star` (on_range p j k))))
(j == i + 1)
(fun _ -> True) | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let on_range_cons_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k `star`
(on_range p i k @==> (p i `star` on_range p j k))
)
(j == i + 1)
(fun _ -> True)
= on_range_le p j k;
on_range_cons p i j k;
intro_implies
(on_range p i k)
(p i `star` on_range p j k)
emp
(fun _ -> on_range_uncons p i j k) | val on_range_cons_with_implies (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
((p i) `star` (on_range p j k))
(fun _ -> (on_range p i k) `star` (on_range p i k @==> ((p i) `star` (on_range p j k))))
(j == i + 1)
(fun _ -> True)
let on_range_cons_with_implies (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
((p i) `star` (on_range p j k))
(fun _ -> (on_range p i k) `star` (on_range p i k @==> ((p i) `star` (on_range p j k))))
(j == i + 1)
(fun _ -> True) = | true | null | false | on_range_le p j k;
on_range_cons p i j k;
intro_implies (on_range p i k)
((p i) `star` (on_range p j k))
emp
(fun _ -> on_range_uncons p i j k) | {
"checked_file": "Steel.ST.OnRange.fsti.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.OnRange.fsti"
} | [] | [
"Steel.Memory.inames",
"Prims.nat",
"Steel.Effect.Common.vprop",
"Steel.ST.Util.intro_implies",
"Steel.ST.OnRange.on_range",
"Steel.Effect.Common.star",
"Steel.Effect.Common.emp",
"Steel.ST.OnRange.on_range_uncons",
"Prims.unit",
"Steel.ST.OnRange.on_range_cons",
"Steel.ST.OnRange.on_range_le",
"Steel.ST.Util.op_At_Equals_Equals_Greater",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Prims.l_True"
] | [] | module Steel.ST.OnRange
include Steel.ST.Util
val on_range (p: (nat -> vprop)) (i j: nat) : vprop
val on_range_le
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> on_range p i j)
True
(fun _ -> i <= j)
val on_range_empty
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
emp
(fun _ -> on_range p i j)
(i == j)
(fun _ -> True)
val on_range_singleton_intro
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
(p i)
(fun _ -> on_range p i j)
(j == i + 1)
(fun _ -> True)
val on_range_singleton_elim
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> p i)
(j == i + 1)
(fun _ -> True)
val on_range_split
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` on_range p j k)
(i <= j /\ j <= k)
(fun _ -> True)
val on_range_join
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhostT unit opened
(on_range p i j `star` on_range p j k)
(fun _ -> on_range p i k)
let on_range_cons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True)
= on_range_singleton_intro p i j;
on_range_join p i j k
let on_range_uncons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p i `star` on_range p j k)
(j == i + 1 /\ j <= k)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p i j
let on_range_cons_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k `star`
(on_range p i k @==> (p i `star` on_range p j k))
)
(j == i + 1) | false | false | Steel.ST.OnRange.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val on_range_cons_with_implies (#opened: _) (p: (nat -> vprop)) (i j k: nat)
: STGhost unit
opened
((p i) `star` (on_range p j k))
(fun _ -> (on_range p i k) `star` (on_range p i k @==> ((p i) `star` (on_range p j k))))
(j == i + 1)
(fun _ -> True) | [] | Steel.ST.OnRange.on_range_cons_with_implies | {
"file_name": "lib/steel/Steel.ST.OnRange.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | p: (_: Prims.nat -> Steel.Effect.Common.vprop) -> i: Prims.nat -> j: Prims.nat -> k: Prims.nat
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | {
"end_col": 38,
"end_line": 107,
"start_col": 2,
"start_line": 101
} |
Steel.ST.Effect.Ghost.STGhost | val on_range_snoc_with_implies (#opened: _) (p: (nat -> vprop)) (i j j' k: nat)
: STGhost unit
opened
((on_range p i j) `star` (p j'))
(fun _ ->
(on_range p i k) `star` ((on_range p i k) `implies_` ((on_range p i j) `star` (p j'))))
(j' == j /\ k == j + 1)
(fun _ -> True) | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let on_range_snoc_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k `star` (on_range p i k `implies_` (on_range p i j `star` p j')))
(j' == j /\ k == j + 1)
(fun _ -> True)
= on_range_le p i j;
on_range_snoc p i j j' k;
intro_implies
(on_range p i k)
(on_range p i j `star` p j')
emp
(fun _ ->
on_range_unsnoc p i j k;
rewrite (p j) (p j')
) | val on_range_snoc_with_implies (#opened: _) (p: (nat -> vprop)) (i j j' k: nat)
: STGhost unit
opened
((on_range p i j) `star` (p j'))
(fun _ ->
(on_range p i k) `star` ((on_range p i k) `implies_` ((on_range p i j) `star` (p j'))))
(j' == j /\ k == j + 1)
(fun _ -> True)
let on_range_snoc_with_implies (#opened: _) (p: (nat -> vprop)) (i j j' k: nat)
: STGhost unit
opened
((on_range p i j) `star` (p j'))
(fun _ ->
(on_range p i k) `star` ((on_range p i k) `implies_` ((on_range p i j) `star` (p j'))))
(j' == j /\ k == j + 1)
(fun _ -> True) = | true | null | false | on_range_le p i j;
on_range_snoc p i j j' k;
intro_implies (on_range p i k)
((on_range p i j) `star` (p j'))
emp
(fun _ ->
on_range_unsnoc p i j k;
rewrite (p j) (p j')) | {
"checked_file": "Steel.ST.OnRange.fsti.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.OnRange.fsti"
} | [] | [
"Steel.Memory.inames",
"Prims.nat",
"Steel.Effect.Common.vprop",
"Steel.ST.Util.intro_implies",
"Steel.ST.OnRange.on_range",
"Steel.Effect.Common.star",
"Steel.Effect.Common.emp",
"Steel.ST.Util.rewrite",
"Prims.unit",
"Steel.ST.OnRange.on_range_unsnoc",
"Steel.ST.OnRange.on_range_snoc",
"Steel.ST.OnRange.on_range_le",
"Steel.ST.Util.implies_",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Prims.l_True"
] | [] | module Steel.ST.OnRange
include Steel.ST.Util
val on_range (p: (nat -> vprop)) (i j: nat) : vprop
val on_range_le
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> on_range p i j)
True
(fun _ -> i <= j)
val on_range_empty
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
emp
(fun _ -> on_range p i j)
(i == j)
(fun _ -> True)
val on_range_singleton_intro
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
(p i)
(fun _ -> on_range p i j)
(j == i + 1)
(fun _ -> True)
val on_range_singleton_elim
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> p i)
(j == i + 1)
(fun _ -> True)
val on_range_split
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` on_range p j k)
(i <= j /\ j <= k)
(fun _ -> True)
val on_range_join
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhostT unit opened
(on_range p i j `star` on_range p j k)
(fun _ -> on_range p i k)
let on_range_cons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True)
= on_range_singleton_intro p i j;
on_range_join p i j k
let on_range_uncons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p i `star` on_range p j k)
(j == i + 1 /\ j <= k)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p i j
let on_range_cons_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k `star`
(on_range p i k @==> (p i `star` on_range p j k))
)
(j == i + 1)
(fun _ -> True)
= on_range_le p j k;
on_range_cons p i j k;
intro_implies
(on_range p i k)
(p i `star` on_range p j k)
emp
(fun _ -> on_range_uncons p i j k)
let on_range_snoc
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1)
(fun _ -> True)
= rewrite (p j') (p j);
on_range_singleton_intro p j k;
on_range_join p i j k
let on_range_unsnoc
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` p j)
(i <= j /\ k == j + 1)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p j k
let on_range_snoc_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k `star` (on_range p i k `implies_` (on_range p i j `star` p j')))
(j' == j /\ k == j + 1) | false | false | Steel.ST.OnRange.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val on_range_snoc_with_implies (#opened: _) (p: (nat -> vprop)) (i j j' k: nat)
: STGhost unit
opened
((on_range p i j) `star` (p j'))
(fun _ ->
(on_range p i k) `star` ((on_range p i k) `implies_` ((on_range p i j) `star` (p j'))))
(j' == j /\ k == j + 1)
(fun _ -> True) | [] | Steel.ST.OnRange.on_range_snoc_with_implies | {
"file_name": "lib/steel/Steel.ST.OnRange.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
p: (_: Prims.nat -> Steel.Effect.Common.vprop) ->
i: Prims.nat ->
j: Prims.nat ->
j': Prims.nat ->
k: Prims.nat
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | {
"end_col": 5,
"end_line": 152,
"start_col": 2,
"start_line": 143
} |
Steel.ST.Effect.Ghost.STGhostT | val on_range_weaken_and_shift
(#opened: _)
(p p': (nat -> vprop))
(delta: int)
(i: nat{i + delta >= 0})
(j: nat)
(phi: (k: nat{i <= k /\ k < j} -> STGhostT unit opened (p k) (fun _ -> p' (k + delta))))
(i': nat{i' == i + delta})
(j': nat{j' == j + delta})
: STGhostT unit
opened
(on_range p i j)
(fun _ -> on_range p' i' j')
(decreases (if j >= i then j - i else 0)) | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec on_range_weaken_and_shift
(#opened: _)
(p p': (nat -> vprop))
(delta: int)
(i: nat { i + delta >= 0 })
(j: nat)
(phi: (k: nat { i <= k /\ k < j }) -> STGhostT unit opened (p k) (fun _ -> p' (k + delta)))
(i': nat { i' == i + delta })
(j': nat { j' == j + delta })
: STGhostT unit opened
(on_range p i j)
(fun _ -> on_range p' i' j')
(decreases (if j >= i then j - i else 0))
= on_range_le p i j;
if j <= i
then begin
drop (on_range p i j);
on_range_empty p' i' j'
end else begin
on_range_split p i (i + 1) j;
on_range_singleton_elim p i (i + 1);
phi i;
rewrite (p' _) (p' i');
on_range_singleton_intro p' i' (i' + 1);
on_range_weaken_and_shift p p' delta (i + 1) j phi (i' + 1) j';
on_range_join p' i' (i' + 1) j'
end | val on_range_weaken_and_shift
(#opened: _)
(p p': (nat -> vprop))
(delta: int)
(i: nat{i + delta >= 0})
(j: nat)
(phi: (k: nat{i <= k /\ k < j} -> STGhostT unit opened (p k) (fun _ -> p' (k + delta))))
(i': nat{i' == i + delta})
(j': nat{j' == j + delta})
: STGhostT unit
opened
(on_range p i j)
(fun _ -> on_range p' i' j')
(decreases (if j >= i then j - i else 0))
let rec on_range_weaken_and_shift
(#opened: _)
(p p': (nat -> vprop))
(delta: int)
(i: nat{i + delta >= 0})
(j: nat)
(phi: (k: nat{i <= k /\ k < j} -> STGhostT unit opened (p k) (fun _ -> p' (k + delta))))
(i': nat{i' == i + delta})
(j': nat{j' == j + delta})
: STGhostT unit
opened
(on_range p i j)
(fun _ -> on_range p' i' j')
(decreases (if j >= i then j - i else 0)) = | true | null | false | on_range_le p i j;
if j <= i
then
(drop (on_range p i j);
on_range_empty p' i' j')
else
(on_range_split p i (i + 1) j;
on_range_singleton_elim p i (i + 1);
phi i;
rewrite (p' _) (p' i');
on_range_singleton_intro p' i' (i' + 1);
on_range_weaken_and_shift p p' delta (i + 1) j phi (i' + 1) j';
on_range_join p' i' (i' + 1) j') | {
"checked_file": "Steel.ST.OnRange.fsti.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.OnRange.fsti"
} | [
""
] | [
"Steel.Memory.inames",
"Prims.nat",
"Steel.Effect.Common.vprop",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_Addition",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.unit",
"Prims.eq2",
"Steel.ST.OnRange.on_range_empty",
"Steel.ST.Util.drop",
"Steel.ST.OnRange.on_range",
"Prims.bool",
"Steel.ST.OnRange.on_range_join",
"Steel.ST.OnRange.on_range_weaken_and_shift",
"Steel.ST.OnRange.on_range_singleton_intro",
"Steel.ST.Util.rewrite",
"Steel.ST.OnRange.on_range_singleton_elim",
"Steel.ST.OnRange.on_range_split",
"Steel.ST.OnRange.on_range_le"
] | [] | module Steel.ST.OnRange
include Steel.ST.Util
val on_range (p: (nat -> vprop)) (i j: nat) : vprop
val on_range_le
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> on_range p i j)
True
(fun _ -> i <= j)
val on_range_empty
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
emp
(fun _ -> on_range p i j)
(i == j)
(fun _ -> True)
val on_range_singleton_intro
(#opened: _)
(p: (nat -> vprop))
(i: nat)
(j: nat)
: STGhost unit opened
(p i)
(fun _ -> on_range p i j)
(j == i + 1)
(fun _ -> True)
val on_range_singleton_elim
(#opened: _)
(p: (nat -> vprop))
(i j: nat)
: STGhost unit opened
(on_range p i j)
(fun _ -> p i)
(j == i + 1)
(fun _ -> True)
val on_range_split
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` on_range p j k)
(i <= j /\ j <= k)
(fun _ -> True)
val on_range_join
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhostT unit opened
(on_range p i j `star` on_range p j k)
(fun _ -> on_range p i k)
let on_range_cons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k)
(j == i + 1)
(fun _ -> True)
= on_range_singleton_intro p i j;
on_range_join p i j k
let on_range_uncons
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p i `star` on_range p j k)
(j == i + 1 /\ j <= k)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p i j
let on_range_cons_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(p i `star` on_range p j k)
(fun _ -> on_range p i k `star`
(on_range p i k @==> (p i `star` on_range p j k))
)
(j == i + 1)
(fun _ -> True)
= on_range_le p j k;
on_range_cons p i j k;
intro_implies
(on_range p i k)
(p i `star` on_range p j k)
emp
(fun _ -> on_range_uncons p i j k)
let on_range_snoc
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k)
(j' == j /\ k == j + 1)
(fun _ -> True)
= rewrite (p j') (p j);
on_range_singleton_intro p j k;
on_range_join p i j k
let on_range_unsnoc
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> on_range p i j `star` p j)
(i <= j /\ k == j + 1)
(fun _ -> True)
= on_range_split p i j k;
on_range_singleton_elim p j k
let on_range_snoc_with_implies
(#opened: _)
(p: (nat -> vprop))
(i j j' k: nat)
: STGhost unit opened
(on_range p i j `star` p j')
(fun _ -> on_range p i k `star` (on_range p i k `implies_` (on_range p i j `star` p j')))
(j' == j /\ k == j + 1)
(fun _ -> True)
= on_range_le p i j;
on_range_snoc p i j j' k;
intro_implies
(on_range p i k)
(on_range p i j `star` p j')
emp
(fun _ ->
on_range_unsnoc p i j k;
rewrite (p j) (p j')
)
let on_range_get
(#opened: _)
(p: (nat -> vprop))
(i j k l: nat)
: STGhost unit opened
(on_range p i l)
(fun _ -> on_range p i j `star` p j `star` on_range p k l)
(i <= j /\ j + 1 == k /\ k <= l)
(fun _ -> True)
= on_range_split p i j l;
on_range_split p j k l;
on_range_singleton_elim p j k
let on_range_put
(#opened: _)
(p: (nat -> vprop))
(i j k l m: nat)
: STGhost unit opened
(on_range p i j `star` p k `star` on_range p l m)
(fun _ -> on_range p i m)
(j == k /\ k + 1 == l)
(fun _ -> True)
= rewrite (p k) (p j);
on_range_singleton_intro p j l;
on_range_join p i j l;
on_range_join p i l m
let on_range_focus
(#opened: _)
(p: (nat -> vprop))
(i j k: nat)
: STGhost unit opened
(on_range p i k)
(fun _ -> p j `star` (p j `implies_` on_range p i k))
(i <= j /\ j < k)
(fun _ -> True)
= on_range_get p i j (j + 1) k;
intro_implies
(p j)
(on_range p i k)
(on_range p i j `star` on_range p (j + 1) k)
(fun _ ->
on_range_put p i j j (j + 1) k
)
let rec on_range_weaken_and_shift
(#opened: _)
(p p': (nat -> vprop))
(delta: int)
(i: nat { i + delta >= 0 })
(j: nat)
(phi: (k: nat { i <= k /\ k < j }) -> STGhostT unit opened (p k) (fun _ -> p' (k + delta)))
(i': nat { i' == i + delta })
(j': nat { j' == j + delta })
: STGhostT unit opened
(on_range p i j)
(fun _ -> on_range p' i' j') | false | false | Steel.ST.OnRange.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val on_range_weaken_and_shift
(#opened: _)
(p p': (nat -> vprop))
(delta: int)
(i: nat{i + delta >= 0})
(j: nat)
(phi: (k: nat{i <= k /\ k < j} -> STGhostT unit opened (p k) (fun _ -> p' (k + delta))))
(i': nat{i' == i + delta})
(j': nat{j' == j + delta})
: STGhostT unit
opened
(on_range p i j)
(fun _ -> on_range p' i' j')
(decreases (if j >= i then j - i else 0)) | [
"recursion"
] | Steel.ST.OnRange.on_range_weaken_and_shift | {
"file_name": "lib/steel/Steel.ST.OnRange.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
p: (_: Prims.nat -> Steel.Effect.Common.vprop) ->
p': (_: Prims.nat -> Steel.Effect.Common.vprop) ->
delta: Prims.int ->
i: Prims.nat{i + delta >= 0} ->
j: Prims.nat ->
phi: (k: Prims.nat{i <= k /\ k < j} -> Steel.ST.Effect.Ghost.STGhostT Prims.unit) ->
i': Prims.nat{i' == i + delta} ->
j': Prims.nat{j' == j + delta}
-> Steel.ST.Effect.Ghost.STGhostT Prims.unit | {
"end_col": 5,
"end_line": 225,
"start_col": 2,
"start_line": 212
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i} | let generate_elem_a (t a: Type0) (max: nat) (i: nat{i <= max}) = | false | null | false | a & s: seq t {length s == i} | {
"checked_file": "Hacl.Spec.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Lib.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Pervasives.Native.tuple2",
"Lib.Sequence.seq",
"Prims.eq2",
"Lib.Sequence.length"
] | [] | module Hacl.Spec.Lib
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
module Loops = Lib.LoopCombinators
module VecLemmas = Lib.Vec.Lemmas
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" | false | false | Hacl.Spec.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val generate_elem_a : t: Type0 -> a: Type0 -> max: Prims.nat -> i: Prims.nat{i <= max} -> Type0 | [] | Hacl.Spec.Lib.generate_elem_a | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Type0 -> a: Type0 -> max: Prims.nat -> i: Prims.nat{i <= max} -> Type0 | {
"end_col": 96,
"end_line": 13,
"start_col": 70,
"start_line": 13
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.