file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.Monotonic.HyperHeap.fsti | FStar.Monotonic.HyperHeap.disjoint | val disjoint (i j: rid) : GTot bool | val disjoint (i j: rid) : GTot bool | let disjoint (i:rid) (j:rid) :GTot bool = not (includes i j) && not (includes j i) | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 82,
"end_line": 64,
"start_col": 0,
"start_line": 64
} | (*
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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | i: FStar.Monotonic.HyperHeap.rid -> j: FStar.Monotonic.HyperHeap.rid -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Monotonic.HyperHeap.rid",
"Prims.op_AmpAmp",
"Prims.op_Negation",
"FStar.Monotonic.HyperHeap.includes",
"Prims.bool"
] | [] | false | false | false | false | false | let disjoint (i j: rid) : GTot bool =
| not (includes i j) && not (includes j i) | false |
FStar.Monotonic.HyperHeap.fsti | FStar.Monotonic.HyperHeap.modifies_one | val modifies_one : r: FStar.Monotonic.HyperHeap.rid ->
m0: FStar.Monotonic.HyperHeap.hmap ->
m1: FStar.Monotonic.HyperHeap.hmap
-> Prims.logical | let modifies_one (r:rid) (m0:hmap) (m1:hmap) = modifies_just (Set.singleton r) m0 m1 | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 84,
"end_line": 118,
"start_col": 0,
"start_line": 118
} | (*
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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
r: FStar.Monotonic.HyperHeap.rid ->
m0: FStar.Monotonic.HyperHeap.hmap ->
m1: FStar.Monotonic.HyperHeap.hmap
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperHeap.rid",
"FStar.Monotonic.HyperHeap.hmap",
"FStar.Monotonic.HyperHeap.modifies_just",
"FStar.Set.singleton",
"Prims.logical"
] | [] | false | false | false | true | true | let modifies_one (r: rid) (m0 m1: hmap) =
| modifies_just (Set.singleton r) m0 m1 | false |
|
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.synth_bitsum_case_injective | 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))] | 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))]
= synth_injective_intro' (synth_case.f x) (fun y z ->
synth_case.f_inj x y z
) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 742,
"start_col": 0,
"start_line": 727
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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))] | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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) | false |
FStar.Monotonic.HyperHeap.fsti | FStar.Monotonic.HyperHeap.equal_on | val equal_on : s: FStar.Set.set FStar.Monotonic.HyperHeap.rid ->
m0: FStar.Monotonic.HyperHeap.hmap ->
m1: FStar.Monotonic.HyperHeap.hmap
-> Prims.logical | 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)) | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 59,
"end_line": 122,
"start_col": 0,
"start_line": 120
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
s: FStar.Set.set FStar.Monotonic.HyperHeap.rid ->
m0: FStar.Monotonic.HyperHeap.hmap ->
m1: FStar.Monotonic.HyperHeap.hmap
-> Prims.logical | Prims.Tot | [
"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"
] | [] | false | false | false | true | true | let equal_on (s: Set.set rid) (m0 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)) | false |
|
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.synth_case_g_f_eq | 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) | 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)
= s.f_g_eq k (s.f k x);
s.f_inj k (s.g k (s.f k x)) x | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 31,
"end_line": 676,
"start_col": 0,
"start_line": 662
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.serialize_bitsum_alt_2 | 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 | 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
= let k = bitsum'_key_of_t b tg in
serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 77,
"end_line": 1046,
"start_col": 0,
"start_line": 1028
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.GTot | [
"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"
] | [] | false | false | false | false | 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) | false |
FStar.Monotonic.HyperHeap.fsti | FStar.Monotonic.HyperHeap.rid_last_component | val rid_last_component (r: rid) : GTot int | val rid_last_component (r: rid) : GTot 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) | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 42,
"start_col": 0,
"start_line": 38
} | (*
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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | r: FStar.Monotonic.HyperHeap.rid -> Prims.GTot Prims.int | Prims.GTot | [
"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"
] | [] | false | false | false | false | 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) | false |
FStar.Monotonic.HyperHeap.fsti | FStar.Monotonic.HyperHeap.disjoint_regions | val disjoint_regions : s1: FStar.Set.set FStar.Monotonic.HyperHeap.rid -> s2: FStar.Set.set FStar.Monotonic.HyperHeap.rid
-> Prims.logical | 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 | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 106,
"end_line": 164,
"start_col": 0,
"start_line": 163
} | (*
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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | s1: FStar.Set.set FStar.Monotonic.HyperHeap.rid -> s2: FStar.Set.set FStar.Monotonic.HyperHeap.rid
-> Prims.logical | Prims.Tot | [
"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"
] | [] | false | false | false | true | true | let disjoint_regions (s1 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 | false |
|
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.parse_bitsum_cases | 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)) | 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))
= 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) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 90,
"end_line": 758,
"start_col": 0,
"start_line": 744
} | 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
) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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)) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.serialize_bitsum_eq' | 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) | 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)
= serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 64,
"end_line": 1026,
"start_col": 0,
"start_line": 1009
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.synth_bitsum_case_recip_inverse | 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))] | 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))] // 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
) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 892,
"start_col": 0,
"start_line": 877
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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))
] | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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))] =
| synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y -> synth_case.f_g_eq x y) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.parse_bitsum_eq | 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))) | 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
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)) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 44,
"end_line": 839,
"start_col": 0,
"start_line": 798
} | 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" | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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))) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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
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))) =
| 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)) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.serialize_bitsum_alt | 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 | 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
=
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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 79,
"end_line": 965,
"start_col": 0,
"start_line": 945
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.GTot | [
"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"
] | [] | false | false | false | false | 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) | false |
StaticAssertions.fst | StaticAssertions.empty_static_asserts | val empty_static_asserts : StaticAssertions.static_asserts | let empty_static_asserts = {
includes = [];
sizeof_assertions = []
} | {
"file_name": "src/3d/StaticAssertions.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 1,
"end_line": 36,
"start_col": 0,
"start_line": 33
} | (*
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
} | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | StaticAssertions.static_asserts | Prims.Tot | [
"total"
] | [] | [
"StaticAssertions.Mkstatic_asserts",
"Prims.Nil",
"Prims.string",
"StaticAssertions.sizeof_assertion"
] | [] | false | false | false | true | false | let empty_static_asserts =
| { includes = []; sizeof_assertions = [] } | false |
|
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.serialize_bitsum_cases | 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)) | 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))
= 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)
()) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 9,
"end_line": 917,
"start_col": 0,
"start_line": 894
} | 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
) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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;
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) ()) | false |
FStar.Monotonic.HyperHeap.fsti | FStar.Monotonic.HyperHeap.extend_post | val extend_post (r: rid) (n c: int) (freeable: bool) : pure_post rid | val extend_post (r: rid) (n c: int) (freeable: bool) : pure_post rid | 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 | {
"file_name": "ulib/FStar.Monotonic.HyperHeap.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 186,
"start_col": 0,
"start_line": 180
} | (*
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)] | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | r: FStar.Monotonic.HyperHeap.rid -> n: Prims.int -> c: Prims.int -> freeable: Prims.bool
-> Prims.pure_post FStar.Monotonic.HyperHeap.rid | Prims.Tot | [
"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"
] | [] | false | false | false | true | false | let extend_post (r: rid) (n 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.serialize_bitsum | 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)) | 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))
= 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) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 70,
"end_line": 943,
"start_col": 0,
"start_line": 919
} | 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)
()) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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) | false |
StaticAssertions.fst | StaticAssertions.no_static_asserts | val no_static_asserts (sas: static_asserts) : Tot bool | val no_static_asserts (sas: static_asserts) : Tot bool | let no_static_asserts (sas: static_asserts) : Tot bool =
Nil? sas.includes &&
Nil? sas.sizeof_assertions | {
"file_name": "src/3d/StaticAssertions.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 28,
"end_line": 75,
"start_col": 0,
"start_line": 73
} | (*
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
} | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | sas: StaticAssertions.static_asserts -> Prims.bool | Prims.Tot | [
"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"
] | [] | false | false | false | true | false | let no_static_asserts (sas: static_asserts) : Tot bool =
| Nil? sas.includes && Nil? sas.sizeof_assertions | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.serialize_bitsum_eq | 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) | 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)
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 1007,
"start_col": 0,
"start_line": 967
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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 | false |
StaticAssertions.fst | StaticAssertions.has_static_asserts | val has_static_asserts (sas: static_asserts) : Tot bool | val has_static_asserts (sas: static_asserts) : Tot bool | let has_static_asserts (sas: static_asserts) : Tot bool =
not (no_static_asserts sas) | {
"file_name": "src/3d/StaticAssertions.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 29,
"end_line": 78,
"start_col": 0,
"start_line": 77
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | sas: StaticAssertions.static_asserts -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"StaticAssertions.static_asserts",
"Prims.op_Negation",
"StaticAssertions.no_static_asserts",
"Prims.bool"
] | [] | false | false | false | true | false | let has_static_asserts (sas: static_asserts) : Tot bool =
| not (no_static_asserts sas) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.serialize_bitsum_eq_2 | 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) | 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)
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 41,
"end_line": 1067,
"start_col": 0,
"start_line": 1048
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.filter_bitsum'_bitsum'_intro | 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)) | 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))
= fun x ->
let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in
phi x xr | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 12,
"end_line": 1157,
"start_col": 0,
"start_line": 1144
} | 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 }) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
StaticAssertions.fst | StaticAssertions.print_static_asserts | val print_static_asserts (sas: static_asserts) : ML string | val print_static_asserts (sas: static_asserts) : ML string | 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 | {
"file_name": "src/3d/StaticAssertions.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 39,
"end_line": 93,
"start_col": 0,
"start_line": 80
} | (*
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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | sas: StaticAssertions.static_asserts -> FStar.All.ML Prims.string | FStar.All.ML | [
"ml"
] | [] | [
"StaticAssertions.static_asserts",
"Prims.op_Hat",
"Prims.string",
"Options.make_includes",
"FStar.String.concat",
"Prims.list",
"FStar.List.map",
"StaticAssertions.sizeof_assertion",
"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__sizeof_assertions",
"StaticAssertions.__proj__Mkstatic_asserts__item__includes"
] | [] | false | true | false | false | 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind' | 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)) | 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))
= 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
) |) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 8,
"end_line": 713,
"start_col": 0,
"start_line": 680
} | 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" | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)))) | Prims.Tot | [
"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"
] | [
"recursion"
] | false | false | false | false | 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)
|) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.filter_bitsum'_bitfield | 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)) | 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))
= fun x -> phi x | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 16,
"end_line": 1101,
"start_col": 0,
"start_line": 1092
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.filter_bitsum'_bitsum_gen | 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)) | 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))
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 32,
"end_line": 1123,
"start_col": 0,
"start_line": 1104
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.parse_bitsum_eq' | 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)) | 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
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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 40,
"end_line": 875,
"start_col": 0,
"start_line": 843
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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))) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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
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)) =
| 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 | false |
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.generate_elem_a | val generate_elem_a : t: Type0 -> a: Type0 -> max: Prims.nat -> i: Prims.nat{i <= max} -> Type0 | let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i} | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 96,
"end_line": 13,
"start_col": 0,
"start_line": 13
} | 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" | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | t: Type0 -> a: Type0 -> max: Prims.nat -> i: Prims.nat{i <= max} -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Pervasives.Native.tuple2",
"Lib.Sequence.seq",
"Prims.eq2",
"Lib.Sequence.length"
] | [] | false | false | false | false | true | let generate_elem_a (t a: Type0) (max: nat) (i: nat{i <= max}) =
| a & s: seq t {length s == i} | false |
|
EverParse3d.Kinds.fsti | EverParse3d.Kinds.kind_unit | val kind_unit:parser_kind false WeakKindStrongPrefix | val kind_unit:parser_kind false WeakKindStrongPrefix | let kind_unit
: parser_kind false WeakKindStrongPrefix
= ret_kind | {
"file_name": "src/3d/prelude/EverParse3d.Kinds.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 10,
"end_line": 124,
"start_col": 0,
"start_line": 122
} | (*
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 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 EverParse3d.Kinds
noextract
type weak_kind =
| WeakKindWeak
| WeakKindStrongPrefix
| WeakKindConsumesAll
inline_for_extraction
noextract
let weak_kind_glb
(k1 k2: weak_kind)
: Tot weak_kind
= if k1 = k2
then k1
else WeakKindWeak
inline_for_extraction
noextract
val parser_kind (nz:bool) (wk: weak_kind) : Type0
inline_for_extraction
noextract
val glb (#nz1:bool) (#wk1: weak_kind) (k1:parser_kind nz1 wk1)
(#nz2:bool) (#wk2: weak_kind) (k2:parser_kind nz2 wk2)
: parser_kind (nz1 && nz2) (weak_kind_glb wk1 wk2)
/// Parser: return
inline_for_extraction
noextract
val ret_kind
: parser_kind false WeakKindStrongPrefix
/// Parser: bind
inline_for_extraction
noextract
val and_then_kind (#nz1:_) (k1:parser_kind nz1 WeakKindStrongPrefix)
(#nz2:_) (#wk2: _) (k2:parser_kind nz2 wk2)
: parser_kind (nz1 || nz2) wk2
inline_for_extraction
noextract
val filter_kind (#nz:_) (#wk: _) (k:parser_kind nz wk)
: parser_kind nz wk
inline_for_extraction
noextract
val impos_kind
: parser_kind true WeakKindStrongPrefix
/// Lists/arrays
inline_for_extraction
noextract
val kind_nlist
: parser_kind false WeakKindStrongPrefix
val kind_all_bytes
: parser_kind false WeakKindConsumesAll
val kind_t_at_most
: parser_kind false WeakKindStrongPrefix
val kind_t_exact
: parser_kind false WeakKindStrongPrefix
val parse_string_kind
: parser_kind true WeakKindStrongPrefix
val kind_all_zeros
: parser_kind false WeakKindConsumesAll
inline_for_extraction noextract
val kind____UINT8
: parser_kind true WeakKindStrongPrefix
inline_for_extraction noextract
val kind____UINT8BE
: parser_kind true WeakKindStrongPrefix
inline_for_extraction noextract
val kind____UINT16BE
: parser_kind true WeakKindStrongPrefix
inline_for_extraction noextract
val kind____UINT32BE
: parser_kind true WeakKindStrongPrefix
inline_for_extraction noextract
val kind____UINT64BE
: parser_kind true WeakKindStrongPrefix
inline_for_extraction noextract
val kind____UINT16
: parser_kind true WeakKindStrongPrefix
inline_for_extraction noextract
val kind____UINT32
: parser_kind true WeakKindStrongPrefix
inline_for_extraction noextract
val kind____UINT64
: parser_kind true WeakKindStrongPrefix | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverParse3d.Kinds.fsti"
} | [
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"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": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Kinds.parser_kind false EverParse3d.Kinds.WeakKindStrongPrefix | Prims.Tot | [
"total"
] | [] | [
"EverParse3d.Kinds.ret_kind"
] | [] | false | false | false | false | false | let kind_unit:parser_kind false WeakKindStrongPrefix =
| ret_kind | false |
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.generate_elems4_a | val generate_elems4_a : t: Type0 -> a: Type0 -> max: Prims.nat -> i: Prims.nat{i <= max / 4} -> Type0 | let generate_elems4_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max / 4}) = a & s:seq t{length s == 4 * i} | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 106,
"end_line": 74,
"start_col": 0,
"start_line": 74
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1)
let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res'
val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2
val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty))
let eq_generate_elems0 #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.eq_repeat_gen0 n (generate_elem_a t a max) (generate_elem_f max f) init2
val generate_elems_unfold:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a
-> i:nat{i < n} -> Lemma
(generate_elems #t #a max (i + 1) f init ==
generate_elem_f max f i (generate_elems #t #a max i f init))
let generate_elems_unfold #t #a max n f init i =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.unfold_repeat_gen (i + 1) (generate_elem_a t a max) (generate_elem_f max f) init2 i | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | t: Type0 -> a: Type0 -> max: Prims.nat -> i: Prims.nat{i <= max / 4} -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Division",
"FStar.Pervasives.Native.tuple2",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.length",
"FStar.Mul.op_Star"
] | [] | false | false | false | false | true | let generate_elems4_a (t a: Type0) (max: nat) (i: nat{i <= max / 4}) =
| a & s: seq t {length s == 4 * i} | false |
|
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.mk_filter_bitsum'_bitsum'_t' | val 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]) | val 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]) | 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) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 102,
"end_line": 1267,
"start_col": 0,
"start_line": 1227
} | 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] | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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}
-> Prims.Tot
(LowParse.Spec.BitSum.filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2) | Prims.Tot | [
"total",
""
] | [
"mk_filter_bitsum'_t'",
"mk_filter_bitsum'_bitsum'_t'"
] | [
"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.filter_bitsum'_bitsum'_nil",
"Prims.unit",
"FStar.List.Tot.Properties.append_l_nil",
"LowParse.Spec.BitSum.filter_bitsum'_bitsum'_cons",
"LowParse.Spec.BitSum.mk_filter_bitsum'_t'",
"LowParse.Spec.BitSum.mk_filter_bitsum'_bitsum'_t'",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Nil",
"FStar.List.Tot.Properties.append_assoc",
"LowParse.Spec.Enum.enum_repr_of_key_append_cons",
"LowParse.Spec.BitSum.filter_bitsum'_bitsum'_t",
"LowParse.Spec.BitSum.bitsum_wellfoundedness",
"LowParse.Spec.BitSum.BitSum'"
] | [
"mutual recursion"
] | false | false | false | false | false | let rec 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) | false |
Spec.Agile.HMAC.fst | Spec.Agile.HMAC.xor | val xor (x: uint8) (v: bytes) : lbytes (Seq.length v) | val xor (x: uint8) (v: bytes) : lbytes (Seq.length v) | let xor (x: uint8) (v: bytes) : lbytes (Seq.length v) =
Spec.Loops.seq_map (logxor x) v | {
"file_name": "specs/Spec.Agile.HMAC.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 18,
"start_col": 0,
"start_line": 17
} | 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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | x: Lib.IntTypes.uint8 -> v: Spec.Hash.Definitions.bytes
-> Spec.Agile.HMAC.lbytes (FStar.Seq.Base.length v) | Prims.Tot | [
"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"
] | [] | false | false | false | false | false | let xor (x: uint8) (v: bytes) : lbytes (Seq.length v) =
| Spec.Loops.seq_map (logxor x) v | false |
EverParse3d.Kinds.fsti | EverParse3d.Kinds.weak_kind_glb | val weak_kind_glb (k1 k2: weak_kind) : Tot weak_kind | val weak_kind_glb (k1 k2: weak_kind) : Tot weak_kind | let weak_kind_glb
(k1 k2: weak_kind)
: Tot weak_kind
= if k1 = k2
then k1
else WeakKindWeak | {
"file_name": "src/3d/prelude/EverParse3d.Kinds.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 19,
"end_line": 32,
"start_col": 0,
"start_line": 27
} | (*
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 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 EverParse3d.Kinds
noextract
type weak_kind =
| WeakKindWeak
| WeakKindStrongPrefix
| WeakKindConsumesAll
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverParse3d.Kinds.fsti"
} | [
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"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": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | k1: EverParse3d.Kinds.weak_kind -> k2: EverParse3d.Kinds.weak_kind -> EverParse3d.Kinds.weak_kind | Prims.Tot | [
"total"
] | [] | [
"EverParse3d.Kinds.weak_kind",
"Prims.op_Equality",
"Prims.bool",
"EverParse3d.Kinds.WeakKindWeak"
] | [] | false | false | false | true | false | let weak_kind_glb (k1 k2: weak_kind) : Tot weak_kind =
| if k1 = k2 then k1 else WeakKindWeak | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.mk_filter_bitsum'_t' | val 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;()]) | val 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;()]) | 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) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 102,
"end_line": 1267,
"start_col": 0,
"start_line": 1227
} | 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] | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size
-> Prims.Tot (LowParse.Spec.BitSum.filter_bitsum'_t b) | Prims.Tot | [
"total",
""
] | [
"mk_filter_bitsum'_t'",
"mk_filter_bitsum'_bitsum'_t'"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"LowParse.Spec.BitSum.filter_bitsum'_bitstop",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.filter_bitsum'_bitfield",
"LowParse.Spec.BitSum.mk_filter_bitsum'_t'",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.filter_bitsum'_bitsum'_intro",
"LowParse.Spec.BitSum.mk_filter_bitsum'_bitsum'_t'",
"Prims.Nil",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.BitSum.filter_bitsum'_t"
] | [
"mutual recursion"
] | false | false | false | false | false | 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) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.destr_bitsum'_bitsum_t | 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)) | 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))
= (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)) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 60,
"end_line": 1370,
"start_col": 0,
"start_line": 1354
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.Tot | [
"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'"
] | [] | false | false | false | false | true | 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)) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.filter_bitsum'_bitsum'_nil | 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 []) | 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 [])
= (fun x xr -> false) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 21,
"end_line": 1171,
"start_col": 0,
"start_line": 1160
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 [] | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.filter_bitsum'_bitsum'_cons | 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)) | 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))
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 28,
"end_line": 1213,
"start_col": 0,
"start_line": 1174
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 @ (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
((k, r) :: l2) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.generate_elems | val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n}) | val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n}) | let generate_elems #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2 | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 76,
"end_line": 41,
"start_col": 0,
"start_line": 39
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1)
let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res'
val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n}) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | max: Prims.nat -> n: Prims.nat{n <= max} -> f: (i: Prims.nat{i < max} -> _: a -> a * t) -> init: a
-> a * s: Lib.Sequence.seq t {Lib.Sequence.length s == n} | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Lib.LoopCombinators.repeat_gen",
"Hacl.Spec.Lib.generate_elem_a",
"Hacl.Spec.Lib.generate_elem_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Sequence.seq",
"Prims.eq2",
"Lib.Sequence.length",
"FStar.Seq.Base.empty"
] | [] | false | false | false | false | false | let generate_elems #t #a max n f init =
| let init2:generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2 | false |
StaticAssertions.fst | StaticAssertions.compute_static_asserts | val compute_static_asserts
(benv: B.global_env)
(senv: TypeSizes.size_env)
(r: option type_refinement)
: ML static_asserts | 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
= 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
} | {
"file_name": "src/3d/StaticAssertions.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 7,
"end_line": 71,
"start_col": 0,
"start_line": 38
} | (*
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 = []
} | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
benv: GlobalEnv.global_env ->
senv: TypeSizes.size_env ->
r: FStar.Pervasives.Native.option Ast.type_refinement
-> FStar.All.ML StaticAssertions.static_asserts | FStar.All.ML | [
"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.List.map",
"FStar.Pervasives.Native.tuple2",
"Ast.with_meta_t",
"Ast.ident'",
"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",
"Ast.__proj__Mktype_refinement__item__type_map",
"Binding.env",
"FStar.Pervasives.Native.Mktuple2",
"Binding.mk_env"
] | [] | false | true | false | false | 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 } | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.destr_bitsum'_bitsum_nil | 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 []) | 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 [])
= (fun u u_if f x ->
assert False;
false_elim ()) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 18,
"end_line": 1401,
"start_col": 0,
"start_line": 1388
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 [] | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 ()) | false |
Spec.Agile.HMAC.fst | Spec.Agile.HMAC.hmac | 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) | 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 =
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 | {
"file_name": "specs/Spec.Agile.HMAC.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 41,
"start_col": 0,
"start_line": 35
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)) | Prims.Pure | [] | [] | [
"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"
] | [] | false | false | false | false | 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 | false |
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.generate_elems_unfold | val generate_elems_unfold:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a
-> i:nat{i < n} -> Lemma
(generate_elems #t #a max (i + 1) f init ==
generate_elem_f max f i (generate_elems #t #a max i f init)) | val generate_elems_unfold:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a
-> i:nat{i < n} -> Lemma
(generate_elems #t #a max (i + 1) f init ==
generate_elem_f max f i (generate_elems #t #a max i f init)) | let generate_elems_unfold #t #a max n f init i =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.unfold_repeat_gen (i + 1) (generate_elem_a t a max) (generate_elem_f max f) init2 i | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 91,
"end_line": 71,
"start_col": 0,
"start_line": 69
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1)
let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res'
val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2
val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty))
let eq_generate_elems0 #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.eq_repeat_gen0 n (generate_elem_a t a max) (generate_elem_f max f) init2
val generate_elems_unfold:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a
-> i:nat{i < n} -> Lemma
(generate_elems #t #a max (i + 1) f init ==
generate_elem_f max f i (generate_elems #t #a max i f init)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
max: Prims.nat ->
n: Prims.nat{n <= max} ->
f: (i: Prims.nat{i < max} -> _: a -> a * t) ->
init: a ->
i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Lib.generate_elems max (i + 1) f init ==
Hacl.Spec.Lib.generate_elem_f max f i (Hacl.Spec.Lib.generate_elems max i f init)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Lib.LoopCombinators.unfold_repeat_gen",
"Prims.op_Addition",
"Hacl.Spec.Lib.generate_elem_a",
"Hacl.Spec.Lib.generate_elem_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Sequence.seq",
"Prims.eq2",
"Lib.Sequence.length",
"FStar.Seq.Base.empty",
"Prims.unit"
] | [] | true | false | true | false | false | let generate_elems_unfold #t #a max n f init i =
| let init2:generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.unfold_repeat_gen (i + 1) (generate_elem_a t a max) (generate_elem_f max f) init2 i | false |
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.generate_elem_f | val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1) | val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1) | let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res' | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 27,
"start_col": 0,
"start_line": 24
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
max: Prims.nat ->
f: (i: Prims.nat{i < max} -> _: a -> a * t) ->
i: Prims.nat{i < max} ->
acc: Hacl.Spec.Lib.generate_elem_a t a max i
-> Hacl.Spec.Lib.generate_elem_a t a max (i + 1) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Lib.generate_elem_a",
"Lib.Sequence.seq",
"Prims.eq2",
"Lib.Sequence.length",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Addition",
"FStar.Seq.Base.seq",
"FStar.Seq.Properties.snoc"
] | [] | false | false | false | false | false | let generate_elem_f #t #a max f i (c, res) =
| let c', e = f i c in
let res' = Seq.snoc res e in
c', res' | false |
FStar.DM4F.Heap.Random.fsti | FStar.DM4F.Heap.Random.size | val size : Prims.int | let size = 10 | {
"file_name": "examples/dm4free/FStar.DM4F.Heap.Random.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 22,
"start_col": 0,
"start_line": 22
} | (*
Copyright 2008-2018 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.DM4F.Heap.Random
(***** Random tape *****)
open FStar.Seq | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Heap.Random.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap",
"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
}
] | {
"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"
} | false | Prims.int | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let size =
| 10 | false |
|
FStar.DM4F.Heap.Random.fsti | FStar.DM4F.Heap.Random.elem | val elem : Type0 | let elem = n:nat{n < q} | {
"file_name": "examples/dm4free/FStar.DM4F.Heap.Random.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 23,
"end_line": 26,
"start_col": 0,
"start_line": 26
} | (*
Copyright 2008-2018 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.DM4F.Heap.Random
(***** Random tape *****)
open FStar.Seq
let size = 10
val q: pos | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Heap.Random.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap",
"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
}
] | {
"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"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.DM4F.Heap.Random.q"
] | [] | false | false | false | true | true | let elem =
| n: nat{n < q} | false |
|
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.generate_elems4_f | val generate_elems4_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max / 4}
-> acc:generate_elems4_a t a max i ->
generate_elems4_a t a max (i + 1) | val generate_elems4_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max / 4}
-> acc:generate_elems4_a t a max i ->
generate_elems4_a t a max (i + 1) | let generate_elems4_f #t #a max f i (c, res) =
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res0 = Seq.snoc res e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
c3, res3 | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 95,
"start_col": 0,
"start_line": 85
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1)
let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res'
val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2
val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty))
let eq_generate_elems0 #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.eq_repeat_gen0 n (generate_elem_a t a max) (generate_elem_f max f) init2
val generate_elems_unfold:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a
-> i:nat{i < n} -> Lemma
(generate_elems #t #a max (i + 1) f init ==
generate_elem_f max f i (generate_elems #t #a max i f init))
let generate_elems_unfold #t #a max n f init i =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.unfold_repeat_gen (i + 1) (generate_elem_a t a max) (generate_elem_f max f) init2 i
let generate_elems4_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max / 4}) = a & s:seq t{length s == 4 * i}
val generate_elems4_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max / 4}
-> acc:generate_elems4_a t a max i ->
generate_elems4_a t a max (i + 1) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
max: Prims.nat ->
f: (i: Prims.nat{i < max} -> _: a -> a * t) ->
i: Prims.nat{i < max / 4} ->
acc: Hacl.Spec.Lib.generate_elems4_a t a max i
-> Hacl.Spec.Lib.generate_elems4_a t a max (i + 1) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Division",
"Hacl.Spec.Lib.generate_elems4_a",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.length",
"FStar.Mul.op_Star",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Addition",
"FStar.Seq.Base.seq",
"FStar.Seq.Properties.snoc"
] | [] | false | false | false | false | false | let generate_elems4_f #t #a max f i (c, res) =
| let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res0 = Seq.snoc res e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
c3, res3 | false |
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.eq_generate_elems0 | val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty)) | val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty)) | let eq_generate_elems0 #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.eq_repeat_gen0 n (generate_elem_a t a max) (generate_elem_f max f) init2 | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 80,
"end_line": 55,
"start_col": 0,
"start_line": 53
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1)
let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res'
val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2
val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | max: Prims.nat -> n: Prims.nat{n <= max} -> f: (i: Prims.nat{i < max} -> _: a -> a * t) -> init: a
-> FStar.Pervasives.Lemma
(ensures Hacl.Spec.Lib.generate_elems max 0 f init == (init, FStar.Seq.Base.empty)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Lib.LoopCombinators.eq_repeat_gen0",
"Hacl.Spec.Lib.generate_elem_a",
"Hacl.Spec.Lib.generate_elem_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Sequence.seq",
"Prims.eq2",
"Lib.Sequence.length",
"FStar.Seq.Base.empty",
"Prims.unit"
] | [] | true | false | true | false | false | let eq_generate_elems0 #t #a max n f init =
| let init2:generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.eq_repeat_gen0 n (generate_elem_a t a max) (generate_elem_f max f) init2 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.synth_bitsum'_recip_BitStop | val synth_bitsum'_recip_BitStop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
: Tot (synth_bitsum'_recip_t #tot #t #cl #0 (BitStop ())) | 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 ()))
= fun _ -> cl.uint_to_t 0 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 25,
"end_line": 1561,
"start_col": 0,
"start_line": 1556
} | 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 }) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | cl: LowParse.BitFields.uint_t tot t
-> LowParse.Spec.BitSum.synth_bitsum'_recip_t (LowParse.Spec.BitSum.BitStop ()) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
FStar.DM4F.Heap.Random.fsti | FStar.DM4F.Heap.Random.sel | val sel : h: FStar.DM4F.Heap.Random.tape -> i: FStar.DM4F.Heap.Random.id -> FStar.DM4F.Heap.Random.elem | let sel = index | {
"file_name": "examples/dm4free/FStar.DM4F.Heap.Random.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 15,
"end_line": 39,
"start_col": 0,
"start_line": 39
} | (*
Copyright 2008-2018 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.DM4F.Heap.Random
(***** Random tape *****)
open FStar.Seq
let size = 10
val q: pos
let elem = n:nat{n < q}
val id : eqtype
val tape : eqtype
val to_id (n:nat{n < size}) : id
val incrementable: id -> bool
val incr (i:id{incrementable i}) : id | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Heap.Random.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap",
"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
}
] | {
"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"
} | false | h: FStar.DM4F.Heap.Random.tape -> i: FStar.DM4F.Heap.Random.id -> FStar.DM4F.Heap.Random.elem | Prims.Tot | [
"total"
] | [] | [
"FStar.DM4F.Heap.Random.index"
] | [] | false | false | false | true | false | let sel =
| index | false |
|
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.generate_elems_unroll4 | val generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n}) | val generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n}) | let generate_elems_unroll4 #t #a max n f init =
let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0) in
(c1, res1) | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 12,
"end_line": 110,
"start_col": 0,
"start_line": 107
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1)
let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res'
val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2
val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty))
let eq_generate_elems0 #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.eq_repeat_gen0 n (generate_elem_a t a max) (generate_elem_f max f) init2
val generate_elems_unfold:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a
-> i:nat{i < n} -> Lemma
(generate_elems #t #a max (i + 1) f init ==
generate_elem_f max f i (generate_elems #t #a max i f init))
let generate_elems_unfold #t #a max n f init i =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.unfold_repeat_gen (i + 1) (generate_elem_a t a max) (generate_elem_f max f) init2 i
let generate_elems4_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max / 4}) = a & s:seq t{length s == 4 * i}
val generate_elems4_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max / 4}
-> acc:generate_elems4_a t a max i ->
generate_elems4_a t a max (i + 1)
let generate_elems4_f #t #a max f i (c, res) =
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res0 = Seq.snoc res e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
c3, res3
val generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n}) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | max: Prims.nat -> n: Prims.nat{n <= max} -> f: (i: Prims.nat{i < max} -> _: a -> a * t) -> init: a
-> a * s: Lib.Sequence.seq t {Lib.Sequence.length s == n} | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.length",
"FStar.Mul.op_Star",
"Prims.op_Division",
"FStar.Pervasives.Native.Mktuple2",
"Hacl.Spec.Lib.generate_elem_a",
"Lib.LoopCombinators.repeat_right",
"Hacl.Spec.Lib.generate_elem_f",
"Hacl.Spec.Lib.generate_elems4_a",
"Lib.LoopCombinators.repeat_gen",
"Hacl.Spec.Lib.generate_elems4_f",
"FStar.Seq.Base.empty"
] | [] | false | false | false | false | false | let generate_elems_unroll4 #t #a max n f init =
| let c0, res0 =
Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty)
in
let c1, res1 =
Loops.repeat_right ((n / 4) * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0)
in
(c1, res1) | false |
Spec.Agile.HMAC.fst | Spec.Agile.HMAC.wrap | val wrap (a: fixed_len_alg) (key: bytes{(Seq.length key) `less_than_max_input_length` a})
: lbytes (block_length a) | 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)
=
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)) | {
"file_name": "specs/Spec.Agile.HMAC.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 15,
"start_col": 0,
"start_line": 8
} | module Spec.Agile.HMAC
open Spec.Hash.Definitions
open Lib.IntTypes
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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)) | false |
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.lemma_generate_elems4 | val lemma_generate_elems4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a -> Lemma
(let (c, res) = generate_elems #t #a max n f init in
let (c1, res1) = generate_blocks 4 (max / 4) (n / 4) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init in
let (c2, res2) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c1, res1) in
c == c2 /\ res == res2) | val lemma_generate_elems4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a -> Lemma
(let (c, res) = generate_elems #t #a max n f init in
let (c1, res1) = generate_blocks 4 (max / 4) (n / 4) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init in
let (c2, res2) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c1, res1) in
c == c2 /\ res == res2) | let lemma_generate_elems4 #t #a max n f init =
lemma_generate_elems4_loop #t #a max n f init;
lemma_generate_elems_unroll4 #t #a max n f init | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 271,
"start_col": 0,
"start_line": 269
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1)
let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res'
val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2
val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty))
let eq_generate_elems0 #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.eq_repeat_gen0 n (generate_elem_a t a max) (generate_elem_f max f) init2
val generate_elems_unfold:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a
-> i:nat{i < n} -> Lemma
(generate_elems #t #a max (i + 1) f init ==
generate_elem_f max f i (generate_elems #t #a max i f init))
let generate_elems_unfold #t #a max n f init i =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.unfold_repeat_gen (i + 1) (generate_elem_a t a max) (generate_elem_f max f) init2 i
let generate_elems4_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max / 4}) = a & s:seq t{length s == 4 * i}
val generate_elems4_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max / 4}
-> acc:generate_elems4_a t a max i ->
generate_elems4_a t a max (i + 1)
let generate_elems4_f #t #a max f i (c, res) =
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res0 = Seq.snoc res e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
c3, res3
val generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems_unroll4 #t #a max n f init =
let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0) in
(c1, res1)
val lemma_generate_elems_unroll4_loop:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max /\ n % 4 = 0}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma
(let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
c0 == c1 /\ res0 == res1)
let lemma_generate_elems_unroll4_loop #t #a max n f init =
let acc_v = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let acc = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
let normalize_v (i:nat{i <= n / 4}) (acc_v:generate_elems4_a t a max i) : generate_elem_a t a max (4 * i) =
let (c, res) = acc_v in
(c, res) in
let aux (i:nat{i < n / 4}) (acc_v:generate_elems4_a t a max i) : Lemma
(normalize_v (i + 1) (generate_elems4_f max f i acc_v) ==
Loops.repeat_right (4 * i) (4 * i + 4)
(generate_elem_a t a max) (generate_elem_f max f) (normalize_v i acc_v)) =
let acc0 = normalize_v i acc_v in
let acc = Loops.repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0 in
Loops.unfold_repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 3);
Loops.unfold_repeat_right (4 * i) (4 * i + 3) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 2);
Loops.unfold_repeat_right (4 * i) (4 * i + 2) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 1);
Loops.unfold_repeat_right (4 * i) (4 * i + 1) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i);
Loops.eq_repeat_right (4 * i) (4 * i) (generate_elem_a t a max) (generate_elem_f max f) acc0;
assert (normalize_v (i + 1) (generate_elems4_f max f i acc_v) == acc);
() in
Classical.forall_intro_2 aux;
VecLemmas.lemma_repeat_gen_vec 4 (n / 4) (generate_elem_a t a max) (generate_elems4_a t a max) normalize_v
(generate_elem_f max f) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty)
val lemma_generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems_unroll4 #t #a max n f init == generate_elems #t #a max n f init)
let lemma_generate_elems_unroll4 #t #a max n f init =
let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0) in
let (c2, res2) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
let (c3, res3) = Loops.repeat_gen (n / 4 * 4) (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
Loops.repeat_right_plus 0 (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
Loops.repeat_gen_def (n / 4 * 4) (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
lemma_generate_elems_unroll4_loop #t #a max (n / 4 * 4) f init
val generate_blocks4_f:
#t:Type0
-> #a:Type0
-> k:nat
-> f:(i:nat{i < 4 * k} -> a -> a & t)
-> i:nat{i < k}
-> c:a
-> tuple2 a (lseq t 4)
let generate_blocks4_f #t #a max f i c =
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
c3, Lib.Sequence.create4 e0 e1 e2 e3
val lemma_generate_elems4_loop_step:
#t:Type0
-> #a:Type0
-> max:nat
-> k:nat{4 * k <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < k}
-> c:a
-> s:seq t{length s == 4 * i} ->
Lemma
(let (c1, res1) = generate_elems4_f #t #a max f i (c, s) in
let (c2, res2) = generate_blocks4_f #t #a k f i c in
c1 == c2 /\ Seq.append s res2 == res1)
let lemma_generate_elems4_loop_step #t #a max k f i c s =
let (c1, res1) = generate_elems4_f #t #a max f i (c, s) in
let (c2, res2) = generate_blocks4_f #t #a k f i c in
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res = Lib.Sequence.create4 e0 e1 e2 e3 in
let res0 = Seq.snoc s e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
Seq.lemma_eq_intro (Seq.append s res) res3
val lemma_generate_elems4_loop:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a -> Lemma
(let (c1, res1) = generate_blocks 4 (max / 4) (n / 4) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init in
let (c2, res2) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
c1 == c2 /\ res1 == res2)
let rec lemma_generate_elems4_loop #t #a max n f init =
let k = n / 4 in
let (c1, res1) = generate_blocks 4 (max / 4) k (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init in
let (c2, res2) = Loops.repeat_gen k (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
if k = 0 then begin
eq_generate_blocks0 4 (max / 4) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init;
Loops.eq_repeat_gen0 k (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) end
else begin
lemma_generate_elems4_loop #t #a max (n - 4) f init;
let (c3, res3) = generate_blocks 4 (max / 4) (k - 1) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init in
let (c4, res4) = Loops.repeat_gen (k - 1) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
//assert (c3 == c4 /\ res3 == res4);
unfold_generate_blocks 4 (max / 4) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init (k - 1);
Loops.unfold_repeat_gen k (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) (k - 1);
//let (acc', s') = generate_blocks4_f #t #a (max / 4) f (k - 1) c3 in
//assert (res1 == Seq.append res3 s');
lemma_generate_elems4_loop_step #t #a max k f (k - 1) c3 res3;
() end
val lemma_generate_elems4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a -> Lemma
(let (c, res) = generate_elems #t #a max n f init in
let (c1, res1) = generate_blocks 4 (max / 4) (n / 4) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init in
let (c2, res2) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c1, res1) in
c == c2 /\ res == res2) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | max: Prims.nat -> n: Prims.nat{n <= max} -> f: (i: Prims.nat{i < max} -> _: a -> a * t) -> init: a
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Lib.generate_elems max n f init in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
let _ =
Lib.Sequence.generate_blocks 4
(max / 4)
(n / 4)
(Lib.LoopCombinators.fixed_a a)
(Hacl.Spec.Lib.generate_blocks4_f (max / 4) f)
init
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in
let _ =
Lib.LoopCombinators.repeat_right ((n / 4) * 4)
n
(Hacl.Spec.Lib.generate_elem_a t a max)
(Hacl.Spec.Lib.generate_elem_f max f)
(c1,
res1)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c2 res2 = _ in
c == c2 /\ res == res2)
<:
Type0)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Lib.lemma_generate_elems_unroll4",
"Prims.unit",
"Hacl.Spec.Lib.lemma_generate_elems4_loop"
] | [] | true | false | true | false | false | let lemma_generate_elems4 #t #a max n f init =
| lemma_generate_elems4_loop #t #a max n f init;
lemma_generate_elems_unroll4 #t #a max n f init | false |
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.lemma_generate_elems_unroll4 | val lemma_generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems_unroll4 #t #a max n f init == generate_elems #t #a max n f init) | val lemma_generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems_unroll4 #t #a max n f init == generate_elems #t #a max n f init) | let lemma_generate_elems_unroll4 #t #a max n f init =
let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0) in
let (c2, res2) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
let (c3, res3) = Loops.repeat_gen (n / 4 * 4) (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
Loops.repeat_right_plus 0 (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
Loops.repeat_gen_def (n / 4 * 4) (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
lemma_generate_elems_unroll4_loop #t #a max (n / 4 * 4) f init | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 174,
"start_col": 0,
"start_line": 165
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1)
let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res'
val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2
val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty))
let eq_generate_elems0 #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.eq_repeat_gen0 n (generate_elem_a t a max) (generate_elem_f max f) init2
val generate_elems_unfold:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a
-> i:nat{i < n} -> Lemma
(generate_elems #t #a max (i + 1) f init ==
generate_elem_f max f i (generate_elems #t #a max i f init))
let generate_elems_unfold #t #a max n f init i =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.unfold_repeat_gen (i + 1) (generate_elem_a t a max) (generate_elem_f max f) init2 i
let generate_elems4_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max / 4}) = a & s:seq t{length s == 4 * i}
val generate_elems4_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max / 4}
-> acc:generate_elems4_a t a max i ->
generate_elems4_a t a max (i + 1)
let generate_elems4_f #t #a max f i (c, res) =
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res0 = Seq.snoc res e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
c3, res3
val generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems_unroll4 #t #a max n f init =
let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0) in
(c1, res1)
val lemma_generate_elems_unroll4_loop:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max /\ n % 4 = 0}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma
(let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
c0 == c1 /\ res0 == res1)
let lemma_generate_elems_unroll4_loop #t #a max n f init =
let acc_v = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let acc = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
let normalize_v (i:nat{i <= n / 4}) (acc_v:generate_elems4_a t a max i) : generate_elem_a t a max (4 * i) =
let (c, res) = acc_v in
(c, res) in
let aux (i:nat{i < n / 4}) (acc_v:generate_elems4_a t a max i) : Lemma
(normalize_v (i + 1) (generate_elems4_f max f i acc_v) ==
Loops.repeat_right (4 * i) (4 * i + 4)
(generate_elem_a t a max) (generate_elem_f max f) (normalize_v i acc_v)) =
let acc0 = normalize_v i acc_v in
let acc = Loops.repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0 in
Loops.unfold_repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 3);
Loops.unfold_repeat_right (4 * i) (4 * i + 3) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 2);
Loops.unfold_repeat_right (4 * i) (4 * i + 2) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 1);
Loops.unfold_repeat_right (4 * i) (4 * i + 1) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i);
Loops.eq_repeat_right (4 * i) (4 * i) (generate_elem_a t a max) (generate_elem_f max f) acc0;
assert (normalize_v (i + 1) (generate_elems4_f max f i acc_v) == acc);
() in
Classical.forall_intro_2 aux;
VecLemmas.lemma_repeat_gen_vec 4 (n / 4) (generate_elem_a t a max) (generate_elems4_a t a max) normalize_v
(generate_elem_f max f) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty)
val lemma_generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems_unroll4 #t #a max n f init == generate_elems #t #a max n f init) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | max: Prims.nat -> n: Prims.nat{n <= max} -> f: (i: Prims.nat{i < max} -> _: a -> a * t) -> init: a
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Lib.generate_elems_unroll4 max n f init == Hacl.Spec.Lib.generate_elems max n f init
) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.length",
"FStar.Mul.op_Star",
"Prims.op_Division",
"Hacl.Spec.Lib.lemma_generate_elems_unroll4_loop",
"Prims.unit",
"Lib.LoopCombinators.repeat_gen_def",
"Hacl.Spec.Lib.generate_elem_a",
"Hacl.Spec.Lib.generate_elem_f",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.empty",
"Lib.LoopCombinators.repeat_right_plus",
"Prims.op_Multiply",
"Lib.LoopCombinators.repeat_gen",
"Lib.LoopCombinators.repeat_right",
"Hacl.Spec.Lib.generate_elems4_a",
"Hacl.Spec.Lib.generate_elems4_f"
] | [] | false | false | true | false | false | let lemma_generate_elems_unroll4 #t #a max n f init =
| let c0, res0 =
Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty)
in
let c1, res1 =
Loops.repeat_right ((n / 4) * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0)
in
let c2, res2 =
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty)
in
let c3, res3 =
Loops.repeat_gen ((n / 4) * 4) (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty)
in
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
Loops.repeat_right_plus 0
((n / 4) * 4)
n
(generate_elem_a t a max)
(generate_elem_f max f)
(init, Seq.empty);
Loops.repeat_gen_def ((n / 4) * 4)
(generate_elem_a t a max)
(generate_elem_f max f)
(init, Seq.empty);
lemma_generate_elems_unroll4_loop #t #a max ((n / 4) * 4) f init | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_intro | 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)) | 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))
= fun x ->
[@inline_let]
let (| k, pl |) = x in
phi k pl | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 10,
"end_line": 1632,
"start_col": 0,
"start_line": 1618
} | 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 |) } ) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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
) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.synth_bitsum'_recip_BitField | 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)) | 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))
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 63,
"end_line": 1576,
"start_col": 0,
"start_line": 1564
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.generate_blocks4_f | val generate_blocks4_f:
#t:Type0
-> #a:Type0
-> k:nat
-> f:(i:nat{i < 4 * k} -> a -> a & t)
-> i:nat{i < k}
-> c:a
-> tuple2 a (lseq t 4) | val generate_blocks4_f:
#t:Type0
-> #a:Type0
-> k:nat
-> f:(i:nat{i < 4 * k} -> a -> a & t)
-> i:nat{i < k}
-> c:a
-> tuple2 a (lseq t 4) | let generate_blocks4_f #t #a max f i c =
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
c3, Lib.Sequence.create4 e0 e1 e2 e3 | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 191,
"start_col": 0,
"start_line": 186
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1)
let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res'
val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2
val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty))
let eq_generate_elems0 #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.eq_repeat_gen0 n (generate_elem_a t a max) (generate_elem_f max f) init2
val generate_elems_unfold:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a
-> i:nat{i < n} -> Lemma
(generate_elems #t #a max (i + 1) f init ==
generate_elem_f max f i (generate_elems #t #a max i f init))
let generate_elems_unfold #t #a max n f init i =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.unfold_repeat_gen (i + 1) (generate_elem_a t a max) (generate_elem_f max f) init2 i
let generate_elems4_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max / 4}) = a & s:seq t{length s == 4 * i}
val generate_elems4_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max / 4}
-> acc:generate_elems4_a t a max i ->
generate_elems4_a t a max (i + 1)
let generate_elems4_f #t #a max f i (c, res) =
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res0 = Seq.snoc res e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
c3, res3
val generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems_unroll4 #t #a max n f init =
let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0) in
(c1, res1)
val lemma_generate_elems_unroll4_loop:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max /\ n % 4 = 0}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma
(let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
c0 == c1 /\ res0 == res1)
let lemma_generate_elems_unroll4_loop #t #a max n f init =
let acc_v = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let acc = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
let normalize_v (i:nat{i <= n / 4}) (acc_v:generate_elems4_a t a max i) : generate_elem_a t a max (4 * i) =
let (c, res) = acc_v in
(c, res) in
let aux (i:nat{i < n / 4}) (acc_v:generate_elems4_a t a max i) : Lemma
(normalize_v (i + 1) (generate_elems4_f max f i acc_v) ==
Loops.repeat_right (4 * i) (4 * i + 4)
(generate_elem_a t a max) (generate_elem_f max f) (normalize_v i acc_v)) =
let acc0 = normalize_v i acc_v in
let acc = Loops.repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0 in
Loops.unfold_repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 3);
Loops.unfold_repeat_right (4 * i) (4 * i + 3) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 2);
Loops.unfold_repeat_right (4 * i) (4 * i + 2) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 1);
Loops.unfold_repeat_right (4 * i) (4 * i + 1) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i);
Loops.eq_repeat_right (4 * i) (4 * i) (generate_elem_a t a max) (generate_elem_f max f) acc0;
assert (normalize_v (i + 1) (generate_elems4_f max f i acc_v) == acc);
() in
Classical.forall_intro_2 aux;
VecLemmas.lemma_repeat_gen_vec 4 (n / 4) (generate_elem_a t a max) (generate_elems4_a t a max) normalize_v
(generate_elem_f max f) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty)
val lemma_generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems_unroll4 #t #a max n f init == generate_elems #t #a max n f init)
let lemma_generate_elems_unroll4 #t #a max n f init =
let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0) in
let (c2, res2) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
let (c3, res3) = Loops.repeat_gen (n / 4 * 4) (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
Loops.repeat_right_plus 0 (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
Loops.repeat_gen_def (n / 4 * 4) (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
lemma_generate_elems_unroll4_loop #t #a max (n / 4 * 4) f init
val generate_blocks4_f:
#t:Type0
-> #a:Type0
-> k:nat
-> f:(i:nat{i < 4 * k} -> a -> a & t)
-> i:nat{i < k}
-> c:a
-> tuple2 a (lseq t 4) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | k: Prims.nat -> f: (i: Prims.nat{i < 4 * k} -> _: a -> a * t) -> i: Prims.nat{i < k} -> c: a
-> a * Lib.Sequence.lseq t 4 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Sequence.lseq",
"Lib.Sequence.create4",
"Prims.op_Addition"
] | [] | false | false | false | false | false | let generate_blocks4_f #t #a max f i c =
| let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
c3, Lib.Sequence.create4 e0 e1 e2 e3 | false |
Spec.Agile.HMAC.fst | Spec.Agile.HMAC.xor_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)) | 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))
=
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)) | {
"file_name": "specs/Spec.Agile.HMAC.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 31,
"start_col": 0,
"start_line": 22
} | 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" | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | FStar.Pervasives.Lemma | [
"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"
] | [
"recursion"
] | false | false | true | false | 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)) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_nil | 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 []) | 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 [])
= fun k _ ->
[@inline_let]
let _ = L.append_l_nil l1 in
false_elim () | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 15,
"end_line": 1649,
"start_col": 0,
"start_line": 1635
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 [] | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 () | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.is_valid_bitfield | 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 | 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
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 46,
"end_line": 1804,
"start_col": 0,
"start_line": 1787
} | 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 *) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.GTot | [
"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'"
] | [
"recursion"
] | false | false | false | false | 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.mk_destr_bitsum'_t | val 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;()]) | val 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;()]) | 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) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 99,
"end_line": 1540,
"start_col": 0,
"start_line": 1493
} | 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] | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size
-> Prims.Tot (LowParse.Spec.BitSum.destr_bitsum'_t b <: Type) | Prims.Tot | [
"total",
""
] | [
"mk_destr_bitsum'_t",
"mk_destr_bitsum'_bitsum_t"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"LowParse.Spec.BitSum.destr_bitsum'_bitstop",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.destr_bitsum'_bitfield",
"LowParse.Spec.BitSum.mk_destr_bitsum'_t",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.destr_bitsum'_bitsum_intro",
"LowParse.Spec.BitSum.mk_destr_bitsum'_bitsum_t",
"Prims.Nil",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.BitSum.destr_bitsum'_t"
] | [
"mutual recursion"
] | false | false | false | false | false | 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) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.is_valid_bitfield_prop | 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)] | 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)]
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 1827,
"start_col": 0,
"start_line": 1806
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)] | FStar.Pervasives.Lemma | [
"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"
] | [
"recursion"
] | false | false | true | false | 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_gen | 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)) | 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))
= 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) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 91,
"end_line": 1597,
"start_col": 0,
"start_line": 1579
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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
) | Prims.Tot | [
"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'"
] | [] | false | false | false | false | 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) | false |
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.lemma_generate_elems4_loop_step | val lemma_generate_elems4_loop_step:
#t:Type0
-> #a:Type0
-> max:nat
-> k:nat{4 * k <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < k}
-> c:a
-> s:seq t{length s == 4 * i} ->
Lemma
(let (c1, res1) = generate_elems4_f #t #a max f i (c, s) in
let (c2, res2) = generate_blocks4_f #t #a k f i c in
c1 == c2 /\ Seq.append s res2 == res1) | val lemma_generate_elems4_loop_step:
#t:Type0
-> #a:Type0
-> max:nat
-> k:nat{4 * k <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < k}
-> c:a
-> s:seq t{length s == 4 * i} ->
Lemma
(let (c1, res1) = generate_elems4_f #t #a max f i (c, s) in
let (c2, res2) = generate_blocks4_f #t #a k f i c in
c1 == c2 /\ Seq.append s res2 == res1) | let lemma_generate_elems4_loop_step #t #a max k f i c s =
let (c1, res1) = generate_elems4_f #t #a max f i (c, s) in
let (c2, res2) = generate_blocks4_f #t #a k f i c in
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res = Lib.Sequence.create4 e0 e1 e2 e3 in
let res0 = Seq.snoc s e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
Seq.lemma_eq_intro (Seq.append s res) res3 | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 222,
"start_col": 0,
"start_line": 208
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1)
let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res'
val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2
val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty))
let eq_generate_elems0 #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.eq_repeat_gen0 n (generate_elem_a t a max) (generate_elem_f max f) init2
val generate_elems_unfold:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a
-> i:nat{i < n} -> Lemma
(generate_elems #t #a max (i + 1) f init ==
generate_elem_f max f i (generate_elems #t #a max i f init))
let generate_elems_unfold #t #a max n f init i =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.unfold_repeat_gen (i + 1) (generate_elem_a t a max) (generate_elem_f max f) init2 i
let generate_elems4_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max / 4}) = a & s:seq t{length s == 4 * i}
val generate_elems4_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max / 4}
-> acc:generate_elems4_a t a max i ->
generate_elems4_a t a max (i + 1)
let generate_elems4_f #t #a max f i (c, res) =
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res0 = Seq.snoc res e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
c3, res3
val generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems_unroll4 #t #a max n f init =
let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0) in
(c1, res1)
val lemma_generate_elems_unroll4_loop:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max /\ n % 4 = 0}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma
(let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
c0 == c1 /\ res0 == res1)
let lemma_generate_elems_unroll4_loop #t #a max n f init =
let acc_v = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let acc = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
let normalize_v (i:nat{i <= n / 4}) (acc_v:generate_elems4_a t a max i) : generate_elem_a t a max (4 * i) =
let (c, res) = acc_v in
(c, res) in
let aux (i:nat{i < n / 4}) (acc_v:generate_elems4_a t a max i) : Lemma
(normalize_v (i + 1) (generate_elems4_f max f i acc_v) ==
Loops.repeat_right (4 * i) (4 * i + 4)
(generate_elem_a t a max) (generate_elem_f max f) (normalize_v i acc_v)) =
let acc0 = normalize_v i acc_v in
let acc = Loops.repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0 in
Loops.unfold_repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 3);
Loops.unfold_repeat_right (4 * i) (4 * i + 3) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 2);
Loops.unfold_repeat_right (4 * i) (4 * i + 2) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 1);
Loops.unfold_repeat_right (4 * i) (4 * i + 1) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i);
Loops.eq_repeat_right (4 * i) (4 * i) (generate_elem_a t a max) (generate_elem_f max f) acc0;
assert (normalize_v (i + 1) (generate_elems4_f max f i acc_v) == acc);
() in
Classical.forall_intro_2 aux;
VecLemmas.lemma_repeat_gen_vec 4 (n / 4) (generate_elem_a t a max) (generate_elems4_a t a max) normalize_v
(generate_elem_f max f) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty)
val lemma_generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems_unroll4 #t #a max n f init == generate_elems #t #a max n f init)
let lemma_generate_elems_unroll4 #t #a max n f init =
let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0) in
let (c2, res2) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
let (c3, res3) = Loops.repeat_gen (n / 4 * 4) (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
Loops.repeat_right_plus 0 (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
Loops.repeat_gen_def (n / 4 * 4) (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
lemma_generate_elems_unroll4_loop #t #a max (n / 4 * 4) f init
val generate_blocks4_f:
#t:Type0
-> #a:Type0
-> k:nat
-> f:(i:nat{i < 4 * k} -> a -> a & t)
-> i:nat{i < k}
-> c:a
-> tuple2 a (lseq t 4)
let generate_blocks4_f #t #a max f i c =
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
c3, Lib.Sequence.create4 e0 e1 e2 e3
val lemma_generate_elems4_loop_step:
#t:Type0
-> #a:Type0
-> max:nat
-> k:nat{4 * k <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < k}
-> c:a
-> s:seq t{length s == 4 * i} ->
Lemma
(let (c1, res1) = generate_elems4_f #t #a max f i (c, s) in
let (c2, res2) = generate_blocks4_f #t #a k f i c in
c1 == c2 /\ Seq.append s res2 == res1) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
max: Prims.nat ->
k: Prims.nat{4 * k <= max} ->
f: (i: Prims.nat{i < max} -> _: a -> a * t) ->
i: Prims.nat{i < k} ->
c: a ->
s: Lib.Sequence.seq t {Lib.Sequence.length s == 4 * i}
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Lib.generate_elems4_f max f i (c, s) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in
let _ = Hacl.Spec.Lib.generate_blocks4_f k f i c in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c2 res2 = _ in
c1 == c2 /\ FStar.Seq.Base.append s res2 == res1)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.length",
"Prims.op_Addition",
"Lib.Sequence.lseq",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Seq.Base.append",
"FStar.Seq.Base.seq",
"FStar.Seq.Properties.snoc",
"Lib.Sequence.create4",
"Prims.unit",
"Hacl.Spec.Lib.generate_blocks4_f",
"Hacl.Spec.Lib.generate_elems4_a",
"Hacl.Spec.Lib.generate_elems4_f",
"FStar.Pervasives.Native.Mktuple2"
] | [] | false | false | true | false | false | let lemma_generate_elems4_loop_step #t #a max k f i c s =
| let c1, res1 = generate_elems4_f #t #a max f i (c, s) in
let c2, res2 = generate_blocks4_f #t #a k f i c in
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res = Lib.Sequence.create4 e0 e1 e2 e3 in
let res0 = Seq.snoc s e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
Seq.lemma_eq_intro (Seq.append s res) res3 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.mk_destr_bitsum'_bitsum_t | val 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]) | val 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]) | 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) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 99,
"end_line": 1540,
"start_col": 0,
"start_line": 1493
} | 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] | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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}
-> Prims.Tot
(LowParse.Spec.BitSum.destr_bitsum'_bitsum_t cl bitsum'_size key key_size e payload l1 l2
<:
Type) | Prims.Tot | [
"total",
""
] | [
"mk_destr_bitsum'_t",
"mk_destr_bitsum'_bitsum_t"
] | [
"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.destr_bitsum'_bitsum_nil",
"Prims.unit",
"FStar.List.Tot.Properties.append_l_nil",
"LowParse.Spec.BitSum.destr_bitsum'_bitsum_cons_nil",
"LowParse.Spec.BitSum.mk_destr_bitsum'_t",
"FStar.List.Tot.Properties.append_assoc",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Nil",
"LowParse.Spec.Enum.enum_repr_of_key_append_cons",
"LowParse.Spec.BitSum.destr_bitsum'_bitsum_cons",
"LowParse.Spec.BitSum.mk_destr_bitsum'_bitsum_t",
"LowParse.Spec.BitSum.destr_bitsum'_bitsum_t",
"LowParse.Spec.BitSum.bitsum_wellfoundedness",
"LowParse.Spec.BitSum.BitSum'"
] | [
"mutual recursion"
] | false | false | false | false | false | let rec 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) | false |
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.lemma_generate_elems4_loop | val lemma_generate_elems4_loop:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a -> Lemma
(let (c1, res1) = generate_blocks 4 (max / 4) (n / 4) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init in
let (c2, res2) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
c1 == c2 /\ res1 == res2) | val lemma_generate_elems4_loop:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a -> Lemma
(let (c1, res1) = generate_blocks 4 (max / 4) (n / 4) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init in
let (c2, res2) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
c1 == c2 /\ res1 == res2) | let rec lemma_generate_elems4_loop #t #a max n f init =
let k = n / 4 in
let (c1, res1) = generate_blocks 4 (max / 4) k (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init in
let (c2, res2) = Loops.repeat_gen k (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
if k = 0 then begin
eq_generate_blocks0 4 (max / 4) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init;
Loops.eq_repeat_gen0 k (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) end
else begin
lemma_generate_elems4_loop #t #a max (n - 4) f init;
let (c3, res3) = generate_blocks 4 (max / 4) (k - 1) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init in
let (c4, res4) = Loops.repeat_gen (k - 1) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
//assert (c3 == c4 /\ res3 == res4);
unfold_generate_blocks 4 (max / 4) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init (k - 1);
Loops.unfold_repeat_gen k (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) (k - 1);
//let (acc', s') = generate_blocks4_f #t #a (max / 4) f (k - 1) c3 in
//assert (res1 == Seq.append res3 s');
lemma_generate_elems4_loop_step #t #a max k f (k - 1) c3 res3;
() end | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 254,
"start_col": 0,
"start_line": 236
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1)
let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res'
val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2
val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty))
let eq_generate_elems0 #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.eq_repeat_gen0 n (generate_elem_a t a max) (generate_elem_f max f) init2
val generate_elems_unfold:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a
-> i:nat{i < n} -> Lemma
(generate_elems #t #a max (i + 1) f init ==
generate_elem_f max f i (generate_elems #t #a max i f init))
let generate_elems_unfold #t #a max n f init i =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.unfold_repeat_gen (i + 1) (generate_elem_a t a max) (generate_elem_f max f) init2 i
let generate_elems4_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max / 4}) = a & s:seq t{length s == 4 * i}
val generate_elems4_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max / 4}
-> acc:generate_elems4_a t a max i ->
generate_elems4_a t a max (i + 1)
let generate_elems4_f #t #a max f i (c, res) =
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res0 = Seq.snoc res e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
c3, res3
val generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems_unroll4 #t #a max n f init =
let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0) in
(c1, res1)
val lemma_generate_elems_unroll4_loop:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max /\ n % 4 = 0}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma
(let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
c0 == c1 /\ res0 == res1)
let lemma_generate_elems_unroll4_loop #t #a max n f init =
let acc_v = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let acc = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
let normalize_v (i:nat{i <= n / 4}) (acc_v:generate_elems4_a t a max i) : generate_elem_a t a max (4 * i) =
let (c, res) = acc_v in
(c, res) in
let aux (i:nat{i < n / 4}) (acc_v:generate_elems4_a t a max i) : Lemma
(normalize_v (i + 1) (generate_elems4_f max f i acc_v) ==
Loops.repeat_right (4 * i) (4 * i + 4)
(generate_elem_a t a max) (generate_elem_f max f) (normalize_v i acc_v)) =
let acc0 = normalize_v i acc_v in
let acc = Loops.repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0 in
Loops.unfold_repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 3);
Loops.unfold_repeat_right (4 * i) (4 * i + 3) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 2);
Loops.unfold_repeat_right (4 * i) (4 * i + 2) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 1);
Loops.unfold_repeat_right (4 * i) (4 * i + 1) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i);
Loops.eq_repeat_right (4 * i) (4 * i) (generate_elem_a t a max) (generate_elem_f max f) acc0;
assert (normalize_v (i + 1) (generate_elems4_f max f i acc_v) == acc);
() in
Classical.forall_intro_2 aux;
VecLemmas.lemma_repeat_gen_vec 4 (n / 4) (generate_elem_a t a max) (generate_elems4_a t a max) normalize_v
(generate_elem_f max f) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty)
val lemma_generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems_unroll4 #t #a max n f init == generate_elems #t #a max n f init)
let lemma_generate_elems_unroll4 #t #a max n f init =
let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0) in
let (c2, res2) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
let (c3, res3) = Loops.repeat_gen (n / 4 * 4) (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
Loops.repeat_right_plus 0 (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
Loops.repeat_gen_def (n / 4 * 4) (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty);
lemma_generate_elems_unroll4_loop #t #a max (n / 4 * 4) f init
val generate_blocks4_f:
#t:Type0
-> #a:Type0
-> k:nat
-> f:(i:nat{i < 4 * k} -> a -> a & t)
-> i:nat{i < k}
-> c:a
-> tuple2 a (lseq t 4)
let generate_blocks4_f #t #a max f i c =
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
c3, Lib.Sequence.create4 e0 e1 e2 e3
val lemma_generate_elems4_loop_step:
#t:Type0
-> #a:Type0
-> max:nat
-> k:nat{4 * k <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < k}
-> c:a
-> s:seq t{length s == 4 * i} ->
Lemma
(let (c1, res1) = generate_elems4_f #t #a max f i (c, s) in
let (c2, res2) = generate_blocks4_f #t #a k f i c in
c1 == c2 /\ Seq.append s res2 == res1)
let lemma_generate_elems4_loop_step #t #a max k f i c s =
let (c1, res1) = generate_elems4_f #t #a max f i (c, s) in
let (c2, res2) = generate_blocks4_f #t #a k f i c in
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res = Lib.Sequence.create4 e0 e1 e2 e3 in
let res0 = Seq.snoc s e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
Seq.lemma_eq_intro (Seq.append s res) res3
val lemma_generate_elems4_loop:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a -> Lemma
(let (c1, res1) = generate_blocks 4 (max / 4) (n / 4) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init in
let (c2, res2) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
c1 == c2 /\ res1 == res2) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | max: Prims.nat -> n: Prims.nat{n <= max} -> f: (i: Prims.nat{i < max} -> _: a -> a * t) -> init: a
-> FStar.Pervasives.Lemma
(ensures
(let _ =
Lib.Sequence.generate_blocks 4
(max / 4)
(n / 4)
(Lib.LoopCombinators.fixed_a a)
(Hacl.Spec.Lib.generate_blocks4_f (max / 4) f)
init
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in
let _ =
Lib.LoopCombinators.repeat_gen (n / 4)
(Hacl.Spec.Lib.generate_elems4_a t a max)
(Hacl.Spec.Lib.generate_elems4_f max f)
(init,
FStar.Seq.Base.empty)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c2 res2 = _ in
c1 == c2 /\ res1 == res2)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Lib.LoopCombinators.fixed_a",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.length",
"FStar.Mul.op_Star",
"Prims.op_Equality",
"Lib.LoopCombinators.eq_repeat_gen0",
"Hacl.Spec.Lib.generate_elems4_a",
"Hacl.Spec.Lib.generate_elems4_f",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.empty",
"Prims.unit",
"Lib.Sequence.eq_generate_blocks0",
"Prims.op_Division",
"Hacl.Spec.Lib.generate_blocks4_f",
"Prims.bool",
"Prims.op_Subtraction",
"Hacl.Spec.Lib.lemma_generate_elems4_loop_step",
"Lib.LoopCombinators.unfold_repeat_gen",
"Lib.Sequence.unfold_generate_blocks",
"Lib.LoopCombinators.repeat_gen",
"Prims.op_Multiply",
"Lib.Sequence.generate_blocks",
"Hacl.Spec.Lib.lemma_generate_elems4_loop"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_generate_elems4_loop #t #a max n f init =
| let k = n / 4 in
let c1, res1 =
generate_blocks 4 (max / 4) k (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init
in
let c2, res2 =
Loops.repeat_gen k (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty)
in
if k = 0
then
(eq_generate_blocks0 4 (max / 4) (Loops.fixed_a a) (generate_blocks4_f #t #a (max / 4) f) init;
Loops.eq_repeat_gen0 k (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty))
else
(lemma_generate_elems4_loop #t #a max (n - 4) f init;
let c3, res3 =
generate_blocks 4
(max / 4)
(k - 1)
(Loops.fixed_a a)
(generate_blocks4_f #t #a (max / 4) f)
init
in
let c4, res4 =
Loops.repeat_gen (k - 1)
(generate_elems4_a t a max)
(generate_elems4_f max f)
(init, Seq.empty)
in
unfold_generate_blocks 4
(max / 4)
(Loops.fixed_a a)
(generate_blocks4_f #t #a (max / 4) f)
init
(k - 1);
Loops.unfold_repeat_gen k
(generate_elems4_a t a max)
(generate_elems4_f max f)
(init, Seq.empty)
(k - 1);
lemma_generate_elems4_loop_step #t #a max k f (k - 1) c3 res3;
()) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.set_valid_bitfield | 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) | 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)
= 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 |) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 126,
"end_line": 1891,
"start_col": 0,
"start_line": 1870
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.Tot | [
"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'"
] | [
"recursion"
] | false | false | false | false | 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
(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 |) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.bitsum'_key_of_t_set_valid_bitfield | 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) | 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)
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 66,
"end_line": 1913,
"start_col": 0,
"start_line": 1893
} | 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 |) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [
"recursion"
] | false | false | true | false | 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 | false |
Hacl.Spec.Lib.fst | Hacl.Spec.Lib.lemma_generate_elems_unroll4_loop | val lemma_generate_elems_unroll4_loop:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max /\ n % 4 = 0}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma
(let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
c0 == c1 /\ res0 == res1) | val lemma_generate_elems_unroll4_loop:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max /\ n % 4 = 0}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma
(let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
c0 == c1 /\ res0 == res1) | let lemma_generate_elems_unroll4_loop #t #a max n f init =
let acc_v = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let acc = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
let normalize_v (i:nat{i <= n / 4}) (acc_v:generate_elems4_a t a max i) : generate_elem_a t a max (4 * i) =
let (c, res) = acc_v in
(c, res) in
let aux (i:nat{i < n / 4}) (acc_v:generate_elems4_a t a max i) : Lemma
(normalize_v (i + 1) (generate_elems4_f max f i acc_v) ==
Loops.repeat_right (4 * i) (4 * i + 4)
(generate_elem_a t a max) (generate_elem_f max f) (normalize_v i acc_v)) =
let acc0 = normalize_v i acc_v in
let acc = Loops.repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0 in
Loops.unfold_repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 3);
Loops.unfold_repeat_right (4 * i) (4 * i + 3) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 2);
Loops.unfold_repeat_right (4 * i) (4 * i + 2) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i + 1);
Loops.unfold_repeat_right (4 * i) (4 * i + 1) (generate_elem_a t a max) (generate_elem_f max f) acc0 (4 * i);
Loops.eq_repeat_right (4 * i) (4 * i) (generate_elem_a t a max) (generate_elem_f max f) acc0;
assert (normalize_v (i + 1) (generate_elems4_f max f i acc_v) == acc);
() in
Classical.forall_intro_2 aux;
VecLemmas.lemma_repeat_gen_vec 4 (n / 4) (generate_elem_a t a max) (generate_elems4_a t a max) normalize_v
(generate_elem_f max f) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) | {
"file_name": "code/bignum/Hacl.Spec.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 153,
"start_col": 0,
"start_line": 125
} | 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"
let generate_elem_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max}) = a & s:seq t{length s == i}
val generate_elem_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max}
-> acc:generate_elem_a t a max i ->
generate_elem_a t a max (i + 1)
let generate_elem_f #t #a max f i (c, res) =
let c', e = f i c in
let res' = Seq.snoc res e in
c', res'
val generate_elems:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) init2
val eq_generate_elems0:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma (generate_elems #t #a max 0 f init == (init, Seq.empty))
let eq_generate_elems0 #t #a max n f init =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.eq_repeat_gen0 n (generate_elem_a t a max) (generate_elem_f max f) init2
val generate_elems_unfold:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a
-> i:nat{i < n} -> Lemma
(generate_elems #t #a max (i + 1) f init ==
generate_elem_f max f i (generate_elems #t #a max i f init))
let generate_elems_unfold #t #a max n f init i =
let init2 : generate_elem_a t a max 0 = (init, Seq.empty) in
Loops.unfold_repeat_gen (i + 1) (generate_elem_a t a max) (generate_elem_f max f) init2 i
let generate_elems4_a (t:Type0) (a:Type0) (max:nat) (i:nat{i <= max / 4}) = a & s:seq t{length s == 4 * i}
val generate_elems4_f:
#t:Type0
-> #a:Type0
-> max:nat
-> f:(i:nat{i < max} -> a -> a & t)
-> i:nat{i < max / 4}
-> acc:generate_elems4_a t a max i ->
generate_elems4_a t a max (i + 1)
let generate_elems4_f #t #a max f i (c, res) =
let c0, e0 = f (4 * i) c in
let c1, e1 = f (4 * i + 1) c0 in
let c2, e2 = f (4 * i + 2) c1 in
let c3, e3 = f (4 * i + 3) c2 in
let res0 = Seq.snoc res e0 in
let res1 = Seq.snoc res0 e1 in
let res2 = Seq.snoc res1 e2 in
let res3 = Seq.snoc res2 e3 in
c3, res3
val generate_elems_unroll4:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Tot (a & s:seq t{length s == n})
let generate_elems_unroll4 #t #a max n f init =
let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_right (n / 4 * 4) n (generate_elem_a t a max) (generate_elem_f max f) (c0, res0) in
(c1, res1)
val lemma_generate_elems_unroll4_loop:
#t:Type0
-> #a:Type0
-> max:nat
-> n:nat{n <= max /\ n % 4 = 0}
-> f:(i:nat{i < max} -> a -> a & t)
-> init:a ->
Lemma
(let (c0, res0) = Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty) in
let (c1, res1) = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
c0 == c1 /\ res0 == res1) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
max: Prims.nat ->
n: Prims.nat{n <= max /\ n % 4 = 0} ->
f: (i: Prims.nat{i < max} -> _: a -> a * t) ->
init: a
-> FStar.Pervasives.Lemma
(ensures
(let _ =
Lib.LoopCombinators.repeat_gen (n / 4)
(Hacl.Spec.Lib.generate_elems4_a t a max)
(Hacl.Spec.Lib.generate_elems4_f max f)
(init,
FStar.Seq.Base.empty)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c0 res0 = _ in
let _ =
Lib.LoopCombinators.repeat_gen n
(Hacl.Spec.Lib.generate_elem_a t a max)
(Hacl.Spec.Lib.generate_elem_f max f)
(init,
FStar.Seq.Base.empty)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in
c0 == c1 /\ res0 == res1)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Lib.LoopCombinators.repeat_gen_def",
"Hacl.Spec.Lib.generate_elem_a",
"Hacl.Spec.Lib.generate_elem_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Sequence.seq",
"Prims.eq2",
"Lib.Sequence.length",
"FStar.Seq.Base.empty",
"Prims.unit",
"Prims.op_Division",
"Hacl.Spec.Lib.generate_elems4_a",
"Hacl.Spec.Lib.generate_elems4_f",
"FStar.Mul.op_Star",
"Lib.Vec.Lemmas.lemma_repeat_gen_vec",
"FStar.Classical.forall_intro_2",
"Prims.op_Addition",
"Lib.LoopCombinators.repeat_right",
"Prims.l_True",
"Prims.squash",
"Prims.op_Multiply",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims._assert",
"Lib.LoopCombinators.eq_repeat_right",
"Lib.LoopCombinators.unfold_repeat_right",
"Lib.LoopCombinators.repeat_gen"
] | [] | false | false | true | false | false | let lemma_generate_elems_unroll4_loop #t #a max n f init =
| let acc_v =
Loops.repeat_gen (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty)
in
let acc = Loops.repeat_gen n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) in
let normalize_v (i: nat{i <= n / 4}) (acc_v: generate_elems4_a t a max i)
: generate_elem_a t a max (4 * i) =
let c, res = acc_v in
(c, res)
in
let aux (i: nat{i < n / 4}) (acc_v: generate_elems4_a t a max i)
: Lemma
(normalize_v (i + 1) (generate_elems4_f max f i acc_v) ==
Loops.repeat_right (4 * i)
(4 * i + 4)
(generate_elem_a t a max)
(generate_elem_f max f)
(normalize_v i acc_v)) =
let acc0 = normalize_v i acc_v in
let acc =
Loops.repeat_right (4 * i) (4 * i + 4) (generate_elem_a t a max) (generate_elem_f max f) acc0
in
Loops.unfold_repeat_right (4 * i)
(4 * i + 4)
(generate_elem_a t a max)
(generate_elem_f max f)
acc0
(4 * i + 3);
Loops.unfold_repeat_right (4 * i)
(4 * i + 3)
(generate_elem_a t a max)
(generate_elem_f max f)
acc0
(4 * i + 2);
Loops.unfold_repeat_right (4 * i)
(4 * i + 2)
(generate_elem_a t a max)
(generate_elem_f max f)
acc0
(4 * i + 1);
Loops.unfold_repeat_right (4 * i)
(4 * i + 1)
(generate_elem_a t a max)
(generate_elem_f max f)
acc0
(4 * i);
Loops.eq_repeat_right (4 * i) (4 * i) (generate_elem_a t a max) (generate_elem_f max f) acc0;
assert (normalize_v (i + 1) (generate_elems4_f max f i acc_v) == acc);
()
in
Classical.forall_intro_2 aux;
VecLemmas.lemma_repeat_gen_vec 4
(n / 4)
(generate_elem_a t a max)
(generate_elems4_a t a max)
normalize_v
(generate_elem_f max f)
(generate_elems4_f max f)
(init, Seq.empty);
Loops.repeat_gen_def (n / 4) (generate_elems4_a t a max) (generate_elems4_f max f) (init, Seq.empty);
Loops.repeat_gen_def n (generate_elem_a t a max) (generate_elem_f max f) (init, Seq.empty) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.get_valid_bitfield | 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)) | 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))
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 47,
"end_line": 1847,
"start_col": 0,
"start_line": 1829
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.Tot | [
"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'"
] | [
"recursion"
] | false | false | false | false | 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.mk_synth_bitsum'_recip_BitSum | val 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]) | val 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]) | 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) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 103,
"end_line": 1783,
"start_col": 0,
"start_line": 1736
} | 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] | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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}
-> Prims.Tot
(LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_t cl bitsum'_size key key_size e payload l1 l2) | Prims.Tot | [
"total",
""
] | [
"mk_synth_bitsum'_recip",
"mk_synth_bitsum'_recip_BitSum"
] | [
"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.synth_bitsum'_recip_BitSum_nil",
"Prims.unit",
"FStar.List.Tot.Properties.append_l_nil",
"LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_cons_nil",
"LowParse.Spec.BitSum.mk_synth_bitsum'_recip",
"FStar.List.Tot.Properties.append_assoc",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Nil",
"LowParse.Spec.Enum.enum_repr_of_key_append_cons",
"LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_cons",
"LowParse.Spec.BitSum.mk_synth_bitsum'_recip_BitSum",
"LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_t",
"LowParse.Spec.BitSum.bitsum_wellfoundedness",
"LowParse.Spec.BitSum.BitSum'"
] | [
"mutual recursion"
] | false | false | false | false | false | let rec 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
) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.get_valid_bitfield_set_valid_bitfield_same | 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) | 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
)
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 73,
"end_line": 1939,
"start_col": 0,
"start_line": 1915
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)) | FStar.Pervasives.Lemma | [
"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"
] | [
"recursion"
] | false | false | true | false | 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.mk_synth_bitsum'_recip | val 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;()]) | val 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;()]) | 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) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 103,
"end_line": 1783,
"start_col": 0,
"start_line": 1736
} | 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] | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size
-> Prims.Tot (LowParse.Spec.BitSum.synth_bitsum'_recip_t b) | Prims.Tot | [
"total",
""
] | [
"mk_synth_bitsum'_recip",
"mk_synth_bitsum'_recip_BitSum"
] | [
"Prims.pos",
"Prims.eqtype",
"LowParse.BitFields.uint_t",
"Prims.nat",
"LowParse.Spec.BitSum.bitsum'",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"LowParse.Spec.BitSum.synth_bitsum'_recip_BitStop",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"LowParse.Spec.BitSum.synth_bitsum'_recip_BitField",
"LowParse.Spec.BitSum.mk_synth_bitsum'_recip",
"LowParse.Spec.Enum.enum",
"LowParse.BitFields.bitfield",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_intro",
"LowParse.Spec.BitSum.mk_synth_bitsum'_recip_BitSum",
"Prims.Nil",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.BitSum.synth_bitsum'_recip_t"
] | [
"mutual recursion"
] | false | false | false | false | false | 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) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_cons | 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)) | 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))
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 33,
"end_line": 1691,
"start_col": 0,
"start_line": 1652
} | 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 () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 @ (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
((k, r) :: l2) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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
[@@ 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 | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.get_valid_bitfield_set_valid_bitfield_other | 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') | 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'
)
= 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' | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 85,
"end_line": 1969,
"start_col": 0,
"start_line": 1941
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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')) | FStar.Pervasives.Lemma | [
"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"
] | [
"recursion"
] | false | false | true | false | 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' | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.synth_bitsum'_recip_BitSum_cons_nil | 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)])) | 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) :: []))
= 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) | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 88,
"end_line": 1732,
"start_col": 0,
"start_line": 1694
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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] | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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
(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) | false |
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.set_valid_bitfield_correct | 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) | 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)
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 57,
"end_line": 1996,
"start_col": 0,
"start_line": 1971
} | 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' | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [
"recursion"
] | false | false | true | false | 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
(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 | false |
Vale.Lib.Seqs_s.fst | Vale.Lib.Seqs_s.compose | val compose: f: ('b -> 'c) -> g: ('a -> 'b) -> 'a -> 'c | val compose: f: ('b -> 'c) -> g: ('a -> 'b) -> 'a -> 'c | let compose (f:'b -> 'c) (g:'a -> 'b) : 'a -> 'c = fun x -> f (g x) | {
"file_name": "vale/specs/defs/Vale.Lib.Seqs_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 67,
"end_line": 5,
"start_col": 0,
"start_line": 5
} | module Vale.Lib.Seqs_s
open FStar.Mul
open FStar.Seq | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Seqs_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: 'b -> 'c) -> g: (_: 'a -> 'b) -> _: 'a -> 'c | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let compose (f: ('b -> 'c)) (g: ('a -> 'b)) : 'a -> 'c =
| fun x -> f (g x) | false |
Vale.Lib.Seqs_s.fst | Vale.Lib.Seqs_s.seq_map | val seq_map (#a #b: Type) (f: (a -> b)) (s: seq a) : seq b | val seq_map (#a #b: Type) (f: (a -> b)) (s: seq a) : seq b | let seq_map (#a #b:Type) (f:a -> b) (s:seq a) : seq b =
init (length s) (compose f (index s)) | {
"file_name": "vale/specs/defs/Vale.Lib.Seqs_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 8,
"start_col": 0,
"start_line": 7
} | module Vale.Lib.Seqs_s
open FStar.Mul
open FStar.Seq
let compose (f:'b -> 'c) (g:'a -> 'b) : 'a -> 'c = fun x -> f (g x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Seqs_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: a -> b) -> s: FStar.Seq.Base.seq a -> FStar.Seq.Base.seq b | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.Seq.Base.init",
"FStar.Seq.Base.length",
"Vale.Lib.Seqs_s.compose",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.index"
] | [] | false | false | false | true | false | let seq_map (#a #b: Type) (f: (a -> b)) (s: seq a) : seq b =
| init (length s) (compose f (index s)) | false |
Vale.Lib.Seqs_s.fst | Vale.Lib.Seqs_s.reverse_seq | val reverse_seq (#a: Type) (s: seq a) : seq a | val reverse_seq (#a: Type) (s: seq a) : seq a | let reverse_seq (#a:Type) (s:seq a) : seq a =
init (length s) (fun i -> index s (length s - i - 1)) | {
"file_name": "vale/specs/defs/Vale.Lib.Seqs_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 14,
"start_col": 0,
"start_line": 13
} | module Vale.Lib.Seqs_s
open FStar.Mul
open FStar.Seq
let compose (f:'b -> 'c) (g:'a -> 'b) : 'a -> 'c = fun x -> f (g x)
let seq_map (#a #b:Type) (f:a -> b) (s:seq a) : seq b =
init (length s) (compose f (index s))
let all_but_last (s:seq 'a {length s > 0}) =
slice s 0 (length s - 1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Seqs_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq a -> FStar.Seq.Base.seq a | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.Seq.Base.init",
"FStar.Seq.Base.length",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Prims.op_Subtraction"
] | [] | false | false | false | true | false | let reverse_seq (#a: Type) (s: seq a) : seq a =
| init (length s) (fun i -> index s (length s - i - 1)) | false |
Vale.Lib.Seqs_s.fst | Vale.Lib.Seqs_s.all_but_last | val all_but_last : s: FStar.Seq.Base.seq 'a {FStar.Seq.Base.length s > 0} -> FStar.Seq.Base.seq 'a | let all_but_last (s:seq 'a {length s > 0}) =
slice s 0 (length s - 1) | {
"file_name": "vale/specs/defs/Vale.Lib.Seqs_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 11,
"start_col": 0,
"start_line": 10
} | module Vale.Lib.Seqs_s
open FStar.Mul
open FStar.Seq
let compose (f:'b -> 'c) (g:'a -> 'b) : 'a -> 'c = fun x -> f (g x)
let seq_map (#a #b:Type) (f:a -> b) (s:seq a) : seq b =
init (length s) (compose f (index s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Seqs_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq 'a {FStar.Seq.Base.length s > 0} -> FStar.Seq.Base.seq 'a | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Seq.Base.length",
"FStar.Seq.Base.slice",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let all_but_last (s: seq 'a {length s > 0}) =
| slice s 0 (length s - 1) | false |
|
LowParse.Spec.BitSum.fst | LowParse.Spec.BitSum.get_valid_bitfield_correct | 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) | 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)
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.BitSum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 55,
"end_line": 1868,
"start_col": 0,
"start_line": 1849
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [
"recursion"
] | false | false | true | false | 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 | false |
CQueue.fst | CQueue.dequeue | val dequeue
(#a: Type)
(x: t a)
(l: Ghost.erased (v a))
: Steel (a & Ghost.erased (v a))
(queue x l)
(fun res -> queue x (snd res))
(requires (fun _ -> Cons? (datas l) == true))
(ensures (fun _ res _ -> datas l == fst res :: datas (snd res))) | val dequeue
(#a: Type)
(x: t a)
(l: Ghost.erased (v a))
: Steel (a & Ghost.erased (v a))
(queue x l)
(fun res -> queue x (snd res))
(requires (fun _ -> Cons? (datas l) == true))
(ensures (fun _ res _ -> datas l == fst res :: datas (snd res))) | let dequeue #a x l =
let head0 = elim_queue_head x l in
let head = read (cllist_head x) in
let u = elim_llist_fragment_head_cons l (cllist_head x) head0 in
change_equal_slprop
(ccell head0)
(ccell head);
let head = elim_ccell head in
let data = read (ccell_data head) in
let next = read (ccell_next head) in
intro_ccell head;
free_cell head;
llist_fragment_head_is_nil u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next;
assert (Nil? u.ll_uncons_tl == ccell_ptrvalue_is_null next);
write (cllist_head x) next;
if ccell_ptrvalue_is_null next
then begin
elim_llist_fragment_head_nil u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next;
write (cllist_tail x) (cllist_head x);
intro_llist_fragment_head_nil [] (cllist_head x) (Ghost.reveal (Ghost.hide next));
intro_queue_head x [] next;
let res = (data, Ghost.hide []) in
change_equal_slprop
(queue_head x [])
(queue x (snd res));
return res
end else begin
llist_fragment_head_cons_change_phead u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next (cllist_head x);
intro_queue_head x u.ll_uncons_tl u.ll_uncons_next;
let res = (data, u.ll_uncons_tl) in
change_equal_slprop
(queue_head x u.ll_uncons_tl)
(queue x (snd res));
return res
end | {
"file_name": "share/steel/examples/steel/CQueue.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 1367,
"start_col": 0,
"start_line": 1333
} | module CQueue
open CQueue.LList
#set-options "--ide_id_info_off"
//Re-define squash, since this module explicitly
//replies on proving equalities of the form `t_of v == squash p`
//which are delicate in the presence of optimizations that
//unfold `Prims.squash (p /\ q)`to _:unit{p /\ q}
//See Issue #2496
let squash (p:Type u#a) : Type0 = squash p
(* BEGIN library *)
let intro_vrewrite_no_norm (#opened:inames)
(v: vprop) (#t: Type) (f: (t_of v) -> GTot t)
: SteelGhost unit opened v (fun _ -> vrewrite v f)
(fun _ -> True) (fun h _ h' -> h' (vrewrite v f) == f (h v))
=
intro_vrewrite v f
let elim_vrewrite_no_norm (#opened:inames)
(v: vprop)
(#t: Type)
(f: ((t_of v) -> GTot t))
: SteelGhost unit opened (vrewrite v f) (fun _ -> v)
(fun _ -> True)
(fun h _ h' -> h (vrewrite v f) == f (h' v))
=
elim_vrewrite v f
let vconst_sel
(#a: Type)
(x: a)
: Tot (selector a (hp_of emp))
= fun _ -> x
[@@ __steel_reduce__]
let vconst'
(#a: Type)
(x: a)
: GTot vprop'
= {
hp = hp_of emp;
t = a;
sel = vconst_sel x;
}
[@@ __steel_reduce__]
let vconst (#a: Type) (x: a) : Tot vprop = VUnit (vconst' x)
let intro_vconst
(#opened: _)
(#a: Type)
(x: a)
: SteelGhost unit opened
emp
(fun _ -> vconst x)
(fun _ -> True)
(fun _ _ h' -> h' (vconst x) == x)
=
change_slprop_rel
emp
(vconst x)
(fun _ y -> y == x)
(fun _ -> ())
let elim_vconst
(#opened: _)
(#a: Type)
(x: a)
: SteelGhost unit opened
(vconst x)
(fun _ -> emp)
(fun _ -> True)
(fun h _ _ -> h (vconst x) == x)
=
change_slprop_rel
(vconst x)
emp
(fun y _ -> y == x)
(fun _ -> ())
let vpure_sel'
(p: prop)
: Tot (selector' (squash p) (Steel.Memory.pure p))
= fun (m: Steel.Memory.hmem (Steel.Memory.pure p)) -> pure_interp p m
let vpure_sel
(p: prop)
: Tot (selector (squash p) (Steel.Memory.pure p))
= vpure_sel' p
[@@ __steel_reduce__]
let vpure'
(p: prop)
: GTot vprop'
= {
hp = Steel.Memory.pure p;
t = squash p;
sel = vpure_sel p;
}
[@@ __steel_reduce__]
let vpure (p: prop) : Tot vprop = VUnit (vpure' p)
let intro_vpure
(#opened: _)
(p: prop)
: SteelGhost unit opened
emp
(fun _ -> vpure p)
(fun _ -> p)
(fun _ _ h' -> p)
=
change_slprop_rel
emp
(vpure p)
(fun _ _ -> p)
(fun m -> pure_interp p m)
let elim_vpure
(#opened: _)
(p: prop)
: SteelGhost unit opened
(vpure p)
(fun _ -> emp)
(fun _ -> True)
(fun _ _ _ -> p)
=
change_slprop_rel
(vpure p)
emp
(fun _ _ -> p)
(fun m -> pure_interp p m; reveal_emp (); intro_emp m)
val intro_vdep2 (#opened:inames)
(v: vprop)
(q: vprop)
(x: t_of v)
(p: (t_of v -> Tot vprop))
: SteelGhost unit opened
(v `star` q)
(fun _ -> vdep v p)
(requires (fun h ->
q == p x /\
x == h v
))
(ensures (fun h _ h' ->
let x2 = h' (vdep v p) in
q == p (h v) /\
dfst x2 == (h v) /\
dsnd x2 == (h q)
))
let intro_vdep2
v q x p
=
intro_vdep v q p
let vbind0_payload
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
(x: t_of a)
: Tot vprop
= vpure (t == t_of (b x)) `star` b x
let vbind0_rewrite
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
(x: normal (t_of (vdep a (vbind0_payload a t b))))
: Tot t
= snd (dsnd x)
[@@__steel_reduce__; __reduce__]
let vbind0
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot vprop
= a `vdep` vbind0_payload a t b `vrewrite` vbind0_rewrite a t b
let vbind_hp // necessary to hide the attribute on hp_of
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot (slprop u#1)
= hp_of (vbind0 a t b)
let vbind_sel // same for hp_sel
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: GTot (selector t (vbind_hp a t b))
= sel_of (vbind0 a t b)
[@@__steel_reduce__]
let vbind'
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: GTot vprop'
= {
hp = vbind_hp a t b;
t = t;
sel = vbind_sel a t b;
}
[@@__steel_reduce__]
let vbind
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot vprop
= VUnit (vbind' a t b)
let intro_vbind
(#opened: _)
(a: vprop)
(b' : vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: SteelGhost unit opened
(a `star` b')
(fun _ -> vbind a t b)
(fun h -> t_of b' == t /\ b' == b (h a))
(fun h _ h' ->
t_of b' == t /\
b' == b (h a) /\
h' (vbind a t b) == h b'
)
=
intro_vpure (t == t_of b');
intro_vdep
a
(vpure (t == t_of b') `star` b')
(vbind0_payload a t b);
intro_vrewrite
(a `vdep` vbind0_payload a t b)
(vbind0_rewrite a t b);
change_slprop_rel
(vbind0 a t b)
(vbind a t b)
(fun x y -> x == y)
(fun _ -> ())
let elim_vbind
(#opened: _)
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: SteelGhost (Ghost.erased (t_of a)) opened
(vbind a t b)
(fun res -> a `star` b (Ghost.reveal res))
(fun h -> True)
(fun h res h' ->
h' a == Ghost.reveal res /\
t == t_of (b (Ghost.reveal res)) /\
h' (b (Ghost.reveal res)) == h (vbind a t b)
)
=
change_slprop_rel
(vbind a t b)
(vbind0 a t b)
(fun x y -> x == y)
(fun _ -> ());
elim_vrewrite
(a `vdep` vbind0_payload a t b)
(vbind0_rewrite a t b);
let res = elim_vdep a (vbind0_payload a t b) in
change_equal_slprop
(vbind0_payload a t b (Ghost.reveal res))
(vpure (t == t_of (b (Ghost.reveal res))) `star` b (Ghost.reveal res));
elim_vpure (t == t_of (b (Ghost.reveal res)));
res
let (==) (#a:_) (x y: a) : prop = x == y
let snoc_inj (#a: Type) (hd1 hd2: list a) (tl1 tl2: a) : Lemma
(requires (hd1 `L.append` [tl1] == hd2 `L.append` [tl2]))
(ensures (hd1 == hd2 /\ tl1 == tl2))
[SMTPat (hd1 `L.append` [tl1]); SMTPat (hd2 `L.append` [tl2])]
= L.lemma_snoc_unsnoc (hd1, tl1);
L.lemma_snoc_unsnoc (hd2, tl2)
[@"opaque_to_smt"]
let unsnoc (#a: Type) (l: list a) : Pure (list a & a)
(requires (Cons? l))
(ensures (fun (hd, tl) -> l == hd `L.append` [tl] /\ L.length hd < L.length l))
=
L.lemma_unsnoc_snoc l;
L.append_length (fst (L.unsnoc l)) [snd (L.unsnoc l)];
L.unsnoc l
let unsnoc_hd (#a: Type) (l: list a) : Pure (list a) (requires (Cons? l)) (ensures (fun l' -> L.length l' <
L.length l)) = fst (unsnoc l)
let unsnoc_tl (#a: Type) (l: list a) : Pure (a) (requires (Cons? l)) (ensures (fun _ -> True)) = snd (unsnoc l)
[@@"opaque_to_smt"]
let snoc (#a: Type) (l: list a) (x: a) : Pure (list a)
(requires True)
(ensures (fun l' ->
Cons? l' /\
unsnoc_hd l' == l /\
unsnoc_tl l' == x
))
=
let l' = L.snoc (l, x) in
L.append_length l [x];
snoc_inj l (unsnoc_hd l') x (unsnoc_tl l');
l'
let snoc_unsnoc
(#a: Type)
(l: list a)
: Lemma
(requires (Cons? l))
(ensures (snoc (unsnoc_hd l) (unsnoc_tl l) == l))
= ()
unfold
let coerce
(#a: Type)
(x: a)
(b: Type)
: Pure b
(requires (a == b))
(ensures (fun y -> a == b /\ x == y))
= x
(* END library *)
let t a = cllist_lvalue a
let v (a: Type0) = list a
let datas
(#a: Type0)
(l: v a)
: Tot (list a)
= l
(* view from the tail *)
let llist_fragment_tail_cons_data_refine
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(d: a)
: Tot prop
= d == unsnoc_tl (Ghost.reveal l)
[@@ __steel_reduce__]
let llist_fragment_tail_cons_lvalue_payload
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(c: ccell_lvalue a)
: Tot vprop
= vptr (ccell_data c) `vrefine` llist_fragment_tail_cons_data_refine l
let ccell_is_lvalue_refine
(a: Type)
(c: ccell_ptrvalue a)
: Tot prop
= ccell_ptrvalue_is_null c == false
[@@ __steel_reduce__ ]
let llist_fragment_tail_cons_next_payload
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(ptail: ref (ccell_ptrvalue a))
: Tot vprop
= vptr ptail `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l
[@@ __steel_reduce__ ]
let llist_fragment_tail_cons_rewrite
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(llist_fragment_tail: vprop { t_of llist_fragment_tail == ref (ccell_ptrvalue a) })
(x: normal (t_of (llist_fragment_tail `vdep` (llist_fragment_tail_cons_next_payload l))))
: Tot (ref (ccell_ptrvalue a))
= let (| _, (| c, _ |) |) = x in
ccell_next c
let rec llist_fragment_tail (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) : Pure vprop
(requires True)
(ensures (fun v -> t_of v == ref (ccell_ptrvalue a)))
(decreases (Ghost.reveal (L.length l)))
= if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
let llist_fragment_tail_eq
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
: Lemma
(llist_fragment_tail l phead == (
if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
))
= assert_norm
(llist_fragment_tail l phead == (
if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
))
let llist_fragment_tail_eq_cons
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
: Lemma
(requires (Cons? l))
(ensures (Cons? l /\
llist_fragment_tail l phead == (
llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
)))
= llist_fragment_tail_eq l phead
unfold
let sel_llist_fragment_tail
(#a:Type) (#p:vprop)
(l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
(h: rmem p { FStar.Tactics.with_tactic selector_tactic (can_be_split p (llist_fragment_tail l phead) /\ True) })
: GTot (ref (ccell_ptrvalue a))
=
coerce (h (llist_fragment_tail l phead)) (ref (ccell_ptrvalue a))
val intro_llist_fragment_tail_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost unit opened
emp
(fun _ -> llist_fragment_tail l phead)
(fun _ -> Nil? l)
(fun _ _ h' -> sel_llist_fragment_tail l phead h' == phead)
let intro_llist_fragment_tail_nil
l phead
=
intro_vconst phead;
change_equal_slprop
(vconst phead)
(llist_fragment_tail l phead)
val elim_llist_fragment_tail_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost unit opened
(llist_fragment_tail l phead)
(fun _ -> emp)
(fun _ -> Nil? l)
(fun h _ _ -> sel_llist_fragment_tail l phead h == phead)
let elim_llist_fragment_tail_nil
l phead
=
change_equal_slprop
(llist_fragment_tail l phead)
(vconst phead);
elim_vconst phead
val intro_llist_fragment_tail_snoc
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(ptail: Ghost.erased (ref (ccell_ptrvalue a)))
(tail: Ghost.erased (ccell_lvalue a))
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_tail l phead `star` vptr ptail `star` vptr (ccell_data tail))
(fun res -> llist_fragment_tail res phead)
(fun h ->
sel_llist_fragment_tail l phead h == Ghost.reveal ptail /\
sel ptail h == Ghost.reveal tail
)
(fun h res h' ->
Ghost.reveal res == snoc (Ghost.reveal l) (sel (ccell_data tail) h) /\
sel_llist_fragment_tail res phead h' == ccell_next tail
)
#push-options "--z3rlimit 16"
let intro_llist_fragment_tail_snoc
#_ #a l phead ptail tail
=
let d = gget (vptr (ccell_data tail)) in
let l' : (l' : Ghost.erased (list a) { Cons? (Ghost.reveal l') }) = Ghost.hide (snoc (Ghost.reveal l) (Ghost.reveal d)) in
intro_vrefine (vptr (ccell_data tail)) (llist_fragment_tail_cons_data_refine l');
intro_vrefine (vptr ptail) (ccell_is_lvalue_refine a);
intro_vdep
(vptr ptail `vrefine` ccell_is_lvalue_refine a)
(vptr (ccell_data tail) `vrefine` llist_fragment_tail_cons_data_refine l')
(llist_fragment_tail_cons_lvalue_payload l');
change_equal_slprop
(llist_fragment_tail l phead)
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead);
intro_vdep
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead)
(vptr ptail `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l')
(llist_fragment_tail_cons_next_payload l');
intro_vrewrite_no_norm
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead `vdep` llist_fragment_tail_cons_next_payload l')
(llist_fragment_tail_cons_rewrite l' (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead));
llist_fragment_tail_eq_cons l' phead;
change_equal_slprop
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead `vdep` llist_fragment_tail_cons_next_payload l' `vrewrite` llist_fragment_tail_cons_rewrite l' (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead))
(llist_fragment_tail l' phead);
let g' = gget (llist_fragment_tail l' phead) in
assert (Ghost.reveal g' == ccell_next tail);
noop ();
l'
#pop-options
[@@erasable]
noeq
type ll_unsnoc_t (a: Type) = {
ll_unsnoc_l: list a;
ll_unsnoc_ptail: ref (ccell_ptrvalue a);
ll_unsnoc_tail: ccell_lvalue a;
}
val elim_llist_fragment_tail_snoc
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost (ll_unsnoc_t a) opened
(llist_fragment_tail l phead)
(fun res -> llist_fragment_tail res.ll_unsnoc_l phead `star` vptr res.ll_unsnoc_ptail `star` vptr (ccell_data res.ll_unsnoc_tail))
(fun _ -> Cons? l)
(fun h res h' ->
Cons? l /\
Ghost.reveal res.ll_unsnoc_l == unsnoc_hd l /\
sel res.ll_unsnoc_ptail h' == res.ll_unsnoc_tail /\
sel (ccell_data res.ll_unsnoc_tail) h'== unsnoc_tl l /\
sel_llist_fragment_tail res.ll_unsnoc_l phead h' == res.ll_unsnoc_ptail /\
sel_llist_fragment_tail l phead h == (ccell_next res.ll_unsnoc_tail)
)
#push-options "--z3rlimit 32"
#restart-solver
let elim_llist_fragment_tail_snoc
#_ #a l phead
=
let l0 : (l0: Ghost.erased (list a) { Cons? l0 }) = Ghost.hide (Ghost.reveal l) in
llist_fragment_tail_eq_cons l0 phead;
change_equal_slprop
(llist_fragment_tail l phead)
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead `vdep` llist_fragment_tail_cons_next_payload l0 `vrewrite` llist_fragment_tail_cons_rewrite l0 (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead));
elim_vrewrite_no_norm
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead `vdep` llist_fragment_tail_cons_next_payload l0)
(llist_fragment_tail_cons_rewrite l0 (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead));
let ptail = elim_vdep
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead)
(llist_fragment_tail_cons_next_payload l0)
in
let ptail0 : Ghost.erased (ref (ccell_ptrvalue a)) = ptail in
change_equal_slprop
(llist_fragment_tail_cons_next_payload l0 (Ghost.reveal ptail))
(vptr (Ghost.reveal ptail0) `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l0);
let tail = elim_vdep
(vptr (Ghost.reveal ptail0) `vrefine` ccell_is_lvalue_refine a)
(llist_fragment_tail_cons_lvalue_payload l0)
in
elim_vrefine (vptr (Ghost.reveal ptail0)) (ccell_is_lvalue_refine a);
let res = {
ll_unsnoc_l = unsnoc_hd l0;
ll_unsnoc_ptail = Ghost.reveal ptail0;
ll_unsnoc_tail = Ghost.reveal tail;
} in
change_equal_slprop
(vptr (Ghost.reveal ptail0))
(vptr res.ll_unsnoc_ptail);
change_equal_slprop
(llist_fragment_tail_cons_lvalue_payload l0 (Ghost.reveal tail))
(vptr (ccell_data res.ll_unsnoc_tail) `vrefine` llist_fragment_tail_cons_data_refine l0);
elim_vrefine
(vptr (ccell_data res.ll_unsnoc_tail))
(llist_fragment_tail_cons_data_refine l0);
change_equal_slprop
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead)
(llist_fragment_tail res.ll_unsnoc_l phead);
res
#pop-options
let rec llist_fragment_tail_append
(#opened: _)
(#a: Type)
(phead0: ref (ccell_ptrvalue a))
(l1: Ghost.erased (list a))
(phead1: Ghost.erased (ref (ccell_ptrvalue a)))
(l2: Ghost.erased (list a))
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_tail l1 phead0 `star` llist_fragment_tail l2 phead1)
(fun res -> llist_fragment_tail res phead0)
(fun h ->
Ghost.reveal phead1 == (sel_llist_fragment_tail l1 phead0) h
)
(fun h res h' ->
Ghost.reveal res == Ghost.reveal l1 `L.append` Ghost.reveal l2 /\
(sel_llist_fragment_tail res phead0) h' == (sel_llist_fragment_tail l2 phead1) h
)
(decreases (L.length (Ghost.reveal l2)))
=
let g1 = gget (llist_fragment_tail l1 phead0) in
assert (Ghost.reveal phead1 == Ghost.reveal g1);
if Nil? l2
then begin
L.append_l_nil (Ghost.reveal l1);
elim_llist_fragment_tail_nil l2 phead1;
l1
end else begin
let res = elim_llist_fragment_tail_snoc l2 (Ghost.reveal phead1) in
let d = gget (vptr (ccell_data res.ll_unsnoc_tail)) in
L.append_assoc (Ghost.reveal l1) (Ghost.reveal res.ll_unsnoc_l) [Ghost.reveal d];
let l3 = llist_fragment_tail_append phead0 l1 phead1 res.ll_unsnoc_l in
intro_llist_fragment_tail_snoc l3 phead0 res.ll_unsnoc_ptail res.ll_unsnoc_tail
end
let queue_tail_refine
(#a: Type)
(tail1: ref (ccell_ptrvalue a))
(tail2: ref (ccell_ptrvalue a))
(tl: normal (t_of (vptr tail2)))
: Tot prop
= ccell_ptrvalue_is_null tl == true /\ tail1 == tail2
[@@__steel_reduce__]
let queue_tail_dep2
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail1: t_of (llist_fragment_tail l (cllist_head x)))
(tail2: ref (ccell_ptrvalue a))
: Tot vprop
= vptr tail2 `vrefine` queue_tail_refine tail1 tail2
[@@__steel_reduce__]
let queue_tail_dep1
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail1: t_of (llist_fragment_tail l (cllist_head x)))
: Tot vprop
= vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail1
[@@__steel_reduce__; __reduce__]
let queue_tail
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: Tot vprop
=
llist_fragment_tail l (cllist_head x) `vdep` queue_tail_dep1 x l
val intro_queue_tail
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail: ref (ccell_ptrvalue a))
: SteelGhost unit opened
(llist_fragment_tail l (cllist_head x) `star` vptr (cllist_tail x) `star` vptr tail)
(fun _ -> queue_tail x l)
(fun h ->
sel_llist_fragment_tail l (cllist_head x) h == tail /\
sel (cllist_tail x) h == tail /\
ccell_ptrvalue_is_null (sel tail h)
)
(fun _ _ _ -> True)
let intro_queue_tail
x l tail
=
intro_vrefine (vptr tail) (queue_tail_refine tail tail);
intro_vdep2
(vptr (cllist_tail x))
(vptr tail `vrefine` queue_tail_refine tail tail)
tail
(queue_tail_dep2 x l tail);
intro_vdep2
(llist_fragment_tail l (cllist_head x))
(vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail)
tail
(queue_tail_dep1 x l)
val elim_queue_tail
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: SteelGhost (Ghost.erased (ref (ccell_ptrvalue a))) opened
(queue_tail x l)
(fun tail -> llist_fragment_tail l (cllist_head x) `star` vptr (cllist_tail x) `star` vptr tail)
(fun h -> True)
(fun _ tail h ->
sel_llist_fragment_tail l (cllist_head x) h == Ghost.reveal tail /\
sel (cllist_tail x) h == Ghost.reveal tail /\
ccell_ptrvalue_is_null (h (vptr tail))
)
let elim_queue_tail
#_ #a x l
=
let tail0 = elim_vdep
(llist_fragment_tail l (cllist_head x))
(queue_tail_dep1 x l)
in
let tail : Ghost.erased (ref (ccell_ptrvalue a)) = tail0 in
change_equal_slprop
(queue_tail_dep1 x l (Ghost.reveal tail0))
(vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail0);
let tail2 = elim_vdep
(vptr (cllist_tail x))
(queue_tail_dep2 x l tail0)
in
let tail3 : Ghost.erased (ref (ccell_ptrvalue a)) = tail2 in
change_equal_slprop
(queue_tail_dep2 x l tail0 (Ghost.reveal tail2))
(vptr tail3 `vrefine` queue_tail_refine tail0 tail3);
elim_vrefine (vptr tail3) (queue_tail_refine tail0 tail3);
change_equal_slprop
(vptr tail3)
(vptr tail);
tail
(* view from the head *)
let llist_fragment_head_data_refine
(#a: Type)
(d: a)
(c: vcell a)
: Tot prop
= c.vcell_data == d
let llist_fragment_head_payload
(#a: Type)
(head: ccell_ptrvalue a)
(d: a)
(llist_fragment_head: (ref (ccell_ptrvalue a) -> ccell_ptrvalue a -> Tot vprop))
(x: t_of (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine d)))
: Tot vprop
=
llist_fragment_head (ccell_next (fst x)) (snd x).vcell_next
let rec llist_fragment_head (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : Tot vprop
(decreases (Ghost.reveal l))
=
if Nil? l
then vconst (phead, head)
else
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
let t_of_llist_fragment_head
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
: Lemma
(t_of (llist_fragment_head l phead head) == ref (ccell_ptrvalue a) & ccell_ptrvalue a)
= ()
unfold
let sel_llist_fragment_head
(#a:Type) (#p:vprop)
(l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
(h: rmem p { FStar.Tactics.with_tactic selector_tactic (can_be_split p (llist_fragment_head l phead head) /\ True) })
: GTot (ref (ccell_ptrvalue a) & ccell_ptrvalue a)
=
coerce (h (llist_fragment_head l phead head)) (ref (ccell_ptrvalue a) & ccell_ptrvalue a)
val intro_llist_fragment_head_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost unit opened
emp
(fun _ -> llist_fragment_head l phead head)
(fun _ -> Nil? l)
(fun _ _ h' -> sel_llist_fragment_head l phead head h' == (phead, head))
let intro_llist_fragment_head_nil
l phead head
=
intro_vconst (phead, head);
change_equal_slprop
(vconst (phead, head))
(llist_fragment_head l phead head)
val elim_llist_fragment_head_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost unit opened
(llist_fragment_head l phead head)
(fun _ -> emp)
(fun _ -> Nil? l)
(fun h _ _ -> sel_llist_fragment_head l phead head h == (phead, head))
let elim_llist_fragment_head_nil
l phead head
=
change_equal_slprop
(llist_fragment_head l phead head)
(vconst (phead, head));
elim_vconst (phead, head)
let llist_fragment_head_eq_cons
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
: Lemma
(requires (Cons? (Ghost.reveal l)))
(ensures (
llist_fragment_head l phead head ==
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
))
= assert_norm
(llist_fragment_head l phead head == (
if Nil? l
then vconst (phead, head)
else
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
))
val intro_llist_fragment_head_cons
(#opened: _)
(#a: Type) (phead: ref (ccell_ptrvalue a)) (head: ccell_lvalue a) (next: (ccell_ptrvalue a)) (tl: Ghost.erased (list a))
: SteelGhost (Ghost.erased (list a)) opened
(ccell head `star` llist_fragment_head tl (ccell_next head) next)
(fun res -> llist_fragment_head res phead head)
(fun h -> (h (ccell head)).vcell_next == next)
(fun h res h' ->
Ghost.reveal res == (h (ccell head)).vcell_data :: Ghost.reveal tl /\
h' (llist_fragment_head res phead head) == h (llist_fragment_head tl (ccell_next head) next)
)
let intro_llist_fragment_head_cons
#_ #a phead head next tl
=
let vc = gget (ccell head) in
let l' : (l' : Ghost.erased (list a) { Cons? l' }) = Ghost.hide (vc.vcell_data :: tl) in
intro_ccell_is_lvalue head;
intro_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l'));
intro_vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l')))
(llist_fragment_head tl (ccell_next head) next)
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l') (llist_fragment_head (L.tl l')));
llist_fragment_head_eq_cons l' phead head;
change_equal_slprop
(vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l')))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l') (llist_fragment_head (L.tl l'))))
(llist_fragment_head l' phead head);
l'
[@@erasable]
noeq
type ll_uncons_t
(a: Type)
= {
ll_uncons_pnext: Ghost.erased (ref (ccell_ptrvalue a));
ll_uncons_next: Ghost.erased (ccell_ptrvalue a);
ll_uncons_tl: Ghost.erased (list a);
}
val elim_llist_fragment_head_cons
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost (ll_uncons_t a) opened
(llist_fragment_head l phead head)
(fun res -> ccell head `star` llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next)
(fun _ -> Cons? (Ghost.reveal l))
(fun h res h' ->
ccell_ptrvalue_is_null head == false /\
Ghost.reveal l == (h' (ccell head)).vcell_data :: Ghost.reveal res.ll_uncons_tl /\
Ghost.reveal res.ll_uncons_pnext == ccell_next head /\
Ghost.reveal res.ll_uncons_next == (h' (ccell head)).vcell_next /\
h' (llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next) == h (llist_fragment_head l phead head)
)
let elim_llist_fragment_head_cons
#_ #a l0 phead head
=
let l : (l : Ghost.erased (list a) { Cons? l }) = l0 in
change_equal_slprop
(llist_fragment_head l0 phead head)
(llist_fragment_head l phead head);
llist_fragment_head_eq_cons l phead head;
change_equal_slprop
(llist_fragment_head l phead head)
(vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l)))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l))));
let x = elim_vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l)))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)))
in
let head2 = gget (ccell_is_lvalue head) in
elim_ccell_is_lvalue head;
elim_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l));
let vhead2 = gget (ccell head) in
let res = {
ll_uncons_pnext = ccell_next head2;
ll_uncons_next = vhead2.vcell_next;
ll_uncons_tl = L.tl l;
} in
change_equal_slprop
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)) (Ghost.reveal x))
(llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next);
res
let rec llist_fragment_head_append
(#opened: _)
(#a: Type)
(l1: Ghost.erased (list a))
(phead1: ref (ccell_ptrvalue a))
(head1: ccell_ptrvalue a)
(l2: Ghost.erased (list a))
(phead2: ref (ccell_ptrvalue a))
(head2: ccell_ptrvalue a)
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_head l1 phead1 head1 `star` llist_fragment_head l2 phead2 head2)
(fun l -> llist_fragment_head l phead1 head1)
(fun h -> sel_llist_fragment_head l1 phead1 head1 h == (Ghost.reveal phead2, Ghost.reveal head2))
(fun h l h' ->
Ghost.reveal l == Ghost.reveal l1 `L.append` Ghost.reveal l2 /\
h' (llist_fragment_head l phead1 head1) == h (llist_fragment_head l2 phead2 head2)
)
(decreases (Ghost.reveal l1))
=
if Nil? l1
then begin
elim_llist_fragment_head_nil l1 phead1 head1;
change_equal_slprop
(llist_fragment_head l2 phead2 head2)
(llist_fragment_head l2 phead1 head1);
l2
end else begin
let u = elim_llist_fragment_head_cons l1 phead1 head1 in
let head1' : Ghost.erased (ccell_lvalue a) = head1 in
let l3 = llist_fragment_head_append u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next l2 phead2 head2 in
change_equal_slprop
(llist_fragment_head l3 u.ll_uncons_pnext u.ll_uncons_next)
(llist_fragment_head l3 (ccell_next head1') u.ll_uncons_next);
change_equal_slprop
(ccell head1)
(ccell head1');
let l4 = intro_llist_fragment_head_cons phead1 head1' u.ll_uncons_next l3 in
change_equal_slprop
(llist_fragment_head l4 phead1 head1')
(llist_fragment_head l4 phead1 head1);
l4
end
let rec llist_fragment_head_to_tail
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost (Ghost.erased (ref (ccell_ptrvalue a))) opened
(vptr phead `star` llist_fragment_head l phead head)
(fun res -> llist_fragment_tail l phead `star` vptr res)
(fun h -> h (vptr phead) == head)
(fun h res h' ->
let v = sel_llist_fragment_head l phead head h in
fst v == Ghost.reveal res /\
fst v == sel_llist_fragment_tail l phead h' /\
snd v == h' (vptr res)
)
(decreases (L.length (Ghost.reveal l)))
=
if Nil? l
then begin
let ptail = Ghost.hide phead in
let gh = gget (vptr phead) in
assert (Ghost.reveal gh == head);
elim_llist_fragment_head_nil l phead head;
intro_llist_fragment_tail_nil l phead;
change_equal_slprop
(vptr phead)
(vptr ptail);
ptail
end else begin
intro_llist_fragment_tail_nil [] phead;
change_equal_slprop
(vptr phead)
(vptr (Ghost.reveal (Ghost.hide phead)));
let uc = elim_llist_fragment_head_cons l phead head in
let head' = elim_ccell_ghost head in
change_equal_slprop
(vptr (ccell_next head'))
(vptr uc.ll_uncons_pnext);
let lc = intro_llist_fragment_tail_snoc [] phead phead head' in
let ptail = llist_fragment_head_to_tail
uc.ll_uncons_tl
uc.ll_uncons_pnext
uc.ll_uncons_next
in
let l' = llist_fragment_tail_append phead lc uc.ll_uncons_pnext uc.ll_uncons_tl in
change_equal_slprop
(llist_fragment_tail l' phead)
(llist_fragment_tail l phead);
ptail
end
#push-options "--z3rlimit 16"
#restart-solver
let rec llist_fragment_tail_to_head
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(ptail: ref (ccell_ptrvalue a))
: SteelGhost (Ghost.erased (ccell_ptrvalue a)) opened
(llist_fragment_tail l phead `star` vptr ptail)
(fun head -> vptr phead `star` llist_fragment_head l phead (Ghost.reveal head))
(fun h -> Ghost.reveal ptail == sel_llist_fragment_tail l phead h)
(fun h head h' ->
let v = sel_llist_fragment_head l phead head h' in
fst v == ptail /\
snd v == h (vptr ptail) /\
h' (vptr phead) == Ghost.reveal head
)
(decreases (L.length (Ghost.reveal l)))
=
if Nil? l
then begin
let g = gget (llist_fragment_tail l phead) in
assert (Ghost.reveal g == ptail);
elim_llist_fragment_tail_nil l phead;
change_equal_slprop
(vptr ptail)
(vptr phead);
let head = gget (vptr phead) in
intro_llist_fragment_head_nil l phead head;
head
end else begin
let us = elim_llist_fragment_tail_snoc l phead in
let tail = gget (vptr ptail) in
assert (ccell_next us.ll_unsnoc_tail == ptail);
intro_llist_fragment_head_nil [] (ccell_next us.ll_unsnoc_tail) tail;
change_equal_slprop
(vptr ptail)
(vptr (ccell_next us.ll_unsnoc_tail));
intro_ccell us.ll_unsnoc_tail;
let lc = intro_llist_fragment_head_cons us.ll_unsnoc_ptail us.ll_unsnoc_tail tail [] in
let head = llist_fragment_tail_to_head us.ll_unsnoc_l phead us.ll_unsnoc_ptail in
let g = gget (llist_fragment_head us.ll_unsnoc_l phead head) in
let g : Ghost.erased (ref (ccell_ptrvalue a) & ccell_ptrvalue a) = Ghost.hide (Ghost.reveal g) in
assert (Ghost.reveal g == (Ghost.reveal us.ll_unsnoc_ptail, Ghost.reveal us.ll_unsnoc_tail));
let l' = llist_fragment_head_append us.ll_unsnoc_l phead head lc us.ll_unsnoc_ptail us.ll_unsnoc_tail in
change_equal_slprop
(llist_fragment_head l' phead head)
(llist_fragment_head l phead head);
head
end
#pop-options
val llist_fragment_head_is_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost unit opened
(llist_fragment_head l phead head)
(fun _ -> llist_fragment_head l phead head)
(fun h -> ccell_ptrvalue_is_null (snd (sel_llist_fragment_head l phead head h)) == true)
(fun h _ h' ->
Nil? l == ccell_ptrvalue_is_null head /\
h' (llist_fragment_head l phead head) == h (llist_fragment_head l phead head)
)
let llist_fragment_head_is_nil
l phead head
=
if Nil? l
then begin
elim_llist_fragment_head_nil l phead head;
assert (ccell_ptrvalue_is_null head == true);
intro_llist_fragment_head_nil l phead head
end else begin
let r = elim_llist_fragment_head_cons l phead head in
let head2 : ccell_lvalue _ = head in
change_equal_slprop
(llist_fragment_head r.ll_uncons_tl r.ll_uncons_pnext r.ll_uncons_next)
(llist_fragment_head r.ll_uncons_tl (ccell_next head2) r.ll_uncons_next);
change_equal_slprop
(ccell head)
(ccell head2);
let l' = intro_llist_fragment_head_cons phead head2 r.ll_uncons_next r.ll_uncons_tl in
change_equal_slprop
(llist_fragment_head l' phead head2)
(llist_fragment_head l phead head)
end
val llist_fragment_head_cons_change_phead
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
(phead' : ref (ccell_ptrvalue a))
: SteelGhost unit opened
(llist_fragment_head l phead head)
(fun _ -> llist_fragment_head l phead' head)
(fun _ -> Cons? l)
(fun h _ h' -> h' (llist_fragment_head l phead' head) == h (llist_fragment_head l phead head))
let llist_fragment_head_cons_change_phead
l phead head phead'
=
let u = elim_llist_fragment_head_cons l phead head in
let head2 : ccell_lvalue _ = head in
change_equal_slprop
(ccell head)
(ccell head2);
change_equal_slprop
(llist_fragment_head u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next)
(llist_fragment_head u.ll_uncons_tl (ccell_next head2) u.ll_uncons_next);
let l' = intro_llist_fragment_head_cons phead' head2 u.ll_uncons_next u.ll_uncons_tl in
change_equal_slprop
(llist_fragment_head l' phead' head2)
(llist_fragment_head l phead' head)
let queue_head_refine
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(hd: ccell_ptrvalue a)
(ptl: t_of (llist_fragment_head l (cllist_head x) hd))
(tl: ref (ccell_ptrvalue a))
: Tot prop
= let ptl : (ref (ccell_ptrvalue a) & ccell_ptrvalue a) = ptl in
tl == fst ptl /\ ccell_ptrvalue_is_null (snd ptl) == true
let queue_head_dep1
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(hd: ccell_ptrvalue a)
(ptl: t_of (llist_fragment_head l (cllist_head x) hd))
: Tot vprop
= vptr (cllist_tail x) `vrefine` queue_head_refine x l hd ptl
let queue_head_dep2
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(hd: ccell_ptrvalue a)
: Tot vprop
= llist_fragment_head l (cllist_head x) hd `vdep` queue_head_dep1 x l hd
[@@__reduce__]
let queue_head
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: Tot vprop
= vptr (cllist_head x) `vdep` queue_head_dep2 x l
val intro_queue_head
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(hd: Ghost.erased (ccell_ptrvalue a))
: SteelGhost unit opened
(vptr (cllist_head x) `star` llist_fragment_head l (cllist_head x) hd `star` vptr (cllist_tail x))
(fun _ -> queue_head x l)
(fun h -> (
let frag = (sel_llist_fragment_head l (cllist_head x) hd) h in
sel (cllist_head x) h == Ghost.reveal hd /\
sel (cllist_tail x) h == fst frag /\
ccell_ptrvalue_is_null (snd frag) == true
))
(fun _ _ _ -> True)
let intro_queue_head
#_ #a x l hd
=
let ptl = gget (llist_fragment_head l (cllist_head x) hd) in
intro_vrefine
(vptr (cllist_tail x))
(queue_head_refine x l hd ptl);
assert_norm (vptr (cllist_tail x) `vrefine` queue_head_refine x l hd ptl == queue_head_dep1 x l hd ptl);
intro_vdep
(llist_fragment_head l (cllist_head x) hd)
(vptr (cllist_tail x) `vrefine` queue_head_refine x l hd ptl)
(queue_head_dep1 x l hd);
intro_vdep
(vptr (cllist_head x))
(llist_fragment_head l (cllist_head x) hd `vdep` queue_head_dep1 x l hd)
(queue_head_dep2 x l)
val elim_queue_head
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: SteelGhost (Ghost.erased (ccell_ptrvalue a)) opened
(queue_head x l)
(fun hd -> vptr (cllist_head x) `star` llist_fragment_head l (cllist_head x) hd `star` vptr (cllist_tail x))
(fun _ -> True)
(fun _ hd h -> (
let frag = (sel_llist_fragment_head l (cllist_head x) hd) h in
sel (cllist_head x) h == Ghost.reveal hd /\
sel (cllist_tail x) h == fst frag /\
ccell_ptrvalue_is_null (snd frag) == true
))
let elim_queue_head
#_ #a x l
=
let hd = elim_vdep
(vptr (cllist_head x))
(queue_head_dep2 x l)
in
let ptl = elim_vdep
(llist_fragment_head l (cllist_head x) hd)
(queue_head_dep1 x l hd)
in
elim_vrefine
(vptr (cllist_tail x))
(queue_head_refine x l hd ptl);
hd
let queue_head_to_tail
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: SteelGhostT unit opened
(queue_head x l)
(fun _ -> queue_tail x l)
=
let hd = elim_queue_head x l in
let tl = llist_fragment_head_to_tail l (cllist_head x) hd in
intro_queue_tail x l tl
let queue_tail_to_head
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: SteelGhostT unit opened
(queue_tail x l)
(fun _ -> queue_head x l)
=
let tl = elim_queue_tail x l in
let hd = llist_fragment_tail_to_head l (cllist_head x) tl in
intro_queue_head x l hd
(* We choose the head representation, since queue_is_empty and dequeue
need the head representation, but only enqueue needs the tail
representation. *)
[@@__reduce__]
let queue x l = queue_head x l
let create_queue a =
let head = ccell_ptrvalue_null a in
let tail : ref (ccell_ptrvalue a) = null in
let l0 = alloc_llist head tail in
let l = elim_cllist l0 in
write (cllist_tail l) (cllist_head l);
intro_llist_fragment_head_nil [] (cllist_head l) (Ghost.reveal (Ghost.hide head));
intro_queue_head l [] head;
let res : (t a & Ghost.erased (v a)) = (l0, Ghost.hide []) in
change_equal_slprop
(queue_head l [])
(queue (fst res) (snd res));
return res
let enqueue #a x l w =
queue_head_to_tail x l;
let ptail0 = elim_queue_tail x l in
let ptail = read (cllist_tail x) in
let c = alloc_cell w (ccell_ptrvalue_null a) in
let c0 = elim_ccell_ghost c in
change_equal_slprop
(vptr ptail0)
(vptr ptail);
write ptail c;
change_equal_slprop
(vptr ptail)
(vptr ptail0);
let l' = intro_llist_fragment_tail_snoc l (cllist_head x) ptail0 c0 in
write (cllist_tail x) (ccell_next c);
intro_queue_tail x l' (ccell_next c0);
queue_tail_to_head x l';
return l'
let queue_is_empty #a x l =
let head0 = elim_queue_head x l in
let head = read (cllist_head x) in
let res = ccell_ptrvalue_is_null head in
llist_fragment_head_is_nil l (cllist_head x) head0;
intro_queue_head x l head0;
return res | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"CQueue.LList.fsti.checked"
],
"interface_file": true,
"source_file": "CQueue.fst"
} | [
{
"abbrev": false,
"full_module": "CQueue.LList",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"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
}
] | {
"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"
} | false | x: CQueue.t a -> l: FStar.Ghost.erased (CQueue.v a)
-> Steel.Effect.Steel (a * FStar.Ghost.erased (CQueue.v a)) | Steel.Effect.Steel | [] | [] | [
"CQueue.t",
"FStar.Ghost.erased",
"CQueue.v",
"CQueue.Cell.ccell_ptrvalue_is_null",
"Steel.Effect.Atomic.return",
"FStar.Pervasives.Native.tuple2",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Effect.Common.vdep",
"Steel.Reference.vptrp",
"CQueue.Cell.ccell_ptrvalue",
"CQueue.LList.cllist_head",
"Steel.FractionalPermission.full_perm",
"CQueue.queue_head_dep2",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.Effect.Atomic.change_equal_slprop",
"CQueue.queue_head",
"Prims.list",
"Prims.Nil",
"CQueue.queue",
"FStar.Pervasives.Native.snd",
"FStar.Pervasives.Native.Mktuple2",
"CQueue.intro_queue_head",
"CQueue.intro_llist_fragment_head_nil",
"FStar.Ghost.reveal",
"Steel.Reference.write",
"Steel.Reference.ref",
"CQueue.LList.cllist_tail",
"CQueue.elim_llist_fragment_head_nil",
"CQueue.__proj__Mkll_uncons_t__item__ll_uncons_tl",
"CQueue.__proj__Mkll_uncons_t__item__ll_uncons_pnext",
"CQueue.__proj__Mkll_uncons_t__item__ll_uncons_next",
"Prims.bool",
"CQueue.llist_fragment_head_cons_change_phead",
"Prims._assert",
"CQueue.op_Equals_Equals",
"Prims.uu___is_Nil",
"CQueue.llist_fragment_head_is_nil",
"CQueue.Cell.free_cell",
"CQueue.Cell.intro_ccell",
"Steel.Reference.read",
"CQueue.Cell.ccell_next",
"CQueue.Cell.ccell_data",
"CQueue.Cell.ccell_lvalue",
"CQueue.Cell.elim_ccell",
"CQueue.Cell.ccell",
"CQueue.ll_uncons_t",
"CQueue.elim_llist_fragment_head_cons",
"CQueue.elim_queue_head"
] | [] | false | true | false | false | false | let dequeue #a x l =
| let head0 = elim_queue_head x l in
let head = read (cllist_head x) in
let u = elim_llist_fragment_head_cons l (cllist_head x) head0 in
change_equal_slprop (ccell head0) (ccell head);
let head = elim_ccell head in
let data = read (ccell_data head) in
let next = read (ccell_next head) in
intro_ccell head;
free_cell head;
llist_fragment_head_is_nil u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next;
assert (Nil? u.ll_uncons_tl == ccell_ptrvalue_is_null next);
write (cllist_head x) next;
if ccell_ptrvalue_is_null next
then
(elim_llist_fragment_head_nil u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next;
write (cllist_tail x) (cllist_head x);
intro_llist_fragment_head_nil [] (cllist_head x) (Ghost.reveal (Ghost.hide next));
intro_queue_head x [] next;
let res = (data, Ghost.hide []) in
change_equal_slprop (queue_head x []) (queue x (snd res));
return res)
else
(llist_fragment_head_cons_change_phead u.ll_uncons_tl
u.ll_uncons_pnext
u.ll_uncons_next
(cllist_head x);
intro_queue_head x u.ll_uncons_tl u.ll_uncons_next;
let res = (data, u.ll_uncons_tl) in
change_equal_slprop (queue_head x u.ll_uncons_tl) (queue x (snd res));
return res) | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.pow2_24 | val pow2_24 : Prims.int | let pow2_24 = 16777216 | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 53,
"start_col": 7,
"start_line": 53
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.int | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let pow2_24 =
| 16777216 | false |
|
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.two_to_seq_to_two_LE | val two_to_seq_to_two_LE (#a:Type) (x:seq2 a) :
Lemma (two_to_seq_LE (seq_to_two_LE x) == x)
[SMTPat (two_to_seq_LE (seq_to_two_LE x))] | val two_to_seq_to_two_LE (#a:Type) (x:seq2 a) :
Lemma (two_to_seq_LE (seq_to_two_LE x) == x)
[SMTPat (two_to_seq_LE (seq_to_two_LE x))] | let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x) | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 13,
"start_col": 0,
"start_line": 12
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Def.Words.Seq_s.seq2 a
-> FStar.Pervasives.Lemma
(ensures Vale.Def.Words.Seq_s.two_to_seq_LE (Vale.Def.Words.Seq_s.seq_to_two_LE x) == x)
[SMTPat (Vale.Def.Words.Seq_s.two_to_seq_LE (Vale.Def.Words.Seq_s.seq_to_two_LE x))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words.Seq_s.seq2",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Words.Seq_s.two_to_seq_LE",
"Vale.Def.Words.Seq_s.seq_to_two_LE",
"Prims.unit"
] | [] | true | false | true | false | false | let two_to_seq_to_two_LE #a x =
| assert (equal (two_to_seq_LE (seq_to_two_LE x)) x) | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.seq_to_seq_four_to_seq_BE | val seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))] | val seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))] | let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 35,
"start_col": 0,
"start_line": 28
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Seq.Base.seq (Vale.Def.Words_s.four a)
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Seq_s.seq_to_seq_four_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE x) == x)
[SMTPat (Vale.Def.Words.Seq_s.seq_to_seq_four_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE x))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.four",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Words.Seq_s.seq_to_seq_four_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"FStar.Pervasives.reveal_opaque",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.op_Division",
"FStar.Mul.op_Star",
"Prims.l_True",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let seq_to_seq_four_to_seq_BE (#a: Type) (x: seq (four a))
: Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))] =
| reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
() | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.seq_four_to_seq_to_seq_four_LE | val seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
[SMTPat (seq_four_to_seq_LE (seq_to_seq_four_LE x))] | val seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
[SMTPat (seq_four_to_seq_LE (seq_to_seq_four_LE x))] | let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 43,
"start_col": 0,
"start_line": 37
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Seq.Base.seq a {FStar.Seq.Base.length x % 4 == 0}
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Seq_s.seq_four_to_seq_LE (Vale.Def.Words.Seq_s.seq_to_seq_four_LE x) == x)
[SMTPat (Vale.Def.Words.Seq_s.seq_four_to_seq_LE (Vale.Def.Words.Seq_s.seq_to_seq_four_LE x))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Words.Seq_s.seq_four_to_seq_LE",
"Vale.Def.Words.Seq_s.seq_to_seq_four_LE",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Words_s.four",
"Prims.op_Division",
"FStar.Mul.op_Star",
"Prims.l_True",
"Prims.squash",
"Prims.l_or",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let seq_four_to_seq_to_seq_four_LE (#a: Type) (x: seq a {length x % 4 == 0})
: Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x) =
| reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
() | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.base_to_nat | val base_to_nat (base: pos) (cs: list (natN base)) : nat | val base_to_nat (base: pos) (cs: list (natN base)) : nat | let rec base_to_nat (base:pos) (cs : list (natN base)) : nat =
match cs with
| [] -> 0
| c :: cs' -> c + base_to_nat base cs' * base | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 89,
"start_col": 0,
"start_line": 86
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
()
unfold let pow2_24 = 16777216 //normalize_term (pow2 24)
#push-options "--z3rlimit 200 --using_facts_from 'Prims Vale.Def.Words_s'"
let lemma_fundamental_div_mod_4 (x:nat32) :
Lemma (x = x % pow2_8 + pow2_8 * ((x / pow2_8) % pow2_8) + pow2_16 * ((x / pow2_16) % pow2_8) + pow2_24 * ((x / pow2_24) % pow2_8))
=
()
#pop-options
let four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))]
=
let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
()
#push-options "--z3rlimit 20 --z3cliopt smt.arith.nl=true"
(* Localized use of NL arith. The makefile passes the option to disable | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.arith.nl=true"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | base: Prims.pos -> cs: Prims.list (Vale.Def.Words_s.natN base) -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Prims.pos",
"Prims.list",
"Vale.Def.Words_s.natN",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Vale.Def.Words.Seq.base_to_nat",
"Prims.nat"
] | [
"recursion"
] | false | false | false | false | false | let rec base_to_nat (base: pos) (cs: list (natN base)) : nat =
| match cs with
| [] -> 0
| c :: cs' -> c + base_to_nat base cs' * base | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.seq_four_to_seq_to_seq_four_BE | val seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
[SMTPat (seq_four_to_seq_BE (seq_to_seq_four_BE x))] | val seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
[SMTPat (seq_four_to_seq_BE (seq_to_seq_four_BE x))] | let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 51,
"start_col": 0,
"start_line": 45
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Seq.Base.seq a {FStar.Seq.Base.length x % 4 == 0}
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Seq_s.seq_four_to_seq_BE (Vale.Def.Words.Seq_s.seq_to_seq_four_BE x) == x)
[SMTPat (Vale.Def.Words.Seq_s.seq_four_to_seq_BE (Vale.Def.Words.Seq_s.seq_to_seq_four_BE x))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Words.Seq_s.seq_to_seq_four_BE",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Words_s.four",
"Prims.op_Division",
"FStar.Mul.op_Star",
"Prims.l_True",
"Prims.squash",
"Prims.l_or",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let seq_four_to_seq_to_seq_four_BE (#a: Type) (x: seq a {length x % 4 == 0})
: Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x) =
| reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
() | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.seq_to_seq_four_to_seq_LE | val seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))] | val seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))] | let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 26,
"start_col": 0,
"start_line": 17
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = () | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Seq.Base.seq (Vale.Def.Words_s.four a)
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Seq_s.seq_to_seq_four_LE (Vale.Def.Words.Seq_s.seq_four_to_seq_LE x) == x)
[SMTPat (Vale.Def.Words.Seq_s.seq_to_seq_four_LE (Vale.Def.Words.Seq_s.seq_four_to_seq_LE x))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.four",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Division",
"Vale.Def.Words.Seq_s.seq_to_seq_four_LE",
"Prims.op_Multiply",
"Vale.Def.Words.Seq_s.seq_four_to_seq_LE",
"FStar.Pervasives.reveal_opaque",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.l_True",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let seq_to_seq_four_to_seq_LE (#a: Type) (x: seq (four a))
: Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))] =
| reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
() | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.four_to_nat_to_four_8 | val four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))] | val four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))] | let four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))]
=
let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 81,
"start_col": 0,
"start_line": 62
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
()
unfold let pow2_24 = 16777216 //normalize_term (pow2 24)
#push-options "--z3rlimit 200 --using_facts_from 'Prims Vale.Def.Words_s'"
let lemma_fundamental_div_mod_4 (x:nat32) :
Lemma (x = x % pow2_8 + pow2_8 * ((x / pow2_8) % pow2_8) + pow2_16 * ((x / pow2_16) % pow2_8) + pow2_24 * ((x / pow2_24) % pow2_8))
=
()
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Def.Words_s.natN (Vale.Def.Words_s.pow2_norm 32)
-> FStar.Pervasives.Lemma
(ensures Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Four_s.nat_to_four 8 x) == x)
[SMTPat (Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Four_s.nat_to_four 8 x))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.pow2_norm",
"Prims.pow2",
"Prims.unit",
"Vale.Def.Words.Seq.lemma_fundamental_div_mod_4",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.nat",
"Prims.l_or",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_imp",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.int",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words_s.int_to_natN",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words_s.Mkfour",
"Prims.op_Modulus",
"Prims.op_Division",
"Prims.pos",
"Prims.l_True",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | false | false | true | false | false | let four_to_nat_to_four_8 (x: natN (pow2_norm 32))
: Lemma (four_to_nat 8 (nat_to_four 8 x) == x) [SMTPat (four_to_nat 8 (nat_to_four 8 x))] =
| let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
() | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.four_to_seq_to_four_LE | val four_to_seq_to_four_LE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_LE (seq_to_four_LE x) == x) | val four_to_seq_to_four_LE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_LE (seq_to_four_LE x) == x) | let four_to_seq_to_four_LE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_LE (seq_to_four_LE x) == x)
=
assert (equal (four_to_seq_LE (seq_to_four_LE x)) x);
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 177,
"start_col": 0,
"start_line": 173
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
()
unfold let pow2_24 = 16777216 //normalize_term (pow2 24)
#push-options "--z3rlimit 200 --using_facts_from 'Prims Vale.Def.Words_s'"
let lemma_fundamental_div_mod_4 (x:nat32) :
Lemma (x = x % pow2_8 + pow2_8 * ((x / pow2_8) % pow2_8) + pow2_16 * ((x / pow2_16) % pow2_8) + pow2_24 * ((x / pow2_24) % pow2_8))
=
()
#pop-options
let four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))]
=
let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
()
#push-options "--z3rlimit 20 --z3cliopt smt.arith.nl=true"
(* Localized use of NL arith. The makefile passes the option to disable
it in this file, so we reenable it here. *)
let rec base_to_nat (base:pos) (cs : list (natN base)) : nat =
match cs with
| [] -> 0
| c :: cs' -> c + base_to_nat base cs' * base
(* NB: right-multiplying by base is a lot better than left-multiplying
since it more closely matches the lemmas in FStar.Math.Lemmas. *)
#pop-options
(* If two lists represent the same number, their heads must match,
otherwise their modulus wrt the base would differ. *)
let base_to_nat_inj_head (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ Cons? x /\ Cons? y)
(ensures List.Tot.hd x == List.Tot.hd y)
=
match x, y with
| x1 :: xs, y1 :: ys ->
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
x1 <: int;
== { small_mod x1 base }
x1 % base;
== { lemma_mod_plus x1 (base_to_nat base xs) base }
(x1 + base_to_nat base xs * base) % base;
== {}
x' % base;
== {}
y' % base;
== {}
(y1 + base_to_nat base ys * base) % base;
== { lemma_mod_plus y1 (base_to_nat base ys) base }
y1 % base;
== { small_mod y1 base }
y1;
}
(* Generalizing the lemma above, if two lists represent the same number,
and they have the same length, they must be the same list. The length requirement
is due to the possibility of trailing zeroes. Another possibility is stating
that one of them is a prefix of the other, which is enough for this module,
even without stating that the "rest" is all zeroes. *)
let rec base_to_nat_inj (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ List.length x == List.length y)
(ensures x == y)
=
match x, y with
| [], [] -> ()
| x1 :: xs, y1 :: ys ->
base_to_nat_inj_head base x y;
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
base_to_nat base xs * base;
== {}
x' - x1;
== {}
y' - y1;
== {}
base_to_nat base ys * base;
};
lemma_cancel_mul (base_to_nat base xs) (base_to_nat base ys) base;
assert (base_to_nat base xs == base_to_nat base ys);
base_to_nat_inj base xs ys
#push-options "--fuel 4"
(* Fuel needed to prove length equality *)
let four_to_nat_inj (x y : four (natN 256)) :
Lemma (requires four_to_nat 8 x == four_to_nat 8 y)
(ensures x == y)
=
let Mkfour x0 x1 x2 x3 = x in
let Mkfour y0 y1 y2 y3 = y in
assert_norm (four_to_nat 8 (Mkfour x0 x1 x2 x3) == base_to_nat 256 [x0; x1; x2; x3]);
assert_norm (four_to_nat 8 (Mkfour y0 y1 y2 y3) == base_to_nat 256 [y0; y1; y2; y3]);
base_to_nat_inj 256 [x0; x1; x2; x3] [y0; y1; y2; y3];
()
#pop-options
let nat_to_four_to_nat (x:four (natN 256)) :
Lemma (nat_to_four 8 (four_to_nat 8 x) == x)
[SMTPat (nat_to_four 8 (four_to_nat 8 x))]
=
four_to_nat_to_four_8 (four_to_nat 8 x);
four_to_nat_inj (nat_to_four 8 (four_to_nat 8 x)) x | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Def.Words.Seq_s.seq4 a
-> FStar.Pervasives.Lemma
(ensures Vale.Def.Words.Seq_s.four_to_seq_LE (Vale.Def.Words.Seq_s.seq_to_four_LE x) == x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words.Seq_s.seq4",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Words.Seq_s.four_to_seq_LE",
"Vale.Def.Words.Seq_s.seq_to_four_LE",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let four_to_seq_to_four_LE (#a: Type) (x: seq4 a) : Lemma (four_to_seq_LE (seq_to_four_LE x) == x) =
| assert (equal (four_to_seq_LE (seq_to_four_LE x)) x);
() | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.nat_to_four_to_nat | val nat_to_four_to_nat (x:four (natN (pow2_norm 8))) :
Lemma (nat_to_four 8 (four_to_nat 8 x) == x)
[SMTPat (nat_to_four 8 (four_to_nat 8 x))] | val nat_to_four_to_nat (x:four (natN (pow2_norm 8))) :
Lemma (nat_to_four 8 (four_to_nat 8 x) == x)
[SMTPat (nat_to_four 8 (four_to_nat 8 x))] | let nat_to_four_to_nat (x:four (natN 256)) :
Lemma (nat_to_four 8 (four_to_nat 8 x) == x)
[SMTPat (nat_to_four 8 (four_to_nat 8 x))]
=
four_to_nat_to_four_8 (four_to_nat 8 x);
four_to_nat_inj (nat_to_four 8 (four_to_nat 8 x)) x | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 171,
"start_col": 0,
"start_line": 166
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
()
unfold let pow2_24 = 16777216 //normalize_term (pow2 24)
#push-options "--z3rlimit 200 --using_facts_from 'Prims Vale.Def.Words_s'"
let lemma_fundamental_div_mod_4 (x:nat32) :
Lemma (x = x % pow2_8 + pow2_8 * ((x / pow2_8) % pow2_8) + pow2_16 * ((x / pow2_16) % pow2_8) + pow2_24 * ((x / pow2_24) % pow2_8))
=
()
#pop-options
let four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))]
=
let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
()
#push-options "--z3rlimit 20 --z3cliopt smt.arith.nl=true"
(* Localized use of NL arith. The makefile passes the option to disable
it in this file, so we reenable it here. *)
let rec base_to_nat (base:pos) (cs : list (natN base)) : nat =
match cs with
| [] -> 0
| c :: cs' -> c + base_to_nat base cs' * base
(* NB: right-multiplying by base is a lot better than left-multiplying
since it more closely matches the lemmas in FStar.Math.Lemmas. *)
#pop-options
(* If two lists represent the same number, their heads must match,
otherwise their modulus wrt the base would differ. *)
let base_to_nat_inj_head (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ Cons? x /\ Cons? y)
(ensures List.Tot.hd x == List.Tot.hd y)
=
match x, y with
| x1 :: xs, y1 :: ys ->
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
x1 <: int;
== { small_mod x1 base }
x1 % base;
== { lemma_mod_plus x1 (base_to_nat base xs) base }
(x1 + base_to_nat base xs * base) % base;
== {}
x' % base;
== {}
y' % base;
== {}
(y1 + base_to_nat base ys * base) % base;
== { lemma_mod_plus y1 (base_to_nat base ys) base }
y1 % base;
== { small_mod y1 base }
y1;
}
(* Generalizing the lemma above, if two lists represent the same number,
and they have the same length, they must be the same list. The length requirement
is due to the possibility of trailing zeroes. Another possibility is stating
that one of them is a prefix of the other, which is enough for this module,
even without stating that the "rest" is all zeroes. *)
let rec base_to_nat_inj (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ List.length x == List.length y)
(ensures x == y)
=
match x, y with
| [], [] -> ()
| x1 :: xs, y1 :: ys ->
base_to_nat_inj_head base x y;
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
base_to_nat base xs * base;
== {}
x' - x1;
== {}
y' - y1;
== {}
base_to_nat base ys * base;
};
lemma_cancel_mul (base_to_nat base xs) (base_to_nat base ys) base;
assert (base_to_nat base xs == base_to_nat base ys);
base_to_nat_inj base xs ys
#push-options "--fuel 4"
(* Fuel needed to prove length equality *)
let four_to_nat_inj (x y : four (natN 256)) :
Lemma (requires four_to_nat 8 x == four_to_nat 8 y)
(ensures x == y)
=
let Mkfour x0 x1 x2 x3 = x in
let Mkfour y0 y1 y2 y3 = y in
assert_norm (four_to_nat 8 (Mkfour x0 x1 x2 x3) == base_to_nat 256 [x0; x1; x2; x3]);
assert_norm (four_to_nat 8 (Mkfour y0 y1 y2 y3) == base_to_nat 256 [y0; y1; y2; y3]);
base_to_nat_inj 256 [x0; x1; x2; x3] [y0; y1; y2; y3];
()
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Def.Words_s.four (Vale.Def.Words_s.natN (Vale.Def.Words_s.pow2_norm 8))
-> FStar.Pervasives.Lemma
(ensures Vale.Def.Words.Four_s.nat_to_four 8 (Vale.Def.Words.Four_s.four_to_nat 8 x) == x)
[SMTPat (Vale.Def.Words.Four_s.nat_to_four 8 (Vale.Def.Words.Four_s.four_to_nat 8 x))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Vale.Def.Words.Seq.four_to_nat_inj",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words.Four_s.four_to_nat",
"Prims.unit",
"Vale.Def.Words.Seq.four_to_nat_to_four_8",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.pow2",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let nat_to_four_to_nat (x: four (natN 256))
: Lemma (nat_to_four 8 (four_to_nat 8 x) == x) [SMTPat (nat_to_four 8 (four_to_nat 8 x))] =
| four_to_nat_to_four_8 (four_to_nat 8 x);
four_to_nat_inj (nat_to_four 8 (four_to_nat 8 x)) x | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.four_to_seq_to_four_BE | val four_to_seq_to_four_BE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_BE (seq_to_four_BE x) == x) | val four_to_seq_to_four_BE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_BE (seq_to_four_BE x) == x) | let four_to_seq_to_four_BE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_BE (seq_to_four_BE x) == x)
=
assert (equal (four_to_seq_BE (seq_to_four_BE x)) x);
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 188,
"start_col": 0,
"start_line": 184
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
()
unfold let pow2_24 = 16777216 //normalize_term (pow2 24)
#push-options "--z3rlimit 200 --using_facts_from 'Prims Vale.Def.Words_s'"
let lemma_fundamental_div_mod_4 (x:nat32) :
Lemma (x = x % pow2_8 + pow2_8 * ((x / pow2_8) % pow2_8) + pow2_16 * ((x / pow2_16) % pow2_8) + pow2_24 * ((x / pow2_24) % pow2_8))
=
()
#pop-options
let four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))]
=
let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
()
#push-options "--z3rlimit 20 --z3cliopt smt.arith.nl=true"
(* Localized use of NL arith. The makefile passes the option to disable
it in this file, so we reenable it here. *)
let rec base_to_nat (base:pos) (cs : list (natN base)) : nat =
match cs with
| [] -> 0
| c :: cs' -> c + base_to_nat base cs' * base
(* NB: right-multiplying by base is a lot better than left-multiplying
since it more closely matches the lemmas in FStar.Math.Lemmas. *)
#pop-options
(* If two lists represent the same number, their heads must match,
otherwise their modulus wrt the base would differ. *)
let base_to_nat_inj_head (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ Cons? x /\ Cons? y)
(ensures List.Tot.hd x == List.Tot.hd y)
=
match x, y with
| x1 :: xs, y1 :: ys ->
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
x1 <: int;
== { small_mod x1 base }
x1 % base;
== { lemma_mod_plus x1 (base_to_nat base xs) base }
(x1 + base_to_nat base xs * base) % base;
== {}
x' % base;
== {}
y' % base;
== {}
(y1 + base_to_nat base ys * base) % base;
== { lemma_mod_plus y1 (base_to_nat base ys) base }
y1 % base;
== { small_mod y1 base }
y1;
}
(* Generalizing the lemma above, if two lists represent the same number,
and they have the same length, they must be the same list. The length requirement
is due to the possibility of trailing zeroes. Another possibility is stating
that one of them is a prefix of the other, which is enough for this module,
even without stating that the "rest" is all zeroes. *)
let rec base_to_nat_inj (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ List.length x == List.length y)
(ensures x == y)
=
match x, y with
| [], [] -> ()
| x1 :: xs, y1 :: ys ->
base_to_nat_inj_head base x y;
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
base_to_nat base xs * base;
== {}
x' - x1;
== {}
y' - y1;
== {}
base_to_nat base ys * base;
};
lemma_cancel_mul (base_to_nat base xs) (base_to_nat base ys) base;
assert (base_to_nat base xs == base_to_nat base ys);
base_to_nat_inj base xs ys
#push-options "--fuel 4"
(* Fuel needed to prove length equality *)
let four_to_nat_inj (x y : four (natN 256)) :
Lemma (requires four_to_nat 8 x == four_to_nat 8 y)
(ensures x == y)
=
let Mkfour x0 x1 x2 x3 = x in
let Mkfour y0 y1 y2 y3 = y in
assert_norm (four_to_nat 8 (Mkfour x0 x1 x2 x3) == base_to_nat 256 [x0; x1; x2; x3]);
assert_norm (four_to_nat 8 (Mkfour y0 y1 y2 y3) == base_to_nat 256 [y0; y1; y2; y3]);
base_to_nat_inj 256 [x0; x1; x2; x3] [y0; y1; y2; y3];
()
#pop-options
let nat_to_four_to_nat (x:four (natN 256)) :
Lemma (nat_to_four 8 (four_to_nat 8 x) == x)
[SMTPat (nat_to_four 8 (four_to_nat 8 x))]
=
four_to_nat_to_four_8 (four_to_nat 8 x);
four_to_nat_inj (nat_to_four 8 (four_to_nat 8 x)) x
let four_to_seq_to_four_LE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_LE (seq_to_four_LE x) == x)
=
assert (equal (four_to_seq_LE (seq_to_four_LE x)) x);
()
let seq_to_four_to_seq_LE (#a:Type) (x:four a) :
Lemma (seq_to_four_LE (four_to_seq_LE x) == x)
=
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Def.Words.Seq_s.seq4 a
-> FStar.Pervasives.Lemma
(ensures Vale.Def.Words.Seq_s.four_to_seq_BE (Vale.Def.Words.Seq_s.seq_to_four_BE x) == x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words.Seq_s.seq4",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Words.Seq_s.four_to_seq_BE",
"Vale.Def.Words.Seq_s.seq_to_four_BE",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let four_to_seq_to_four_BE (#a: Type) (x: seq4 a) : Lemma (four_to_seq_BE (seq_to_four_BE x) == x) =
| assert (equal (four_to_seq_BE (seq_to_four_BE x)) x);
() | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.four_to_seq_LE_is_seq_four_to_seq_LE | val four_to_seq_LE_is_seq_four_to_seq_LE(#a:Type) (x:four a) :
Lemma (four_to_seq_LE x == seq_four_to_seq_LE (create 1 x)) | val four_to_seq_LE_is_seq_four_to_seq_LE(#a:Type) (x:four a) :
Lemma (four_to_seq_LE x == seq_four_to_seq_LE (create 1 x)) | let four_to_seq_LE_is_seq_four_to_seq_LE(#a:Type) (x:four a) :
Lemma (four_to_seq_LE x == seq_four_to_seq_LE (create 1 x))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
let s0 = four_to_seq_LE x in
let s1 = seq_four_to_seq_LE (create 1 x) in
assert (equal s0 s1);
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 202,
"start_col": 0,
"start_line": 195
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
()
unfold let pow2_24 = 16777216 //normalize_term (pow2 24)
#push-options "--z3rlimit 200 --using_facts_from 'Prims Vale.Def.Words_s'"
let lemma_fundamental_div_mod_4 (x:nat32) :
Lemma (x = x % pow2_8 + pow2_8 * ((x / pow2_8) % pow2_8) + pow2_16 * ((x / pow2_16) % pow2_8) + pow2_24 * ((x / pow2_24) % pow2_8))
=
()
#pop-options
let four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))]
=
let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
()
#push-options "--z3rlimit 20 --z3cliopt smt.arith.nl=true"
(* Localized use of NL arith. The makefile passes the option to disable
it in this file, so we reenable it here. *)
let rec base_to_nat (base:pos) (cs : list (natN base)) : nat =
match cs with
| [] -> 0
| c :: cs' -> c + base_to_nat base cs' * base
(* NB: right-multiplying by base is a lot better than left-multiplying
since it more closely matches the lemmas in FStar.Math.Lemmas. *)
#pop-options
(* If two lists represent the same number, their heads must match,
otherwise their modulus wrt the base would differ. *)
let base_to_nat_inj_head (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ Cons? x /\ Cons? y)
(ensures List.Tot.hd x == List.Tot.hd y)
=
match x, y with
| x1 :: xs, y1 :: ys ->
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
x1 <: int;
== { small_mod x1 base }
x1 % base;
== { lemma_mod_plus x1 (base_to_nat base xs) base }
(x1 + base_to_nat base xs * base) % base;
== {}
x' % base;
== {}
y' % base;
== {}
(y1 + base_to_nat base ys * base) % base;
== { lemma_mod_plus y1 (base_to_nat base ys) base }
y1 % base;
== { small_mod y1 base }
y1;
}
(* Generalizing the lemma above, if two lists represent the same number,
and they have the same length, they must be the same list. The length requirement
is due to the possibility of trailing zeroes. Another possibility is stating
that one of them is a prefix of the other, which is enough for this module,
even without stating that the "rest" is all zeroes. *)
let rec base_to_nat_inj (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ List.length x == List.length y)
(ensures x == y)
=
match x, y with
| [], [] -> ()
| x1 :: xs, y1 :: ys ->
base_to_nat_inj_head base x y;
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
base_to_nat base xs * base;
== {}
x' - x1;
== {}
y' - y1;
== {}
base_to_nat base ys * base;
};
lemma_cancel_mul (base_to_nat base xs) (base_to_nat base ys) base;
assert (base_to_nat base xs == base_to_nat base ys);
base_to_nat_inj base xs ys
#push-options "--fuel 4"
(* Fuel needed to prove length equality *)
let four_to_nat_inj (x y : four (natN 256)) :
Lemma (requires four_to_nat 8 x == four_to_nat 8 y)
(ensures x == y)
=
let Mkfour x0 x1 x2 x3 = x in
let Mkfour y0 y1 y2 y3 = y in
assert_norm (four_to_nat 8 (Mkfour x0 x1 x2 x3) == base_to_nat 256 [x0; x1; x2; x3]);
assert_norm (four_to_nat 8 (Mkfour y0 y1 y2 y3) == base_to_nat 256 [y0; y1; y2; y3]);
base_to_nat_inj 256 [x0; x1; x2; x3] [y0; y1; y2; y3];
()
#pop-options
let nat_to_four_to_nat (x:four (natN 256)) :
Lemma (nat_to_four 8 (four_to_nat 8 x) == x)
[SMTPat (nat_to_four 8 (four_to_nat 8 x))]
=
four_to_nat_to_four_8 (four_to_nat 8 x);
four_to_nat_inj (nat_to_four 8 (four_to_nat 8 x)) x
let four_to_seq_to_four_LE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_LE (seq_to_four_LE x) == x)
=
assert (equal (four_to_seq_LE (seq_to_four_LE x)) x);
()
let seq_to_four_to_seq_LE (#a:Type) (x:four a) :
Lemma (seq_to_four_LE (four_to_seq_LE x) == x)
=
()
let four_to_seq_to_four_BE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_BE (seq_to_four_BE x) == x)
=
assert (equal (four_to_seq_BE (seq_to_four_BE x)) x);
()
let seq_to_four_to_seq_BE (#a:Type) (x:four a) :
Lemma (seq_to_four_BE (four_to_seq_BE x) == x)
=
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Def.Words_s.four a
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Seq_s.four_to_seq_LE x ==
Vale.Def.Words.Seq_s.seq_four_to_seq_LE (FStar.Seq.Base.create 1 x)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words_s.four",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Multiply",
"FStar.Seq.Base.create",
"Vale.Def.Words.Seq_s.seq_four_to_seq_LE",
"Vale.Def.Words.Seq_s.seq4",
"Vale.Def.Words.Seq_s.four_to_seq_LE",
"FStar.Pervasives.reveal_opaque",
"FStar.Mul.op_Star",
"Prims.l_True",
"Prims.squash",
"Prims.l_or",
"Prims.nat",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let four_to_seq_LE_is_seq_four_to_seq_LE (#a: Type) (x: four a)
: Lemma (four_to_seq_LE x == seq_four_to_seq_LE (create 1 x)) =
| reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
let s0 = four_to_seq_LE x in
let s1 = seq_four_to_seq_LE (create 1 x) in
assert (equal s0 s1);
() | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.seq_nat8_to_seq_nat32_to_seq_nat8_BE | val seq_nat8_to_seq_nat32_to_seq_nat8_BE (x:seq nat32) :
Lemma (seq_nat8_to_seq_nat32_BE (seq_nat32_to_seq_nat8_BE x) == x)
[SMTPat (seq_nat8_to_seq_nat32_BE (seq_nat32_to_seq_nat8_BE x))] | val seq_nat8_to_seq_nat32_to_seq_nat8_BE (x:seq nat32) :
Lemma (seq_nat8_to_seq_nat32_BE (seq_nat32_to_seq_nat8_BE x) == x)
[SMTPat (seq_nat8_to_seq_nat32_BE (seq_nat32_to_seq_nat8_BE x))] | let seq_nat8_to_seq_nat32_to_seq_nat8_BE (x:seq nat32) :
Lemma (seq_nat8_to_seq_nat32_BE (seq_nat32_to_seq_nat8_BE x) == x)
=
assert (equal (seq_nat8_to_seq_nat32_BE (seq_nat32_to_seq_nat8_BE x)) x);
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 223,
"start_col": 0,
"start_line": 219
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
()
unfold let pow2_24 = 16777216 //normalize_term (pow2 24)
#push-options "--z3rlimit 200 --using_facts_from 'Prims Vale.Def.Words_s'"
let lemma_fundamental_div_mod_4 (x:nat32) :
Lemma (x = x % pow2_8 + pow2_8 * ((x / pow2_8) % pow2_8) + pow2_16 * ((x / pow2_16) % pow2_8) + pow2_24 * ((x / pow2_24) % pow2_8))
=
()
#pop-options
let four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))]
=
let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
()
#push-options "--z3rlimit 20 --z3cliopt smt.arith.nl=true"
(* Localized use of NL arith. The makefile passes the option to disable
it in this file, so we reenable it here. *)
let rec base_to_nat (base:pos) (cs : list (natN base)) : nat =
match cs with
| [] -> 0
| c :: cs' -> c + base_to_nat base cs' * base
(* NB: right-multiplying by base is a lot better than left-multiplying
since it more closely matches the lemmas in FStar.Math.Lemmas. *)
#pop-options
(* If two lists represent the same number, their heads must match,
otherwise their modulus wrt the base would differ. *)
let base_to_nat_inj_head (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ Cons? x /\ Cons? y)
(ensures List.Tot.hd x == List.Tot.hd y)
=
match x, y with
| x1 :: xs, y1 :: ys ->
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
x1 <: int;
== { small_mod x1 base }
x1 % base;
== { lemma_mod_plus x1 (base_to_nat base xs) base }
(x1 + base_to_nat base xs * base) % base;
== {}
x' % base;
== {}
y' % base;
== {}
(y1 + base_to_nat base ys * base) % base;
== { lemma_mod_plus y1 (base_to_nat base ys) base }
y1 % base;
== { small_mod y1 base }
y1;
}
(* Generalizing the lemma above, if two lists represent the same number,
and they have the same length, they must be the same list. The length requirement
is due to the possibility of trailing zeroes. Another possibility is stating
that one of them is a prefix of the other, which is enough for this module,
even without stating that the "rest" is all zeroes. *)
let rec base_to_nat_inj (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ List.length x == List.length y)
(ensures x == y)
=
match x, y with
| [], [] -> ()
| x1 :: xs, y1 :: ys ->
base_to_nat_inj_head base x y;
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
base_to_nat base xs * base;
== {}
x' - x1;
== {}
y' - y1;
== {}
base_to_nat base ys * base;
};
lemma_cancel_mul (base_to_nat base xs) (base_to_nat base ys) base;
assert (base_to_nat base xs == base_to_nat base ys);
base_to_nat_inj base xs ys
#push-options "--fuel 4"
(* Fuel needed to prove length equality *)
let four_to_nat_inj (x y : four (natN 256)) :
Lemma (requires four_to_nat 8 x == four_to_nat 8 y)
(ensures x == y)
=
let Mkfour x0 x1 x2 x3 = x in
let Mkfour y0 y1 y2 y3 = y in
assert_norm (four_to_nat 8 (Mkfour x0 x1 x2 x3) == base_to_nat 256 [x0; x1; x2; x3]);
assert_norm (four_to_nat 8 (Mkfour y0 y1 y2 y3) == base_to_nat 256 [y0; y1; y2; y3]);
base_to_nat_inj 256 [x0; x1; x2; x3] [y0; y1; y2; y3];
()
#pop-options
let nat_to_four_to_nat (x:four (natN 256)) :
Lemma (nat_to_four 8 (four_to_nat 8 x) == x)
[SMTPat (nat_to_four 8 (four_to_nat 8 x))]
=
four_to_nat_to_four_8 (four_to_nat 8 x);
four_to_nat_inj (nat_to_four 8 (four_to_nat 8 x)) x
let four_to_seq_to_four_LE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_LE (seq_to_four_LE x) == x)
=
assert (equal (four_to_seq_LE (seq_to_four_LE x)) x);
()
let seq_to_four_to_seq_LE (#a:Type) (x:four a) :
Lemma (seq_to_four_LE (four_to_seq_LE x) == x)
=
()
let four_to_seq_to_four_BE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_BE (seq_to_four_BE x) == x)
=
assert (equal (four_to_seq_BE (seq_to_four_BE x)) x);
()
let seq_to_four_to_seq_BE (#a:Type) (x:four a) :
Lemma (seq_to_four_BE (four_to_seq_BE x) == x)
=
()
let four_to_seq_LE_is_seq_four_to_seq_LE(#a:Type) (x:four a) :
Lemma (four_to_seq_LE x == seq_four_to_seq_LE (create 1 x))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
let s0 = four_to_seq_LE x in
let s1 = seq_four_to_seq_LE (create 1 x) in
assert (equal s0 s1);
()
let four_to_seq_BE_is_seq_four_to_seq_BE (x:four nat32) :
Lemma (four_to_seq_BE x == seq_four_to_seq_BE (create 1 x))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #nat32);
let s0 = four_to_seq_BE x in
let s1 = seq_four_to_seq_BE (create 1 x) in
assert (equal s0 s1);
()
let seq_nat8_to_seq_nat32_to_seq_nat8_LE (x:seq nat32) :
Lemma (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x) == x)
=
assert (equal (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x)) x);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Seq.Base.seq Vale.Def.Words_s.nat32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_BE (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE
x) ==
x)
[
SMTPat (Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_BE (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE
x))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_BE",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let seq_nat8_to_seq_nat32_to_seq_nat8_BE (x: seq nat32)
: Lemma (seq_nat8_to_seq_nat32_BE (seq_nat32_to_seq_nat8_BE x) == x) =
| assert (equal (seq_nat8_to_seq_nat32_BE (seq_nat32_to_seq_nat8_BE x)) x);
() | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.four_to_nat_inj | val four_to_nat_inj (x y: four (natN 256))
: Lemma (requires four_to_nat 8 x == four_to_nat 8 y) (ensures x == y) | val four_to_nat_inj (x y: four (natN 256))
: Lemma (requires four_to_nat 8 x == four_to_nat 8 y) (ensures x == y) | let four_to_nat_inj (x y : four (natN 256)) :
Lemma (requires four_to_nat 8 x == four_to_nat 8 y)
(ensures x == y)
=
let Mkfour x0 x1 x2 x3 = x in
let Mkfour y0 y1 y2 y3 = y in
assert_norm (four_to_nat 8 (Mkfour x0 x1 x2 x3) == base_to_nat 256 [x0; x1; x2; x3]);
assert_norm (four_to_nat 8 (Mkfour y0 y1 y2 y3) == base_to_nat 256 [y0; y1; y2; y3]);
base_to_nat_inj 256 [x0; x1; x2; x3] [y0; y1; y2; y3];
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 163,
"start_col": 0,
"start_line": 154
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
()
unfold let pow2_24 = 16777216 //normalize_term (pow2 24)
#push-options "--z3rlimit 200 --using_facts_from 'Prims Vale.Def.Words_s'"
let lemma_fundamental_div_mod_4 (x:nat32) :
Lemma (x = x % pow2_8 + pow2_8 * ((x / pow2_8) % pow2_8) + pow2_16 * ((x / pow2_16) % pow2_8) + pow2_24 * ((x / pow2_24) % pow2_8))
=
()
#pop-options
let four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))]
=
let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
()
#push-options "--z3rlimit 20 --z3cliopt smt.arith.nl=true"
(* Localized use of NL arith. The makefile passes the option to disable
it in this file, so we reenable it here. *)
let rec base_to_nat (base:pos) (cs : list (natN base)) : nat =
match cs with
| [] -> 0
| c :: cs' -> c + base_to_nat base cs' * base
(* NB: right-multiplying by base is a lot better than left-multiplying
since it more closely matches the lemmas in FStar.Math.Lemmas. *)
#pop-options
(* If two lists represent the same number, their heads must match,
otherwise their modulus wrt the base would differ. *)
let base_to_nat_inj_head (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ Cons? x /\ Cons? y)
(ensures List.Tot.hd x == List.Tot.hd y)
=
match x, y with
| x1 :: xs, y1 :: ys ->
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
x1 <: int;
== { small_mod x1 base }
x1 % base;
== { lemma_mod_plus x1 (base_to_nat base xs) base }
(x1 + base_to_nat base xs * base) % base;
== {}
x' % base;
== {}
y' % base;
== {}
(y1 + base_to_nat base ys * base) % base;
== { lemma_mod_plus y1 (base_to_nat base ys) base }
y1 % base;
== { small_mod y1 base }
y1;
}
(* Generalizing the lemma above, if two lists represent the same number,
and they have the same length, they must be the same list. The length requirement
is due to the possibility of trailing zeroes. Another possibility is stating
that one of them is a prefix of the other, which is enough for this module,
even without stating that the "rest" is all zeroes. *)
let rec base_to_nat_inj (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ List.length x == List.length y)
(ensures x == y)
=
match x, y with
| [], [] -> ()
| x1 :: xs, y1 :: ys ->
base_to_nat_inj_head base x y;
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
base_to_nat base xs * base;
== {}
x' - x1;
== {}
y' - y1;
== {}
base_to_nat base ys * base;
};
lemma_cancel_mul (base_to_nat base xs) (base_to_nat base ys) base;
assert (base_to_nat base xs == base_to_nat base ys);
base_to_nat_inj base xs ys
#push-options "--fuel 4" | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 4,
"initial_ifuel": 0,
"max_fuel": 4,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: Vale.Def.Words_s.four (Vale.Def.Words_s.natN 256) ->
y: Vale.Def.Words_s.four (Vale.Def.Words_s.natN 256)
-> FStar.Pervasives.Lemma
(requires Vale.Def.Words.Four_s.four_to_nat 8 x == Vale.Def.Words.Four_s.four_to_nat 8 y)
(ensures x == y) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.unit",
"Vale.Def.Words.Seq.base_to_nat_inj",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.nat",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words_s.Mkfour",
"Prims.pow2",
"Vale.Def.Words.Seq.base_to_nat",
"FStar.Mul.op_Star",
"Prims.squash",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let four_to_nat_inj (x y: four (natN 256))
: Lemma (requires four_to_nat 8 x == four_to_nat 8 y) (ensures x == y) =
| let Mkfour x0 x1 x2 x3 = x in
let Mkfour y0 y1 y2 y3 = y in
assert_norm (four_to_nat 8 (Mkfour x0 x1 x2 x3) == base_to_nat 256 [x0; x1; x2; x3]);
assert_norm (four_to_nat 8 (Mkfour y0 y1 y2 y3) == base_to_nat 256 [y0; y1; y2; y3]);
base_to_nat_inj 256 [x0; x1; x2; x3] [y0; y1; y2; y3];
() | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.seq_nat8_to_seq_uint8_to_seq_nat8 | val seq_nat8_to_seq_uint8_to_seq_nat8 (x:seq UInt8.t) :
Lemma (seq_nat8_to_seq_uint8 (seq_uint8_to_seq_nat8 x) == x)
[SMTPat (seq_nat8_to_seq_uint8 (seq_uint8_to_seq_nat8 x))] | val seq_nat8_to_seq_uint8_to_seq_nat8 (x:seq UInt8.t) :
Lemma (seq_nat8_to_seq_uint8 (seq_uint8_to_seq_nat8 x) == x)
[SMTPat (seq_nat8_to_seq_uint8 (seq_uint8_to_seq_nat8 x))] | let seq_nat8_to_seq_uint8_to_seq_nat8 (x:seq UInt8.t) =
assert (equal (seq_nat8_to_seq_uint8 (seq_uint8_to_seq_nat8 x)) x) | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 234,
"start_col": 0,
"start_line": 233
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
()
unfold let pow2_24 = 16777216 //normalize_term (pow2 24)
#push-options "--z3rlimit 200 --using_facts_from 'Prims Vale.Def.Words_s'"
let lemma_fundamental_div_mod_4 (x:nat32) :
Lemma (x = x % pow2_8 + pow2_8 * ((x / pow2_8) % pow2_8) + pow2_16 * ((x / pow2_16) % pow2_8) + pow2_24 * ((x / pow2_24) % pow2_8))
=
()
#pop-options
let four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))]
=
let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
()
#push-options "--z3rlimit 20 --z3cliopt smt.arith.nl=true"
(* Localized use of NL arith. The makefile passes the option to disable
it in this file, so we reenable it here. *)
let rec base_to_nat (base:pos) (cs : list (natN base)) : nat =
match cs with
| [] -> 0
| c :: cs' -> c + base_to_nat base cs' * base
(* NB: right-multiplying by base is a lot better than left-multiplying
since it more closely matches the lemmas in FStar.Math.Lemmas. *)
#pop-options
(* If two lists represent the same number, their heads must match,
otherwise their modulus wrt the base would differ. *)
let base_to_nat_inj_head (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ Cons? x /\ Cons? y)
(ensures List.Tot.hd x == List.Tot.hd y)
=
match x, y with
| x1 :: xs, y1 :: ys ->
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
x1 <: int;
== { small_mod x1 base }
x1 % base;
== { lemma_mod_plus x1 (base_to_nat base xs) base }
(x1 + base_to_nat base xs * base) % base;
== {}
x' % base;
== {}
y' % base;
== {}
(y1 + base_to_nat base ys * base) % base;
== { lemma_mod_plus y1 (base_to_nat base ys) base }
y1 % base;
== { small_mod y1 base }
y1;
}
(* Generalizing the lemma above, if two lists represent the same number,
and they have the same length, they must be the same list. The length requirement
is due to the possibility of trailing zeroes. Another possibility is stating
that one of them is a prefix of the other, which is enough for this module,
even without stating that the "rest" is all zeroes. *)
let rec base_to_nat_inj (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ List.length x == List.length y)
(ensures x == y)
=
match x, y with
| [], [] -> ()
| x1 :: xs, y1 :: ys ->
base_to_nat_inj_head base x y;
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
base_to_nat base xs * base;
== {}
x' - x1;
== {}
y' - y1;
== {}
base_to_nat base ys * base;
};
lemma_cancel_mul (base_to_nat base xs) (base_to_nat base ys) base;
assert (base_to_nat base xs == base_to_nat base ys);
base_to_nat_inj base xs ys
#push-options "--fuel 4"
(* Fuel needed to prove length equality *)
let four_to_nat_inj (x y : four (natN 256)) :
Lemma (requires four_to_nat 8 x == four_to_nat 8 y)
(ensures x == y)
=
let Mkfour x0 x1 x2 x3 = x in
let Mkfour y0 y1 y2 y3 = y in
assert_norm (four_to_nat 8 (Mkfour x0 x1 x2 x3) == base_to_nat 256 [x0; x1; x2; x3]);
assert_norm (four_to_nat 8 (Mkfour y0 y1 y2 y3) == base_to_nat 256 [y0; y1; y2; y3]);
base_to_nat_inj 256 [x0; x1; x2; x3] [y0; y1; y2; y3];
()
#pop-options
let nat_to_four_to_nat (x:four (natN 256)) :
Lemma (nat_to_four 8 (four_to_nat 8 x) == x)
[SMTPat (nat_to_four 8 (four_to_nat 8 x))]
=
four_to_nat_to_four_8 (four_to_nat 8 x);
four_to_nat_inj (nat_to_four 8 (four_to_nat 8 x)) x
let four_to_seq_to_four_LE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_LE (seq_to_four_LE x) == x)
=
assert (equal (four_to_seq_LE (seq_to_four_LE x)) x);
()
let seq_to_four_to_seq_LE (#a:Type) (x:four a) :
Lemma (seq_to_four_LE (four_to_seq_LE x) == x)
=
()
let four_to_seq_to_four_BE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_BE (seq_to_four_BE x) == x)
=
assert (equal (four_to_seq_BE (seq_to_four_BE x)) x);
()
let seq_to_four_to_seq_BE (#a:Type) (x:four a) :
Lemma (seq_to_four_BE (four_to_seq_BE x) == x)
=
()
let four_to_seq_LE_is_seq_four_to_seq_LE(#a:Type) (x:four a) :
Lemma (four_to_seq_LE x == seq_four_to_seq_LE (create 1 x))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
let s0 = four_to_seq_LE x in
let s1 = seq_four_to_seq_LE (create 1 x) in
assert (equal s0 s1);
()
let four_to_seq_BE_is_seq_four_to_seq_BE (x:four nat32) :
Lemma (four_to_seq_BE x == seq_four_to_seq_BE (create 1 x))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #nat32);
let s0 = four_to_seq_BE x in
let s1 = seq_four_to_seq_BE (create 1 x) in
assert (equal s0 s1);
()
let seq_nat8_to_seq_nat32_to_seq_nat8_LE (x:seq nat32) :
Lemma (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x) == x)
=
assert (equal (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x)) x);
()
let seq_nat8_to_seq_nat32_to_seq_nat8_BE (x:seq nat32) :
Lemma (seq_nat8_to_seq_nat32_BE (seq_nat32_to_seq_nat8_BE x) == x)
=
assert (equal (seq_nat8_to_seq_nat32_BE (seq_nat32_to_seq_nat8_BE x)) x);
()
let seq_nat32_to_seq_nat8_to_seq_nat32_LE (x:seq nat8{length x % 4 == 0}) :
Lemma (seq_nat32_to_seq_nat8_LE (seq_nat8_to_seq_nat32_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #nat8);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
assert (equal (seq_nat32_to_seq_nat8_LE (seq_nat8_to_seq_nat32_LE x)) x);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Seq.Base.seq FStar.UInt8.t
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 x) ==
x)
[
SMTPat (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8
x))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.UInt8.t",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8",
"Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8",
"Prims.unit"
] | [] | true | false | true | false | false | let seq_nat8_to_seq_uint8_to_seq_nat8 (x: seq UInt8.t) =
| assert (equal (seq_nat8_to_seq_uint8 (seq_uint8_to_seq_nat8 x)) x) | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.four_to_seq_BE_is_seq_four_to_seq_BE | val four_to_seq_BE_is_seq_four_to_seq_BE (x:four nat32) :
Lemma (four_to_seq_BE x == seq_four_to_seq_BE (create 1 x)) | val four_to_seq_BE_is_seq_four_to_seq_BE (x:four nat32) :
Lemma (four_to_seq_BE x == seq_four_to_seq_BE (create 1 x)) | let four_to_seq_BE_is_seq_four_to_seq_BE (x:four nat32) :
Lemma (four_to_seq_BE x == seq_four_to_seq_BE (create 1 x))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #nat32);
let s0 = four_to_seq_BE x in
let s1 = seq_four_to_seq_BE (create 1 x) in
assert (equal s0 s1);
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 211,
"start_col": 0,
"start_line": 204
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
()
unfold let pow2_24 = 16777216 //normalize_term (pow2 24)
#push-options "--z3rlimit 200 --using_facts_from 'Prims Vale.Def.Words_s'"
let lemma_fundamental_div_mod_4 (x:nat32) :
Lemma (x = x % pow2_8 + pow2_8 * ((x / pow2_8) % pow2_8) + pow2_16 * ((x / pow2_16) % pow2_8) + pow2_24 * ((x / pow2_24) % pow2_8))
=
()
#pop-options
let four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))]
=
let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
()
#push-options "--z3rlimit 20 --z3cliopt smt.arith.nl=true"
(* Localized use of NL arith. The makefile passes the option to disable
it in this file, so we reenable it here. *)
let rec base_to_nat (base:pos) (cs : list (natN base)) : nat =
match cs with
| [] -> 0
| c :: cs' -> c + base_to_nat base cs' * base
(* NB: right-multiplying by base is a lot better than left-multiplying
since it more closely matches the lemmas in FStar.Math.Lemmas. *)
#pop-options
(* If two lists represent the same number, their heads must match,
otherwise their modulus wrt the base would differ. *)
let base_to_nat_inj_head (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ Cons? x /\ Cons? y)
(ensures List.Tot.hd x == List.Tot.hd y)
=
match x, y with
| x1 :: xs, y1 :: ys ->
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
x1 <: int;
== { small_mod x1 base }
x1 % base;
== { lemma_mod_plus x1 (base_to_nat base xs) base }
(x1 + base_to_nat base xs * base) % base;
== {}
x' % base;
== {}
y' % base;
== {}
(y1 + base_to_nat base ys * base) % base;
== { lemma_mod_plus y1 (base_to_nat base ys) base }
y1 % base;
== { small_mod y1 base }
y1;
}
(* Generalizing the lemma above, if two lists represent the same number,
and they have the same length, they must be the same list. The length requirement
is due to the possibility of trailing zeroes. Another possibility is stating
that one of them is a prefix of the other, which is enough for this module,
even without stating that the "rest" is all zeroes. *)
let rec base_to_nat_inj (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ List.length x == List.length y)
(ensures x == y)
=
match x, y with
| [], [] -> ()
| x1 :: xs, y1 :: ys ->
base_to_nat_inj_head base x y;
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
base_to_nat base xs * base;
== {}
x' - x1;
== {}
y' - y1;
== {}
base_to_nat base ys * base;
};
lemma_cancel_mul (base_to_nat base xs) (base_to_nat base ys) base;
assert (base_to_nat base xs == base_to_nat base ys);
base_to_nat_inj base xs ys
#push-options "--fuel 4"
(* Fuel needed to prove length equality *)
let four_to_nat_inj (x y : four (natN 256)) :
Lemma (requires four_to_nat 8 x == four_to_nat 8 y)
(ensures x == y)
=
let Mkfour x0 x1 x2 x3 = x in
let Mkfour y0 y1 y2 y3 = y in
assert_norm (four_to_nat 8 (Mkfour x0 x1 x2 x3) == base_to_nat 256 [x0; x1; x2; x3]);
assert_norm (four_to_nat 8 (Mkfour y0 y1 y2 y3) == base_to_nat 256 [y0; y1; y2; y3]);
base_to_nat_inj 256 [x0; x1; x2; x3] [y0; y1; y2; y3];
()
#pop-options
let nat_to_four_to_nat (x:four (natN 256)) :
Lemma (nat_to_four 8 (four_to_nat 8 x) == x)
[SMTPat (nat_to_four 8 (four_to_nat 8 x))]
=
four_to_nat_to_four_8 (four_to_nat 8 x);
four_to_nat_inj (nat_to_four 8 (four_to_nat 8 x)) x
let four_to_seq_to_four_LE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_LE (seq_to_four_LE x) == x)
=
assert (equal (four_to_seq_LE (seq_to_four_LE x)) x);
()
let seq_to_four_to_seq_LE (#a:Type) (x:four a) :
Lemma (seq_to_four_LE (four_to_seq_LE x) == x)
=
()
let four_to_seq_to_four_BE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_BE (seq_to_four_BE x) == x)
=
assert (equal (four_to_seq_BE (seq_to_four_BE x)) x);
()
let seq_to_four_to_seq_BE (#a:Type) (x:four a) :
Lemma (seq_to_four_BE (four_to_seq_BE x) == x)
=
()
let four_to_seq_LE_is_seq_four_to_seq_LE(#a:Type) (x:four a) :
Lemma (four_to_seq_LE x == seq_four_to_seq_LE (create 1 x))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
let s0 = four_to_seq_LE x in
let s1 = seq_four_to_seq_LE (create 1 x) in
assert (equal s0 s1);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Def.Words_s.four Vale.Def.Words_s.nat32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Seq_s.four_to_seq_BE x ==
Vale.Def.Words.Seq_s.seq_four_to_seq_BE (FStar.Seq.Base.create 1 x)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.nat32",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Multiply",
"FStar.Seq.Base.create",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Words.Seq_s.seq4",
"Vale.Def.Words.Seq_s.four_to_seq_BE",
"FStar.Pervasives.reveal_opaque",
"FStar.Mul.op_Star",
"Prims.l_True",
"Prims.squash",
"Prims.l_or",
"Prims.nat",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let four_to_seq_BE_is_seq_four_to_seq_BE (x: four nat32)
: Lemma (four_to_seq_BE x == seq_four_to_seq_BE (create 1 x)) =
| reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #nat32);
let s0 = four_to_seq_BE x in
let s1 = seq_four_to_seq_BE (create 1 x) in
assert (equal s0 s1);
() | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.seq_nat8_to_seq_uint8_injective | val seq_nat8_to_seq_uint8_injective (b b':seq nat8) : Lemma
(requires equal (seq_nat8_to_seq_uint8 b) (seq_nat8_to_seq_uint8 b'))
(ensures b == b') | val seq_nat8_to_seq_uint8_injective (b b':seq nat8) : Lemma
(requires equal (seq_nat8_to_seq_uint8 b) (seq_nat8_to_seq_uint8 b'))
(ensures b == b') | let seq_nat8_to_seq_uint8_injective b b' =
seq_map_injective UInt8.uint_to_t b b' | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 240,
"start_col": 0,
"start_line": 239
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
()
unfold let pow2_24 = 16777216 //normalize_term (pow2 24)
#push-options "--z3rlimit 200 --using_facts_from 'Prims Vale.Def.Words_s'"
let lemma_fundamental_div_mod_4 (x:nat32) :
Lemma (x = x % pow2_8 + pow2_8 * ((x / pow2_8) % pow2_8) + pow2_16 * ((x / pow2_16) % pow2_8) + pow2_24 * ((x / pow2_24) % pow2_8))
=
()
#pop-options
let four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))]
=
let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
()
#push-options "--z3rlimit 20 --z3cliopt smt.arith.nl=true"
(* Localized use of NL arith. The makefile passes the option to disable
it in this file, so we reenable it here. *)
let rec base_to_nat (base:pos) (cs : list (natN base)) : nat =
match cs with
| [] -> 0
| c :: cs' -> c + base_to_nat base cs' * base
(* NB: right-multiplying by base is a lot better than left-multiplying
since it more closely matches the lemmas in FStar.Math.Lemmas. *)
#pop-options
(* If two lists represent the same number, their heads must match,
otherwise their modulus wrt the base would differ. *)
let base_to_nat_inj_head (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ Cons? x /\ Cons? y)
(ensures List.Tot.hd x == List.Tot.hd y)
=
match x, y with
| x1 :: xs, y1 :: ys ->
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
x1 <: int;
== { small_mod x1 base }
x1 % base;
== { lemma_mod_plus x1 (base_to_nat base xs) base }
(x1 + base_to_nat base xs * base) % base;
== {}
x' % base;
== {}
y' % base;
== {}
(y1 + base_to_nat base ys * base) % base;
== { lemma_mod_plus y1 (base_to_nat base ys) base }
y1 % base;
== { small_mod y1 base }
y1;
}
(* Generalizing the lemma above, if two lists represent the same number,
and they have the same length, they must be the same list. The length requirement
is due to the possibility of trailing zeroes. Another possibility is stating
that one of them is a prefix of the other, which is enough for this module,
even without stating that the "rest" is all zeroes. *)
let rec base_to_nat_inj (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ List.length x == List.length y)
(ensures x == y)
=
match x, y with
| [], [] -> ()
| x1 :: xs, y1 :: ys ->
base_to_nat_inj_head base x y;
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
base_to_nat base xs * base;
== {}
x' - x1;
== {}
y' - y1;
== {}
base_to_nat base ys * base;
};
lemma_cancel_mul (base_to_nat base xs) (base_to_nat base ys) base;
assert (base_to_nat base xs == base_to_nat base ys);
base_to_nat_inj base xs ys
#push-options "--fuel 4"
(* Fuel needed to prove length equality *)
let four_to_nat_inj (x y : four (natN 256)) :
Lemma (requires four_to_nat 8 x == four_to_nat 8 y)
(ensures x == y)
=
let Mkfour x0 x1 x2 x3 = x in
let Mkfour y0 y1 y2 y3 = y in
assert_norm (four_to_nat 8 (Mkfour x0 x1 x2 x3) == base_to_nat 256 [x0; x1; x2; x3]);
assert_norm (four_to_nat 8 (Mkfour y0 y1 y2 y3) == base_to_nat 256 [y0; y1; y2; y3]);
base_to_nat_inj 256 [x0; x1; x2; x3] [y0; y1; y2; y3];
()
#pop-options
let nat_to_four_to_nat (x:four (natN 256)) :
Lemma (nat_to_four 8 (four_to_nat 8 x) == x)
[SMTPat (nat_to_four 8 (four_to_nat 8 x))]
=
four_to_nat_to_four_8 (four_to_nat 8 x);
four_to_nat_inj (nat_to_four 8 (four_to_nat 8 x)) x
let four_to_seq_to_four_LE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_LE (seq_to_four_LE x) == x)
=
assert (equal (four_to_seq_LE (seq_to_four_LE x)) x);
()
let seq_to_four_to_seq_LE (#a:Type) (x:four a) :
Lemma (seq_to_four_LE (four_to_seq_LE x) == x)
=
()
let four_to_seq_to_four_BE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_BE (seq_to_four_BE x) == x)
=
assert (equal (four_to_seq_BE (seq_to_four_BE x)) x);
()
let seq_to_four_to_seq_BE (#a:Type) (x:four a) :
Lemma (seq_to_four_BE (four_to_seq_BE x) == x)
=
()
let four_to_seq_LE_is_seq_four_to_seq_LE(#a:Type) (x:four a) :
Lemma (four_to_seq_LE x == seq_four_to_seq_LE (create 1 x))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
let s0 = four_to_seq_LE x in
let s1 = seq_four_to_seq_LE (create 1 x) in
assert (equal s0 s1);
()
let four_to_seq_BE_is_seq_four_to_seq_BE (x:four nat32) :
Lemma (four_to_seq_BE x == seq_four_to_seq_BE (create 1 x))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #nat32);
let s0 = four_to_seq_BE x in
let s1 = seq_four_to_seq_BE (create 1 x) in
assert (equal s0 s1);
()
let seq_nat8_to_seq_nat32_to_seq_nat8_LE (x:seq nat32) :
Lemma (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x) == x)
=
assert (equal (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x)) x);
()
let seq_nat8_to_seq_nat32_to_seq_nat8_BE (x:seq nat32) :
Lemma (seq_nat8_to_seq_nat32_BE (seq_nat32_to_seq_nat8_BE x) == x)
=
assert (equal (seq_nat8_to_seq_nat32_BE (seq_nat32_to_seq_nat8_BE x)) x);
()
let seq_nat32_to_seq_nat8_to_seq_nat32_LE (x:seq nat8{length x % 4 == 0}) :
Lemma (seq_nat32_to_seq_nat8_LE (seq_nat8_to_seq_nat32_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #nat8);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
assert (equal (seq_nat32_to_seq_nat8_LE (seq_nat8_to_seq_nat32_LE x)) x);
()
let seq_nat8_to_seq_uint8_to_seq_nat8 (x:seq UInt8.t) =
assert (equal (seq_nat8_to_seq_uint8 (seq_uint8_to_seq_nat8 x)) x)
let seq_uint8_to_seq_nat8_to_seq_uint8 (x:seq nat8) =
assert (equal (seq_uint8_to_seq_nat8 (seq_nat8_to_seq_uint8 x)) x) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> b': FStar.Seq.Base.seq Vale.Def.Words_s.nat8
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.equal (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 b)
(Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 b')) (ensures b == b') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Vale.Lib.Seqs.seq_map_injective",
"FStar.UInt8.t",
"FStar.UInt8.uint_to_t",
"Prims.unit"
] | [] | true | false | true | false | false | let seq_nat8_to_seq_uint8_injective b b' =
| seq_map_injective UInt8.uint_to_t b b' | false |
Vale.Def.Words.Seq.fst | Vale.Def.Words.Seq.seq_nat8_to_seq_nat32_to_seq_nat8_LE | val seq_nat8_to_seq_nat32_to_seq_nat8_LE (x:seq nat32) :
Lemma (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x) == x)
[SMTPat (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x))] | val seq_nat8_to_seq_nat32_to_seq_nat8_LE (x:seq nat32) :
Lemma (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x) == x)
[SMTPat (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x))] | let seq_nat8_to_seq_nat32_to_seq_nat8_LE (x:seq nat32) :
Lemma (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x) == x)
=
assert (equal (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x)) x);
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Seq.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 217,
"start_col": 0,
"start_line": 213
} | module Vale.Def.Words.Seq
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open FStar.Mul
open Vale.Lib.Meta
open Vale.Lib.Seqs_s
open Vale.Lib.Seqs
let two_to_seq_to_two_LE #a x =
assert (equal (two_to_seq_LE (seq_to_two_LE x)) x)
let seq_to_two_to_seq_LE #a x = ()
let seq_to_seq_four_to_seq_LE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_LE (seq_four_to_seq_LE x) == x)
[SMTPat (seq_to_seq_four_LE (seq_four_to_seq_LE x))]
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
let bytes = seq_four_to_seq_LE x in
let fours = seq_to_seq_four_LE bytes in
assert (equal fours x);
()
let seq_to_seq_four_to_seq_BE (#a:Type) (x:seq (four a)) :
Lemma (seq_to_seq_four_BE (seq_four_to_seq_BE x) == x)
[SMTPat (seq_to_seq_four_BE (seq_four_to_seq_BE x))]
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_to_seq_four_BE (seq_four_to_seq_BE x)) x);
()
let seq_four_to_seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_LE (seq_to_seq_four_LE x) == x)
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (seq_four_to_seq_LE (seq_to_seq_four_LE x)) x);
()
let seq_four_to_seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) :
Lemma (seq_four_to_seq_BE (seq_to_seq_four_BE x) == x)
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (seq_four_to_seq_BE (seq_to_seq_four_BE x)) x);
()
unfold let pow2_24 = 16777216 //normalize_term (pow2 24)
#push-options "--z3rlimit 200 --using_facts_from 'Prims Vale.Def.Words_s'"
let lemma_fundamental_div_mod_4 (x:nat32) :
Lemma (x = x % pow2_8 + pow2_8 * ((x / pow2_8) % pow2_8) + pow2_16 * ((x / pow2_16) % pow2_8) + pow2_24 * ((x / pow2_24) % pow2_8))
=
()
#pop-options
let four_to_nat_to_four_8 (x:natN (pow2_norm 32)) :
Lemma (four_to_nat 8 (nat_to_four 8 x) == x)
[SMTPat (four_to_nat 8 (nat_to_four 8 x))]
=
let size = 8 in
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let n3 = pow2_norm (3 * size) in
let n4 = pow2_norm (4 * size) in
assert_norm (pow2 8 == 256);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
let fourX = nat_to_four 8 x in
assert_norm (nat_to_four 8 x == Mkfour (x % n1) ((x / n1) % n1) ((x / n2) % n1) ((x / n3) % n1));
let Mkfour x0 x1 x2 x3 = fourX in
let x' = x0 + x1 * n1 + x2 * n2 + x3 * n3 in
assert_norm (four_to_nat 8 fourX == int_to_natN n4 (x0 + x1 * n1 + x2 * n2 + x3 * n3));
lemma_fundamental_div_mod_4 x;
()
#push-options "--z3rlimit 20 --z3cliopt smt.arith.nl=true"
(* Localized use of NL arith. The makefile passes the option to disable
it in this file, so we reenable it here. *)
let rec base_to_nat (base:pos) (cs : list (natN base)) : nat =
match cs with
| [] -> 0
| c :: cs' -> c + base_to_nat base cs' * base
(* NB: right-multiplying by base is a lot better than left-multiplying
since it more closely matches the lemmas in FStar.Math.Lemmas. *)
#pop-options
(* If two lists represent the same number, their heads must match,
otherwise their modulus wrt the base would differ. *)
let base_to_nat_inj_head (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ Cons? x /\ Cons? y)
(ensures List.Tot.hd x == List.Tot.hd y)
=
match x, y with
| x1 :: xs, y1 :: ys ->
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
x1 <: int;
== { small_mod x1 base }
x1 % base;
== { lemma_mod_plus x1 (base_to_nat base xs) base }
(x1 + base_to_nat base xs * base) % base;
== {}
x' % base;
== {}
y' % base;
== {}
(y1 + base_to_nat base ys * base) % base;
== { lemma_mod_plus y1 (base_to_nat base ys) base }
y1 % base;
== { small_mod y1 base }
y1;
}
(* Generalizing the lemma above, if two lists represent the same number,
and they have the same length, they must be the same list. The length requirement
is due to the possibility of trailing zeroes. Another possibility is stating
that one of them is a prefix of the other, which is enough for this module,
even without stating that the "rest" is all zeroes. *)
let rec base_to_nat_inj (base:pos) (x y : list (natN base)) :
Lemma (requires base_to_nat base x == base_to_nat base y /\ List.length x == List.length y)
(ensures x == y)
=
match x, y with
| [], [] -> ()
| x1 :: xs, y1 :: ys ->
base_to_nat_inj_head base x y;
let x' = base_to_nat base x in
let y' = base_to_nat base y in
let open FStar.Math.Lemmas in
calc (==) {
base_to_nat base xs * base;
== {}
x' - x1;
== {}
y' - y1;
== {}
base_to_nat base ys * base;
};
lemma_cancel_mul (base_to_nat base xs) (base_to_nat base ys) base;
assert (base_to_nat base xs == base_to_nat base ys);
base_to_nat_inj base xs ys
#push-options "--fuel 4"
(* Fuel needed to prove length equality *)
let four_to_nat_inj (x y : four (natN 256)) :
Lemma (requires four_to_nat 8 x == four_to_nat 8 y)
(ensures x == y)
=
let Mkfour x0 x1 x2 x3 = x in
let Mkfour y0 y1 y2 y3 = y in
assert_norm (four_to_nat 8 (Mkfour x0 x1 x2 x3) == base_to_nat 256 [x0; x1; x2; x3]);
assert_norm (four_to_nat 8 (Mkfour y0 y1 y2 y3) == base_to_nat 256 [y0; y1; y2; y3]);
base_to_nat_inj 256 [x0; x1; x2; x3] [y0; y1; y2; y3];
()
#pop-options
let nat_to_four_to_nat (x:four (natN 256)) :
Lemma (nat_to_four 8 (four_to_nat 8 x) == x)
[SMTPat (nat_to_four 8 (four_to_nat 8 x))]
=
four_to_nat_to_four_8 (four_to_nat 8 x);
four_to_nat_inj (nat_to_four 8 (four_to_nat 8 x)) x
let four_to_seq_to_four_LE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_LE (seq_to_four_LE x) == x)
=
assert (equal (four_to_seq_LE (seq_to_four_LE x)) x);
()
let seq_to_four_to_seq_LE (#a:Type) (x:four a) :
Lemma (seq_to_four_LE (four_to_seq_LE x) == x)
=
()
let four_to_seq_to_four_BE (#a:Type) (x:seq4 a) :
Lemma (four_to_seq_BE (seq_to_four_BE x) == x)
=
assert (equal (four_to_seq_BE (seq_to_four_BE x)) x);
()
let seq_to_four_to_seq_BE (#a:Type) (x:four a) :
Lemma (seq_to_four_BE (four_to_seq_BE x) == x)
=
()
let four_to_seq_LE_is_seq_four_to_seq_LE(#a:Type) (x:four a) :
Lemma (four_to_seq_LE x == seq_four_to_seq_LE (create 1 x))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
let s0 = four_to_seq_LE x in
let s1 = seq_four_to_seq_LE (create 1 x) in
assert (equal s0 s1);
()
let four_to_seq_BE_is_seq_four_to_seq_BE (x:four nat32) :
Lemma (four_to_seq_BE x == seq_four_to_seq_BE (create 1 x))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #nat32);
let s0 = four_to_seq_BE x in
let s1 = seq_four_to_seq_BE (create 1 x) in
assert (equal s0 s1);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Seq.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Seq.Base.seq Vale.Def.Words_s.nat32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE
x) ==
x)
[
SMTPat (Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE
x))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let seq_nat8_to_seq_nat32_to_seq_nat8_LE (x: seq nat32)
: Lemma (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x) == x) =
| assert (equal (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE x)) x);
() | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.