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
listlengths
0
2
mutual_with
listlengths
0
11
ideal_premises
listlengths
0
236
proof_features
listlengths
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
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.code_key256
val code_key256 : Vale.X64.Decls.va_code
let code_key256 = GF.va_code_Keyhash_init IA.win AES_256
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 177, "start_col": 0, "start_line": 177 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s) noextract let code_key128 = GF.va_code_Keyhash_init IA.win AES_128 [@__reduce__] noextract let lowstar_key128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key128 dom [] _ _ (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_key128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key128 dom (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key256_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key256_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key256_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key256_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key256_pre s) (key256_post s)) (key256_lemma' s)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.X64.Decls.va_code
Prims.Tot
[ "total" ]
[]
[ "Vale.AES.X64.GF128_Init.va_code_Keyhash_init", "Vale.Interop.Assumptions.win", "Vale.AES.AES_common_s.AES_256" ]
[]
false
false
false
true
false
let code_key256 =
GF.va_code_Keyhash_init IA.win AES_256
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.key256_post
val key256_post: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom
val key256_post: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom
let key256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 145, "start_col": 0, "start_line": 136 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s) noextract let code_key128 = GF.va_code_Keyhash_init IA.win AES_128 [@__reduce__] noextract let lowstar_key128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key128 dom [] _ _ (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_key128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key128 dom (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Words_s.nat32) -> Vale.AsLowStar.ValeSig.vale_post Vale.Stdcalls.X64.AesHash.dom
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.X64.Decls.va_code", "Vale.Stdcalls.X64.AesHash.b128", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "Vale.AES.X64.GF128_Init.va_ens_Keyhash_init", "Vale.Interop.Assumptions.win", "Vale.AES.AES_common_s.AES_256", "FStar.Ghost.reveal", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "Prims.prop" ]
[]
false
false
false
true
false
let key256_post: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom =
fun (s: Ghost.erased (Seq.seq nat32)) (c: V.va_code) (input_b: b128) (output_b: b128) (va_s0: V.va_state) (va_s1: V.va_state) (f: V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.key256_pre
val key256_pre: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom
val key256_pre: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom
let key256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 133, "start_col": 0, "start_line": 126 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s) noextract let code_key128 = GF.va_code_Keyhash_init IA.win AES_128 [@__reduce__] noextract let lowstar_key128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key128 dom [] _ _ (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_key128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key128 dom (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* Need to rearrange the order of arguments *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Words_s.nat32) -> Vale.AsLowStar.ValeSig.vale_pre Vale.Stdcalls.X64.AesHash.dom
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.X64.Decls.va_code", "Vale.Stdcalls.X64.AesHash.b128", "Vale.X64.Decls.va_state", "Vale.AES.X64.GF128_Init.va_req_Keyhash_init", "Vale.Interop.Assumptions.win", "Vale.AES.AES_common_s.AES_256", "FStar.Ghost.reveal", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "Prims.prop" ]
[]
false
false
false
true
false
let key256_pre: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom =
fun (s: Ghost.erased (Seq.seq nat32)) (c: V.va_code) (input_b: b128) (output_b: b128) (va_s0: V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b)
false
Vale.Wrapper.X64.AES.fsti
Vale.Wrapper.X64.AES.key_offset
val key_offset : a: Vale.AES.AES_common_s.algorithm {a = Vale.AES.AES_common_s.AES_128 \/ a = Vale.AES.AES_common_s.AES_256} -> Prims.int
let key_offset (a: algorithm { a = AES_128 \/ a = AES_256 }) = match a with | AES_128 -> 176 | AES_256 -> 240
{ "file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.AES.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 35, "start_col": 0, "start_line": 32 }
module Vale.Wrapper.X64.AES open Vale.X64.CPU_Features_s open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.AES.AES_s open Vale.Interop.Base open Vale.Def.Types_s unfold let uint8_p = B.buffer UInt8.t let length_aux (b:uint8_p) : Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0) = let db = get_downview b in DV.length_eq db let length_aux2 (b:uint8_p) : Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0) = let db = get_downview b in DV.length_eq db
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Wrapper.X64.AES.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "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
a: Vale.AES.AES_common_s.algorithm {a = Vale.AES.AES_common_s.AES_128 \/ a = Vale.AES.AES_common_s.AES_256} -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "Vale.AES.AES_common_s.algorithm", "Prims.l_or", "Prims.b2t", "Prims.op_Equality", "Vale.AES.AES_common_s.AES_128", "Vale.AES.AES_common_s.AES_256", "Prims.int" ]
[]
false
false
false
false
false
let key_offset (a: algorithm{a = AES_128 \/ a = AES_256}) =
match a with | AES_128 -> 176 | AES_256 -> 240
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.code_key128
val code_key128 : Vale.X64.Decls.va_code
let code_key128 = GF.va_code_Keyhash_init IA.win AES_128
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 101, "start_col": 0, "start_line": 101 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.X64.Decls.va_code
Prims.Tot
[ "total" ]
[]
[ "Vale.AES.X64.GF128_Init.va_code_Keyhash_init", "Vale.Interop.Assumptions.win", "Vale.AES.AES_common_s.AES_128" ]
[]
false
false
false
true
false
let code_key128 =
GF.va_code_Keyhash_init IA.win AES_128
false
Vale.Wrapper.X64.AES.fsti
Vale.Wrapper.X64.AES.key_expansion_st
val key_expansion_st : a: Vale.AES.AES_common_s.algorithm {a = Vale.AES.AES_common_s.AES_128 \/ a = Vale.AES.AES_common_s.AES_256} -> Type0
let key_expansion_st (a: algorithm { a = AES_128 \/ a = AES_256 }) = (input_key_b:uint8_p) -> (output_key_expansion_b:uint8_p) -> Stack unit (requires fun h0 -> B.disjoint input_key_b output_key_expansion_b /\ B.live h0 input_key_b /\ B.live h0 output_key_expansion_b /\ B.length input_key_b = key_length a /\ B.length output_key_expansion_b = key_offset a /\ aesni_enabled && avx_enabled && sse_enabled) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer output_key_expansion_b) h0 h1 /\ (let key = seq_nat8_to_seq_nat32_LE (seq_uint8_to_seq_nat8 (B.as_seq h0 input_key_b)) in Seq.equal (B.as_seq h1 output_key_expansion_b) (seq_nat8_to_seq_uint8 (le_seq_quad32_to_bytes (key_to_round_keys_LE a key)))))
{ "file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.AES.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 88, "end_line": 62, "start_col": 0, "start_line": 44 }
module Vale.Wrapper.X64.AES open Vale.X64.CPU_Features_s open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.AES.AES_s open Vale.Interop.Base open Vale.Def.Types_s unfold let uint8_p = B.buffer UInt8.t let length_aux (b:uint8_p) : Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0) = let db = get_downview b in DV.length_eq db let length_aux2 (b:uint8_p) : Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0) = let db = get_downview b in DV.length_eq db inline_for_extraction unfold let key_offset (a: algorithm { a = AES_128 \/ a = AES_256 }) = match a with | AES_128 -> 176 | AES_256 -> 240 inline_for_extraction unfold let key_length (a: algorithm { a = AES_128 \/ a = AES_256 }) = match a with | AES_128 -> 16 | AES_256 -> 32
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Wrapper.X64.AES.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "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
a: Vale.AES.AES_common_s.algorithm {a = Vale.AES.AES_common_s.AES_128 \/ a = Vale.AES.AES_common_s.AES_256} -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.AES.AES_common_s.algorithm", "Prims.l_or", "Prims.b2t", "Prims.op_Equality", "Vale.AES.AES_common_s.AES_128", "Vale.AES.AES_common_s.AES_256", "Vale.Wrapper.X64.AES.uint8_p", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.disjoint", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.live", "Prims.int", "LowStar.Monotonic.Buffer.length", "Vale.Wrapper.X64.AES.key_length", "Vale.Wrapper.X64.AES.key_offset", "Prims.op_AmpAmp", "Vale.X64.CPU_Features_s.aesni_enabled", "Vale.X64.CPU_Features_s.avx_enabled", "Vale.X64.CPU_Features_s.sse_enabled", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "FStar.Seq.Base.equal", "LowStar.Monotonic.Buffer.as_seq", "Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Vale.AES.AES_s.key_to_round_keys_LE", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32", "Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE", "Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8" ]
[]
false
false
false
false
true
let key_expansion_st (a: algorithm{a = AES_128 \/ a = AES_256}) =
input_key_b: uint8_p -> output_key_expansion_b: uint8_p -> Stack unit (requires fun h0 -> B.disjoint input_key_b output_key_expansion_b /\ B.live h0 input_key_b /\ B.live h0 output_key_expansion_b /\ B.length input_key_b = key_length a /\ B.length output_key_expansion_b = key_offset a /\ aesni_enabled && avx_enabled && sse_enabled) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer output_key_expansion_b) h0 h1 /\ (let key = seq_nat8_to_seq_nat32_LE (seq_uint8_to_seq_nat8 (B.as_seq h0 input_key_b)) in Seq.equal (B.as_seq h1 output_key_expansion_b) (seq_nat8_to_seq_uint8 (le_seq_quad32_to_bytes (key_to_round_keys_LE a key)))))
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.aes128_keyhash_init
val aes128_keyhash_init : Vale.Interop.Base.normal (s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.Stdcalls.X64.AesHash.lowstar_key128_t s)
let aes128_keyhash_init //: normal ((s:Ghost.erased (Seq.seq nat32)) -> lowstar_key128_t s) = as_normal_t #((s:Ghost.erased (Seq.seq nat32)) -> lowstar_key128_t s) (fun (s:Ghost.erased (Seq.seq nat32)) -> lowstar_key128 s)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 132, "end_line": 202, "start_col": 0, "start_line": 201 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s) noextract let code_key128 = GF.va_code_Keyhash_init IA.win AES_128 [@__reduce__] noextract let lowstar_key128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key128 dom [] _ _ (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_key128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key128 dom (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key256_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key256_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key256_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key256_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key256_pre s) (key256_post s)) (key256_lemma' s) noextract let code_key256 = GF.va_code_Keyhash_init IA.win AES_256 [@__reduce__] noextract let lowstar_key256_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key256 dom [] _ _ (W.mk_prediction code_key256 dom [] ((key256_lemma s) code_key256 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_key256 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key256_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key256 dom (W.mk_prediction code_key256 dom [] ((key256_lemma s) code_key256 IA.win))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Interop.Base.normal (s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.Stdcalls.X64.AesHash.lowstar_key128_t s)
Prims.Tot
[ "total" ]
[]
[ "Vale.Stdcalls.X64.AesHash.as_normal_t", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Stdcalls.X64.AesHash.lowstar_key128_t", "Vale.Stdcalls.X64.AesHash.lowstar_key128" ]
[]
false
false
false
false
false
let aes128_keyhash_init =
as_normal_t #(s: Ghost.erased (Seq.seq nat32) -> lowstar_key128_t s) (fun (s: Ghost.erased (Seq.seq nat32)) -> lowstar_key128 s)
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.walk
val walk (#kt #vt: _) (repr: repr_t kt vt) (idx: nat) (k: kt) (off: nat{off <= repr.sz}) : option vt
val walk (#kt #vt: _) (repr: repr_t kt vt) (idx: nat) (k: kt) (off: nat{off <= repr.sz}) : option vt
let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 15, "end_line": 119, "start_col": 0, "start_line": 116 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
repr: Pulse.Lib.HashTable.Spec.repr_t kt vt -> idx: Prims.nat -> k: kt -> off: Prims.nat{off <= Mkrepr_t?.sz repr} -> FStar.Pervasives.Native.option vt
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Pulse.Lib.HashTable.Spec.walk_get_idx", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.None" ]
[]
false
false
false
false
false
let walk #kt #vt (repr: repr_t kt vt) (idx: nat) (k: kt) (off: nat{off <= repr.sz}) : option vt =
match walk_get_idx repr idx k off with | Some (v, _) -> Some v | _ -> None
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.aes256_keyhash_init
val aes256_keyhash_init : Vale.Interop.Base.normal (s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.Stdcalls.X64.AesHash.lowstar_key256_t s)
let aes256_keyhash_init //: normal ((s:Ghost.erased (Seq.seq nat32)) -> lowstar_key256_t s) = as_normal_t #((s:Ghost.erased (Seq.seq nat32)) -> lowstar_key256_t s) (fun (s:Ghost.erased (Seq.seq nat32)) -> lowstar_key256 s)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 132, "end_line": 206, "start_col": 0, "start_line": 205 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s) noextract let code_key128 = GF.va_code_Keyhash_init IA.win AES_128 [@__reduce__] noextract let lowstar_key128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key128 dom [] _ _ (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_key128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key128 dom (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key256_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key256_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key256_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key256_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key256_pre s) (key256_post s)) (key256_lemma' s) noextract let code_key256 = GF.va_code_Keyhash_init IA.win AES_256 [@__reduce__] noextract let lowstar_key256_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key256 dom [] _ _ (W.mk_prediction code_key256 dom [] ((key256_lemma s) code_key256 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_key256 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key256_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key256 dom (W.mk_prediction code_key256 dom [] ((key256_lemma s) code_key256 IA.win)) [@ (CCConv "stdcall") ] let aes128_keyhash_init //: normal ((s:Ghost.erased (Seq.seq nat32)) -> lowstar_key128_t s) = as_normal_t #((s:Ghost.erased (Seq.seq nat32)) -> lowstar_key128_t s) (fun (s:Ghost.erased (Seq.seq nat32)) -> lowstar_key128 s)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Interop.Base.normal (s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.Stdcalls.X64.AesHash.lowstar_key256_t s)
Prims.Tot
[ "total" ]
[]
[ "Vale.Stdcalls.X64.AesHash.as_normal_t", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Stdcalls.X64.AesHash.lowstar_key256_t", "Vale.Stdcalls.X64.AesHash.lowstar_key256" ]
[]
false
false
false
false
false
let aes256_keyhash_init =
as_normal_t #(s: Ghost.erased (Seq.seq nat32) -> lowstar_key256_t s) (fun (s: Ghost.erased (Seq.seq nat32)) -> lowstar_key256 s)
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.repr_t_sz
val repr_t_sz : kt: Prims.eqtype -> vt: Type -> sz: Prims.pos -> Type
let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz}
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 53, "end_line": 182, "start_col": 0, "start_line": 182 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
kt: Prims.eqtype -> vt: Type -> sz: Prims.pos -> Type
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Prims.pos", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.eq2", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz" ]
[]
false
false
false
true
true
let repr_t_sz kt vt sz =
r: repr_t kt vt {r.sz == sz}
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.repr_related
val repr_related : r1: Pulse.Lib.HashTable.Spec.repr_t kt vt -> r2: Pulse.Lib.HashTable.Spec.repr_t kt vt -> Prims.logical
let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 40, "end_line": 180, "start_col": 0, "start_line": 179 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie }
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
r1: Pulse.Lib.HashTable.Spec.repr_t kt vt -> r2: Pulse.Lib.HashTable.Spec.repr_t kt vt -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.l_and", "Prims.eq2", "Prims.nat", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__hashf", "Prims.pos", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.logical" ]
[]
false
false
false
false
true
let repr_related #kt #vt (r1: repr_t kt vt) (r2: repr_t kt vt) =
r1.hashf == r2.hashf /\ r1.sz == r2.sz
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.canonical_index
val canonical_index (#kt: eqtype) (#vt: _) (key: kt) (repr: repr_t kt vt) : nat
val canonical_index (#kt: eqtype) (#vt: _) (key: kt) (repr: repr_t kt vt) : nat
let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 26, "end_line": 56, "start_col": 0, "start_line": 55 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat }
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
key: kt -> repr: Pulse.Lib.HashTable.Spec.repr_t kt vt -> Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.op_Modulus", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__hashf", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.nat" ]
[]
false
false
false
false
false
let canonical_index (#kt: eqtype) #vt (key: kt) (repr: repr_t kt vt) : nat =
repr.hashf key % repr.sz
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.used_not_by
val used_not_by (#kt #kv: _) (repr: repr_t kt kv) (k: kt) (i: nat{i < repr.sz}) : prop
val used_not_by (#kt #kv: _) (repr: repr_t kt kv) (k: kt) (i: nat{i < repr.sz}) : prop
let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 52, "end_line": 327, "start_col": 0, "start_line": 326 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
repr: Pulse.Lib.HashTable.Spec.repr_t kt kv -> k: kt -> i: Prims.nat{i < Mkrepr_t?.sz repr} -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.l_or", "Pulse.Lib.HashTable.Spec.strong_used_not_by", "Pulse.Lib.HashTable.Spec.uu___is_Zombie", "Pulse.Lib.HashTable.Spec.op_At_At", "Prims.prop" ]
[]
false
false
false
false
true
let used_not_by #kt #kv (repr: repr_t kt kv) (k: kt) (i: nat{i < repr.sz}) : prop =
strong_used_not_by repr k i \/ Zombie? (repr @@ i)
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.as_t
val as_t (#a: Type) (x: normal a) : a
val as_t (#a: Type) (x: normal a) : a
let as_t (#a:Type) (x:normal a) : a = x
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 31, "start_col": 0, "start_line": 31 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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.Interop.Base.normal a -> a
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.Base.normal" ]
[]
false
false
false
true
false
let as_t (#a: Type) (x: normal a) : a =
x
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.strong_used_not_by
val strong_used_not_by (#kt #kv: _) (repr: repr_t kt kv) (k: kt) (i: nat{i < repr.sz}) : prop
val strong_used_not_by (#kt #kv: _) (repr: repr_t kt kv) (k: kt) (i: nat{i < repr.sz}) : prop
let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 324, "start_col": 0, "start_line": 323 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
repr: Pulse.Lib.HashTable.Spec.repr_t kt kv -> k: kt -> i: Prims.nat{i < Mkrepr_t?.sz repr} -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.l_and", "Pulse.Lib.HashTable.Spec.uu___is_Used", "Pulse.Lib.HashTable.Spec.op_At_At", "Prims.op_disEquality", "Pulse.Lib.HashTable.Spec.__proj__Used__item__k", "Prims.prop" ]
[]
false
false
false
false
true
let strong_used_not_by #kt #kv (repr: repr_t kt kv) (k: kt) (i: nat{i < repr.sz}) : prop =
(Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k)
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.as_normal_t
val as_normal_t (#a: Type) (x: a) : normal a
val as_normal_t (#a: Type) (x: a) : normal a
let as_normal_t (#a:Type) (x:a) : normal a = x
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 33, "start_col": 0, "start_line": 33 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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: a -> Vale.Interop.Base.normal a
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.Base.normal" ]
[]
false
false
false
true
false
let as_normal_t (#a: Type) (x: a) : normal a =
x
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.dom
val dom:IX64.arity_ok_stdcall td
val dom:IX64.arity_ok_stdcall td
let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 46, "start_col": 0, "start_line": 43 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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
Vale.Interop.X64.arity_ok_stdcall Vale.Interop.Base.td
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.List.Tot.Base.length", "Vale.Interop.Base.td", "Prims.list", "Prims.Cons", "Vale.Stdcalls.X64.AesHash.t128_no_mod", "Vale.Stdcalls.X64.AesHash.t128_mod", "Prims.Nil" ]
[]
false
false
false
true
false
let dom:IX64.arity_ok_stdcall td =
let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y
false
Steel.HigherReference.fst
Steel.HigherReference.pts_to_perm
val pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ref a) : SteelGhost unit u (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> p `lesser_equal_perm` full_perm)
val pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ref a) : SteelGhost unit u (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> p `lesser_equal_perm` full_perm)
let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ())
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 61, "end_line": 130, "start_col": 0, "start_line": 125 }
(* Copyright 2020 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 Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ())
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "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: Steel.HigherReference.ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "Steel.HigherReference.ref", "Steel.Effect.Atomic.rewrite_slprop", "Steel.HigherReference.pts_to'", "FStar.Ghost.hide", "Steel.HigherReference.pts_to", "Steel.Memory.mem", "Prims.unit", "Steel.Effect.Atomic.intro_pure", "Steel.HigherReference.perm_ok", "Steel.Effect.Atomic.elim_pure" ]
[]
false
true
false
false
false
let pts_to_perm #_ #_ #p #v r =
rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ())
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.lowstar_key128
val lowstar_key128 (s: Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s
val lowstar_key128 (s: Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s
let lowstar_key128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key128 dom (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 78, "end_line": 121, "start_col": 0, "start_line": 116 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s) noextract let code_key128 = GF.va_code_Keyhash_init IA.win AES_128 [@__reduce__] noextract let lowstar_key128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key128 dom [] _ _ (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* And here's the gcm wrapper itself *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.Stdcalls.X64.AesHash.lowstar_key128_t s
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Interop.X64.wrap_weak_stdcall", "Vale.Stdcalls.X64.AesHash.code_key128", "Vale.Stdcalls.X64.AesHash.dom", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.Stdcalls.X64.AesHash.key128_pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.Stdcalls.X64.AesHash.key128_post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.Stdcalls.X64.AesHash.key128_lemma", "Vale.Interop.Assumptions.win", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.List.Tot.Base.length", "Vale.Interop.Base.td", "Prims.list", "Vale.Stdcalls.X64.AesHash.lowstar_key128_t" ]
[]
false
false
false
false
false
let lowstar_key128 (s: Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s =
assert_norm (List.length dom + List.length ([] <: list arg) <= 4); IX64.wrap_weak_stdcall code_key128 dom (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win))
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.not_full
val not_full (#kt #vt: _) (r: repr_t kt vt) : Type0
val not_full (#kt #vt: _) (r: repr_t kt vt) : Type0
let not_full #kt #vt (r:repr_t kt vt) : Type0 = exists i. ~(Used? (r @@ i ))
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 30, "end_line": 555, "start_col": 0, "start_line": 554 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_zombie_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i:nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc (==>) { (canonical_index k repr + i) % sz == idx; ==> {} (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ==> { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_del #kt #vt #sz spec (repr : repr_t_sz kt vt sz) idx k v : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx)) = let spec' = spec -- k in let repr' = del_ repr idx in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin let Some (v', i') = lookup_repr_index repr' k' in assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then begin assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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: Pulse.Lib.HashTable.Spec.repr_t kt vt -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.l_Exists", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.l_not", "Pulse.Lib.HashTable.Spec.uu___is_Used", "Pulse.Lib.HashTable.Spec.op_At_At" ]
[]
false
false
false
false
true
let not_full #kt #vt (r: repr_t kt vt) : Type0 =
exists i. ~(Used? (r @@ i))
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.lowstar_key256_t
val lowstar_key256_t : s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Type0
let lowstar_key256_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key256 dom [] _ _ (W.mk_prediction code_key256 dom [] ((key256_lemma s) code_key256 IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 78, "end_line": 188, "start_col": 0, "start_line": 180 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s) noextract let code_key128 = GF.va_code_Keyhash_init IA.win AES_128 [@__reduce__] noextract let lowstar_key128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key128 dom [] _ _ (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_key128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key128 dom (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key256_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key256_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key256_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key256_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key256_pre s) (key256_post s)) (key256_lemma' s) noextract let code_key256 = GF.va_code_Keyhash_init IA.win AES_256
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall", "Vale.Stdcalls.X64.AesHash.code_key256", "Vale.Stdcalls.X64.AesHash.dom", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Vale.Stdcalls.X64.AesHash.key256_pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.Stdcalls.X64.AesHash.key256_post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.Stdcalls.X64.AesHash.key256_lemma", "Vale.Interop.Assumptions.win", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.List.Tot.Base.length", "Vale.Interop.Base.td", "Prims.list" ]
[]
false
false
false
true
true
let lowstar_key256_t (s: Ghost.erased (Seq.seq nat32)) =
assert_norm (List.length dom + List.length ([] <: list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key256 dom [] _ _ (W.mk_prediction code_key256 dom [] ((key256_lemma s) code_key256 IA.win))
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.lowstar_key128_t
val lowstar_key128_t : s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Type0
let lowstar_key128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key128 dom [] _ _ (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 78, "end_line": 112, "start_col": 0, "start_line": 104 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s) noextract let code_key128 = GF.va_code_Keyhash_init IA.win AES_128
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall", "Vale.Stdcalls.X64.AesHash.code_key128", "Vale.Stdcalls.X64.AesHash.dom", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Vale.Stdcalls.X64.AesHash.key128_pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.Stdcalls.X64.AesHash.key128_post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.Stdcalls.X64.AesHash.key128_lemma", "Vale.Interop.Assumptions.win", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.List.Tot.Base.length", "Vale.Interop.Base.td", "Prims.list" ]
[]
false
false
false
true
true
let lowstar_key128_t (s: Ghost.erased (Seq.seq nat32)) =
assert_norm (List.length dom + List.length ([] <: list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key128 dom [] _ _ (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win))
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lookup_repr_index
val lookup_repr_index (#kt #vt: _) (repr: repr_t kt vt) (k: kt) : option (vt & nat)
val lookup_repr_index (#kt #vt: _) (repr: repr_t kt vt) (k: kt) : option (vt & nat)
let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 29, "end_line": 131, "start_col": 0, "start_line": 128 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
repr: Pulse.Lib.HashTable.Spec.repr_t kt vt -> k: kt -> FStar.Pervasives.Native.option (vt * Prims.nat)
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Pulse.Lib.HashTable.Spec.walk_get_idx", "Prims.nat", "Pulse.Lib.HashTable.Spec.canonical_index", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let lookup_repr_index #kt #vt (repr: repr_t kt vt) (k: kt) : option (vt & nat) =
let idx = canonical_index k repr in walk_get_idx repr idx k 0
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.key128_lemma
val key128_lemma : s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.AsLowStar.ValeSig.vale_sig_stdcall (Vale.Stdcalls.X64.AesHash.key128_pre s) (Vale.Stdcalls.X64.AesHash.key128_post s)
let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 131, "end_line": 98, "start_col": 0, "start_line": 98 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.AsLowStar.ValeSig.vale_sig_stdcall (Vale.Stdcalls.X64.AesHash.key128_pre s) (Vale.Stdcalls.X64.AesHash.key128_post s)
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Stdcalls.X64.AesHash.as_t", "Vale.AsLowStar.ValeSig.vale_sig_stdcall", "Vale.Stdcalls.X64.AesHash.dom", "Vale.Stdcalls.X64.AesHash.key128_pre", "Vale.Stdcalls.X64.AesHash.key128_post", "Vale.Stdcalls.X64.AesHash.key128_lemma'" ]
[]
false
false
false
false
false
let key128_lemma (s: Ghost.erased (Seq.seq nat32)) =
as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s)
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.walk_get_idx
val walk_get_idx (#kt #vt: _) (repr: repr_t kt vt) (idx: nat) (k: kt) (off: nat{off <= repr.sz}) : Tot (o: (option (vt & nat)) { match o with | Some (v, i) -> i < repr.sz /\ repr @@ i == Used k v | None -> true }) (decreases repr.sz - off)
val walk_get_idx (#kt #vt: _) (repr: repr_t kt vt) (idx: nat) (k: kt) (off: nat{off <= repr.sz}) : Tot (o: (option (vt & nat)) { match o with | Some (v, i) -> i < repr.sz /\ repr @@ i == Used k v | None -> true }) (decreases repr.sz - off)
let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 86, "start_col": 0, "start_line": 70 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx'
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
repr: Pulse.Lib.HashTable.Spec.repr_t kt vt -> idx: Prims.nat -> k: kt -> off: Prims.nat{off <= Mkrepr_t?.sz repr} -> Prims.Tot (o: FStar.Pervasives.Native.option (vt * Prims.nat) { (match o with | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ v i) -> i < Mkrepr_t?.sz repr /\ repr @@ i == Pulse.Lib.HashTable.Spec.Used k v | FStar.Pervasives.Native.None #_ -> true) <: Type0 })
Prims.Tot
[ "total", "" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Prims.op_GreaterThan", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.tuple2", "Prims.bool", "Pulse.Lib.HashTable.Spec.op_At_At", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Pulse.Lib.HashTable.Spec.walk_get_idx", "Prims.op_Addition", "FStar.Pervasives.Native.option", "Prims.op_LessThan", "Prims.eq2", "Pulse.Lib.HashTable.Spec.cell", "Pulse.Lib.HashTable.Spec.Used", "Prims.op_Modulus" ]
[ "recursion" ]
false
false
false
false
false
let rec walk_get_idx #kt #vt (repr: repr_t kt vt) (idx: nat) (k: kt) (off: nat{off <= repr.sz}) : Tot (o: (option (vt & nat)) { match o with | Some (v, i) -> i < repr.sz /\ repr @@ i == Used k v | None -> true }) (decreases repr.sz - off) =
if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v, idx') else walk_get_idx repr idx k (off + 1) | Zombie -> walk_get_idx repr idx k (off + 1)
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.all_used_not_by
val all_used_not_by (#kt #kv: _) (repr: repr_t kt kv) (idx: (n: nat{n < repr.sz})) (len: nat) (k: kt) : prop
val all_used_not_by (#kt #kv: _) (repr: repr_t kt kv) (idx: (n: nat{n < repr.sz})) (len: nat) (k: kt) : prop
let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 65, "end_line": 330, "start_col": 0, "start_line": 329 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
repr: Pulse.Lib.HashTable.Spec.repr_t kt kv -> idx: n: Prims.nat{n < Mkrepr_t?.sz repr} -> len: Prims.nat -> k: kt -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.l_Forall", "Pulse.Lib.HashTable.Spec.used_not_by", "Prims.op_Modulus", "Prims.op_Addition", "Prims.prop" ]
[]
false
false
false
false
true
let all_used_not_by #kt #kv (repr: repr_t kt kv) (idx: (n: nat{n < repr.sz})) (len: nat) (k: kt) : prop =
forall (i: nat{i < len}). used_not_by repr k ((idx + i) % repr.sz)
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lookup_index
val lookup_index (#kt #vt: _) (ht: pht_t kt vt) (k: kt) : option (vt & nat)
val lookup_index (#kt #vt: _) (ht: pht_t kt vt) (k: kt) : option (vt & nat)
let lookup_index #kt #vt (ht : pht_t kt vt) (k : kt) : option (vt & nat) = lookup_repr_index ht.repr k
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 29, "end_line": 709, "start_col": 0, "start_line": 706 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_zombie_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i:nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc (==>) { (canonical_index k repr + i) % sz == idx; ==> {} (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ==> { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_del #kt #vt #sz spec (repr : repr_t_sz kt vt sz) idx k v : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx)) = let spec' = spec -- k in let repr' = del_ repr idx in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin let Some (v', i') = lookup_repr_index repr' k' in assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then begin assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let not_full #kt #vt (r:repr_t kt vt) : Type0 = exists i. ~(Used? (r @@ i )) #set-options "--split_queries always" let rec insert_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr /\ not_full repr}) (k : kt) (v : vt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (strong_all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then ( // Impossible! table was not full let aux (i:nat{i < sz}) : Lemma (Used? (repr @@ i)) = assert (all_used_not_by repr cidx sz k); let off = (i - cidx) % sz in calc (==) { (cidx + off) % sz; == {} (cidx + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_lemma cidx sz } (cidx % sz + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_distributivity cidx (i-cidx) sz } i % sz; == { Math.Lemmas.modulo_lemma i sz } i; }; assert (Used? (repr @@ i)); () in Classical.forall_intro aux; unreachable () ) else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_used_upd spec repr off k v v'; upd_ repr idx k v end else begin assert (all_used_not_by repr cidx (off+1) k); insert_repr_walk #kt #vt #sz #spec repr k v (off+1) cidx () () end | Clean -> (**)lemma_clean_upd spec repr off k v; upd_ repr idx k v | Zombie -> match lookup_repr_index repr k with | Some (v_old,i) -> ( (**)lemma_del spec repr i k v_old; // Don't need these asserts let cidx = canonical_index k repr in assert (all_used_not_by repr cidx off k); // GM: Removing this assert, not needed now it seems //assert (if idx >= cidx then i > idx || i <= cidx else i > idx /\ i <= cidx); assert (all_used_not_by (del_ repr i) cidx off k); (**)lemma_zombie_upd #_ #_ #sz (spec -- k) (del_ repr i) off k v; upd_ (del_ repr i) idx k v ) | None -> ( (**)lemma_zombie_upd spec repr off k v; upd_ repr idx k v ) let insert_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (v : vt) : Pure (r':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) r' /\ repr_related repr r' }) (requires not_full repr) (ensures fun _ -> True) = let cidx = canonical_index k repr in let res = insert_repr_walk #kt #vt #sz #spec repr k v 0 cidx () () in res let rec delete_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec -- k) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then repr // If we reach this, the element was not in the table else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_del spec repr idx k v'; del_ repr idx end else begin assert (all_used_not_by repr cidx (off+1) k); delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () end | Clean -> repr | Zombie -> delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () let delete_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) : r':repr_t_sz kt vt sz{ pht_models (spec -- k) r' /\ repr_related repr r' } = let cidx = canonical_index k repr in let res = delete_repr_walk #kt #vt #sz #spec repr k 0 cidx () () in res // TODO: This states we can only insert on a non-full table, // but that's only if the key we want to insert is not already present, // so it's stronger than it should be. This is anyway perhaps not important // for this pure implementation, as the Pulse implementation could always // keep one cell free and trivially satisfy this invariant. let insert #kt #vt (ht : pht_t kt vt{not_full ht.repr}) (k : kt) (v : vt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec ++ (k,v)) } = { ht with spec = Ghost.hide (ht.spec ++ (k,v)); repr = insert_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k v; inv = () } let delete #kt #vt (ht : pht_t kt vt) (k : kt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec -- k) } = { ht with spec = Ghost.hide (ht.spec -- k); repr = delete_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k; inv = () } let lookup #kt #vt (ht : pht_t kt vt) (k : kt) : o:(option vt){o == lookup_spec ht.spec k} = lookup_repr ht.repr k
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
ht: Pulse.Lib.HashTable.Spec.pht_t kt vt -> k: kt -> FStar.Pervasives.Native.option (vt * Prims.nat)
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.pht_t", "Pulse.Lib.HashTable.Spec.lookup_repr_index", "Pulse.Lib.HashTable.Spec.__proj__Mkpht_t__item__repr", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Prims.nat" ]
[]
false
false
false
false
false
let lookup_index #kt #vt (ht: pht_t kt vt) (k: kt) : option (vt & nat) =
lookup_repr_index ht.repr k
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lookup_repr
val lookup_repr (#kt #vt: _) (repr: repr_t kt vt) (k: kt) : option vt
val lookup_repr (#kt #vt: _) (repr: repr_t kt vt) (k: kt) : option vt
let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 19, "end_line": 124, "start_col": 0, "start_line": 122 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
repr: Pulse.Lib.HashTable.Spec.repr_t kt vt -> k: kt -> FStar.Pervasives.Native.option vt
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Pulse.Lib.HashTable.Spec.walk", "Prims.nat", "Pulse.Lib.HashTable.Spec.canonical_index", "FStar.Pervasives.Native.option" ]
[]
false
false
false
false
false
let lookup_repr #kt #vt (repr: repr_t kt vt) (k: kt) : option vt =
let idx = canonical_index k repr in walk repr idx k 0
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.strong_all_used_not_by
val strong_all_used_not_by (#kt #kv: _) (repr: repr_t kt kv) (idx: (n: nat{n < repr.sz})) (len: nat) (k: kt) : prop
val strong_all_used_not_by (#kt #kv: _) (repr: repr_t kt kv) (idx: (n: nat{n < repr.sz})) (len: nat) (k: kt) : prop
let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 72, "end_line": 333, "start_col": 0, "start_line": 332 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
repr: Pulse.Lib.HashTable.Spec.repr_t kt kv -> idx: n: Prims.nat{n < Mkrepr_t?.sz repr} -> len: Prims.nat -> k: kt -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.l_Forall", "Pulse.Lib.HashTable.Spec.strong_used_not_by", "Prims.op_Modulus", "Prims.op_Addition", "Prims.prop" ]
[]
false
false
false
false
true
let strong_all_used_not_by #kt #kv (repr: repr_t kt kv) (idx: (n: nat{n < repr.sz})) (len: nat) (k: kt) : prop =
forall (i: nat{i < len}). strong_used_not_by repr k ((idx + i) % repr.sz)
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.key128_lemma'
val key128_lemma' (s: Ghost.erased (Seq.seq nat32)) (code: V.va_code) (_win: bool) (input_b output_b: b128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b)))
val key128_lemma' (s: Ghost.erased (Seq.seq nat32)) (code: V.va_code) (_win: bool) (input_b output_b: b128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b)))
let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 95, "start_col": 0, "start_line": 74 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20"
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> code: Vale.X64.Decls.va_code -> _win: Prims.bool -> input_b: Vale.Stdcalls.X64.AesHash.b128 -> output_b: Vale.Stdcalls.X64.AesHash.b128 -> va_s0: Vale.X64.Decls.va_state -> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel)
Prims.Ghost
[]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.X64.Decls.va_code", "Prims.bool", "Vale.Stdcalls.X64.AesHash.b128", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "FStar.Pervasives.Native.tuple2", "Vale.X64.State.vale_state", "Vale.AES.X64.GF128_Init.va_lemma_Keyhash_init", "Vale.Interop.Assumptions.win", "Vale.AES.AES_common_s.AES_128", "FStar.Ghost.reveal", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.Stdcalls.X64.AesHash.key128_pre", "Prims.l_and", "Vale.X64.Decls.eval_code", "Vale.AsLowStar.ValeSig.vale_calling_conventions_stdcall", "Vale.Stdcalls.X64.AesHash.key128_post", "Vale.X64.Memory.buffer_writeable" ]
[]
false
false
false
false
false
let key128_lemma' (s: Ghost.erased (Seq.seq nat32)) (code: V.va_code) (_win: bool) (input_b output_b: b128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b))) =
let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f)
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.lowstar_key256
val lowstar_key256 (s: Ghost.erased (Seq.seq nat32)) : lowstar_key256_t s
val lowstar_key256 (s: Ghost.erased (Seq.seq nat32)) : lowstar_key256_t s
let lowstar_key256 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key256_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key256 dom (W.mk_prediction code_key256 dom [] ((key256_lemma s) code_key256 IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 78, "end_line": 197, "start_col": 0, "start_line": 192 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s) noextract let code_key128 = GF.va_code_Keyhash_init IA.win AES_128 [@__reduce__] noextract let lowstar_key128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key128 dom [] _ _ (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_key128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key128 dom (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key256_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key256_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key256_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key256_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key256_pre s) (key256_post s)) (key256_lemma' s) noextract let code_key256 = GF.va_code_Keyhash_init IA.win AES_256 [@__reduce__] noextract let lowstar_key256_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key256 dom [] _ _ (W.mk_prediction code_key256 dom [] ((key256_lemma s) code_key256 IA.win)) (* And here's the gcm wrapper itself *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.Stdcalls.X64.AesHash.lowstar_key256_t s
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Interop.X64.wrap_weak_stdcall", "Vale.Stdcalls.X64.AesHash.code_key256", "Vale.Stdcalls.X64.AesHash.dom", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.Stdcalls.X64.AesHash.key256_pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.Stdcalls.X64.AesHash.key256_post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.Stdcalls.X64.AesHash.key256_lemma", "Vale.Interop.Assumptions.win", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.List.Tot.Base.length", "Vale.Interop.Base.td", "Prims.list", "Vale.Stdcalls.X64.AesHash.lowstar_key256_t" ]
[]
false
false
false
false
false
let lowstar_key256 (s: Ghost.erased (Seq.seq nat32)) : lowstar_key256_t s =
assert_norm (List.length dom + List.length ([] <: list arg) <= 4); IX64.wrap_weak_stdcall code_key256 dom (W.mk_prediction code_key256 dom [] ((key256_lemma s) code_key256 IA.win))
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.key256_lemma
val key256_lemma : s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.AsLowStar.ValeSig.vale_sig_stdcall (Vale.Stdcalls.X64.AesHash.key256_pre s) (Vale.Stdcalls.X64.AesHash.key256_post s)
let key256_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key256_pre s) (key256_post s)) (key256_lemma' s)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 131, "end_line": 174, "start_col": 0, "start_line": 174 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s) noextract let code_key128 = GF.va_code_Keyhash_init IA.win AES_128 [@__reduce__] noextract let lowstar_key128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key128 dom [] _ _ (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_key128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key128 dom (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key256_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key256_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key256_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.AsLowStar.ValeSig.vale_sig_stdcall (Vale.Stdcalls.X64.AesHash.key256_pre s) (Vale.Stdcalls.X64.AesHash.key256_post s)
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Stdcalls.X64.AesHash.as_t", "Vale.AsLowStar.ValeSig.vale_sig_stdcall", "Vale.Stdcalls.X64.AesHash.dom", "Vale.Stdcalls.X64.AesHash.key256_pre", "Vale.Stdcalls.X64.AesHash.key256_post", "Vale.Stdcalls.X64.AesHash.key256_lemma'" ]
[]
false
false
false
false
false
let key256_lemma (s: Ghost.erased (Seq.seq nat32)) =
as_t #(VSig.vale_sig_stdcall (key256_pre s) (key256_post s)) (key256_lemma' s)
false
Steel.ST.HigherArray.fst
Steel.ST.HigherArray.gather
val gather (#opened: _) (#elt: Type) (a: array elt) (#x1: Seq.seq elt) (p1: P.perm) (#x2: Seq.seq elt) (p2: P.perm) : STGhost unit opened (pts_to a p1 x1 `star` pts_to a p2 x2) (fun _ -> pts_to a (p1 `P.sum_perm` p2) x1) (True) (fun _ -> x1 == x2)
val gather (#opened: _) (#elt: Type) (a: array elt) (#x1: Seq.seq elt) (p1: P.perm) (#x2: Seq.seq elt) (p2: P.perm) : STGhost unit opened (pts_to a p1 x1 `star` pts_to a p2 x2) (fun _ -> pts_to a (p1 `P.sum_perm` p2) x1) (True) (fun _ -> x1 == x2)
let gather a #x1 p1 #x2 p2 = elim_pts_to a p1 x1; elim_pts_to a p2 x2; let _ = R.gather (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 p1) (mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) x2 p2) in mk_carrier_gather (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 x2 p1 p2; mk_carrier_valid_sum_perm (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 p1 p2; intro_pts_to a (p1 `P.sum_perm` p2) x1
{ "file_name": "lib/steel/Steel.ST.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 40, "end_line": 409, "start_col": 0, "start_line": 399 }
(* Copyright 2022 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 Steel.ST.HigherArray module P = Steel.PCMFrac module R = Steel.ST.PCMReference module M = FStar.Map module PM = Steel.PCMMap [@@noextract_to "krml"] let index_t (len: Ghost.erased nat) : Tot Type0 = (i: nat { i < len }) [@@noextract_to "krml"] let carrier (elt: Type u#a) (len: Ghost.erased nat) : Tot Type = PM.map (index_t len) (P.fractional elt) [@@noextract_to "krml"] let pcm (elt: Type u#a) (len: Ghost.erased nat) : Tot (P.pcm (carrier elt len)) = PM.pointwise (index_t len) (P.pcm_frac #elt) [@@noextract_to "krml"] let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.one let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.composable [@@noextract_to "krml"] let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.op [@@noextract_to "krml"] let mk_carrier (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p: P.perm) : Tot (carrier elt len) = let f (i: nat) : Tot (P.fractional elt) = if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s then None else Some (Seq.index s (i - offset), p) in M.map_literal f let mk_carrier_inj (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: P.perm) : Lemma (requires ( mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\ offset + Seq.length s1 <= len /\ offset + Seq.length s2 <= len )) (ensures ( s1 `Seq.equal` s2 /\ (Seq.length s1 > 0 ==> p1 == p2) )) = assert (forall (i: nat) . i < Seq.length s1 ==> (M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1))); assert (forall (i: nat) . i < Seq.length s2 ==> M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2)) [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: US.t & ref _ (pcm elt (US.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = US.v (dfst b) [@@noextract_to "krml"] noeq type ptr (elt: Type u#a) : Type0 = { base_len: Ghost.erased US.t; // U32.t to prove that A.read, A.write offset computation does not overflow. TODO: replace U32.t with size_t base: (r: ref _ (pcm elt (US.v base_len)) { core_ref_is_null r ==> US.v base_len == 0 }); offset: (offset: nat { offset <= US.v base_len }); } let null_ptr a = { base_len = 0sz; base = null #_ #(pcm a 0) ; offset = 0 } let is_null_ptr p = is_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr _ = () let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: P.perm) : Tot prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.P.v <=. one)) [@__reduce__] let pts_to0 (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : Tot vprop = R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p) `star` pure ( valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let pts_to (#elt: Type u#1) (a: array elt) ([@@@ smt_fallback ] p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop = pts_to0 a p s // this lemma is necessary because Steel.PCMReference is marked unfold let change_r_pts_to (#opened: _) (#carrier: Type u#1) (#pcm: P.pcm carrier) (p: ref carrier pcm) (v: carrier) (#carrier': Type u#1) (#pcm': P.pcm carrier') (p': ref carrier' pcm') (v': carrier') : STGhost unit opened (R.pts_to p v) (fun _ -> R.pts_to p' v') (// keep on distinct lines for error messages carrier == carrier' /\ pcm == pcm' /\ p == p' /\ v == v') (fun _ -> True) = rewrite (R.pts_to p v) (R.pts_to p' v') let intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened (R.pts_to (ptr_of a).base v) (fun _ -> pts_to a p s) ( v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\ valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) (fun _ -> True) = change_r_pts_to (ptr_of a).base v (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p); intro_pure _; rewrite (pts_to0 a p s) (pts_to a p s) let elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened (pts_to a p s) (fun _ -> R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p)) (True) (fun _ -> valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) = rewrite (pts_to a p s) (pts_to0 a p s); elim_pure _ let pts_to_length a s = elim_pts_to a _ s; intro_pts_to a _ s let pts_to_not_null a s = elim_pts_to a _ s; R.pts_to_not_null _ _; intro_pts_to a _ s let mk_carrier_joinable (#elt: Type) (len: nat) (offset: nat) (s1: Seq.seq elt) (p1: P.perm) (s2: Seq.seq elt) (p2: P.perm) : Lemma (requires ( offset + Seq.length s1 <= len /\ Seq.length s1 == Seq.length s2 /\ P.joinable (pcm elt len) (mk_carrier len offset s1 p1) (mk_carrier len offset s2 p2) )) (ensures ( s1 `Seq.equal` s2 )) = let lem (i: nat { 0 <= i /\ i < Seq.length s1 }) : Lemma (Seq.index s1 i == Seq.index s2 i) [SMTPat (Seq.index s1 i); SMTPat (Seq.index s2 i)] = assert ( forall z . ( P.compatible (pcm elt len) (mk_carrier len offset s1 p1) z /\ P.compatible (pcm elt len) (mk_carrier len offset s2 p2) z ) ==> begin match M.sel z (offset + i) with | None -> False | Some (v, _) -> v == Seq.index s1 i /\ v == Seq.index s2 i end ) in () let pure_star_interp' (p:slprop u#a) (q:prop) (m:mem) : Lemma (interp (p `Steel.Memory.star` Steel.Memory.pure q) m <==> interp p m /\ q) = pure_star_interp p q m; emp_unit p let pts_to_inj a p1 s1 p2 s2 m = Classical.forall_intro reveal_pure; pure_star_interp' (hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1))) ( valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s1) p1 /\ Seq.length s1 == length a ) m; pure_star_interp' (hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2))) ( valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s2) p2 /\ Seq.length s2 == length a ) m; pts_to_join (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1) (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2) m; mk_carrier_joinable (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1 s2 p2 [@@noextract_to "krml"] let malloc0 (#elt: Type) (x: elt) (n: US.t) : ST (array elt) emp (fun a -> pts_to a P.full_perm (Seq.create (US.v n) x)) (True) (fun a -> length a == US.v n /\ base_len (base (ptr_of a)) == US.v n ) = let c : carrier elt (US.v n) = mk_carrier (US.v n) 0 (Seq.create (US.v n) x) P.full_perm in let base : ref (carrier elt (US.v n)) (pcm elt (US.v n)) = R.alloc c in R.pts_to_not_null base _; let p = { base_len = n; base = base; offset = 0; } in let a = (| p, Ghost.hide (US.v n) |) in change_r_pts_to base c (ptr_of a).base c; intro_pts_to a P.full_perm (Seq.create (US.v n) x); return a let malloc_ptr x n = let a = malloc0 x n in let (| p, _ |) = a in rewrite (pts_to _ _ _) (pts_to (| p, Ghost.hide (US.v n) |) _ _); return p [@@noextract_to "krml"] let free0 (#elt: Type) (#s: Ghost.erased (Seq.seq elt)) (a: array elt) : ST unit (pts_to a P.full_perm s) (fun _ -> emp) ( length a == base_len (base (ptr_of a)) ) (fun _ -> True) = drop (pts_to a _ _) let free_ptr a = free0 _ let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: P.perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (P.sum_perm p1 p2) let mk_carrier_share (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: P.perm) : Lemma (requires (valid_sum_perm len offset (Seq.length s) p1 p2)) (ensures ( let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 /\ mk_carrier len offset s (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2) )) = () let share #_ #_ #x a p p1 p2 = elim_pts_to a p x; mk_carrier_share (US.v (ptr_of a).base_len) (ptr_of a).offset x p1 p2; R.split (ptr_of a).base _ (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p1) (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p2); intro_pts_to a p1 x; intro_pts_to a p2 x let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: P.perm) : Lemma (requires ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) (ensures ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `P.sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `P.sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 )) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `P.sum_perm` p2) (p1 `P.sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: P.perm) : Lemma (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (P.composable (M.sel c1 offset) (M.sel c2 offset) <==> valid_perm len offset (Seq.length s) (P.sum_perm p1 p2)) else ()
{ "checked_file": "/", "dependencies": [ "Steel.ST.PCMReference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.PCMMap.fst.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Steel.PCMMap", "short_module": "PM" }, { "abbrev": true, "full_module": "FStar.Map", "short_module": "M" }, { "abbrev": true, "full_module": "Steel.ST.PCMReference", "short_module": "R" }, { "abbrev": true, "full_module": "Steel.PCMFrac", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
a: Steel.ST.HigherArray.array elt -> p1: Steel.FractionalPermission.perm -> p2: Steel.FractionalPermission.perm -> Steel.ST.Effect.Ghost.STGhost Prims.unit
Steel.ST.Effect.Ghost.STGhost
[]
[]
[ "Steel.Memory.inames", "Steel.ST.HigherArray.array", "FStar.Seq.Base.seq", "Steel.FractionalPermission.perm", "Steel.ST.HigherArray.intro_pts_to", "FStar.PCM.op", "Steel.ST.HigherArray.carrier", "FStar.Ghost.hide", "Prims.nat", "FStar.SizeT.v", "FStar.Ghost.reveal", "FStar.SizeT.t", "Steel.ST.HigherArray.__proj__Mkptr__item__base_len", "Steel.ST.HigherArray.ptr_of", "Steel.ST.HigherArray.pcm", "Steel.ST.HigherArray.mk_carrier", "Steel.ST.HigherArray.__proj__Mkptr__item__offset", "Steel.FractionalPermission.sum_perm", "Prims.unit", "Steel.ST.HigherArray.mk_carrier_valid_sum_perm", "Steel.ST.HigherArray.mk_carrier_gather", "FStar.PCM.composable", "Steel.ST.PCMReference.gather", "Steel.ST.HigherArray.__proj__Mkptr__item__base", "Steel.ST.HigherArray.elim_pts_to" ]
[]
false
true
false
false
false
let gather a #x1 p1 #x2 p2 =
elim_pts_to a p1 x1; elim_pts_to a p2 x2; let _ = R.gather (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 p1) (mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) x2 p2) in mk_carrier_gather (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 x2 p1 p2; mk_carrier_valid_sum_perm (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 p1 p2; intro_pts_to a (p1 `P.sum_perm` p2) x1
false
PulseByExample.fst
PulseByExample.fstar_five
val fstar_five:int
val fstar_five:int
let fstar_five : int = 5
{ "file_name": "share/steel/examples/pulse/by-example/PulseByExample.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 24, "end_line": 30, "start_col": 0, "start_line": 30 }
(* Copyright 2023 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 PulseByExample module PM = Pulse.Main open Pulse.Lib.Core (* Things to note: - syntax extension notation - 1 or more arguments - precondition and postcondition *)
{ "checked_file": "/", "dependencies": [ "Pulse.Main.fsti.checked", "Pulse.Lib.Reference.fsti.checked", "Pulse.Lib.Core.fsti.checked", "Pulse.Lib.BoundedIntegers.fst.checked", "Pulse.Lib.Array.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "PulseByExample.fst" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Main", "short_module": "PM" }, { "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 fstar_five:int =
5
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.aunb_shrink
val aunb_shrink (#kt #kv: _) (repr: repr_t kt kv) (idx: (n: nat{n < repr.sz})) (off: nat) (k: kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx + 1) % repr.sz) (off - 1) k)
val aunb_shrink (#kt #kv: _) (repr: repr_t kt kv) (idx: (n: nat{n < repr.sz})) (off: nat) (k: kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx + 1) % repr.sz) (off - 1) k)
let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; ()
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 6, "end_line": 361, "start_col": 0, "start_line": 340 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = ()
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
repr: Pulse.Lib.HashTable.Spec.repr_t kt kv -> idx: n: Prims.nat{n < Mkrepr_t?.sz repr} -> off: Prims.nat -> k: kt -> FStar.Pervasives.Lemma (requires Pulse.Lib.HashTable.Spec.all_used_not_by repr idx off k /\ off > 0) (ensures Pulse.Lib.HashTable.Spec.all_used_not_by repr ((idx + 1) % Mkrepr_t?.sz repr) (off - 1) k)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.unit", "FStar.Classical.forall_intro", "Prims.op_Subtraction", "Pulse.Lib.HashTable.Spec.used_not_by", "Prims.op_Modulus", "Prims.op_Addition", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims._assert", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.Cons", "FStar.Preorder.relation", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.modulo_add", "Prims.op_Equality", "FStar.Math.Lemmas.lemma_mod_twice", "Prims.pos", "Prims.l_and", "Pulse.Lib.HashTable.Spec.all_used_not_by", "Prims.op_GreaterThan" ]
[]
false
false
true
false
false
let aunb_shrink #kt #kv (repr: repr_t kt kv) (idx: (n: nat{n < repr.sz})) (off: nat) (k: kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx + 1) % repr.sz) (off - 1) k) =
let sz = repr.sz in let sidx = (idx + 1) % sz in let open FStar.Math.Lemmas in let aux (i: nat{i < off - 1}) : Lemma (used_not_by repr k ((sidx + i) % sz)) = assert (used_not_by repr k ((idx + (i + 1)) % repr.sz)); calc ( == ) { (sidx + i) % sz; ( == ) { () } (((idx + 1) % sz) + i) % sz; ( == ) { (lemma_mod_twice (idx + 1) sz; assert (sidx % sz = (idx + 1) % sz); modulo_add sz i sidx (idx + 1)) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx + i) % sz)); () in Classical.forall_intro #(i: nat{i < off - 1}) aux; ()
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.delete_repr
val delete_repr (#kt #vt #sz: _) (#spec: erased (spec_t kt vt)) (repr: repr_t_sz kt vt sz {pht_models spec repr}) (k: kt) : r': repr_t_sz kt vt sz {pht_models (spec -- k) r' /\ repr_related repr r'}
val delete_repr (#kt #vt #sz: _) (#spec: erased (spec_t kt vt)) (repr: repr_t_sz kt vt sz {pht_models spec repr}) (k: kt) : r': repr_t_sz kt vt sz {pht_models (spec -- k) r' /\ repr_related repr r'}
let delete_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) : r':repr_t_sz kt vt sz{ pht_models (spec -- k) r' /\ repr_related repr r' } = let cidx = canonical_index k repr in let res = delete_repr_walk #kt #vt #sz #spec repr k 0 cidx () () in res
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 680, "start_col": 0, "start_line": 671 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_zombie_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i:nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc (==>) { (canonical_index k repr + i) % sz == idx; ==> {} (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ==> { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_del #kt #vt #sz spec (repr : repr_t_sz kt vt sz) idx k v : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx)) = let spec' = spec -- k in let repr' = del_ repr idx in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin let Some (v', i') = lookup_repr_index repr' k' in assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then begin assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let not_full #kt #vt (r:repr_t kt vt) : Type0 = exists i. ~(Used? (r @@ i )) #set-options "--split_queries always" let rec insert_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr /\ not_full repr}) (k : kt) (v : vt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (strong_all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then ( // Impossible! table was not full let aux (i:nat{i < sz}) : Lemma (Used? (repr @@ i)) = assert (all_used_not_by repr cidx sz k); let off = (i - cidx) % sz in calc (==) { (cidx + off) % sz; == {} (cidx + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_lemma cidx sz } (cidx % sz + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_distributivity cidx (i-cidx) sz } i % sz; == { Math.Lemmas.modulo_lemma i sz } i; }; assert (Used? (repr @@ i)); () in Classical.forall_intro aux; unreachable () ) else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_used_upd spec repr off k v v'; upd_ repr idx k v end else begin assert (all_used_not_by repr cidx (off+1) k); insert_repr_walk #kt #vt #sz #spec repr k v (off+1) cidx () () end | Clean -> (**)lemma_clean_upd spec repr off k v; upd_ repr idx k v | Zombie -> match lookup_repr_index repr k with | Some (v_old,i) -> ( (**)lemma_del spec repr i k v_old; // Don't need these asserts let cidx = canonical_index k repr in assert (all_used_not_by repr cidx off k); // GM: Removing this assert, not needed now it seems //assert (if idx >= cidx then i > idx || i <= cidx else i > idx /\ i <= cidx); assert (all_used_not_by (del_ repr i) cidx off k); (**)lemma_zombie_upd #_ #_ #sz (spec -- k) (del_ repr i) off k v; upd_ (del_ repr i) idx k v ) | None -> ( (**)lemma_zombie_upd spec repr off k v; upd_ repr idx k v ) let insert_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (v : vt) : Pure (r':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) r' /\ repr_related repr r' }) (requires not_full repr) (ensures fun _ -> True) = let cidx = canonical_index k repr in let res = insert_repr_walk #kt #vt #sz #spec repr k v 0 cidx () () in res let rec delete_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec -- k) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then repr // If we reach this, the element was not in the table else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_del spec repr idx k v'; del_ repr idx end else begin assert (all_used_not_by repr cidx (off+1) k); delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () end | Clean -> repr | Zombie -> delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () ()
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
repr: Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz {Pulse.Lib.HashTable.Spec.pht_models (FStar.Ghost.reveal spec) repr} -> k: kt -> r': Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz { Pulse.Lib.HashTable.Spec.pht_models (FStar.Ghost.reveal spec -- k) r' /\ Pulse.Lib.HashTable.Spec.repr_related repr r' }
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Prims.pos", "FStar.Ghost.erased", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.repr_t_sz", "Pulse.Lib.HashTable.Spec.pht_models", "FStar.Ghost.reveal", "Prims.l_and", "Pulse.Lib.HashTable.Spec.op_Subtraction_Subtraction", "Pulse.Lib.HashTable.Spec.repr_related", "Pulse.Lib.HashTable.Spec.delete_repr_walk", "Prims.nat", "Pulse.Lib.HashTable.Spec.canonical_index" ]
[]
false
false
false
false
false
let delete_repr #kt #vt #sz (#spec: erased (spec_t kt vt)) (repr: repr_t_sz kt vt sz {pht_models spec repr}) (k: kt) : r': repr_t_sz kt vt sz {pht_models (spec -- k) r' /\ repr_related repr r'} =
let cidx = canonical_index k repr in let res = delete_repr_walk #kt #vt #sz #spec repr k 0 cidx () () in res
false
PulseByExample.fst
PulseByExample.pulse_five_in_fstar
val pulse_five_in_fstar : Pulse.Lib.Core.stt Prims.int Pulse.Lib.Core.emp (fun x -> Pulse.Lib.Core.pure (x == 5))
let pulse_five_in_fstar = five ()
{ "file_name": "share/steel/examples/pulse/by-example/PulseByExample.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 33, "end_line": 42, "start_col": 0, "start_line": 42 }
(* Copyright 2023 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 PulseByExample module PM = Pulse.Main open Pulse.Lib.Core (* Things to note: - syntax extension notation - 1 or more arguments - precondition and postcondition *) //SNIPPET_START: five let fstar_five : int = 5 ```pulse fn five () requires emp returns n:int ensures pure (n == 5) { fstar_five } ```
{ "checked_file": "/", "dependencies": [ "Pulse.Main.fsti.checked", "Pulse.Lib.Reference.fsti.checked", "Pulse.Lib.Core.fsti.checked", "Pulse.Lib.BoundedIntegers.fst.checked", "Pulse.Lib.Array.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "PulseByExample.fst" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Main", "short_module": "PM" }, { "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
Pulse.Lib.Core.stt Prims.int Pulse.Lib.Core.emp (fun x -> Pulse.Lib.Core.pure (x == 5))
Prims.Tot
[ "total" ]
[]
[ "PulseByExample.five" ]
[]
false
false
false
false
false
let pulse_five_in_fstar =
five ()
false
Steel.HigherReference.fst
Steel.HigherReference.cas_action
val cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:erased t) (v_old:t) (v_new:t) : action_except (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
val cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:erased t) (v_old:t) (v_new:t) : action_except (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
let cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:Ghost.erased t) (v_old:t) (v_new:t) (fr:slprop) : MstTot (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (cas_provides r v v_new) fr (fun _ -> True) (fun _ _ _ -> True) = let m0 : full_mem = NMSTTotal.get () in let fv = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let fv' = Some (v_new, full_perm) in assert (interp Mem.(pts_to_sl r full_perm v `star` fr `star` locks_invariant uses m0) m0); assert (interp Mem.(pts_to r fv `star` pure (perm_ok full_perm) `star` fr `star` locks_invariant uses m0) m0); cas_action_helper (Mem.pts_to r fv) (Mem.pure (perm_ok full_perm)) fr (locks_invariant uses m0) m0; assert (interp Mem.((pts_to r fv `star` pure (perm_ok full_perm)) `star` locks_invariant uses m0) m0); let fv_actual = Mem.frame (Mem.pure (perm_ok full_perm)) (sel_action uses r fv) fr in assert (compatible pcm_frac fv fv_actual); let Some (v', p) = fv_actual in assert (v == Ghost.hide v'); assert (p == full_perm); let b = if eq v' v_old then (Mem.frame (Mem.pure (perm_ok full_perm)) (upd_action uses r fv fv') fr; true) else false in b
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 6, "end_line": 385, "start_col": 0, "start_line": 349 }
(* Copyright 2020 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 Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in calc (equiv) { p `star` q; (equiv) { star_commutative p q } q `star` p; (equiv) { equiv_extensional_on_star q r p } r `star` p; (equiv) { star_commutative p r } p `star` r; } let cas_action_helper (p q r s:slprop) (m:mem) : Lemma (requires interp Mem.(p `star` q `star` r `star` s) m) (ensures interp Mem.(p `star` q `star` s) m) = let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { p `star` q `star` r `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } (p `star` q `star` s) `star` r; }; assert (interp ((p `star` q `star` s) `star` r) m); affine_star (p `star` q `star` s) r m
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "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
eq: (x: t -> y: t -> b: Prims.bool{b <==> x == y}) -> r: Steel.HigherReference.ref t -> v: FStar.Ghost.erased t -> v_old: t -> v_new: t -> Steel.Memory.action_except (b: Prims.bool{b <==> FStar.Ghost.reveal v == v_old}) uses (Steel.HigherReference.pts_to_sl r Steel.FractionalPermission.full_perm (FStar.Ghost.reveal v) ) (fun b -> (match b with | true -> Steel.HigherReference.pts_to_sl r Steel.FractionalPermission.full_perm v_new | _ -> Steel.HigherReference.pts_to_sl r Steel.FractionalPermission.full_perm (FStar.Ghost.reveal v)) <: Steel.Memory.slprop)
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Prims.l_iff", "Prims.b2t", "Prims.eq2", "Steel.Memory.inames", "Steel.HigherReference.ref", "FStar.Ghost.erased", "Steel.Memory.slprop", "Steel.FractionalPermission.perm", "FStar.Ghost.reveal", "Prims.unit", "Steel.Memory.frame", "Steel.Memory.pts_to", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac", "Steel.Memory.mem", "Prims.l_True", "Prims.prop", "Steel.Memory.pure", "Steel.HigherReference.perm_ok", "Steel.FractionalPermission.full_perm", "Steel.Memory.upd_action", "Prims._assert", "FStar.Ghost.hide", "FStar.PCM.compatible", "Steel.Memory.sel_action", "Steel.Memory.interp", "Steel.Memory.star", "Steel.Memory.locks_invariant", "Steel.HigherReference.cas_action_helper", "Steel.HigherReference.pts_to_sl", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Steel.Memory.full_mem", "FStar.NMSTTotal.get", "Steel.Memory.mem_evolves", "Steel.HigherReference.cas_provides" ]
[]
false
false
false
false
false
let cas_action (#t: Type) (eq: (x: t -> y: t -> b: bool{b <==> (x == y)})) (#uses: inames) (r: ref t) (v: Ghost.erased t) (v_old v_new: t) (fr: slprop) : MstTot (b: bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (cas_provides r v v_new) fr (fun _ -> True) (fun _ _ _ -> True) =
let m0:full_mem = NMSTTotal.get () in let fv = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let fv' = Some (v_new, full_perm) in assert (interp Mem.(((pts_to_sl r full_perm v) `star` fr) `star` (locks_invariant uses m0)) m0); assert (interp Mem.((((pts_to r fv) `star` (pure (perm_ok full_perm))) `star` fr) `star` (locks_invariant uses m0)) m0); cas_action_helper (Mem.pts_to r fv) (Mem.pure (perm_ok full_perm)) fr (locks_invariant uses m0) m0; assert (interp Mem.(((pts_to r fv) `star` (pure (perm_ok full_perm))) `star` (locks_invariant uses m0)) m0); let fv_actual = Mem.frame (Mem.pure (perm_ok full_perm)) (sel_action uses r fv) fr in assert (compatible pcm_frac fv fv_actual); let Some (v', p) = fv_actual in assert (v == Ghost.hide v'); assert (p == full_perm); let b = if eq v' v_old then (Mem.frame (Mem.pure (perm_ok full_perm)) (upd_action uses r fv fv') fr; true) else false in b
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lemma_walk_from_canonical_all_used
val lemma_walk_from_canonical_all_used (#kt #kv: _) (repr: repr_t kt kv) (off: nat{off < repr.sz}) (k v: _) : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v)
val lemma_walk_from_canonical_all_used (#kt #kv: _) (repr: repr_t kt kv) (off: nat{off < repr.sz}) (k v: _) : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v)
let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); ()
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 4, "end_line": 388, "start_col": 0, "start_line": 364 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; ()
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
repr: Pulse.Lib.HashTable.Spec.repr_t kt kv -> off: Prims.nat{off < Mkrepr_t?.sz repr} -> k: kt -> v: kv -> FStar.Pervasives.Lemma (requires Pulse.Lib.HashTable.Spec.all_used_not_by repr (Pulse.Lib.HashTable.Spec.canonical_index k repr) off k /\ repr @@ (Pulse.Lib.HashTable.Spec.canonical_index k repr + off) % Mkrepr_t?.sz repr == Pulse.Lib.HashTable.Spec.Used k v) (ensures Pulse.Lib.HashTable.Spec.lookup_repr repr k == FStar.Pervasives.Native.Some v)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Pervasives.Native.option", "Pulse.Lib.HashTable.Spec.lookup_repr", "FStar.Pervasives.Native.Some", "Pulse.Lib.HashTable.Spec.walk", "Prims.int", "Prims.op_Modulus", "FStar.Math.Lemmas.modulo_lemma", "Prims.op_LessThanOrEqual", "Prims.squash", "Pulse.Lib.HashTable.Spec.all_used_not_by", "Prims.op_Addition", "Prims.op_Subtraction", "Prims.l_True", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_Equality", "Prims.l_or", "Prims.bool", "Pulse.Lib.HashTable.Spec.aunb_shrink", "Prims.op_GreaterThanOrEqual", "FStar.Math.Lemmas.modulo_distributivity", "Pulse.Lib.HashTable.Spec.canonical_index", "Prims.pos", "Prims.l_and", "Pulse.Lib.HashTable.Spec.cell", "Pulse.Lib.HashTable.Spec.op_At_At", "Pulse.Lib.HashTable.Spec.Used" ]
[]
false
false
true
false
false
let lemma_walk_from_canonical_all_used #kt #kv (repr: repr_t kt kv) (off: nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) =
let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off': nat{off' <= off}) (_: squash (all_used_not_by repr ((cidx + off') % sz) (off - off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else (Math.Lemmas.modulo_distributivity (cidx + off') 1 sz; assert (sz >= 2); Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx + off' + 1) % sz); aunb_shrink repr ((cidx + off') % sz) (off - off') k; aux (off' + 1) ()) in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); ()
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.walk_get_idx_upd
val walk_get_idx_upd (#kt #vt: _) (repr1 repr2: repr_t kt vt) (idx: nat) (k: kt) (off: nat{off <= repr1.sz}) (idx': nat{idx' < repr1.sz /\ Used? (repr1 @@ idx')}) (v: vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off)
val walk_get_idx_upd (#kt #vt: _) (repr1 repr2: repr_t kt vt) (idx: nat) (k: kt) (off: nat{off <= repr1.sz}) (idx': nat{idx' < repr1.sz /\ Used? (repr1 @@ idx')}) (v: vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off)
let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 65, "end_line": 112, "start_col": 0, "start_line": 88 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
repr1: Pulse.Lib.HashTable.Spec.repr_t kt vt -> repr2: Pulse.Lib.HashTable.Spec.repr_t kt vt -> idx: Prims.nat -> k: kt -> off: Prims.nat{off <= Mkrepr_t?.sz repr1} -> idx': Prims.nat{idx' < Mkrepr_t?.sz repr1 /\ Used? (repr1 @@ idx')} -> v: vt -> FStar.Pervasives.Lemma (requires (let _ = repr1 @@ idx' in (let Pulse.Lib.HashTable.Spec.Used #_ #_ k' _ = _ in repr2 == Pulse.Lib.HashTable.Spec.Mkrepr_t (Mkrepr_t?.sz repr1) (FStar.Seq.Base.upd (Mkrepr_t?.seq repr1) idx' (Pulse.Lib.HashTable.Spec.Used k' v)) (Mkrepr_t?.hashf repr1)) <: Type0)) (ensures (let _ = repr1 @@ idx' in (let Pulse.Lib.HashTable.Spec.Used #_ #_ _ _ = _ in let o1 = Pulse.Lib.HashTable.Spec.walk_get_idx repr1 idx k off in let o2 = Pulse.Lib.HashTable.Spec.walk_get_idx repr2 idx k off in (match o1, o2 with | FStar.Pervasives.Native.Mktuple2 #_ #_ (FStar.Pervasives.Native.None #_) (FStar.Pervasives.Native.None #_) -> Prims.l_True | FStar.Pervasives.Native.Mktuple2 #_ #_ (FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ _ i1)) (FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ v2 i2)) -> i1 == i2 /\ FStar.Seq.Base.index (Mkrepr_t?.seq repr2) i2 == Pulse.Lib.HashTable.Spec.Used k v2 | _ -> Prims.l_False) <: Type0) <: Type0)) (decreases Mkrepr_t?.sz repr1 - off)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.l_and", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.uu___is_Used", "Pulse.Lib.HashTable.Spec.op_At_At", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "Prims.op_GreaterThan", "Prims.bool", "Pulse.Lib.HashTable.Spec.walk_get_idx_upd", "Prims.op_Addition", "Prims.unit", "Prims.op_Modulus", "Prims.eq2", "Pulse.Lib.HashTable.Spec.Mkrepr_t", "FStar.Seq.Base.upd", "Pulse.Lib.HashTable.Spec.cell", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__seq", "Pulse.Lib.HashTable.Spec.Used", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__hashf", "Prims.squash", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Prims.l_True", "FStar.Seq.Base.index", "Prims.l_False", "Pulse.Lib.HashTable.Spec.walk_get_idx", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec walk_get_idx_upd #kt #vt (repr1: repr_t kt vt) (repr2: repr_t kt vt) (idx: nat) (k: kt) (off: nat{off <= repr1.sz}) (idx': nat{idx' < repr1.sz /\ Used? (repr1 @@ idx')}) (v: vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) =
if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off + 1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off + 1) idx' v
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lemma_del_lookup_walk
val lemma_del_lookup_walk (#kt #vt #sz: _) (spec1 spec2: spec_t kt vt) (repr1 repr2: repr_t_sz kt vt sz) (upos k v: _) (k': _{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k')
val lemma_del_lookup_walk (#kt #vt #sz: _) (spec1 spec2: spec_t kt vt) (repr1 repr2: repr_t_sz kt vt sz) (upos k v: _) (k': _{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k')
let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 7, "end_line": 288, "start_col": 0, "start_line": 256 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
spec1: Pulse.Lib.HashTable.Spec.spec_t kt vt -> spec2: Pulse.Lib.HashTable.Spec.spec_t kt vt -> repr1: Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz -> repr2: Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz -> upos: i: Prims.int{i >= 0 /\ i < Mkrepr_t?.sz repr2 /\ (i >= 0) /\ (i < Mkrepr_t?.sz repr1)} -> k: kt -> v: vt -> k': kt{~(k == k')} -> FStar.Pervasives.Lemma (requires Pulse.Lib.HashTable.Spec.repr_related repr1 repr2 /\ (forall (i: Prims.int{i >= 0 /\ i < Mkrepr_t?.sz repr2 /\ (i >= 0) /\ (i < Mkrepr_t?.sz repr1)}). i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ Pulse.Lib.HashTable.Spec.pht_models spec1 repr1 /\ repr1 @@ upos == Pulse.Lib.HashTable.Spec.Used k v /\ repr2 @@ upos == Pulse.Lib.HashTable.Spec.Zombie /\ spec2 == spec1 -- k) (ensures Pulse.Lib.HashTable.Spec.lookup_repr repr1 k' == Pulse.Lib.HashTable.Spec.lookup_repr repr2 k')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "Prims.pos", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.repr_t_sz", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.l_not", "Prims.eq2", "Prims.nat", "Prims.op_LessThanOrEqual", "Prims.unit", "Prims.op_Subtraction", "FStar.Pervasives.Native.option", "Pulse.Lib.HashTable.Spec.walk", "Pulse.Lib.HashTable.Spec.lookup_repr", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_Equality", "Prims.l_or", "Prims.op_GreaterThan", "Prims.bool", "Prims.op_Modulus", "Prims.op_Addition", "Pulse.Lib.HashTable.Spec.op_At_At", "Pulse.Lib.HashTable.Spec.canonical_index", "Pulse.Lib.HashTable.Spec.repr_related", "Prims.l_Forall", "Prims.l_imp", "Prims.op_disEquality", "Pulse.Lib.HashTable.Spec.cell", "Pulse.Lib.HashTable.Spec.pht_models", "Pulse.Lib.HashTable.Spec.Used", "Pulse.Lib.HashTable.Spec.Zombie", "Pulse.Lib.HashTable.Spec.op_Subtraction_Subtraction" ]
[]
false
false
true
false
false
let lemma_del_lookup_walk #kt #vt #sz (spec1: spec_t kt vt) (spec2: spec_t kt vt) (repr1: repr_t_sz kt vt sz) (repr2: repr_t_sz kt vt sz) upos k v (k': _{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') =
let idx' = canonical_index k' repr1 in let rec aux (off: nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off + 1) else match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off + 1) | Zombie -> aux (off + 1) in aux 0
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.key256_lemma'
val key256_lemma' (s: Ghost.erased (Seq.seq nat32)) (code: V.va_code) (_win: bool) (input_b output_b: b128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key256_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key256_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b)))
val key256_lemma' (s: Ghost.erased (Seq.seq nat32)) (code: V.va_code) (_win: bool) (input_b output_b: b128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key256_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key256_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b)))
let key256_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key256_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key256_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 171, "start_col": 0, "start_line": 150 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let key128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (input_b:b128) (output_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key128_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key128_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b) )) = let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f) noextract let key128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (key128_pre s) (key128_post s)) (key128_lemma' s) noextract let code_key128 = GF.va_code_Keyhash_init IA.win AES_128 [@__reduce__] noextract let lowstar_key128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.as_lowstar_sig_t_weak_stdcall code_key128 dom [] _ _ (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_key128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_key128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 4); IX64.wrap_weak_stdcall code_key128 dom (W.mk_prediction code_key128 dom [] ((key128_lemma s) code_key128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) [@__reduce__] noextract let key256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f #set-options "--z3rlimit 20"
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> code: Vale.X64.Decls.va_code -> _win: Prims.bool -> input_b: Vale.Stdcalls.X64.AesHash.b128 -> output_b: Vale.Stdcalls.X64.AesHash.b128 -> va_s0: Vale.X64.Decls.va_state -> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel)
Prims.Ghost
[]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.X64.Decls.va_code", "Prims.bool", "Vale.Stdcalls.X64.AesHash.b128", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "FStar.Pervasives.Native.tuple2", "Vale.X64.State.vale_state", "Vale.AES.X64.GF128_Init.va_lemma_Keyhash_init", "Vale.Interop.Assumptions.win", "Vale.AES.AES_common_s.AES_256", "FStar.Ghost.reveal", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.Stdcalls.X64.AesHash.key256_pre", "Prims.l_and", "Vale.X64.Decls.eval_code", "Vale.AsLowStar.ValeSig.vale_calling_conventions_stdcall", "Vale.Stdcalls.X64.AesHash.key256_post", "Vale.X64.Memory.buffer_writeable" ]
[]
false
false
false
false
false
let key256_lemma' (s: Ghost.erased (Seq.seq nat32)) (code: V.va_code) (_win: bool) (input_b output_b: b128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires key256_pre s code input_b output_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ key256_post s code input_b output_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer input_b) /\ ME.buffer_writeable (as_vale_buffer output_b))) =
let va_s1, f = GF.va_lemma_Keyhash_init code va_s0 IA.win AES_256 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 input_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 output_b; (va_s1, f)
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.delete
val delete (#kt #vt: _) (ht: pht_t kt vt) (k: kt) : ht': (pht_t kt vt){ht'.spec == Ghost.hide (ht.spec -- k)}
val delete (#kt #vt: _) (ht: pht_t kt vt) (k: kt) : ht': (pht_t kt vt){ht'.spec == Ghost.hide (ht.spec -- k)}
let delete #kt #vt (ht : pht_t kt vt) (k : kt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec -- k) } = { ht with spec = Ghost.hide (ht.spec -- k); repr = delete_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k; inv = () }
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 22, "end_line": 699, "start_col": 0, "start_line": 694 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_zombie_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i:nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc (==>) { (canonical_index k repr + i) % sz == idx; ==> {} (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ==> { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_del #kt #vt #sz spec (repr : repr_t_sz kt vt sz) idx k v : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx)) = let spec' = spec -- k in let repr' = del_ repr idx in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin let Some (v', i') = lookup_repr_index repr' k' in assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then begin assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let not_full #kt #vt (r:repr_t kt vt) : Type0 = exists i. ~(Used? (r @@ i )) #set-options "--split_queries always" let rec insert_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr /\ not_full repr}) (k : kt) (v : vt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (strong_all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then ( // Impossible! table was not full let aux (i:nat{i < sz}) : Lemma (Used? (repr @@ i)) = assert (all_used_not_by repr cidx sz k); let off = (i - cidx) % sz in calc (==) { (cidx + off) % sz; == {} (cidx + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_lemma cidx sz } (cidx % sz + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_distributivity cidx (i-cidx) sz } i % sz; == { Math.Lemmas.modulo_lemma i sz } i; }; assert (Used? (repr @@ i)); () in Classical.forall_intro aux; unreachable () ) else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_used_upd spec repr off k v v'; upd_ repr idx k v end else begin assert (all_used_not_by repr cidx (off+1) k); insert_repr_walk #kt #vt #sz #spec repr k v (off+1) cidx () () end | Clean -> (**)lemma_clean_upd spec repr off k v; upd_ repr idx k v | Zombie -> match lookup_repr_index repr k with | Some (v_old,i) -> ( (**)lemma_del spec repr i k v_old; // Don't need these asserts let cidx = canonical_index k repr in assert (all_used_not_by repr cidx off k); // GM: Removing this assert, not needed now it seems //assert (if idx >= cidx then i > idx || i <= cidx else i > idx /\ i <= cidx); assert (all_used_not_by (del_ repr i) cidx off k); (**)lemma_zombie_upd #_ #_ #sz (spec -- k) (del_ repr i) off k v; upd_ (del_ repr i) idx k v ) | None -> ( (**)lemma_zombie_upd spec repr off k v; upd_ repr idx k v ) let insert_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (v : vt) : Pure (r':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) r' /\ repr_related repr r' }) (requires not_full repr) (ensures fun _ -> True) = let cidx = canonical_index k repr in let res = insert_repr_walk #kt #vt #sz #spec repr k v 0 cidx () () in res let rec delete_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec -- k) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then repr // If we reach this, the element was not in the table else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_del spec repr idx k v'; del_ repr idx end else begin assert (all_used_not_by repr cidx (off+1) k); delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () end | Clean -> repr | Zombie -> delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () let delete_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) : r':repr_t_sz kt vt sz{ pht_models (spec -- k) r' /\ repr_related repr r' } = let cidx = canonical_index k repr in let res = delete_repr_walk #kt #vt #sz #spec repr k 0 cidx () () in res // TODO: This states we can only insert on a non-full table, // but that's only if the key we want to insert is not already present, // so it's stronger than it should be. This is anyway perhaps not important // for this pure implementation, as the Pulse implementation could always // keep one cell free and trivially satisfy this invariant. let insert #kt #vt (ht : pht_t kt vt{not_full ht.repr}) (k : kt) (v : vt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec ++ (k,v)) } = { ht with spec = Ghost.hide (ht.spec ++ (k,v)); repr = insert_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k v; inv = () }
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
ht: Pulse.Lib.HashTable.Spec.pht_t kt vt -> k: kt -> ht': Pulse.Lib.HashTable.Spec.pht_t kt vt {Mkpht_t?.spec ht' == FStar.Ghost.hide (FStar.Ghost.reveal (Mkpht_t?.spec ht) -- k)}
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.pht_t", "Pulse.Lib.HashTable.Spec.Mkpht_t", "FStar.Ghost.hide", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.op_Subtraction_Subtraction", "FStar.Ghost.reveal", "Pulse.Lib.HashTable.Spec.__proj__Mkpht_t__item__spec", "Pulse.Lib.HashTable.Spec.delete_repr", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Pulse.Lib.HashTable.Spec.__proj__Mkpht_t__item__repr", "Prims.eq2", "FStar.Ghost.erased" ]
[]
false
false
false
false
false
let delete #kt #vt (ht: pht_t kt vt) (k: kt) : ht': (pht_t kt vt){ht'.spec == Ghost.hide (ht.spec -- k)} =
{ ht with spec = Ghost.hide (ht.spec -- k); repr = delete_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k; inv = () }
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lookup
val lookup (#kt #vt: _) (ht: pht_t kt vt) (k: kt) : o: (option vt){o == lookup_spec ht.spec k}
val lookup (#kt #vt: _) (ht: pht_t kt vt) (k: kt) : o: (option vt){o == lookup_spec ht.spec k}
let lookup #kt #vt (ht : pht_t kt vt) (k : kt) : o:(option vt){o == lookup_spec ht.spec k} = lookup_repr ht.repr k
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 23, "end_line": 704, "start_col": 0, "start_line": 701 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_zombie_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i:nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc (==>) { (canonical_index k repr + i) % sz == idx; ==> {} (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ==> { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_del #kt #vt #sz spec (repr : repr_t_sz kt vt sz) idx k v : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx)) = let spec' = spec -- k in let repr' = del_ repr idx in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin let Some (v', i') = lookup_repr_index repr' k' in assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then begin assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let not_full #kt #vt (r:repr_t kt vt) : Type0 = exists i. ~(Used? (r @@ i )) #set-options "--split_queries always" let rec insert_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr /\ not_full repr}) (k : kt) (v : vt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (strong_all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then ( // Impossible! table was not full let aux (i:nat{i < sz}) : Lemma (Used? (repr @@ i)) = assert (all_used_not_by repr cidx sz k); let off = (i - cidx) % sz in calc (==) { (cidx + off) % sz; == {} (cidx + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_lemma cidx sz } (cidx % sz + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_distributivity cidx (i-cidx) sz } i % sz; == { Math.Lemmas.modulo_lemma i sz } i; }; assert (Used? (repr @@ i)); () in Classical.forall_intro aux; unreachable () ) else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_used_upd spec repr off k v v'; upd_ repr idx k v end else begin assert (all_used_not_by repr cidx (off+1) k); insert_repr_walk #kt #vt #sz #spec repr k v (off+1) cidx () () end | Clean -> (**)lemma_clean_upd spec repr off k v; upd_ repr idx k v | Zombie -> match lookup_repr_index repr k with | Some (v_old,i) -> ( (**)lemma_del spec repr i k v_old; // Don't need these asserts let cidx = canonical_index k repr in assert (all_used_not_by repr cidx off k); // GM: Removing this assert, not needed now it seems //assert (if idx >= cidx then i > idx || i <= cidx else i > idx /\ i <= cidx); assert (all_used_not_by (del_ repr i) cidx off k); (**)lemma_zombie_upd #_ #_ #sz (spec -- k) (del_ repr i) off k v; upd_ (del_ repr i) idx k v ) | None -> ( (**)lemma_zombie_upd spec repr off k v; upd_ repr idx k v ) let insert_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (v : vt) : Pure (r':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) r' /\ repr_related repr r' }) (requires not_full repr) (ensures fun _ -> True) = let cidx = canonical_index k repr in let res = insert_repr_walk #kt #vt #sz #spec repr k v 0 cidx () () in res let rec delete_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec -- k) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then repr // If we reach this, the element was not in the table else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_del spec repr idx k v'; del_ repr idx end else begin assert (all_used_not_by repr cidx (off+1) k); delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () end | Clean -> repr | Zombie -> delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () let delete_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) : r':repr_t_sz kt vt sz{ pht_models (spec -- k) r' /\ repr_related repr r' } = let cidx = canonical_index k repr in let res = delete_repr_walk #kt #vt #sz #spec repr k 0 cidx () () in res // TODO: This states we can only insert on a non-full table, // but that's only if the key we want to insert is not already present, // so it's stronger than it should be. This is anyway perhaps not important // for this pure implementation, as the Pulse implementation could always // keep one cell free and trivially satisfy this invariant. let insert #kt #vt (ht : pht_t kt vt{not_full ht.repr}) (k : kt) (v : vt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec ++ (k,v)) } = { ht with spec = Ghost.hide (ht.spec ++ (k,v)); repr = insert_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k v; inv = () } let delete #kt #vt (ht : pht_t kt vt) (k : kt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec -- k) } = { ht with spec = Ghost.hide (ht.spec -- k); repr = delete_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k; inv = () }
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
ht: Pulse.Lib.HashTable.Spec.pht_t kt vt -> k: kt -> o: FStar.Pervasives.Native.option vt {o == Pulse.Lib.HashTable.Spec.lookup_spec (FStar.Ghost.reveal (Mkpht_t?.spec ht)) k}
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.pht_t", "Pulse.Lib.HashTable.Spec.lookup_repr", "Pulse.Lib.HashTable.Spec.__proj__Mkpht_t__item__repr", "FStar.Pervasives.Native.option", "Prims.eq2", "Pulse.Lib.HashTable.Spec.lookup_spec", "FStar.Ghost.reveal", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.__proj__Mkpht_t__item__spec" ]
[]
false
false
false
false
false
let lookup #kt #vt (ht: pht_t kt vt) (k: kt) : o: (option vt){o == lookup_spec ht.spec k} =
lookup_repr ht.repr k
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lookup_index_us
val lookup_index_us (#kt #vt: _) (ht: pht_t kt vt) (k: kt) : option US.t
val lookup_index_us (#kt #vt: _) (ht: pht_t kt vt) (k: kt) : option US.t
let lookup_index_us #kt #vt (ht : pht_t kt vt) (k : kt) : option US.t = let o = lookup_repr_index ht.repr k in match o with | Some (_, i) -> Some (US.uint_to_t i) | None -> None
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 16, "end_line": 723, "start_col": 0, "start_line": 718 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_zombie_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i:nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc (==>) { (canonical_index k repr + i) % sz == idx; ==> {} (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ==> { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_del #kt #vt #sz spec (repr : repr_t_sz kt vt sz) idx k v : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx)) = let spec' = spec -- k in let repr' = del_ repr idx in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin let Some (v', i') = lookup_repr_index repr' k' in assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then begin assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let not_full #kt #vt (r:repr_t kt vt) : Type0 = exists i. ~(Used? (r @@ i )) #set-options "--split_queries always" let rec insert_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr /\ not_full repr}) (k : kt) (v : vt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (strong_all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then ( // Impossible! table was not full let aux (i:nat{i < sz}) : Lemma (Used? (repr @@ i)) = assert (all_used_not_by repr cidx sz k); let off = (i - cidx) % sz in calc (==) { (cidx + off) % sz; == {} (cidx + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_lemma cidx sz } (cidx % sz + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_distributivity cidx (i-cidx) sz } i % sz; == { Math.Lemmas.modulo_lemma i sz } i; }; assert (Used? (repr @@ i)); () in Classical.forall_intro aux; unreachable () ) else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_used_upd spec repr off k v v'; upd_ repr idx k v end else begin assert (all_used_not_by repr cidx (off+1) k); insert_repr_walk #kt #vt #sz #spec repr k v (off+1) cidx () () end | Clean -> (**)lemma_clean_upd spec repr off k v; upd_ repr idx k v | Zombie -> match lookup_repr_index repr k with | Some (v_old,i) -> ( (**)lemma_del spec repr i k v_old; // Don't need these asserts let cidx = canonical_index k repr in assert (all_used_not_by repr cidx off k); // GM: Removing this assert, not needed now it seems //assert (if idx >= cidx then i > idx || i <= cidx else i > idx /\ i <= cidx); assert (all_used_not_by (del_ repr i) cidx off k); (**)lemma_zombie_upd #_ #_ #sz (spec -- k) (del_ repr i) off k v; upd_ (del_ repr i) idx k v ) | None -> ( (**)lemma_zombie_upd spec repr off k v; upd_ repr idx k v ) let insert_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (v : vt) : Pure (r':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) r' /\ repr_related repr r' }) (requires not_full repr) (ensures fun _ -> True) = let cidx = canonical_index k repr in let res = insert_repr_walk #kt #vt #sz #spec repr k v 0 cidx () () in res let rec delete_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec -- k) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then repr // If we reach this, the element was not in the table else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_del spec repr idx k v'; del_ repr idx end else begin assert (all_used_not_by repr cidx (off+1) k); delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () end | Clean -> repr | Zombie -> delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () let delete_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) : r':repr_t_sz kt vt sz{ pht_models (spec -- k) r' /\ repr_related repr r' } = let cidx = canonical_index k repr in let res = delete_repr_walk #kt #vt #sz #spec repr k 0 cidx () () in res // TODO: This states we can only insert on a non-full table, // but that's only if the key we want to insert is not already present, // so it's stronger than it should be. This is anyway perhaps not important // for this pure implementation, as the Pulse implementation could always // keep one cell free and trivially satisfy this invariant. let insert #kt #vt (ht : pht_t kt vt{not_full ht.repr}) (k : kt) (v : vt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec ++ (k,v)) } = { ht with spec = Ghost.hide (ht.spec ++ (k,v)); repr = insert_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k v; inv = () } let delete #kt #vt (ht : pht_t kt vt) (k : kt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec -- k) } = { ht with spec = Ghost.hide (ht.spec -- k); repr = delete_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k; inv = () } let lookup #kt #vt (ht : pht_t kt vt) (k : kt) : o:(option vt){o == lookup_spec ht.spec k} = lookup_repr ht.repr k let lookup_index #kt #vt (ht : pht_t kt vt) (k : kt) : option (vt & nat) = lookup_repr_index ht.repr k // let lookup_index_us #kt #vt (ht : pht_t kt vt) (k : kt) // : option (vt & US.t) // = let o = lookup_repr_index ht.repr k in // match o with // | Some (v,i) -> Some (v, US.uint_to_t i) // | None -> None
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
ht: Pulse.Lib.HashTable.Spec.pht_t kt vt -> k: kt -> FStar.Pervasives.Native.option FStar.SizeT.t
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.pht_t", "Prims.nat", "FStar.Pervasives.Native.Some", "FStar.SizeT.t", "FStar.SizeT.uint_to_t", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Pulse.Lib.HashTable.Spec.lookup_repr_index", "Pulse.Lib.HashTable.Spec.__proj__Mkpht_t__item__repr" ]
[]
false
false
false
false
false
let lookup_index_us #kt #vt (ht: pht_t kt vt) (k: kt) : option US.t =
let o = lookup_repr_index ht.repr k in match o with | Some (_, i) -> Some (US.uint_to_t i) | None -> None
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lemma_used_upd_lookup_walk
val lemma_used_upd_lookup_walk (#kt #vt #sz: _) (spec1 spec2: spec_t kt vt) (repr1 repr2: repr_t_sz kt vt sz) (idx k: _) (k': _{k =!= k'}) (v v': vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k, v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k')
val lemma_used_upd_lookup_walk (#kt #vt #sz: _) (spec1 spec2: spec_t kt vt) (repr1 repr2: repr_t_sz kt vt sz) (idx k: _) (k': _{k =!= k'}) (v v': vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k, v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k')
let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 7, "end_line": 254, "start_col": 0, "start_line": 218 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
spec1: Pulse.Lib.HashTable.Spec.spec_t kt vt -> spec2: Pulse.Lib.HashTable.Spec.spec_t kt vt -> repr1: Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz -> repr2: Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz -> idx: i: Prims.int{i >= 0 /\ i < Mkrepr_t?.sz repr2 /\ (i >= 0) /\ (i < Mkrepr_t?.sz repr1)} -> k: kt -> k': kt{~(k == k')} -> v: vt -> v': vt -> FStar.Pervasives.Lemma (requires Pulse.Lib.HashTable.Spec.repr_related repr1 repr2 /\ (forall (i: Prims.int{i >= 0 /\ i < Mkrepr_t?.sz repr2 /\ (i >= 0) /\ (i < Mkrepr_t?.sz repr1)}). i < Mkrepr_t?.sz repr1 /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ Pulse.Lib.HashTable.Spec.pht_models spec1 repr1 /\ repr1 @@ idx == Pulse.Lib.HashTable.Spec.Used k v' /\ repr2 @@ idx == Pulse.Lib.HashTable.Spec.Used k v /\ repr2 == Pulse.Lib.HashTable.Spec.upd_ repr1 idx k v /\ spec2 == spec1 ++ (k, v)) (ensures Pulse.Lib.HashTable.Spec.lookup_repr repr1 k' == Pulse.Lib.HashTable.Spec.lookup_repr repr2 k')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "Prims.pos", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.repr_t_sz", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.l_not", "Prims.eq2", "Prims.nat", "Prims.op_LessThanOrEqual", "Prims.unit", "Prims.op_Subtraction", "FStar.Pervasives.Native.option", "Pulse.Lib.HashTable.Spec.walk", "Pulse.Lib.HashTable.Spec.lookup_repr", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_Equality", "Prims.l_or", "Prims.op_GreaterThan", "Prims.bool", "Prims.op_Modulus", "Prims.op_Addition", "Pulse.Lib.HashTable.Spec.op_At_At", "Pulse.Lib.HashTable.Spec.canonical_index", "Pulse.Lib.HashTable.Spec.repr_related", "Prims.l_Forall", "Prims.l_imp", "Prims.op_disEquality", "Pulse.Lib.HashTable.Spec.cell", "Pulse.Lib.HashTable.Spec.pht_models", "Pulse.Lib.HashTable.Spec.Used", "Pulse.Lib.HashTable.Spec.repr_t", "Pulse.Lib.HashTable.Spec.upd_", "Pulse.Lib.HashTable.Spec.op_Plus_Plus", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
false
true
false
false
let lemma_used_upd_lookup_walk #kt #vt #sz (spec1: spec_t kt vt) (spec2: spec_t kt vt) (repr1: repr_t_sz kt vt sz) (repr2: repr_t_sz kt vt sz) idx k (k': _{k =!= k'}) (v: vt) (v': vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k, v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') =
let idx' = canonical_index k' repr1 in let rec aux (off: nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off + 1) else match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off + 1) | Zombie -> aux (off + 1) in aux 0
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.validate_sum_cases_t_eq
val validate_sum_cases_t_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y: validate_sum_cases_t t pc k) : GTot Type0
val validate_sum_cases_t_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y: validate_sum_cases_t t pc k) : GTot Type0
let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 43, "start_col": 0, "start_line": 37 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Sum.sum_key t -> x: LowParse.Low.Sum.validate_sum_cases_t t pc k -> y: LowParse.Low.Sum.validate_sum_cases_t t pc k -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Sum.validate_sum_cases_t", "Prims.l_True" ]
[]
false
false
false
false
true
let validate_sum_cases_t_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y: validate_sum_cases_t t pc k) : GTot Type0 =
True
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.validate_sum_aux_payload_eq
val validate_sum_aux_payload_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0)
val validate_sum_aux_payload_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0)
let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 17, "end_line": 100, "start_col": 0, "start_line": 95 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) )))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Enum.maybe_enum_key (LowParse.Spec.Sum.sum_enum t) -> _: LowParse.Low.Sum.validate_sum_aux_payload_t t pc k -> _: LowParse.Low.Sum.validate_sum_aux_payload_t t pc k -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Low.Sum.validate_sum_aux_payload_t", "Prims.l_True" ]
[]
false
false
false
false
true
let validate_sum_aux_payload_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) =
fun _ _ -> True
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.dll_insert_before
val dll_insert_before (#t:Type0) (n':node t) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d) /\ n' `L.memP` as_list h0 d)) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ as_payload_list h1 d == l_insert_before' (as_list h0 d `L.index_of` n') (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_before n' (as_list h0 d) n))
val dll_insert_before (#t:Type0) (n':node t) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d) /\ n' `L.memP` as_list h0 d)) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ as_payload_list h1 d == l_insert_before' (as_list h0 d `L.index_of` n') (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_before n' (as_list h0 d) n))
let dll_insert_before #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_before (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.lhead)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.ltail)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; // assert (n' `L.memP` as_list h1 d); _lemma_prev_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.blink =!= B.null) #((n'@h0).DLL.blink =!= B.null /\ (n'@h0).DLL.blink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.blink); // assert ((n'@h0).DLL.blink =!= B.null ==> (n'@h0).DLL.blink `L.memP` as_list h1 d); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.blink (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n')); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (n'@h0).DLL.blink)); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in _lemma_split_using_splitAt (as_list h00 d) n'; _lemma_append_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (as_list h00 d); _lemma_length_g_node_vals h00 (as_list h00 d); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); // assert ((as_list h00 d `L.index_of` n') < L.length (g_node_vals h00 (as_list h00 d))); _lemma_insertion_maintains_unchanged_node_vals h0 h1 (as_list h0 d) (as_list h1 d) n' n; // assert (unchanged_node_vals h0 h1 (as_list h0 d)); _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h00 d); // assert (g_node_vals h11 (as_list h00 d) == g_node_vals h00 (as_list h00 d)); // assert ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in // let m1, m2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // g_node_vals h11 // (l1 `L.append` l2) == (m1 `L.append` m2) /\ L.length l1 = L.length m1); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); _lemma_length_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.append_length_inv_head (g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (g_node_vals h11 (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (fst (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n; // assert (n `L.memP` as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); // assert (g_node_val h1 n == g_node_val h0 n); _lemma_append_g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) (let l1, l2 = L.split_using (as_list h00 d) n' in (n :: l2)); // assert (g_node_vals h11 ( // let l1, l2 = L.split_using (as_list h00 d) n' in // l1 `L.append` (n :: l2)) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (l_insert_before n' (as_list h00 d) n) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (as_list h11 d) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_payload_list h00 d) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == l_insert_before' // (as_list h00 d `L.index_of` n') (as_payload_list h00 d) (g_node_val h00 n)); ()
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 696, "start_col": 0, "start_line": 609 }
(* Copyright 2008-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 DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y let has_prev d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n > 0) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) 0); y let next_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n); (!*n).DLL.flink let prev_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n - 1); (!*n).DLL.blink /// Stateful DoublyLinkedList operations /// /// These are most likely what you want to be using when writing /// code. The rest of this interface lets you talk about these /// operations easily. #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_insert_at_head #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_head (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_insert_at_tail #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_tail (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_append_contains h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d); _lemma_append_g_node_vals h11 (as_list h0 d) [n]; L.lemma_unsnoc_is_last (as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); _lemma_append_g_node_vals h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_append h00 h11 (as_list h0 d) [n] #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "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": 2, "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": 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": 80, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n': DoublyLinkedListIface.node t -> d: DoublyLinkedListIface.dll t -> n: DoublyLinkedListIface.node t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "DoublyLinkedListIface.node", "DoublyLinkedListIface.dll", "Prims.unit", "DoublyLinkedListIface._lemma_append_g_node_vals", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Properties.split_using", "DoublyLinkedListIface.as_list", "Prims.Cons", "DoublyLinkedListIface._lemma_extract_unchanged_node_val", "DoublyLinkedListIface._lemma_insertion_maintains_memP", "FStar.List.Tot.Properties.append_length_inv_head", "DoublyLinkedListIface.g_node_vals", "FStar.Pervasives.Native.fst", "FStar.List.Tot.Base.splitAt", "FStar.List.Tot.Properties.index_of", "FStar.Pervasives.Native.snd", "DoublyLinkedListIface._lemma_length_g_node_vals", "FStar.List.Pure.Properties.lemma_splitAt_append", "DoublyLinkedListIface._lemma_unchanged_node_vals_maintains_changes", "DoublyLinkedListIface._lemma_insertion_maintains_unchanged_node_vals", "DoublyLinkedListIface._lemma_split_using_splitAt", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.HyperStack.ST.pop_frame", "DoublyLinkedListIface._lemma_node_in_list_or_null_is_included", "DoublyLinkedList.__proj__Mknode__item__blink", "DoublyLinkedListIface.op_At", "DoublyLinkedList.node", "DoublyLinkedListIface._lemma_node_in_list_is_included", "FStar.Classical.arrow_to_impl", "Prims.l_not", "Prims.eq2", "LowStar.Buffer.buffer", "LowStar.Buffer.null", "Prims.l_and", "FStar.List.Tot.Base.memP", "Prims.squash", "DoublyLinkedListIface._lemma_prev_node_in_list", "DoublyLinkedListIface._lemma_unchanged_node_vals_transitive", "Prims._assert", "DoublyLinkedListIface._pred_nl_disjoint", "LowStar.BufferOps.op_Star_Equals", "DoublyLinkedList.dll", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.dll_insert_before", "LowStar.BufferOps.op_Bang_Star", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let dll_insert_before #t n' d n =
let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_before (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; _lemma_prev_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n' @ h0).DLL.blink =!= B.null) #((n' @ h0).DLL.blink =!= B.null /\ (n' @ h0).DLL.blink `L.memP` (as_list h1 d)) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n' @ h0).DLL.blink); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n' @ h0).DLL.blink (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_split_using_splitAt (as_list h00 d) n'; _lemma_append_g_node_vals h11 (fst (L.splitAt ((as_list h00 d) `L.index_of` n') (as_list h00 d))) (snd (L.splitAt ((as_list h00 d) `L.index_of` n') (as_list h00 d))); L.lemma_splitAt_append ((as_list h00 d) `L.index_of` n') (as_list h00 d); _lemma_length_g_node_vals h00 (as_list h00 d); L.lemma_splitAt_append ((as_list h00 d) `L.index_of` n') (g_node_vals h00 (as_list h00 d)); _lemma_insertion_maintains_unchanged_node_vals h0 h1 (as_list h0 d) (as_list h1 d) n' n; _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h00 d); L.lemma_splitAt_append ((as_list h00 d) `L.index_of` n') (g_node_vals h00 (as_list h00 d)); _lemma_length_g_node_vals h11 (fst (L.splitAt ((as_list h00 d) `L.index_of` n') (as_list h00 d))); L.append_length_inv_head (g_node_vals h11 (fst (L.splitAt ((as_list h00 d) `L.index_of` n') (as_list h00 d)))) (g_node_vals h11 (snd (L.splitAt ((as_list h00 d) `L.index_of` n') (as_list h00 d)))) (fst (L.splitAt ((as_list h00 d) `L.index_of` n') (g_node_vals h00 (as_list h00 d)))) (snd (L.splitAt ((as_list h00 d) `L.index_of` n') (g_node_vals h00 (as_list h00 d)))); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n; _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); _lemma_append_g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) (let l1, l2 = L.split_using (as_list h00 d) n' in (n :: l2)); ()
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lemma_clean_upd
val lemma_clean_upd (#kt #vt spec: _) (repr: repr_t kt vt) (off: nat{off < repr.sz}) (k v: _) : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k, v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v))
val lemma_clean_upd (#kt #vt spec: _) (repr: repr_t kt vt) (off: nat{off < repr.sz}) (k v: _) : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k, v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v))
let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 61, "end_line": 425, "start_col": 0, "start_line": 391 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
spec: Pulse.Lib.HashTable.Spec.spec_t kt vt -> repr: Pulse.Lib.HashTable.Spec.repr_t kt vt -> off: Prims.nat{off < Mkrepr_t?.sz repr} -> k: kt -> v: vt -> FStar.Pervasives.Lemma (requires Pulse.Lib.HashTable.Spec.pht_models spec repr /\ None? (Pulse.Lib.HashTable.Spec.lookup_repr repr k) /\ repr @@ (Pulse.Lib.HashTable.Spec.canonical_index k repr + off) % Mkrepr_t?.sz repr == Pulse.Lib.HashTable.Spec.Clean /\ Pulse.Lib.HashTable.Spec.all_used_not_by repr (Pulse.Lib.HashTable.Spec.canonical_index k repr) off k) (ensures Pulse.Lib.HashTable.Spec.pht_models (spec ++ (k, v)) (Pulse.Lib.HashTable.Spec.upd_ repr ((Pulse.Lib.HashTable.Spec.canonical_index k repr + off) % Mkrepr_t?.sz repr) k v))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "FStar.Classical.forall_intro_3", "Prims.l_imp", "Prims.eq2", "Pulse.Lib.HashTable.Spec.cell", "Pulse.Lib.HashTable.Spec.op_At_At", "Pulse.Lib.HashTable.Spec.Used", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Pulse.Lib.HashTable.Spec.lookup_repr_index", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "FStar.Classical.move_requires_3", "Prims.unit", "FStar.Classical.forall_intro", "FStar.Pervasives.Native.uu___is_Some", "Pulse.Lib.HashTable.Spec.lookup_repr", "Pulse.Lib.HashTable.Spec.lookup_spec", "FStar.Classical.move_requires", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_Equality", "Pulse.Lib.HashTable.Spec.lemma_walk_from_canonical_all_used", "Prims.bool", "Pulse.Lib.HashTable.Spec.lemma_clean_upd_lookup_walk", "Pulse.Lib.HashTable.Spec.upd_", "Prims.int", "Prims.op_Modulus", "Prims.op_Addition", "Pulse.Lib.HashTable.Spec.canonical_index", "Pulse.Lib.HashTable.Spec.op_Plus_Plus", "Prims.pos", "Prims.l_and", "Pulse.Lib.HashTable.Spec.pht_models", "FStar.Pervasives.Native.uu___is_None", "Pulse.Lib.HashTable.Spec.Clean", "Pulse.Lib.HashTable.Spec.all_used_not_by" ]
[]
false
false
true
false
false
let lemma_clean_upd #kt #vt spec (repr: repr_t kt vt) (off: nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k, v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) =
let sz = repr.sz in let spec' = spec ++ (k, v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k': kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k': kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i': nat{i' < sz}) (k': kt) (v': vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3)
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lemma_del
val lemma_del (#kt #vt #sz spec: _) (repr: repr_t_sz kt vt sz) (idx k v: _) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx))
val lemma_del (#kt #vt #sz spec: _) (repr: repr_t_sz kt vt sz) (idx k v: _) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx))
let lemma_del #kt #vt #sz spec (repr : repr_t_sz kt vt sz) idx k v : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx)) = let spec' = spec -- k in let repr' = del_ repr idx in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin let Some (v', i') = lookup_repr_index repr' k' in assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then begin assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 61, "end_line": 552, "start_col": 0, "start_line": 514 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_zombie_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i:nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc (==>) { (canonical_index k repr + i) % sz == idx; ==> {} (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ==> { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
spec: Pulse.Lib.HashTable.Spec.spec_t kt vt -> repr: Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz -> idx: n: Prims.nat{n < FStar.Seq.Base.length (Mkrepr_t?.seq repr)} -> k: kt -> v: vt -> FStar.Pervasives.Lemma (requires Pulse.Lib.HashTable.Spec.pht_models spec repr /\ Some? (Pulse.Lib.HashTable.Spec.lookup_repr repr k) /\ repr @@ idx == Pulse.Lib.HashTable.Spec.Used k v) (ensures Pulse.Lib.HashTable.Spec.pht_models (spec -- k) (Pulse.Lib.HashTable.Spec.del_ repr idx))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "Prims.pos", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.repr_t_sz", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.length", "Pulse.Lib.HashTable.Spec.cell", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__seq", "FStar.Classical.forall_intro_3", "Prims.l_imp", "Prims.eq2", "Pulse.Lib.HashTable.Spec.op_At_At", "Pulse.Lib.HashTable.Spec.Used", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Pulse.Lib.HashTable.Spec.lookup_repr_index", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "FStar.Classical.move_requires_3", "Prims.unit", "FStar.Classical.forall_intro", "FStar.Pervasives.Native.uu___is_Some", "Pulse.Lib.HashTable.Spec.lookup_repr", "Pulse.Lib.HashTable.Spec.lookup_spec", "FStar.Classical.move_requires", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_Equality", "Prims._assert", "Prims.op_disEquality", "Prims.l_or", "Prims.bool", "Pulse.Lib.HashTable.Spec.lemma_del_lookup_walk", "Pulse.Lib.HashTable.Spec.repr_t", "Pulse.Lib.HashTable.Spec.del_", "Pulse.Lib.HashTable.Spec.op_Subtraction_Subtraction", "Prims.l_and", "Pulse.Lib.HashTable.Spec.pht_models" ]
[]
false
false
true
false
false
let lemma_del #kt #vt #sz spec (repr: repr_t_sz kt vt sz) idx k v : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx)) =
let spec' = spec -- k in let repr' = del_ repr idx in let aux1 (k': kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k': kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then let Some (v', i') = lookup_repr_index repr' k' in assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i': nat{i' < sz}) (k': kt) (v': vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then (assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); ()) else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3)
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.delete_repr_walk
val delete_repr_walk: #kt: _ -> #vt: _ -> #sz: _ -> #spec: erased (spec_t kt vt) -> repr: repr_t_sz kt vt sz {pht_models spec repr} -> k: kt -> off: nat{off <= sz} -> cidx: nat{cidx = canonical_index k repr} -> squash (all_used_not_by repr cidx off k) -> squash (walk repr cidx k off == lookup_repr repr k) -> Tot (repr': repr_t_sz kt vt sz {pht_models (spec -- k) repr' /\ repr_related repr repr'}) (decreases sz - off)
val delete_repr_walk: #kt: _ -> #vt: _ -> #sz: _ -> #spec: erased (spec_t kt vt) -> repr: repr_t_sz kt vt sz {pht_models spec repr} -> k: kt -> off: nat{off <= sz} -> cidx: nat{cidx = canonical_index k repr} -> squash (all_used_not_by repr cidx off k) -> squash (walk repr cidx k off == lookup_repr repr k) -> Tot (repr': repr_t_sz kt vt sz {pht_models (spec -- k) repr' /\ repr_related repr repr'}) (decreases sz - off)
let rec delete_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec -- k) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then repr // If we reach this, the element was not in the table else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_del spec repr idx k v'; del_ repr idx end else begin assert (all_used_not_by repr cidx (off+1) k); delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () end | Clean -> repr | Zombie -> delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () ()
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 76, "end_line": 669, "start_col": 0, "start_line": 642 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_zombie_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i:nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc (==>) { (canonical_index k repr + i) % sz == idx; ==> {} (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ==> { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_del #kt #vt #sz spec (repr : repr_t_sz kt vt sz) idx k v : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx)) = let spec' = spec -- k in let repr' = del_ repr idx in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin let Some (v', i') = lookup_repr_index repr' k' in assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then begin assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let not_full #kt #vt (r:repr_t kt vt) : Type0 = exists i. ~(Used? (r @@ i )) #set-options "--split_queries always" let rec insert_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr /\ not_full repr}) (k : kt) (v : vt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (strong_all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then ( // Impossible! table was not full let aux (i:nat{i < sz}) : Lemma (Used? (repr @@ i)) = assert (all_used_not_by repr cidx sz k); let off = (i - cidx) % sz in calc (==) { (cidx + off) % sz; == {} (cidx + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_lemma cidx sz } (cidx % sz + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_distributivity cidx (i-cidx) sz } i % sz; == { Math.Lemmas.modulo_lemma i sz } i; }; assert (Used? (repr @@ i)); () in Classical.forall_intro aux; unreachable () ) else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_used_upd spec repr off k v v'; upd_ repr idx k v end else begin assert (all_used_not_by repr cidx (off+1) k); insert_repr_walk #kt #vt #sz #spec repr k v (off+1) cidx () () end | Clean -> (**)lemma_clean_upd spec repr off k v; upd_ repr idx k v | Zombie -> match lookup_repr_index repr k with | Some (v_old,i) -> ( (**)lemma_del spec repr i k v_old; // Don't need these asserts let cidx = canonical_index k repr in assert (all_used_not_by repr cidx off k); // GM: Removing this assert, not needed now it seems //assert (if idx >= cidx then i > idx || i <= cidx else i > idx /\ i <= cidx); assert (all_used_not_by (del_ repr i) cidx off k); (**)lemma_zombie_upd #_ #_ #sz (spec -- k) (del_ repr i) off k v; upd_ (del_ repr i) idx k v ) | None -> ( (**)lemma_zombie_upd spec repr off k v; upd_ repr idx k v ) let insert_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (v : vt) : Pure (r':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) r' /\ repr_related repr r' }) (requires not_full repr) (ensures fun _ -> True) = let cidx = canonical_index k repr in let res = insert_repr_walk #kt #vt #sz #spec repr k v 0 cidx () () in res
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
repr: Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz {Pulse.Lib.HashTable.Spec.pht_models (FStar.Ghost.reveal spec) repr} -> k: kt -> off: Prims.nat{off <= sz} -> cidx: Prims.nat{cidx = Pulse.Lib.HashTable.Spec.canonical_index k repr} -> _: Prims.squash (Pulse.Lib.HashTable.Spec.all_used_not_by repr cidx off k) -> _: Prims.squash (Pulse.Lib.HashTable.Spec.walk repr cidx k off == Pulse.Lib.HashTable.Spec.lookup_repr repr k) -> Prims.Tot (repr': Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz { Pulse.Lib.HashTable.Spec.pht_models (FStar.Ghost.reveal spec -- k) repr' /\ Pulse.Lib.HashTable.Spec.repr_related repr repr' })
Prims.Tot
[ "total", "" ]
[]
[ "Prims.eqtype", "Prims.pos", "FStar.Ghost.erased", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.repr_t_sz", "Pulse.Lib.HashTable.Spec.pht_models", "FStar.Ghost.reveal", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Pulse.Lib.HashTable.Spec.canonical_index", "Prims.squash", "Pulse.Lib.HashTable.Spec.all_used_not_by", "Prims.eq2", "FStar.Pervasives.Native.option", "Pulse.Lib.HashTable.Spec.walk", "Pulse.Lib.HashTable.Spec.lookup_repr", "Prims.int", "Prims.l_or", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Prims.op_GreaterThan", "Prims.bool", "Pulse.Lib.HashTable.Spec.op_At_At", "Pulse.Lib.HashTable.Spec.del_", "Prims.unit", "Pulse.Lib.HashTable.Spec.lemma_del", "Pulse.Lib.HashTable.Spec.delete_repr_walk", "Prims.op_Addition", "Prims._assert", "Pulse.Lib.HashTable.Spec.op_Subtraction_Subtraction", "Pulse.Lib.HashTable.Spec.repr_related", "Prims.op_Modulus" ]
[ "recursion" ]
false
false
false
false
false
let rec delete_repr_walk #kt #vt #sz (#spec: erased (spec_t kt vt)) (repr: repr_t_sz kt vt sz {pht_models spec repr}) (k: kt) (off: nat{off <= sz}) (cidx: nat{cidx = canonical_index k repr}) (_: squash (all_used_not_by repr cidx off k)) (_: squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr': repr_t_sz kt vt sz {pht_models (spec -- k) repr' /\ repr_related repr repr'}) (decreases sz - off) =
if off = sz then repr else let idx = (cidx + off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then (lemma_del spec repr idx k v'; del_ repr idx) else (assert (all_used_not_by repr cidx (off + 1) k); delete_repr_walk #kt #vt #sz #spec repr k (off + 1) cidx () ()) | Clean -> repr | Zombie -> delete_repr_walk #kt #vt #sz #spec repr k (off + 1) cidx () ()
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.upd_pht
val upd_pht: #kt: eqtype -> #vt: Type -> pht: pht_t kt vt -> idx: _ -> k: kt -> v: vt -> squash (lookup_index_us pht k == Some idx) -> pht_t kt vt
val upd_pht: #kt: eqtype -> #vt: Type -> pht: pht_t kt vt -> idx: _ -> k: kt -> v: vt -> squash (lookup_index_us pht k == Some idx) -> pht_t kt vt
let upd_pht (#kt:eqtype) (#vt:Type) (pht:pht_t kt vt) idx (k:kt) (v:vt) (_:squash (lookup_index_us pht k == Some idx)) : pht_t kt vt = let spec' = Ghost.hide (pht.spec ++ (k, v)) in let repr' = upd_ pht.repr (US.v idx) k v in let Used k v' = pht.repr @@ US.v idx in let cidx = canonical_index #kt #vt k pht.repr in walk_get_idx_upd pht.repr repr' cidx k 0 (US.v idx) v; assert (lookup_repr_index repr' k == Some (v, US.v idx)); introduce forall (k':kt { k' =!= k }). lookup_repr repr' k' == lookup_repr pht.repr k' with lemma_used_upd_lookup_walk #_ #_ #pht.repr.sz pht.spec spec' pht.repr repr' (US.v idx) k k' v v'; { pht with spec = spec'; repr = repr'; inv = () }
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 23, "end_line": 741, "start_col": 0, "start_line": 725 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_zombie_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i:nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc (==>) { (canonical_index k repr + i) % sz == idx; ==> {} (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ==> { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_del #kt #vt #sz spec (repr : repr_t_sz kt vt sz) idx k v : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx)) = let spec' = spec -- k in let repr' = del_ repr idx in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin let Some (v', i') = lookup_repr_index repr' k' in assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then begin assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let not_full #kt #vt (r:repr_t kt vt) : Type0 = exists i. ~(Used? (r @@ i )) #set-options "--split_queries always" let rec insert_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr /\ not_full repr}) (k : kt) (v : vt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (strong_all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then ( // Impossible! table was not full let aux (i:nat{i < sz}) : Lemma (Used? (repr @@ i)) = assert (all_used_not_by repr cidx sz k); let off = (i - cidx) % sz in calc (==) { (cidx + off) % sz; == {} (cidx + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_lemma cidx sz } (cidx % sz + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_distributivity cidx (i-cidx) sz } i % sz; == { Math.Lemmas.modulo_lemma i sz } i; }; assert (Used? (repr @@ i)); () in Classical.forall_intro aux; unreachable () ) else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_used_upd spec repr off k v v'; upd_ repr idx k v end else begin assert (all_used_not_by repr cidx (off+1) k); insert_repr_walk #kt #vt #sz #spec repr k v (off+1) cidx () () end | Clean -> (**)lemma_clean_upd spec repr off k v; upd_ repr idx k v | Zombie -> match lookup_repr_index repr k with | Some (v_old,i) -> ( (**)lemma_del spec repr i k v_old; // Don't need these asserts let cidx = canonical_index k repr in assert (all_used_not_by repr cidx off k); // GM: Removing this assert, not needed now it seems //assert (if idx >= cidx then i > idx || i <= cidx else i > idx /\ i <= cidx); assert (all_used_not_by (del_ repr i) cidx off k); (**)lemma_zombie_upd #_ #_ #sz (spec -- k) (del_ repr i) off k v; upd_ (del_ repr i) idx k v ) | None -> ( (**)lemma_zombie_upd spec repr off k v; upd_ repr idx k v ) let insert_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (v : vt) : Pure (r':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) r' /\ repr_related repr r' }) (requires not_full repr) (ensures fun _ -> True) = let cidx = canonical_index k repr in let res = insert_repr_walk #kt #vt #sz #spec repr k v 0 cidx () () in res let rec delete_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec -- k) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then repr // If we reach this, the element was not in the table else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_del spec repr idx k v'; del_ repr idx end else begin assert (all_used_not_by repr cidx (off+1) k); delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () end | Clean -> repr | Zombie -> delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () let delete_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) : r':repr_t_sz kt vt sz{ pht_models (spec -- k) r' /\ repr_related repr r' } = let cidx = canonical_index k repr in let res = delete_repr_walk #kt #vt #sz #spec repr k 0 cidx () () in res // TODO: This states we can only insert on a non-full table, // but that's only if the key we want to insert is not already present, // so it's stronger than it should be. This is anyway perhaps not important // for this pure implementation, as the Pulse implementation could always // keep one cell free and trivially satisfy this invariant. let insert #kt #vt (ht : pht_t kt vt{not_full ht.repr}) (k : kt) (v : vt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec ++ (k,v)) } = { ht with spec = Ghost.hide (ht.spec ++ (k,v)); repr = insert_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k v; inv = () } let delete #kt #vt (ht : pht_t kt vt) (k : kt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec -- k) } = { ht with spec = Ghost.hide (ht.spec -- k); repr = delete_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k; inv = () } let lookup #kt #vt (ht : pht_t kt vt) (k : kt) : o:(option vt){o == lookup_spec ht.spec k} = lookup_repr ht.repr k let lookup_index #kt #vt (ht : pht_t kt vt) (k : kt) : option (vt & nat) = lookup_repr_index ht.repr k // let lookup_index_us #kt #vt (ht : pht_t kt vt) (k : kt) // : option (vt & US.t) // = let o = lookup_repr_index ht.repr k in // match o with // | Some (v,i) -> Some (v, US.uint_to_t i) // | None -> None let lookup_index_us #kt #vt (ht : pht_t kt vt) (k : kt) : option US.t = let o = lookup_repr_index ht.repr k in match o with | Some (_, i) -> Some (US.uint_to_t i) | None -> None
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
pht: Pulse.Lib.HashTable.Spec.pht_t kt vt -> idx: FStar.SizeT.t -> k: kt -> v: vt -> _: Prims.squash (Pulse.Lib.HashTable.Spec.lookup_index_us pht k == FStar.Pervasives.Native.Some idx) -> Pulse.Lib.HashTable.Spec.pht_t kt vt
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.pht_t", "FStar.SizeT.t", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "Pulse.Lib.HashTable.Spec.lookup_index_us", "FStar.Pervasives.Native.Some", "Pulse.Lib.HashTable.Spec.Mkpht_t", "Prims.unit", "FStar.Classical.Sugar.forall_intro", "Prims.l_not", "Pulse.Lib.HashTable.Spec.lookup_repr", "Pulse.Lib.HashTable.Spec.__proj__Mkpht_t__item__repr", "Pulse.Lib.HashTable.Spec.lemma_used_upd_lookup_walk", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "FStar.Ghost.reveal", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.__proj__Mkpht_t__item__spec", "FStar.SizeT.v", "Prims._assert", "FStar.Pervasives.Native.tuple2", "Prims.nat", "Pulse.Lib.HashTable.Spec.lookup_repr_index", "FStar.Pervasives.Native.Mktuple2", "Pulse.Lib.HashTable.Spec.walk_get_idx_upd", "Pulse.Lib.HashTable.Spec.canonical_index", "Pulse.Lib.HashTable.Spec.cell", "Pulse.Lib.HashTable.Spec.op_At_At", "Pulse.Lib.HashTable.Spec.repr_t", "Pulse.Lib.HashTable.Spec.upd_", "FStar.Ghost.erased", "FStar.Ghost.hide", "Pulse.Lib.HashTable.Spec.op_Plus_Plus" ]
[]
false
false
false
false
false
let upd_pht (#kt: eqtype) (#vt: Type) (pht: pht_t kt vt) idx (k: kt) (v: vt) (_: squash (lookup_index_us pht k == Some idx)) : pht_t kt vt =
let spec' = Ghost.hide (pht.spec ++ (k, v)) in let repr' = upd_ pht.repr (US.v idx) k v in let Used k v' = pht.repr @@ US.v idx in let cidx = canonical_index #kt #vt k pht.repr in walk_get_idx_upd pht.repr repr' cidx k 0 (US.v idx) v; assert (lookup_repr_index repr' k == Some (v, US.v idx)); introduce forall (k': kt{k' =!= k}) . lookup_repr repr' k' == lookup_repr pht.repr k' with lemma_used_upd_lookup_walk #_ #_ #pht.repr.sz pht.spec spec' pht.repr repr' (US.v idx) k k' v v'; { pht with spec = spec'; repr = repr'; inv = () }
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lemma_zombie_upd_lookup_walk
val lemma_zombie_upd_lookup_walk (#kt #vt #sz: _) (spec spec': spec_t kt vt) (repr repr': repr_t_sz kt vt sz) (idx k v: _) (k': _{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k, v)) (ensures lookup_repr repr k' == lookup_repr repr' k')
val lemma_zombie_upd_lookup_walk (#kt #vt #sz: _) (spec spec': spec_t kt vt) (repr repr': repr_t_sz kt vt sz) (idx k v: _) (k': _{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k, v)) (ensures lookup_repr repr k' == lookup_repr repr' k')
let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 7, "end_line": 321, "start_col": 0, "start_line": 290 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
spec: Pulse.Lib.HashTable.Spec.spec_t kt vt -> spec': Pulse.Lib.HashTable.Spec.spec_t kt vt -> repr: Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz -> repr': Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz -> idx: i: Prims.int{i >= 0 /\ i < Mkrepr_t?.sz repr' /\ (i >= 0) /\ (i < Mkrepr_t?.sz repr)} -> k: kt -> v: vt -> k': kt{~(k == k')} -> FStar.Pervasives.Lemma (requires Pulse.Lib.HashTable.Spec.repr_related repr repr' /\ (forall (i: Prims.int{i >= 0 /\ i < Mkrepr_t?.sz repr' /\ (i >= 0) /\ (i < Mkrepr_t?.sz repr)}). i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ Pulse.Lib.HashTable.Spec.pht_models spec repr /\ repr' == Pulse.Lib.HashTable.Spec.upd_ repr idx k v /\ repr @@ idx == Pulse.Lib.HashTable.Spec.Zombie /\ spec' == spec ++ (k, v)) (ensures Pulse.Lib.HashTable.Spec.lookup_repr repr k' == Pulse.Lib.HashTable.Spec.lookup_repr repr' k')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "Prims.pos", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.repr_t_sz", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.l_not", "Prims.eq2", "Prims.nat", "Prims.op_LessThanOrEqual", "Prims.unit", "Prims.op_Subtraction", "FStar.Pervasives.Native.option", "Pulse.Lib.HashTable.Spec.walk", "Pulse.Lib.HashTable.Spec.lookup_repr", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_Equality", "Prims.l_or", "Prims.op_GreaterThan", "Prims.bool", "Prims.op_Modulus", "Prims.op_Addition", "Pulse.Lib.HashTable.Spec.op_At_At", "Pulse.Lib.HashTable.Spec.canonical_index", "Pulse.Lib.HashTable.Spec.repr_related", "Prims.l_Forall", "Prims.l_imp", "Prims.op_disEquality", "Pulse.Lib.HashTable.Spec.cell", "Pulse.Lib.HashTable.Spec.pht_models", "Pulse.Lib.HashTable.Spec.repr_t", "Pulse.Lib.HashTable.Spec.upd_", "Pulse.Lib.HashTable.Spec.Zombie", "Pulse.Lib.HashTable.Spec.op_Plus_Plus", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
false
true
false
false
let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec: spec_t kt vt) (spec': spec_t kt vt) (repr: repr_t_sz kt vt sz) (repr': repr_t_sz kt vt sz) idx k v (k': _{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k, v)) (ensures lookup_repr repr k' == lookup_repr repr' k') =
let idx' = canonical_index k' repr in let rec aux (off: nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off + 1) else match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off + 1) | Zombie -> aux (off + 1) in aux 0
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.validate_sum
val validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc))
val validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc))
let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr)
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 72, "end_line": 202, "start_col": 0, "start_line": 192 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> v: LowParse.Low.Base.validator p -> p32: LowParse.Low.Base.leaf_reader p -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> pc32: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.validator (FStar.Pervasives.dsnd (pc x))) -> destr: LowParse.Spec.Enum.dep_maybe_enum_destr_t (LowParse.Spec.Sum.sum_enum t) (LowParse.Low.Sum.validate_sum_aux_payload_t t pc) -> LowParse.Low.Base.validator (LowParse.Spec.Sum.parse_sum t p pc)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Low.Base.validator", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Sum.sum_type_of_tag", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Enum.dep_maybe_enum_destr_t", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Low.Sum.validate_sum_aux_payload_t", "LowParse.Low.Sum.validate_sum_aux", "LowParse.Low.Sum.validate_sum_aux_payload", "LowParse.Spec.Sum.parse_sum_kind", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.parse_sum" ]
[]
false
false
false
false
false
let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) =
validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr)
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.jump_sum_cases_t_eq
val jump_sum_cases_t_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y: jump_sum_cases_t t pc k) : GTot Type0
val jump_sum_cases_t_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y: jump_sum_cases_t t pc k) : GTot Type0
let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 306, "start_col": 0, "start_line": 300 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Sum.sum_key t -> x: LowParse.Low.Sum.jump_sum_cases_t t pc k -> y: LowParse.Low.Sum.jump_sum_cases_t t pc k -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Sum.jump_sum_cases_t", "Prims.l_True" ]
[]
false
false
false
false
true
let jump_sum_cases_t_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y: jump_sum_cases_t t pc k) : GTot Type0 =
True
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lemma_used_upd
val lemma_used_upd (#kt #vt #sz spec: _) (repr: repr_t_sz kt vt sz) (off: nat{off < sz}) (k: _) (v v': vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k, v)) (upd_ repr ((canonical_index k repr + off) % sz) k v))
val lemma_used_upd (#kt #vt #sz spec: _) (repr: repr_t_sz kt vt sz) (off: nat{off < sz}) (k: _) (v v': vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k, v)) (upd_ repr ((canonical_index k repr + off) % sz) k v))
let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 61, "end_line": 463, "start_col": 0, "start_line": 427 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
spec: Pulse.Lib.HashTable.Spec.spec_t kt vt -> repr: Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz -> off: Prims.nat{off < sz} -> k: kt -> v: vt -> v': vt -> FStar.Pervasives.Lemma (requires Pulse.Lib.HashTable.Spec.pht_models spec repr /\ Some? (Pulse.Lib.HashTable.Spec.lookup_repr repr k) /\ repr @@ (Pulse.Lib.HashTable.Spec.canonical_index k repr + off) % sz == Pulse.Lib.HashTable.Spec.Used k v' /\ Pulse.Lib.HashTable.Spec.all_used_not_by repr (Pulse.Lib.HashTable.Spec.canonical_index k repr) off k) (ensures Pulse.Lib.HashTable.Spec.pht_models (spec ++ (k, v)) (Pulse.Lib.HashTable.Spec.upd_ repr ((Pulse.Lib.HashTable.Spec.canonical_index k repr + off) % sz) k v))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "Prims.pos", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.repr_t_sz", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Classical.forall_intro_3", "Prims.l_imp", "Prims.eq2", "Pulse.Lib.HashTable.Spec.cell", "Pulse.Lib.HashTable.Spec.op_At_At", "Pulse.Lib.HashTable.Spec.Used", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Pulse.Lib.HashTable.Spec.lookup_repr_index", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "FStar.Classical.move_requires_3", "Prims.unit", "FStar.Classical.forall_intro", "FStar.Pervasives.Native.uu___is_Some", "Pulse.Lib.HashTable.Spec.lookup_repr", "Pulse.Lib.HashTable.Spec.lookup_spec", "FStar.Classical.move_requires", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_Equality", "Pulse.Lib.HashTable.Spec.lemma_walk_from_canonical_all_used", "Prims._assert", "Prims.bool", "Pulse.Lib.HashTable.Spec.lemma_used_upd_lookup_walk", "Pulse.Lib.HashTable.Spec.repr_t", "Pulse.Lib.HashTable.Spec.upd_", "Prims.int", "Prims.op_Modulus", "Prims.op_Addition", "Pulse.Lib.HashTable.Spec.canonical_index", "Pulse.Lib.HashTable.Spec.op_Plus_Plus", "Prims.l_and", "Pulse.Lib.HashTable.Spec.pht_models", "Pulse.Lib.HashTable.Spec.all_used_not_by" ]
[]
false
false
true
false
false
let lemma_used_upd #kt #vt #sz spec (repr: repr_t_sz kt vt sz) (off: nat{off < sz}) k (v: vt) (v': vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k, v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) =
let spec' = spec ++ (k, v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k': kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k': kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i': nat{i' < sz}) (k': kt) (v'': vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then (assert (lookup_repr_index repr k == Some (v', idx)); lemma_walk_from_canonical_all_used repr' off k v; ()) else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3)
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.full_not_full
val full_not_full (#kt #vt: _) (r: repr_t kt vt) (k: kt) : Lemma (requires not_full r /\ strong_all_used_not_by r (canonical_index k r) r.sz k) (ensures False)
val full_not_full (#kt #vt: _) (r: repr_t kt vt) (k: kt) : Lemma (requires not_full r /\ strong_all_used_not_by r (canonical_index k r) r.sz k) (ensures False)
let full_not_full #kt #vt (r:repr_t kt vt) (k:kt) : Lemma (requires not_full r /\ strong_all_used_not_by r (canonical_index k r) r.sz k) (ensures False) = eliminate exists (i:nat { i < r.sz }). ~(Used? (r @@ i)) returns False with _ . ( assert (~(Used? (r@@i))); eliminate_strong_all_used_not_by r k i )
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 778, "start_col": 0, "start_line": 767 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_zombie_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i:nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc (==>) { (canonical_index k repr + i) % sz == idx; ==> {} (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ==> { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_del #kt #vt #sz spec (repr : repr_t_sz kt vt sz) idx k v : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx)) = let spec' = spec -- k in let repr' = del_ repr idx in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin let Some (v', i') = lookup_repr_index repr' k' in assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then begin assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let not_full #kt #vt (r:repr_t kt vt) : Type0 = exists i. ~(Used? (r @@ i )) #set-options "--split_queries always" let rec insert_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr /\ not_full repr}) (k : kt) (v : vt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (strong_all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then ( // Impossible! table was not full let aux (i:nat{i < sz}) : Lemma (Used? (repr @@ i)) = assert (all_used_not_by repr cidx sz k); let off = (i - cidx) % sz in calc (==) { (cidx + off) % sz; == {} (cidx + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_lemma cidx sz } (cidx % sz + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_distributivity cidx (i-cidx) sz } i % sz; == { Math.Lemmas.modulo_lemma i sz } i; }; assert (Used? (repr @@ i)); () in Classical.forall_intro aux; unreachable () ) else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_used_upd spec repr off k v v'; upd_ repr idx k v end else begin assert (all_used_not_by repr cidx (off+1) k); insert_repr_walk #kt #vt #sz #spec repr k v (off+1) cidx () () end | Clean -> (**)lemma_clean_upd spec repr off k v; upd_ repr idx k v | Zombie -> match lookup_repr_index repr k with | Some (v_old,i) -> ( (**)lemma_del spec repr i k v_old; // Don't need these asserts let cidx = canonical_index k repr in assert (all_used_not_by repr cidx off k); // GM: Removing this assert, not needed now it seems //assert (if idx >= cidx then i > idx || i <= cidx else i > idx /\ i <= cidx); assert (all_used_not_by (del_ repr i) cidx off k); (**)lemma_zombie_upd #_ #_ #sz (spec -- k) (del_ repr i) off k v; upd_ (del_ repr i) idx k v ) | None -> ( (**)lemma_zombie_upd spec repr off k v; upd_ repr idx k v ) let insert_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (v : vt) : Pure (r':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) r' /\ repr_related repr r' }) (requires not_full repr) (ensures fun _ -> True) = let cidx = canonical_index k repr in let res = insert_repr_walk #kt #vt #sz #spec repr k v 0 cidx () () in res let rec delete_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec -- k) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then repr // If we reach this, the element was not in the table else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_del spec repr idx k v'; del_ repr idx end else begin assert (all_used_not_by repr cidx (off+1) k); delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () end | Clean -> repr | Zombie -> delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () let delete_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) : r':repr_t_sz kt vt sz{ pht_models (spec -- k) r' /\ repr_related repr r' } = let cidx = canonical_index k repr in let res = delete_repr_walk #kt #vt #sz #spec repr k 0 cidx () () in res // TODO: This states we can only insert on a non-full table, // but that's only if the key we want to insert is not already present, // so it's stronger than it should be. This is anyway perhaps not important // for this pure implementation, as the Pulse implementation could always // keep one cell free and trivially satisfy this invariant. let insert #kt #vt (ht : pht_t kt vt{not_full ht.repr}) (k : kt) (v : vt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec ++ (k,v)) } = { ht with spec = Ghost.hide (ht.spec ++ (k,v)); repr = insert_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k v; inv = () } let delete #kt #vt (ht : pht_t kt vt) (k : kt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec -- k) } = { ht with spec = Ghost.hide (ht.spec -- k); repr = delete_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k; inv = () } let lookup #kt #vt (ht : pht_t kt vt) (k : kt) : o:(option vt){o == lookup_spec ht.spec k} = lookup_repr ht.repr k let lookup_index #kt #vt (ht : pht_t kt vt) (k : kt) : option (vt & nat) = lookup_repr_index ht.repr k // let lookup_index_us #kt #vt (ht : pht_t kt vt) (k : kt) // : option (vt & US.t) // = let o = lookup_repr_index ht.repr k in // match o with // | Some (v,i) -> Some (v, US.uint_to_t i) // | None -> None let lookup_index_us #kt #vt (ht : pht_t kt vt) (k : kt) : option US.t = let o = lookup_repr_index ht.repr k in match o with | Some (_, i) -> Some (US.uint_to_t i) | None -> None let upd_pht (#kt:eqtype) (#vt:Type) (pht:pht_t kt vt) idx (k:kt) (v:vt) (_:squash (lookup_index_us pht k == Some idx)) : pht_t kt vt = let spec' = Ghost.hide (pht.spec ++ (k, v)) in let repr' = upd_ pht.repr (US.v idx) k v in let Used k v' = pht.repr @@ US.v idx in let cidx = canonical_index #kt #vt k pht.repr in walk_get_idx_upd pht.repr repr' cidx k 0 (US.v idx) v; assert (lookup_repr_index repr' k == Some (v, US.v idx)); introduce forall (k':kt { k' =!= k }). lookup_repr repr' k' == lookup_repr pht.repr k' with lemma_used_upd_lookup_walk #_ #_ #pht.repr.sz pht.spec spec' pht.repr repr' (US.v idx) k k' v v'; { pht with spec = spec'; repr = repr'; inv = () } #push-options "--z3rlimit_factor 2" let eliminate_strong_all_used_not_by #kt #vt (r:repr_t kt vt) (k:kt) (i:nat{i < r.sz}) : Lemma (requires strong_all_used_not_by r (canonical_index k r) r.sz k) (ensures Used? (r @@ i) /\ Used?.k (r @@ i) <> k) = let j = canonical_index k r in if (j < i) then ( assert (i == (j + (i-j)) % r.sz); assert (Used? (r @@ i)) ) else ( let k = ((r.sz - j) + i) in assert (i == (j + k) % r.sz); if (k < r.sz) then ( assert (Used? (r @@ i)) ) else ( assert (i == (j + 0) % r.sz); assert (Used? (r @@ ((j + 0) % r.sz))) ) ) #pop-options
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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: Pulse.Lib.HashTable.Spec.repr_t kt vt -> k: kt -> FStar.Pervasives.Lemma (requires Pulse.Lib.HashTable.Spec.not_full r /\ Pulse.Lib.HashTable.Spec.strong_all_used_not_by r (Pulse.Lib.HashTable.Spec.canonical_index k r) (Mkrepr_t?.sz r) k) (ensures Prims.l_False)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "FStar.Classical.Sugar.exists_elim", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.l_not", "Pulse.Lib.HashTable.Spec.uu___is_Used", "Pulse.Lib.HashTable.Spec.op_At_At", "Prims.l_False", "Prims.squash", "Pulse.Lib.HashTable.Spec.eliminate_strong_all_used_not_by", "Prims.unit", "Prims._assert", "Prims.l_and", "Pulse.Lib.HashTable.Spec.not_full", "Pulse.Lib.HashTable.Spec.strong_all_used_not_by", "Pulse.Lib.HashTable.Spec.canonical_index", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let full_not_full #kt #vt (r: repr_t kt vt) (k: kt) : Lemma (requires not_full r /\ strong_all_used_not_by r (canonical_index k r) r.sz k) (ensures False) =
eliminate exists (i: nat{i < r.sz}). ~(Used? (r @@ i)) returns False with _. (assert (~(Used? (r @@ i))); eliminate_strong_all_used_not_by r k i)
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lemma_zombie_upd
val lemma_zombie_upd (#kt #vt #sz spec: _) (repr: repr_t_sz kt vt sz) (off: nat{off < sz}) (k v: _) : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k, v)) (upd_ repr ((canonical_index k repr + off) % sz) k v))
val lemma_zombie_upd (#kt #vt #sz spec: _) (repr: repr_t_sz kt vt sz) (off: nat{off < sz}) (k v: _) : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k, v)) (upd_ repr ((canonical_index k repr + off) % sz) k v))
let lemma_zombie_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i:nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc (==>) { (canonical_index k repr + i) % sz == idx; ==> {} (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ==> { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 61, "end_line": 512, "start_col": 0, "start_line": 465 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
spec: Pulse.Lib.HashTable.Spec.spec_t kt vt -> repr: Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz -> off: Prims.nat{off < sz} -> k: kt -> v: vt -> FStar.Pervasives.Lemma (requires Pulse.Lib.HashTable.Spec.pht_models spec repr /\ None? (Pulse.Lib.HashTable.Spec.lookup_repr repr k) /\ repr @@ (Pulse.Lib.HashTable.Spec.canonical_index k repr + off) % sz == Pulse.Lib.HashTable.Spec.Zombie /\ Pulse.Lib.HashTable.Spec.all_used_not_by repr (Pulse.Lib.HashTable.Spec.canonical_index k repr) off k) (ensures Pulse.Lib.HashTable.Spec.pht_models (spec ++ (k, v)) (Pulse.Lib.HashTable.Spec.upd_ repr ((Pulse.Lib.HashTable.Spec.canonical_index k repr + off) % sz) k v))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "Prims.pos", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.repr_t_sz", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Classical.forall_intro_3", "Prims.l_imp", "Prims.eq2", "Pulse.Lib.HashTable.Spec.cell", "Pulse.Lib.HashTable.Spec.op_At_At", "Pulse.Lib.HashTable.Spec.Used", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Pulse.Lib.HashTable.Spec.lookup_repr_index", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "FStar.Classical.move_requires_3", "Prims.unit", "FStar.Classical.forall_intro", "FStar.Pervasives.Native.uu___is_Some", "Pulse.Lib.HashTable.Spec.lookup_repr", "Pulse.Lib.HashTable.Spec.lookup_spec", "FStar.Classical.move_requires", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_Equality", "Pulse.Lib.HashTable.Spec.lemma_walk_from_canonical_all_used", "Prims.bool", "Pulse.Lib.HashTable.Spec.lemma_zombie_upd_lookup_walk", "Prims._assert", "Pulse.Lib.HashTable.Spec.all_used_not_by", "Pulse.Lib.HashTable.Spec.canonical_index", "Pulse.Lib.HashTable.Spec.used_not_by", "Prims.op_Modulus", "Prims.op_Addition", "Prims.l_True", "FStar.Calc.calc_finish", "Prims.logical", "Prims.int", "Prims.l_or", "Prims.Cons", "FStar.Preorder.relation", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Calc.calc_push_impl", "FStar.Math.Lemmas.lemma_mod_plus_injective", "Pulse.Lib.HashTable.Spec.repr_t", "Pulse.Lib.HashTable.Spec.upd_", "Pulse.Lib.HashTable.Spec.op_Plus_Plus", "Prims.l_and", "Pulse.Lib.HashTable.Spec.pht_models", "FStar.Pervasives.Native.uu___is_None", "Pulse.Lib.HashTable.Spec.Zombie" ]
[]
false
false
true
false
false
let lemma_zombie_upd #kt #vt #sz spec (repr: repr_t_sz kt vt sz) (off: nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k, v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) =
let spec' = spec ++ (k, v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i: nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc ( ==> ) { (canonical_index k repr + i) % sz == idx; ( ==> ) { () } (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ( ==> ) { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k': kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then (lemma_walk_from_canonical_all_used repr' off k v; ()) else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k': kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i': nat{i' < sz}) (k': kt) (v': vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3)
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lemma_clean_upd_lookup_walk
val lemma_clean_upd_lookup_walk (#kt #vt #sz: _) (spec1 spec2: spec_t kt vt) (repr1 repr2: repr_t_sz kt vt sz) (idx k v: _) (k': _{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k, v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k')
val lemma_clean_upd_lookup_walk (#kt #vt #sz: _) (spec1 spec2: spec_t kt vt) (repr1 repr2: repr_t_sz kt vt sz) (idx k v: _) (k': _{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k, v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k')
let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 7, "end_line": 216, "start_col": 0, "start_line": 184 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz}
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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
spec1: Pulse.Lib.HashTable.Spec.spec_t kt vt -> spec2: Pulse.Lib.HashTable.Spec.spec_t kt vt -> repr1: Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz -> repr2: Pulse.Lib.HashTable.Spec.repr_t_sz kt vt sz -> idx: i: Prims.int{i >= 0 /\ i < Mkrepr_t?.sz repr2 /\ (i >= 0) /\ (i < Mkrepr_t?.sz repr1)} -> k: kt -> v: vt -> k': kt{~(k == k')} -> FStar.Pervasives.Lemma (requires Pulse.Lib.HashTable.Spec.repr_related repr1 repr2 /\ (forall (i: Prims.int{i >= 0 /\ i < Mkrepr_t?.sz repr2 /\ (i >= 0) /\ (i < Mkrepr_t?.sz repr1)}). i < Mkrepr_t?.sz repr1 /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (Pulse.Lib.HashTable.Spec.lookup_repr repr1 k) /\ Pulse.Lib.HashTable.Spec.pht_models spec1 repr1 /\ repr1 @@ idx == Pulse.Lib.HashTable.Spec.Clean /\ repr2 == Pulse.Lib.HashTable.Spec.upd_ repr1 idx k v /\ spec2 == spec1 ++ (k, v)) (ensures Pulse.Lib.HashTable.Spec.lookup_repr repr1 k' == Pulse.Lib.HashTable.Spec.lookup_repr repr2 k')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "Prims.pos", "Pulse.Lib.HashTable.Spec.spec_t", "Pulse.Lib.HashTable.Spec.repr_t_sz", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims.l_not", "Prims.eq2", "Prims.nat", "Prims.op_LessThanOrEqual", "Prims.unit", "Prims.op_Subtraction", "FStar.Pervasives.Native.option", "Pulse.Lib.HashTable.Spec.walk", "Pulse.Lib.HashTable.Spec.lookup_repr", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_Equality", "Prims.l_or", "Prims.op_GreaterThan", "Prims.bool", "Prims.op_Modulus", "Prims.op_Addition", "Pulse.Lib.HashTable.Spec.op_At_At", "Pulse.Lib.HashTable.Spec.canonical_index", "Pulse.Lib.HashTable.Spec.repr_related", "Prims.l_Forall", "Prims.l_imp", "Prims.op_disEquality", "Pulse.Lib.HashTable.Spec.cell", "FStar.Pervasives.Native.uu___is_None", "Pulse.Lib.HashTable.Spec.pht_models", "Pulse.Lib.HashTable.Spec.Clean", "Pulse.Lib.HashTable.Spec.repr_t", "Pulse.Lib.HashTable.Spec.upd_", "Pulse.Lib.HashTable.Spec.op_Plus_Plus", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
false
true
false
false
let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1: spec_t kt vt) (spec2: spec_t kt vt) (repr1: repr_t_sz kt vt sz) (repr2: repr_t_sz kt vt sz) idx k v (k': _{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k, v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') =
let idx' = canonical_index k' repr1 in let rec aux (off: nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off + 1) else match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off + 1) | Zombie -> aux (off + 1) in aux 0
false
Steel.ST.HigherArray.fst
Steel.ST.HigherArray.index0
val index0 (#t: Type) (#p: P.perm) (a: array t) (#s: Ghost.erased (Seq.seq t)) (i: US.t) : ST t (pts_to a p s) (fun _ -> pts_to a p s) (US.v i < length a \/ US.v i < Seq.length s) (fun res -> Seq.length s == length a /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i))
val index0 (#t: Type) (#p: P.perm) (a: array t) (#s: Ghost.erased (Seq.seq t)) (i: US.t) : ST t (pts_to a p s) (fun _ -> pts_to a p s) (US.v i < length a \/ US.v i < Seq.length s) (fun res -> Seq.length s == length a /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i))
let index0 (#t: Type) (#p: P.perm) (a: array t) (#s: Ghost.erased (Seq.seq t)) (i: US.t) : ST t (pts_to a p s) (fun _ -> pts_to a p s) (US.v i < length a \/ US.v i < Seq.length s) (fun res -> Seq.length s == length a /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i)) = elim_pts_to a p s; let s' = R.read (ptr_of a).base _ in let res = fst (Some?.v (M.sel s' ((ptr_of a).offset + US.v i))) in intro_pts_to a p s; return res
{ "file_name": "lib/steel/Steel.ST.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 12, "end_line": 428, "start_col": 0, "start_line": 414 }
(* Copyright 2022 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 Steel.ST.HigherArray module P = Steel.PCMFrac module R = Steel.ST.PCMReference module M = FStar.Map module PM = Steel.PCMMap [@@noextract_to "krml"] let index_t (len: Ghost.erased nat) : Tot Type0 = (i: nat { i < len }) [@@noextract_to "krml"] let carrier (elt: Type u#a) (len: Ghost.erased nat) : Tot Type = PM.map (index_t len) (P.fractional elt) [@@noextract_to "krml"] let pcm (elt: Type u#a) (len: Ghost.erased nat) : Tot (P.pcm (carrier elt len)) = PM.pointwise (index_t len) (P.pcm_frac #elt) [@@noextract_to "krml"] let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.one let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.composable [@@noextract_to "krml"] let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.op [@@noextract_to "krml"] let mk_carrier (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p: P.perm) : Tot (carrier elt len) = let f (i: nat) : Tot (P.fractional elt) = if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s then None else Some (Seq.index s (i - offset), p) in M.map_literal f let mk_carrier_inj (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: P.perm) : Lemma (requires ( mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\ offset + Seq.length s1 <= len /\ offset + Seq.length s2 <= len )) (ensures ( s1 `Seq.equal` s2 /\ (Seq.length s1 > 0 ==> p1 == p2) )) = assert (forall (i: nat) . i < Seq.length s1 ==> (M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1))); assert (forall (i: nat) . i < Seq.length s2 ==> M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2)) [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: US.t & ref _ (pcm elt (US.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = US.v (dfst b) [@@noextract_to "krml"] noeq type ptr (elt: Type u#a) : Type0 = { base_len: Ghost.erased US.t; // U32.t to prove that A.read, A.write offset computation does not overflow. TODO: replace U32.t with size_t base: (r: ref _ (pcm elt (US.v base_len)) { core_ref_is_null r ==> US.v base_len == 0 }); offset: (offset: nat { offset <= US.v base_len }); } let null_ptr a = { base_len = 0sz; base = null #_ #(pcm a 0) ; offset = 0 } let is_null_ptr p = is_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr _ = () let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: P.perm) : Tot prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.P.v <=. one)) [@__reduce__] let pts_to0 (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : Tot vprop = R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p) `star` pure ( valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let pts_to (#elt: Type u#1) (a: array elt) ([@@@ smt_fallback ] p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop = pts_to0 a p s // this lemma is necessary because Steel.PCMReference is marked unfold let change_r_pts_to (#opened: _) (#carrier: Type u#1) (#pcm: P.pcm carrier) (p: ref carrier pcm) (v: carrier) (#carrier': Type u#1) (#pcm': P.pcm carrier') (p': ref carrier' pcm') (v': carrier') : STGhost unit opened (R.pts_to p v) (fun _ -> R.pts_to p' v') (// keep on distinct lines for error messages carrier == carrier' /\ pcm == pcm' /\ p == p' /\ v == v') (fun _ -> True) = rewrite (R.pts_to p v) (R.pts_to p' v') let intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened (R.pts_to (ptr_of a).base v) (fun _ -> pts_to a p s) ( v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\ valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) (fun _ -> True) = change_r_pts_to (ptr_of a).base v (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p); intro_pure _; rewrite (pts_to0 a p s) (pts_to a p s) let elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened (pts_to a p s) (fun _ -> R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p)) (True) (fun _ -> valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) = rewrite (pts_to a p s) (pts_to0 a p s); elim_pure _ let pts_to_length a s = elim_pts_to a _ s; intro_pts_to a _ s let pts_to_not_null a s = elim_pts_to a _ s; R.pts_to_not_null _ _; intro_pts_to a _ s let mk_carrier_joinable (#elt: Type) (len: nat) (offset: nat) (s1: Seq.seq elt) (p1: P.perm) (s2: Seq.seq elt) (p2: P.perm) : Lemma (requires ( offset + Seq.length s1 <= len /\ Seq.length s1 == Seq.length s2 /\ P.joinable (pcm elt len) (mk_carrier len offset s1 p1) (mk_carrier len offset s2 p2) )) (ensures ( s1 `Seq.equal` s2 )) = let lem (i: nat { 0 <= i /\ i < Seq.length s1 }) : Lemma (Seq.index s1 i == Seq.index s2 i) [SMTPat (Seq.index s1 i); SMTPat (Seq.index s2 i)] = assert ( forall z . ( P.compatible (pcm elt len) (mk_carrier len offset s1 p1) z /\ P.compatible (pcm elt len) (mk_carrier len offset s2 p2) z ) ==> begin match M.sel z (offset + i) with | None -> False | Some (v, _) -> v == Seq.index s1 i /\ v == Seq.index s2 i end ) in () let pure_star_interp' (p:slprop u#a) (q:prop) (m:mem) : Lemma (interp (p `Steel.Memory.star` Steel.Memory.pure q) m <==> interp p m /\ q) = pure_star_interp p q m; emp_unit p let pts_to_inj a p1 s1 p2 s2 m = Classical.forall_intro reveal_pure; pure_star_interp' (hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1))) ( valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s1) p1 /\ Seq.length s1 == length a ) m; pure_star_interp' (hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2))) ( valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s2) p2 /\ Seq.length s2 == length a ) m; pts_to_join (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1) (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2) m; mk_carrier_joinable (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1 s2 p2 [@@noextract_to "krml"] let malloc0 (#elt: Type) (x: elt) (n: US.t) : ST (array elt) emp (fun a -> pts_to a P.full_perm (Seq.create (US.v n) x)) (True) (fun a -> length a == US.v n /\ base_len (base (ptr_of a)) == US.v n ) = let c : carrier elt (US.v n) = mk_carrier (US.v n) 0 (Seq.create (US.v n) x) P.full_perm in let base : ref (carrier elt (US.v n)) (pcm elt (US.v n)) = R.alloc c in R.pts_to_not_null base _; let p = { base_len = n; base = base; offset = 0; } in let a = (| p, Ghost.hide (US.v n) |) in change_r_pts_to base c (ptr_of a).base c; intro_pts_to a P.full_perm (Seq.create (US.v n) x); return a let malloc_ptr x n = let a = malloc0 x n in let (| p, _ |) = a in rewrite (pts_to _ _ _) (pts_to (| p, Ghost.hide (US.v n) |) _ _); return p [@@noextract_to "krml"] let free0 (#elt: Type) (#s: Ghost.erased (Seq.seq elt)) (a: array elt) : ST unit (pts_to a P.full_perm s) (fun _ -> emp) ( length a == base_len (base (ptr_of a)) ) (fun _ -> True) = drop (pts_to a _ _) let free_ptr a = free0 _ let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: P.perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (P.sum_perm p1 p2) let mk_carrier_share (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: P.perm) : Lemma (requires (valid_sum_perm len offset (Seq.length s) p1 p2)) (ensures ( let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 /\ mk_carrier len offset s (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2) )) = () let share #_ #_ #x a p p1 p2 = elim_pts_to a p x; mk_carrier_share (US.v (ptr_of a).base_len) (ptr_of a).offset x p1 p2; R.split (ptr_of a).base _ (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p1) (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p2); intro_pts_to a p1 x; intro_pts_to a p2 x let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: P.perm) : Lemma (requires ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) (ensures ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `P.sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `P.sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 )) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `P.sum_perm` p2) (p1 `P.sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: P.perm) : Lemma (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (P.composable (M.sel c1 offset) (M.sel c2 offset) <==> valid_perm len offset (Seq.length s) (P.sum_perm p1 p2)) else () let gather a #x1 p1 #x2 p2 = elim_pts_to a p1 x1; elim_pts_to a p2 x2; let _ = R.gather (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 p1) (mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) x2 p2) in mk_carrier_gather (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 x2 p1 p2; mk_carrier_valid_sum_perm (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 p1 p2; intro_pts_to a (p1 `P.sum_perm` p2) x1 #push-options "--z3rlimit 16"
{ "checked_file": "/", "dependencies": [ "Steel.ST.PCMReference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.PCMMap.fst.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Steel.PCMMap", "short_module": "PM" }, { "abbrev": true, "full_module": "FStar.Map", "short_module": "M" }, { "abbrev": true, "full_module": "Steel.ST.PCMReference", "short_module": "R" }, { "abbrev": true, "full_module": "Steel.PCMFrac", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Steel.ST.HigherArray.array t -> i: FStar.SizeT.t -> Steel.ST.Effect.ST t
Steel.ST.Effect.ST
[]
[]
[ "Steel.FractionalPermission.perm", "Steel.ST.HigherArray.array", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "FStar.SizeT.t", "Steel.ST.Util.return", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.ST.HigherArray.pts_to", "FStar.Ghost.reveal", "Steel.Effect.Common.vprop", "Prims.unit", "Steel.ST.HigherArray.intro_pts_to", "Steel.ST.HigherArray.mk_carrier", "FStar.SizeT.v", "Steel.ST.HigherArray.__proj__Mkptr__item__base_len", "Steel.ST.HigherArray.ptr_of", "Steel.ST.HigherArray.__proj__Mkptr__item__offset", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.Pervasives.Native.tuple2", "FStar.Map.sel", "Steel.ST.HigherArray.index_t", "Prims.nat", "Steel.PCMFrac.fractional", "Prims.op_Addition", "Steel.ST.HigherArray.carrier", "Steel.ST.PCMReference.read", "Steel.ST.HigherArray.pcm", "Steel.ST.HigherArray.__proj__Mkptr__item__base", "Steel.ST.HigherArray.elim_pts_to", "Prims.l_or", "Prims.b2t", "Prims.op_LessThan", "Steel.ST.HigherArray.length", "FStar.Seq.Base.length", "Prims.l_True", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.index" ]
[]
false
true
false
false
false
let index0 (#t: Type) (#p: P.perm) (a: array t) (#s: Ghost.erased (Seq.seq t)) (i: US.t) : ST t (pts_to a p s) (fun _ -> pts_to a p s) (US.v i < length a \/ US.v i < Seq.length s) (fun res -> Seq.length s == length a /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i)) =
elim_pts_to a p s; let s' = R.read (ptr_of a).base _ in let res = fst (Some?.v (M.sel s' ((ptr_of a).offset + US.v i))) in intro_pts_to a p s; return res
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.jump_sum_aux_payload_eq
val jump_sum_aux_payload_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0)
val jump_sum_aux_payload_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0)
let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 17, "end_line": 363, "start_col": 0, "start_line": 358 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res )))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Enum.maybe_enum_key (LowParse.Spec.Sum.sum_enum t) -> _: LowParse.Low.Sum.jump_sum_aux_payload_t t pc k -> _: LowParse.Low.Sum.jump_sum_aux_payload_t t pc k -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Low.Sum.jump_sum_aux_payload_t", "Prims.l_True" ]
[]
false
false
false
false
true
let jump_sum_aux_payload_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) =
fun _ _ -> True
false
Vale.FDefMulx.X64.fst
Vale.FDefMulx.X64.va_lemma_MulAdd18
val va_lemma_MulAdd18 : va_b0:va_code -> va_s0:va_state -> r0:va_operand_reg_opr64 -> r1:va_operand_reg_opr64 -> r2:va_operand_reg_opr64 -> r3:va_operand_reg_opr64 -> r4:va_operand_reg_opr64 -> r5:va_operand_reg_opr64 -> r6:va_operand_reg_opr64 -> r7:va_operand_reg_opr64 -> regRotate:nat -> bA:buffer64 -> bB:buffer64 -> bD:buffer64 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_MulAdd18 r0 r1 r2 r3 r4 r5 r6 r7) va_s0 /\ va_is_dst_reg_opr64 r0 va_s0 /\ va_is_dst_reg_opr64 r1 va_s0 /\ va_is_dst_reg_opr64 r2 va_s0 /\ va_is_dst_reg_opr64 r3 va_s0 /\ va_is_dst_reg_opr64 r4 va_s0 /\ va_is_dst_reg_opr64 r5 va_s0 /\ va_is_dst_reg_opr64 r6 va_s0 /\ va_is_dst_reg_opr64 r7 va_s0 /\ va_get_ok va_s0 /\ (let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in Vale.X64.Decls.valid_cf (va_get_flags va_s0) /\ flag_cf (va_get_flags va_s0) == 0 /\ (Vale.X64.Decls.valid_of (va_get_flags va_s0) /\ flag_of (va_get_flags va_s0) == 0)) /\ (let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in adx_enabled /\ bmi2_enabled /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rRcx va_s0) bA 8 (va_get_mem_layout va_s0) Public /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rRsi va_s0) bB 1 (va_get_mem_layout va_s0) Public /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rRdi va_s0) bD 1 (va_get_mem_layout va_s0) Public /\ FStar.Seq.Base.length #Vale.Def.Types_s.nat64 as0 == 8 /\ r0 == operand_reg8 (regRotate + 0) /\ r1 == operand_reg8 (regRotate + 1) /\ r2 == operand_reg8 (regRotate + 2) /\ r3 == operand_reg8 (regRotate + 3) /\ r4 == operand_reg8 (regRotate + 4) /\ r5 == operand_reg8 (regRotate + 5) /\ r6 == operand_reg8 (regRotate + 6) /\ r7 == operand_reg8 (regRotate + 7)))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in Vale.X64.Decls.valid_cf (va_get_flags va_sM) /\ flag_cf (va_get_flags va_sM) == 0 /\ (Vale.X64.Decls.valid_of (va_get_flags va_sM) /\ flag_of (va_get_flags va_sM) == 0)) /\ (let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in let (b:Vale.Def.Types_s.nat64) = Vale.X64.Decls.buffer64_read bB 0 (va_get_mem_heaplet 0 va_s0) in let (d:Vale.Def.Types_s.nat64) = Vale.X64.Decls.buffer64_read bD 0 (va_get_mem_heaplet 0 va_s0) in let (xs:(seq nat64)) = make_seq9 #nat64 (Vale.X64.Decls.buffer64_read bD 0 (va_get_mem_heaplet 0 va_sM)) (va_eval_reg_opr64 va_sM r1) (va_eval_reg_opr64 va_sM r2) (va_eval_reg_opr64 va_sM r3) (va_eval_reg_opr64 va_sM r4) (va_eval_reg_opr64 va_sM r5) (va_eval_reg_opr64 va_sM r6) (va_eval_reg_opr64 va_sM r7) (va_eval_reg_opr64 va_sM r0) in sum_pow_seq xs == sum_pow_seq rs + b `op_Multiply` sum_pow_seq as0 + d) /\ va_state_eq va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 0 va_sM (va_update_flags va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM (va_update_operand_reg_opr64 r7 va_sM (va_update_operand_reg_opr64 r6 va_sM (va_update_operand_reg_opr64 r5 va_sM (va_update_operand_reg_opr64 r4 va_sM (va_update_operand_reg_opr64 r3 va_sM (va_update_operand_reg_opr64 r2 va_sM (va_update_operand_reg_opr64 r1 va_sM (va_update_operand_reg_opr64 r0 va_sM va_s0))))))))))))))))))
val va_lemma_MulAdd18 : va_b0:va_code -> va_s0:va_state -> r0:va_operand_reg_opr64 -> r1:va_operand_reg_opr64 -> r2:va_operand_reg_opr64 -> r3:va_operand_reg_opr64 -> r4:va_operand_reg_opr64 -> r5:va_operand_reg_opr64 -> r6:va_operand_reg_opr64 -> r7:va_operand_reg_opr64 -> regRotate:nat -> bA:buffer64 -> bB:buffer64 -> bD:buffer64 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_MulAdd18 r0 r1 r2 r3 r4 r5 r6 r7) va_s0 /\ va_is_dst_reg_opr64 r0 va_s0 /\ va_is_dst_reg_opr64 r1 va_s0 /\ va_is_dst_reg_opr64 r2 va_s0 /\ va_is_dst_reg_opr64 r3 va_s0 /\ va_is_dst_reg_opr64 r4 va_s0 /\ va_is_dst_reg_opr64 r5 va_s0 /\ va_is_dst_reg_opr64 r6 va_s0 /\ va_is_dst_reg_opr64 r7 va_s0 /\ va_get_ok va_s0 /\ (let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in Vale.X64.Decls.valid_cf (va_get_flags va_s0) /\ flag_cf (va_get_flags va_s0) == 0 /\ (Vale.X64.Decls.valid_of (va_get_flags va_s0) /\ flag_of (va_get_flags va_s0) == 0)) /\ (let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in adx_enabled /\ bmi2_enabled /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rRcx va_s0) bA 8 (va_get_mem_layout va_s0) Public /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rRsi va_s0) bB 1 (va_get_mem_layout va_s0) Public /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rRdi va_s0) bD 1 (va_get_mem_layout va_s0) Public /\ FStar.Seq.Base.length #Vale.Def.Types_s.nat64 as0 == 8 /\ r0 == operand_reg8 (regRotate + 0) /\ r1 == operand_reg8 (regRotate + 1) /\ r2 == operand_reg8 (regRotate + 2) /\ r3 == operand_reg8 (regRotate + 3) /\ r4 == operand_reg8 (regRotate + 4) /\ r5 == operand_reg8 (regRotate + 5) /\ r6 == operand_reg8 (regRotate + 6) /\ r7 == operand_reg8 (regRotate + 7)))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in Vale.X64.Decls.valid_cf (va_get_flags va_sM) /\ flag_cf (va_get_flags va_sM) == 0 /\ (Vale.X64.Decls.valid_of (va_get_flags va_sM) /\ flag_of (va_get_flags va_sM) == 0)) /\ (let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in let (b:Vale.Def.Types_s.nat64) = Vale.X64.Decls.buffer64_read bB 0 (va_get_mem_heaplet 0 va_s0) in let (d:Vale.Def.Types_s.nat64) = Vale.X64.Decls.buffer64_read bD 0 (va_get_mem_heaplet 0 va_s0) in let (xs:(seq nat64)) = make_seq9 #nat64 (Vale.X64.Decls.buffer64_read bD 0 (va_get_mem_heaplet 0 va_sM)) (va_eval_reg_opr64 va_sM r1) (va_eval_reg_opr64 va_sM r2) (va_eval_reg_opr64 va_sM r3) (va_eval_reg_opr64 va_sM r4) (va_eval_reg_opr64 va_sM r5) (va_eval_reg_opr64 va_sM r6) (va_eval_reg_opr64 va_sM r7) (va_eval_reg_opr64 va_sM r0) in sum_pow_seq xs == sum_pow_seq rs + b `op_Multiply` sum_pow_seq as0 + d) /\ va_state_eq va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 0 va_sM (va_update_flags va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM (va_update_operand_reg_opr64 r7 va_sM (va_update_operand_reg_opr64 r6 va_sM (va_update_operand_reg_opr64 r5 va_sM (va_update_operand_reg_opr64 r4 va_sM (va_update_operand_reg_opr64 r3 va_sM (va_update_operand_reg_opr64 r2 va_sM (va_update_operand_reg_opr64 r1 va_sM (va_update_operand_reg_opr64 r0 va_sM va_s0))))))))))))))))))
let va_lemma_MulAdd18 va_b0 va_s0 r0 r1 r2 r3 r4 r5 r6 r7 regRotate bA bB bD = va_reveal_opaque (`%va_code_MulAdd18) (va_code_MulAdd18 r0 r1 r2 r3 r4 r5 r6 r7); let (va_old_s:va_state) = va_s0 in let (va_b1:va_codes) = va_get_block va_b0 in let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in let (b:Vale.Def.Types_s.nat64) = Vale.X64.Decls.buffer64_read bB 0 (va_get_mem_heaplet 0 va_s0) in let (d:Vale.Def.Types_s.nat64) = Vale.X64.Decls.buffer64_read bD 0 (va_get_mem_heaplet 0 va_s0) in Vale.Bignum.Defs.reveal_add_lo_all (); let (va_s12, va_fc12) = va_lemma_Mem64_lemma (va_hd va_b1) va_s0 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 0 bB 0 Public in let va_b12 = va_tl va_b1 in let (va_s13, va_fc13) = va_lemma_Mov64 (va_hd va_b12) va_s12 (va_op_dst_opr64_reg64 rRdx) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 0 Public) in let va_b13 = va_tl va_b12 in let (va_s14, va_fc14) = va_lemma_Mem64_lemma (va_hd va_b13) va_s13 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRdi) 0 bD 0 Public in let va_b14 = va_tl va_b13 in let (va_s15, va_fc15) = va_lemma_Adox_64 (va_hd va_b14) va_s14 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRdi) 0 Public) in let va_b15 = va_tl va_b14 in let (va_s16, va_fc16) = va_lemma_Mem64_lemma (va_hd va_b15) va_s15 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (0 `op_Multiply` 8) bA 0 Public in let va_b16 = va_tl va_b15 in let (va_s17, va_fc17) = va_lemma_Mulx_64 (va_hd va_b16) va_s16 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (0 `op_Multiply` 8) Public) in let va_b17 = va_tl va_b16 in let (va_s18, va_fc18) = va_lemma_Adcx_64 (va_hd va_b17) va_s17 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_op_opr64_reg64 rRax) in let va_b18 = va_tl va_b17 in let (va_s19, va_fc19) = va_lemma_Adox_64 (va_hd va_b18) va_s18 (va_coerce_reg_opr64_to_dst_opr64 r1) (va_op_opr64_reg64 rRbx) in let va_b19 = va_tl va_b18 in let (va_s20, va_fc20) = va_lemma_Mem64_lemma (va_hd va_b19) va_s19 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (1 `op_Multiply` 8) bA 1 Public in let va_b20 = va_tl va_b19 in let (va_s21, va_fc21) = va_lemma_Mulx_64 (va_hd va_b20) va_s20 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (1 `op_Multiply` 8) Public) in let va_b21 = va_tl va_b20 in let (va_s22, va_fc22) = va_lemma_Adcx_64 (va_hd va_b21) va_s21 (va_coerce_reg_opr64_to_dst_opr64 r1) (va_op_opr64_reg64 rRax) in let va_b22 = va_tl va_b21 in let (va_s23, va_fc23) = va_lemma_Adox_64 (va_hd va_b22) va_s22 (va_coerce_reg_opr64_to_dst_opr64 r2) (va_op_opr64_reg64 rRbx) in let va_b23 = va_tl va_b22 in let (va_s24, va_fc24) = va_lemma_Mem64_lemma (va_hd va_b23) va_s23 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (2 `op_Multiply` 8) bA 2 Public in let va_b24 = va_tl va_b23 in let (va_s25, va_fc25) = va_lemma_Mulx_64 (va_hd va_b24) va_s24 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (2 `op_Multiply` 8) Public) in let va_b25 = va_tl va_b24 in let (va_s26, va_fc26) = va_lemma_Adcx_64 (va_hd va_b25) va_s25 (va_coerce_reg_opr64_to_dst_opr64 r2) (va_op_opr64_reg64 rRax) in let va_b26 = va_tl va_b25 in let (va_s27, va_fc27) = va_lemma_Adox_64 (va_hd va_b26) va_s26 (va_coerce_reg_opr64_to_dst_opr64 r3) (va_op_opr64_reg64 rRbx) in let va_b27 = va_tl va_b26 in let (va_s28, va_fc28) = va_lemma_Mem64_lemma (va_hd va_b27) va_s27 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (3 `op_Multiply` 8) bA 3 Public in let va_b28 = va_tl va_b27 in let (va_s29, va_fc29) = va_lemma_Mulx_64 (va_hd va_b28) va_s28 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (3 `op_Multiply` 8) Public) in let va_b29 = va_tl va_b28 in let (va_s30, va_fc30) = va_lemma_Adcx_64 (va_hd va_b29) va_s29 (va_coerce_reg_opr64_to_dst_opr64 r3) (va_op_opr64_reg64 rRax) in let va_b30 = va_tl va_b29 in let (va_s31, va_fc31) = va_lemma_Adox_64 (va_hd va_b30) va_s30 (va_coerce_reg_opr64_to_dst_opr64 r4) (va_op_opr64_reg64 rRbx) in let va_b31 = va_tl va_b30 in let (va_s32, va_fc32) = va_lemma_Mem64_lemma (va_hd va_b31) va_s31 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (4 `op_Multiply` 8) bA 4 Public in let va_b32 = va_tl va_b31 in let (va_s33, va_fc33) = va_lemma_Mulx_64 (va_hd va_b32) va_s32 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (4 `op_Multiply` 8) Public) in let va_b33 = va_tl va_b32 in let (va_s34, va_fc34) = va_lemma_Adcx_64 (va_hd va_b33) va_s33 (va_coerce_reg_opr64_to_dst_opr64 r4) (va_op_opr64_reg64 rRax) in let va_b34 = va_tl va_b33 in let (va_s35, va_fc35) = va_lemma_Adox_64 (va_hd va_b34) va_s34 (va_coerce_reg_opr64_to_dst_opr64 r5) (va_op_opr64_reg64 rRbx) in let va_b35 = va_tl va_b34 in let (va_s36, va_fc36) = va_lemma_Mem64_lemma (va_hd va_b35) va_s35 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (5 `op_Multiply` 8) bA 5 Public in let va_b36 = va_tl va_b35 in let (va_s37, va_fc37) = va_lemma_Mulx_64 (va_hd va_b36) va_s36 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (5 `op_Multiply` 8) Public) in let va_b37 = va_tl va_b36 in let (va_s38, va_fc38) = va_lemma_Adcx_64 (va_hd va_b37) va_s37 (va_coerce_reg_opr64_to_dst_opr64 r5) (va_op_opr64_reg64 rRax) in let va_b38 = va_tl va_b37 in let (va_s39, va_fc39) = va_lemma_Adox_64 (va_hd va_b38) va_s38 (va_coerce_reg_opr64_to_dst_opr64 r6) (va_op_opr64_reg64 rRbx) in let va_b39 = va_tl va_b38 in let (va_s40, va_fc40) = va_lemma_Mem64_lemma (va_hd va_b39) va_s39 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (6 `op_Multiply` 8) bA 6 Public in let va_b40 = va_tl va_b39 in let (va_s41, va_fc41) = va_lemma_Mulx_64 (va_hd va_b40) va_s40 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (6 `op_Multiply` 8) Public) in let va_b41 = va_tl va_b40 in let (va_s42, va_fc42) = va_lemma_Adcx_64 (va_hd va_b41) va_s41 (va_coerce_reg_opr64_to_dst_opr64 r6) (va_op_opr64_reg64 rRax) in let va_b42 = va_tl va_b41 in let (va_s43, va_fc43) = va_lemma_Adox_64 (va_hd va_b42) va_s42 (va_coerce_reg_opr64_to_dst_opr64 r7) (va_op_opr64_reg64 rRbx) in let va_b43 = va_tl va_b42 in let (va_s44, va_fc44) = va_lemma_Mem64_lemma (va_hd va_b43) va_s43 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (7 `op_Multiply` 8) bA 7 Public in let va_b44 = va_tl va_b43 in let (va_s45, va_fc45) = va_lemma_Mulx_64 (va_hd va_b44) va_s44 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (7 `op_Multiply` 8) Public) in let va_b45 = va_tl va_b44 in let (va_s46, va_fc46) = va_lemma_Adcx_64 (va_hd va_b45) va_s45 (va_coerce_reg_opr64_to_dst_opr64 r7) (va_op_opr64_reg64 rRax) in let va_b46 = va_tl va_b45 in let (va_s47, va_fc47) = va_lemma_Store64_buffer (va_hd va_b46) va_s46 (va_op_heaplet_mem_heaplet 0) (va_op_reg_opr64_reg64 rRdi) r0 0 Public bD 0 in let va_b47 = va_tl va_b46 in let (va_s48, va_fc48) = va_lemma_Mov64 (va_hd va_b47) va_s47 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_const_opr64 0) in let va_b48 = va_tl va_b47 in let (va_s49, va_fc49) = va_lemma_Adcx_64 (va_hd va_b48) va_s48 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_coerce_reg_opr64_to_opr64 r0) in let va_b49 = va_tl va_b48 in let (va_s50, va_fc50) = va_lemma_Adox_64 (va_hd va_b49) va_s49 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_op_opr64_reg64 rRbx) in let va_b50 = va_tl va_b49 in let (l:(va_int_range 8 8)) = 8 in let (ys:(seq nat64)) = init_ys b as0 in let (zs:(seq nat64)) = init_zs b as0 d in let (qs:(seq nat64)) = __proj__Mktuple2__item___1 #(seq nat64) #nat1 (seq_add rs zs 0) in let (xs:(seq nat64)) = make_seq9 #nat64 (Vale.X64.Decls.buffer64_read bD 0 (va_get_mem_heaplet 0 va_s50)) (va_eval_reg_opr64 va_s50 r1) (va_eval_reg_opr64 va_s50 r2) (va_eval_reg_opr64 va_s50 r3) (va_eval_reg_opr64 va_s50 r4) (va_eval_reg_opr64 va_s50 r5) (va_eval_reg_opr64 va_s50 r6) (va_eval_reg_opr64 va_s50 r7) (va_eval_reg_opr64 va_s50 r0) in lemma_seq_add_is_norm rs zs 0 (l + 1); lemma_seq_add_is_norm qs ys 0 (l + 1); lemma_scale_add l b d as0 rs ys zs qs xs; assert (FStar.Seq.Base.equal #nat64 xs (__proj__Mktuple2__item___1 #(seq nat64) #nat1 (seq_add qs ys 0))); let va_forall_lemma () : Lemma (requires true) (ensures (flag_cf (va_get_flags va_s50) == 0 /\ flag_of (va_get_flags va_s50) == 0)) = ( Vale.Bignum.Defs.reveal_add_hi_all (); () ) in va_forall_lemma (); let (va_sM, va_f50) = va_lemma_empty_total va_s50 va_b50 in let va_f49 = va_lemma_merge_total va_b49 va_s49 va_fc50 va_s50 va_f50 va_sM in let va_f48 = va_lemma_merge_total va_b48 va_s48 va_fc49 va_s49 va_f49 va_sM in let va_f47 = va_lemma_merge_total va_b47 va_s47 va_fc48 va_s48 va_f48 va_sM in let va_f46 = va_lemma_merge_total va_b46 va_s46 va_fc47 va_s47 va_f47 va_sM in let va_f45 = va_lemma_merge_total va_b45 va_s45 va_fc46 va_s46 va_f46 va_sM in let va_f44 = va_lemma_merge_total va_b44 va_s44 va_fc45 va_s45 va_f45 va_sM in let va_f43 = va_lemma_merge_total va_b43 va_s43 va_fc44 va_s44 va_f44 va_sM in let va_f42 = va_lemma_merge_total va_b42 va_s42 va_fc43 va_s43 va_f43 va_sM in let va_f41 = va_lemma_merge_total va_b41 va_s41 va_fc42 va_s42 va_f42 va_sM in let va_f40 = va_lemma_merge_total va_b40 va_s40 va_fc41 va_s41 va_f41 va_sM in let va_f39 = va_lemma_merge_total va_b39 va_s39 va_fc40 va_s40 va_f40 va_sM in let va_f38 = va_lemma_merge_total va_b38 va_s38 va_fc39 va_s39 va_f39 va_sM in let va_f37 = va_lemma_merge_total va_b37 va_s37 va_fc38 va_s38 va_f38 va_sM in let va_f36 = va_lemma_merge_total va_b36 va_s36 va_fc37 va_s37 va_f37 va_sM in let va_f35 = va_lemma_merge_total va_b35 va_s35 va_fc36 va_s36 va_f36 va_sM in let va_f34 = va_lemma_merge_total va_b34 va_s34 va_fc35 va_s35 va_f35 va_sM in let va_f33 = va_lemma_merge_total va_b33 va_s33 va_fc34 va_s34 va_f34 va_sM in let va_f32 = va_lemma_merge_total va_b32 va_s32 va_fc33 va_s33 va_f33 va_sM in let va_f31 = va_lemma_merge_total va_b31 va_s31 va_fc32 va_s32 va_f32 va_sM in let va_f30 = va_lemma_merge_total va_b30 va_s30 va_fc31 va_s31 va_f31 va_sM in let va_f29 = va_lemma_merge_total va_b29 va_s29 va_fc30 va_s30 va_f30 va_sM in let va_f28 = va_lemma_merge_total va_b28 va_s28 va_fc29 va_s29 va_f29 va_sM in let va_f27 = va_lemma_merge_total va_b27 va_s27 va_fc28 va_s28 va_f28 va_sM in let va_f26 = va_lemma_merge_total va_b26 va_s26 va_fc27 va_s27 va_f27 va_sM in let va_f25 = va_lemma_merge_total va_b25 va_s25 va_fc26 va_s26 va_f26 va_sM in let va_f24 = va_lemma_merge_total va_b24 va_s24 va_fc25 va_s25 va_f25 va_sM in let va_f23 = va_lemma_merge_total va_b23 va_s23 va_fc24 va_s24 va_f24 va_sM in let va_f22 = va_lemma_merge_total va_b22 va_s22 va_fc23 va_s23 va_f23 va_sM in let va_f21 = va_lemma_merge_total va_b21 va_s21 va_fc22 va_s22 va_f22 va_sM in let va_f20 = va_lemma_merge_total va_b20 va_s20 va_fc21 va_s21 va_f21 va_sM in let va_f19 = va_lemma_merge_total va_b19 va_s19 va_fc20 va_s20 va_f20 va_sM in let va_f18 = va_lemma_merge_total va_b18 va_s18 va_fc19 va_s19 va_f19 va_sM in let va_f17 = va_lemma_merge_total va_b17 va_s17 va_fc18 va_s18 va_f18 va_sM in let va_f16 = va_lemma_merge_total va_b16 va_s16 va_fc17 va_s17 va_f17 va_sM in let va_f15 = va_lemma_merge_total va_b15 va_s15 va_fc16 va_s16 va_f16 va_sM in let va_f14 = va_lemma_merge_total va_b14 va_s14 va_fc15 va_s15 va_f15 va_sM in let va_f13 = va_lemma_merge_total va_b13 va_s13 va_fc14 va_s14 va_f14 va_sM in let va_f12 = va_lemma_merge_total va_b12 va_s12 va_fc13 va_s13 va_f13 va_sM in let va_fM = va_lemma_merge_total va_b1 va_s0 va_fc12 va_s12 va_f12 va_sM in (va_sM, va_fM)
{ "file_name": "obj/Vale.FDefMulx.X64.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 413, "start_col": 0, "start_line": 215 }
module Vale.FDefMulx.X64 open Vale.Def.Types_s open Vale.Arch.Types open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsStack open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.X64.CPU_Features_s open Vale.Bignum.Defs open Vale.Bignum.Lemmas open Vale.Bignum.X64 open FStar.Mul open FStar.Seq open Vale.Def.Words_s unfold let (.[]) = index //[@"opaque_to_smt"] let make_seq9 (#a:Type0) (v0 v1 v2 v3 v4 v5 v6 v7 v8:a) : seq a = init 9 (fun i -> if i = 0 then v0 else if i = 1 then v1 else if i = 2 then v2 else if i = 3 then v3 else if i = 4 then v4 else if i = 5 then v5 else if i = 6 then v6 else if i = 7 then v7 else v8) let operand_reg8 (n:nat) : operand64 = oreg (Reg 0 (8 + n % 8)) //-- lemma_seq_add_is_norm //-- //-- lemma_scale_add //-- //-- MulAdd18 #push-options "--z3rlimit 80 --max_fuel 1 --max_ifuel 0" val va_code_MulAdd18 : r0:va_operand_reg_opr64 -> r1:va_operand_reg_opr64 -> r2:va_operand_reg_opr64 -> r3:va_operand_reg_opr64 -> r4:va_operand_reg_opr64 -> r5:va_operand_reg_opr64 -> r6:va_operand_reg_opr64 -> r7:va_operand_reg_opr64 -> Tot va_code [@ "opaque_to_smt"] let va_code_MulAdd18 r0 r1 r2 r3 r4 r5 r6 r7 = (va_Block (va_CCons (va_code_Mem64_lemma ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRdx) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 0 Public)) (va_CCons (va_code_Mem64_lemma ()) (va_CCons (va_code_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRdi) 0 Public)) (va_CCons (va_code_Mem64_lemma ()) (va_CCons (va_code_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (0 `op_Multiply` 8) Public)) (va_CCons (va_code_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_op_opr64_reg64 rRax)) (va_CCons (va_code_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r1) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mem64_lemma ()) (va_CCons (va_code_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (1 `op_Multiply` 8) Public)) (va_CCons (va_code_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r1) (va_op_opr64_reg64 rRax)) (va_CCons (va_code_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r2) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mem64_lemma ()) (va_CCons (va_code_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (2 `op_Multiply` 8) Public)) (va_CCons (va_code_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r2) (va_op_opr64_reg64 rRax)) (va_CCons (va_code_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r3) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mem64_lemma ()) (va_CCons (va_code_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (3 `op_Multiply` 8) Public)) (va_CCons (va_code_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r3) (va_op_opr64_reg64 rRax)) (va_CCons (va_code_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r4) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mem64_lemma ()) (va_CCons (va_code_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (4 `op_Multiply` 8) Public)) (va_CCons (va_code_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r4) (va_op_opr64_reg64 rRax)) (va_CCons (va_code_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r5) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mem64_lemma ()) (va_CCons (va_code_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (5 `op_Multiply` 8) Public)) (va_CCons (va_code_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r5) (va_op_opr64_reg64 rRax)) (va_CCons (va_code_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r6) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mem64_lemma ()) (va_CCons (va_code_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (6 `op_Multiply` 8) Public)) (va_CCons (va_code_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r6) (va_op_opr64_reg64 rRax)) (va_CCons (va_code_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r7) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mem64_lemma ()) (va_CCons (va_code_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (7 `op_Multiply` 8) Public)) (va_CCons (va_code_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r7) (va_op_opr64_reg64 rRax)) (va_CCons (va_code_Store64_buffer (va_op_heaplet_mem_heaplet 0) (va_op_reg_opr64_reg64 rRdi) r0 0 Public) (va_CCons (va_code_Mov64 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_const_opr64 0)) (va_CCons (va_code_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_coerce_reg_opr64_to_opr64 r0)) (va_CCons (va_code_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_op_opr64_reg64 rRbx)) (va_CNil ()))))))))))))))))))))))))))))))))))))))))) val va_codegen_success_MulAdd18 : r0:va_operand_reg_opr64 -> r1:va_operand_reg_opr64 -> r2:va_operand_reg_opr64 -> r3:va_operand_reg_opr64 -> r4:va_operand_reg_opr64 -> r5:va_operand_reg_opr64 -> r6:va_operand_reg_opr64 -> r7:va_operand_reg_opr64 -> Tot va_pbool [@ "opaque_to_smt"] let va_codegen_success_MulAdd18 r0 r1 r2 r3 r4 r5 r6 r7 = (va_pbool_and (va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRdx) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 0 Public)) (va_pbool_and (va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRdi) 0 Public)) (va_pbool_and (va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (0 `op_Multiply` 8) Public)) (va_pbool_and (va_codegen_success_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_op_opr64_reg64 rRax)) (va_pbool_and (va_codegen_success_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r1) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (1 `op_Multiply` 8) Public)) (va_pbool_and (va_codegen_success_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r1) (va_op_opr64_reg64 rRax)) (va_pbool_and (va_codegen_success_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r2) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (2 `op_Multiply` 8) Public)) (va_pbool_and (va_codegen_success_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r2) (va_op_opr64_reg64 rRax)) (va_pbool_and (va_codegen_success_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r3) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (3 `op_Multiply` 8) Public)) (va_pbool_and (va_codegen_success_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r3) (va_op_opr64_reg64 rRax)) (va_pbool_and (va_codegen_success_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r4) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (4 `op_Multiply` 8) Public)) (va_pbool_and (va_codegen_success_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r4) (va_op_opr64_reg64 rRax)) (va_pbool_and (va_codegen_success_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r5) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (5 `op_Multiply` 8) Public)) (va_pbool_and (va_codegen_success_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r5) (va_op_opr64_reg64 rRax)) (va_pbool_and (va_codegen_success_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r6) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (6 `op_Multiply` 8) Public)) (va_pbool_and (va_codegen_success_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r6) (va_op_opr64_reg64 rRax)) (va_pbool_and (va_codegen_success_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r7) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mulx_64 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (7 `op_Multiply` 8) Public)) (va_pbool_and (va_codegen_success_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r7) (va_op_opr64_reg64 rRax)) (va_pbool_and (va_codegen_success_Store64_buffer (va_op_heaplet_mem_heaplet 0) (va_op_reg_opr64_reg64 rRdi) r0 0 Public) (va_pbool_and (va_codegen_success_Mov64 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_const_opr64 0)) (va_pbool_and (va_codegen_success_Adcx_64 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_coerce_reg_opr64_to_opr64 r0)) (va_pbool_and (va_codegen_success_Adox_64 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_op_opr64_reg64 rRbx)) (va_ttrue ())))))))))))))))))))))))))))))))))))))))) val va_lemma_MulAdd18 : va_b0:va_code -> va_s0:va_state -> r0:va_operand_reg_opr64 -> r1:va_operand_reg_opr64 -> r2:va_operand_reg_opr64 -> r3:va_operand_reg_opr64 -> r4:va_operand_reg_opr64 -> r5:va_operand_reg_opr64 -> r6:va_operand_reg_opr64 -> r7:va_operand_reg_opr64 -> regRotate:nat -> bA:buffer64 -> bB:buffer64 -> bD:buffer64 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_MulAdd18 r0 r1 r2 r3 r4 r5 r6 r7) va_s0 /\ va_is_dst_reg_opr64 r0 va_s0 /\ va_is_dst_reg_opr64 r1 va_s0 /\ va_is_dst_reg_opr64 r2 va_s0 /\ va_is_dst_reg_opr64 r3 va_s0 /\ va_is_dst_reg_opr64 r4 va_s0 /\ va_is_dst_reg_opr64 r5 va_s0 /\ va_is_dst_reg_opr64 r6 va_s0 /\ va_is_dst_reg_opr64 r7 va_s0 /\ va_get_ok va_s0 /\ (let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in Vale.X64.Decls.valid_cf (va_get_flags va_s0) /\ flag_cf (va_get_flags va_s0) == 0 /\ (Vale.X64.Decls.valid_of (va_get_flags va_s0) /\ flag_of (va_get_flags va_s0) == 0)) /\ (let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in adx_enabled /\ bmi2_enabled /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rRcx va_s0) bA 8 (va_get_mem_layout va_s0) Public /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rRsi va_s0) bB 1 (va_get_mem_layout va_s0) Public /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rRdi va_s0) bD 1 (va_get_mem_layout va_s0) Public /\ FStar.Seq.Base.length #Vale.Def.Types_s.nat64 as0 == 8 /\ r0 == operand_reg8 (regRotate + 0) /\ r1 == operand_reg8 (regRotate + 1) /\ r2 == operand_reg8 (regRotate + 2) /\ r3 == operand_reg8 (regRotate + 3) /\ r4 == operand_reg8 (regRotate + 4) /\ r5 == operand_reg8 (regRotate + 5) /\ r6 == operand_reg8 (regRotate + 6) /\ r7 == operand_reg8 (regRotate + 7)))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in Vale.X64.Decls.valid_cf (va_get_flags va_sM) /\ flag_cf (va_get_flags va_sM) == 0 /\ (Vale.X64.Decls.valid_of (va_get_flags va_sM) /\ flag_of (va_get_flags va_sM) == 0)) /\ (let (as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64)) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let (rs:(seq nat64)) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in let (b:Vale.Def.Types_s.nat64) = Vale.X64.Decls.buffer64_read bB 0 (va_get_mem_heaplet 0 va_s0) in let (d:Vale.Def.Types_s.nat64) = Vale.X64.Decls.buffer64_read bD 0 (va_get_mem_heaplet 0 va_s0) in let (xs:(seq nat64)) = make_seq9 #nat64 (Vale.X64.Decls.buffer64_read bD 0 (va_get_mem_heaplet 0 va_sM)) (va_eval_reg_opr64 va_sM r1) (va_eval_reg_opr64 va_sM r2) (va_eval_reg_opr64 va_sM r3) (va_eval_reg_opr64 va_sM r4) (va_eval_reg_opr64 va_sM r5) (va_eval_reg_opr64 va_sM r6) (va_eval_reg_opr64 va_sM r7) (va_eval_reg_opr64 va_sM r0) in sum_pow_seq xs == sum_pow_seq rs + b `op_Multiply` sum_pow_seq as0 + d) /\ va_state_eq va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 0 va_sM (va_update_flags va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM (va_update_operand_reg_opr64 r7 va_sM (va_update_operand_reg_opr64 r6 va_sM (va_update_operand_reg_opr64 r5 va_sM (va_update_operand_reg_opr64 r4 va_sM (va_update_operand_reg_opr64 r3 va_sM (va_update_operand_reg_opr64 r2 va_sM (va_update_operand_reg_opr64 r1 va_sM (va_update_operand_reg_opr64 r0 va_sM va_s0))))))))))))))))))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsStack.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Bignum.X64.fsti.checked", "Vale.Bignum.Lemmas.fsti.checked", "Vale.Bignum.Defs.fsti.checked", "Vale.Arch.Types.fsti.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.FDefMulx.X64.fst" }
[ { "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.Bignum.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Bignum.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Bignum.Defs", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsStack", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Bignum.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Bignum.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Bignum.Defs", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsStack", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.FDefMulx", "short_module": null }, { "abbrev": false, "full_module": "Vale.FDefMulx", "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": 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": 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": 80, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
va_b0: Vale.X64.Decls.va_code -> va_s0: Vale.X64.Decls.va_state -> r0: Vale.X64.Decls.va_operand_reg_opr64 -> r1: Vale.X64.Decls.va_operand_reg_opr64 -> r2: Vale.X64.Decls.va_operand_reg_opr64 -> r3: Vale.X64.Decls.va_operand_reg_opr64 -> r4: Vale.X64.Decls.va_operand_reg_opr64 -> r5: Vale.X64.Decls.va_operand_reg_opr64 -> r6: Vale.X64.Decls.va_operand_reg_opr64 -> r7: Vale.X64.Decls.va_operand_reg_opr64 -> regRotate: Prims.nat -> bA: Vale.X64.Memory.buffer64 -> bB: Vale.X64.Memory.buffer64 -> bD: Vale.X64.Memory.buffer64 -> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel)
Prims.Ghost
[]
[]
[ "Vale.X64.Decls.va_code", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_operand_reg_opr64", "Prims.nat", "Vale.X64.Memory.buffer64", "Vale.X64.Decls.va_fuel", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.Decls.va_lemma_merge_total", "FStar.Pervasives.Native.tuple2", "Vale.X64.State.vale_state", "Vale.X64.Decls.va_lemma_empty_total", "Prims.unit", "Prims.b2t", "Prims.squash", "Prims.l_and", "Prims.eq2", "Prims.int", "Vale.Bignum.X64.flag_cf", "Vale.X64.State.__proj__Mkvale_state__item__vs_flags", "Vale.Bignum.X64.flag_of", "Prims.Nil", "FStar.Pervasives.pattern", "Vale.Bignum.Defs.reveal_add_hi_all", "Vale.X64.Decls.va_get_flags", "Prims._assert", "FStar.Seq.Base.equal", "Vale.Def.Words_s.nat64", "FStar.Pervasives.Native.__proj__Mktuple2__item___1", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat1", "Vale.Bignum.Lemmas.seq_add", "Vale.Def.Words_s.pow2_64", "Vale.Bignum.Lemmas.lemma_scale_add", "Vale.Bignum.Lemmas.lemma_seq_add_is_norm", "Prims.op_Addition", "Vale.FDefMulx.X64.make_seq9", "Vale.X64.Decls.buffer64_read", "Vale.X64.Decls.va_get_mem_heaplet", "Vale.X64.Decls.va_eval_reg_opr64", "Vale.Bignum.Lemmas.init_zs", "Vale.Bignum.Lemmas.init_ys", "Vale.X64.Decls.va_int_range", "Prims.list", "Vale.X64.Machine_s.precode", "Vale.X64.Decls.ins", "Vale.X64.Decls.ocmp", "Vale.X64.Decls.va_tl", "Vale.Bignum.X64.va_lemma_Adox_64", "Vale.X64.Decls.va_hd", "Vale.X64.Decls.va_coerce_reg_opr64_to_dst_opr64", "Vale.X64.Decls.va_op_opr64_reg64", "Vale.X64.Machine_s.rRbx", "Vale.Bignum.X64.va_lemma_Adcx_64", "Vale.X64.Decls.va_coerce_reg_opr64_to_opr64", "Vale.X64.InsBasic.va_lemma_Mov64", "Vale.X64.Decls.va_const_opr64", "Vale.X64.InsMem.va_lemma_Store64_buffer", "Vale.X64.Decls.va_op_heaplet_mem_heaplet", "Vale.X64.Decls.va_op_reg_opr64_reg64", "Vale.X64.Machine_s.rRdi", "Vale.Arch.HeapTypes_s.Public", "Vale.X64.Machine_s.rRax", "Vale.Bignum.X64.va_lemma_Mulx_64", "Vale.X64.Decls.va_op_dst_opr64_reg64", "Vale.X64.Decls.va_opr_code_Mem64", "Vale.X64.Decls.va_op_reg64_reg64", "Vale.X64.Machine_s.rRcx", "Prims.op_Multiply", "Vale.X64.InsMem.va_lemma_Mem64_lemma", "Vale.X64.Machine_s.rRdx", "Vale.X64.Machine_s.rRsi", "Vale.Bignum.Defs.reveal_add_lo_all", "Vale.X64.Decls.s64", "Vale.X64.Decls.va_get_block", "Vale.X64.Decls.va_reveal_opaque", "Vale.FDefMulx.X64.va_code_MulAdd18" ]
[]
false
false
false
false
false
let va_lemma_MulAdd18 va_b0 va_s0 r0 r1 r2 r3 r4 r5 r6 r7 regRotate bA bB bD =
va_reveal_opaque (`%va_code_MulAdd18) (va_code_MulAdd18 r0 r1 r2 r3 r4 r5 r6 r7); let va_old_s:va_state = va_s0 in let va_b1:va_codes = va_get_block va_b0 in let as0:(FStar.Seq.Base.seq Vale.Def.Types_s.nat64) = Vale.X64.Decls.s64 (va_get_mem_heaplet 0 va_s0) bA in let rs:(seq nat64) = make_seq9 #nat64 (va_eval_reg_opr64 va_s0 r0) (va_eval_reg_opr64 va_s0 r1) (va_eval_reg_opr64 va_s0 r2) (va_eval_reg_opr64 va_s0 r3) (va_eval_reg_opr64 va_s0 r4) (va_eval_reg_opr64 va_s0 r5) (va_eval_reg_opr64 va_s0 r6) (va_eval_reg_opr64 va_s0 r7) 0 in let b:Vale.Def.Types_s.nat64 = Vale.X64.Decls.buffer64_read bB 0 (va_get_mem_heaplet 0 va_s0) in let d:Vale.Def.Types_s.nat64 = Vale.X64.Decls.buffer64_read bD 0 (va_get_mem_heaplet 0 va_s0) in Vale.Bignum.Defs.reveal_add_lo_all (); let va_s12, va_fc12 = va_lemma_Mem64_lemma (va_hd va_b1) va_s0 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 0 bB 0 Public in let va_b12 = va_tl va_b1 in let va_s13, va_fc13 = va_lemma_Mov64 (va_hd va_b12) va_s12 (va_op_dst_opr64_reg64 rRdx) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 0 Public) in let va_b13 = va_tl va_b12 in let va_s14, va_fc14 = va_lemma_Mem64_lemma (va_hd va_b13) va_s13 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRdi) 0 bD 0 Public in let va_b14 = va_tl va_b13 in let va_s15, va_fc15 = va_lemma_Adox_64 (va_hd va_b14) va_s14 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRdi) 0 Public) in let va_b15 = va_tl va_b14 in let va_s16, va_fc16 = va_lemma_Mem64_lemma (va_hd va_b15) va_s15 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (0 `op_Multiply` 8) bA 0 Public in let va_b16 = va_tl va_b15 in let va_s17, va_fc17 = va_lemma_Mulx_64 (va_hd va_b16) va_s16 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (0 `op_Multiply` 8) Public) in let va_b17 = va_tl va_b16 in let va_s18, va_fc18 = va_lemma_Adcx_64 (va_hd va_b17) va_s17 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_op_opr64_reg64 rRax) in let va_b18 = va_tl va_b17 in let va_s19, va_fc19 = va_lemma_Adox_64 (va_hd va_b18) va_s18 (va_coerce_reg_opr64_to_dst_opr64 r1) (va_op_opr64_reg64 rRbx) in let va_b19 = va_tl va_b18 in let va_s20, va_fc20 = va_lemma_Mem64_lemma (va_hd va_b19) va_s19 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (1 `op_Multiply` 8) bA 1 Public in let va_b20 = va_tl va_b19 in let va_s21, va_fc21 = va_lemma_Mulx_64 (va_hd va_b20) va_s20 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (1 `op_Multiply` 8) Public) in let va_b21 = va_tl va_b20 in let va_s22, va_fc22 = va_lemma_Adcx_64 (va_hd va_b21) va_s21 (va_coerce_reg_opr64_to_dst_opr64 r1) (va_op_opr64_reg64 rRax) in let va_b22 = va_tl va_b21 in let va_s23, va_fc23 = va_lemma_Adox_64 (va_hd va_b22) va_s22 (va_coerce_reg_opr64_to_dst_opr64 r2) (va_op_opr64_reg64 rRbx) in let va_b23 = va_tl va_b22 in let va_s24, va_fc24 = va_lemma_Mem64_lemma (va_hd va_b23) va_s23 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (2 `op_Multiply` 8) bA 2 Public in let va_b24 = va_tl va_b23 in let va_s25, va_fc25 = va_lemma_Mulx_64 (va_hd va_b24) va_s24 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (2 `op_Multiply` 8) Public) in let va_b25 = va_tl va_b24 in let va_s26, va_fc26 = va_lemma_Adcx_64 (va_hd va_b25) va_s25 (va_coerce_reg_opr64_to_dst_opr64 r2) (va_op_opr64_reg64 rRax) in let va_b26 = va_tl va_b25 in let va_s27, va_fc27 = va_lemma_Adox_64 (va_hd va_b26) va_s26 (va_coerce_reg_opr64_to_dst_opr64 r3) (va_op_opr64_reg64 rRbx) in let va_b27 = va_tl va_b26 in let va_s28, va_fc28 = va_lemma_Mem64_lemma (va_hd va_b27) va_s27 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (3 `op_Multiply` 8) bA 3 Public in let va_b28 = va_tl va_b27 in let va_s29, va_fc29 = va_lemma_Mulx_64 (va_hd va_b28) va_s28 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (3 `op_Multiply` 8) Public) in let va_b29 = va_tl va_b28 in let va_s30, va_fc30 = va_lemma_Adcx_64 (va_hd va_b29) va_s29 (va_coerce_reg_opr64_to_dst_opr64 r3) (va_op_opr64_reg64 rRax) in let va_b30 = va_tl va_b29 in let va_s31, va_fc31 = va_lemma_Adox_64 (va_hd va_b30) va_s30 (va_coerce_reg_opr64_to_dst_opr64 r4) (va_op_opr64_reg64 rRbx) in let va_b31 = va_tl va_b30 in let va_s32, va_fc32 = va_lemma_Mem64_lemma (va_hd va_b31) va_s31 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (4 `op_Multiply` 8) bA 4 Public in let va_b32 = va_tl va_b31 in let va_s33, va_fc33 = va_lemma_Mulx_64 (va_hd va_b32) va_s32 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (4 `op_Multiply` 8) Public) in let va_b33 = va_tl va_b32 in let va_s34, va_fc34 = va_lemma_Adcx_64 (va_hd va_b33) va_s33 (va_coerce_reg_opr64_to_dst_opr64 r4) (va_op_opr64_reg64 rRax) in let va_b34 = va_tl va_b33 in let va_s35, va_fc35 = va_lemma_Adox_64 (va_hd va_b34) va_s34 (va_coerce_reg_opr64_to_dst_opr64 r5) (va_op_opr64_reg64 rRbx) in let va_b35 = va_tl va_b34 in let va_s36, va_fc36 = va_lemma_Mem64_lemma (va_hd va_b35) va_s35 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (5 `op_Multiply` 8) bA 5 Public in let va_b36 = va_tl va_b35 in let va_s37, va_fc37 = va_lemma_Mulx_64 (va_hd va_b36) va_s36 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (5 `op_Multiply` 8) Public) in let va_b37 = va_tl va_b36 in let va_s38, va_fc38 = va_lemma_Adcx_64 (va_hd va_b37) va_s37 (va_coerce_reg_opr64_to_dst_opr64 r5) (va_op_opr64_reg64 rRax) in let va_b38 = va_tl va_b37 in let va_s39, va_fc39 = va_lemma_Adox_64 (va_hd va_b38) va_s38 (va_coerce_reg_opr64_to_dst_opr64 r6) (va_op_opr64_reg64 rRbx) in let va_b39 = va_tl va_b38 in let va_s40, va_fc40 = va_lemma_Mem64_lemma (va_hd va_b39) va_s39 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (6 `op_Multiply` 8) bA 6 Public in let va_b40 = va_tl va_b39 in let va_s41, va_fc41 = va_lemma_Mulx_64 (va_hd va_b40) va_s40 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (6 `op_Multiply` 8) Public) in let va_b41 = va_tl va_b40 in let va_s42, va_fc42 = va_lemma_Adcx_64 (va_hd va_b41) va_s41 (va_coerce_reg_opr64_to_dst_opr64 r6) (va_op_opr64_reg64 rRax) in let va_b42 = va_tl va_b41 in let va_s43, va_fc43 = va_lemma_Adox_64 (va_hd va_b42) va_s42 (va_coerce_reg_opr64_to_dst_opr64 r7) (va_op_opr64_reg64 rRbx) in let va_b43 = va_tl va_b42 in let va_s44, va_fc44 = va_lemma_Mem64_lemma (va_hd va_b43) va_s43 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (7 `op_Multiply` 8) bA 7 Public in let va_b44 = va_tl va_b43 in let va_s45, va_fc45 = va_lemma_Mulx_64 (va_hd va_b44) va_s44 (va_op_dst_opr64_reg64 rRbx) (va_op_dst_opr64_reg64 rRax) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRcx) (7 `op_Multiply` 8) Public) in let va_b45 = va_tl va_b44 in let va_s46, va_fc46 = va_lemma_Adcx_64 (va_hd va_b45) va_s45 (va_coerce_reg_opr64_to_dst_opr64 r7) (va_op_opr64_reg64 rRax) in let va_b46 = va_tl va_b45 in let va_s47, va_fc47 = va_lemma_Store64_buffer (va_hd va_b46) va_s46 (va_op_heaplet_mem_heaplet 0) (va_op_reg_opr64_reg64 rRdi) r0 0 Public bD 0 in let va_b47 = va_tl va_b46 in let va_s48, va_fc48 = va_lemma_Mov64 (va_hd va_b47) va_s47 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_const_opr64 0) in let va_b48 = va_tl va_b47 in let va_s49, va_fc49 = va_lemma_Adcx_64 (va_hd va_b48) va_s48 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_coerce_reg_opr64_to_opr64 r0) in let va_b49 = va_tl va_b48 in let va_s50, va_fc50 = va_lemma_Adox_64 (va_hd va_b49) va_s49 (va_coerce_reg_opr64_to_dst_opr64 r0) (va_op_opr64_reg64 rRbx) in let va_b50 = va_tl va_b49 in let l:(va_int_range 8 8) = 8 in let ys:(seq nat64) = init_ys b as0 in let zs:(seq nat64) = init_zs b as0 d in let qs:(seq nat64) = __proj__Mktuple2__item___1 #(seq nat64) #nat1 (seq_add rs zs 0) in let xs:(seq nat64) = make_seq9 #nat64 (Vale.X64.Decls.buffer64_read bD 0 (va_get_mem_heaplet 0 va_s50)) (va_eval_reg_opr64 va_s50 r1) (va_eval_reg_opr64 va_s50 r2) (va_eval_reg_opr64 va_s50 r3) (va_eval_reg_opr64 va_s50 r4) (va_eval_reg_opr64 va_s50 r5) (va_eval_reg_opr64 va_s50 r6) (va_eval_reg_opr64 va_s50 r7) (va_eval_reg_opr64 va_s50 r0) in lemma_seq_add_is_norm rs zs 0 (l + 1); lemma_seq_add_is_norm qs ys 0 (l + 1); lemma_scale_add l b d as0 rs ys zs qs xs; assert (FStar.Seq.Base.equal #nat64 xs (__proj__Mktuple2__item___1 #(seq nat64) #nat1 (seq_add qs ys 0))); let va_forall_lemma () : Lemma (requires true) (ensures (flag_cf (va_get_flags va_s50) == 0 /\ flag_of (va_get_flags va_s50) == 0)) = (Vale.Bignum.Defs.reveal_add_hi_all (); ()) in va_forall_lemma (); let va_sM, va_f50 = va_lemma_empty_total va_s50 va_b50 in let va_f49 = va_lemma_merge_total va_b49 va_s49 va_fc50 va_s50 va_f50 va_sM in let va_f48 = va_lemma_merge_total va_b48 va_s48 va_fc49 va_s49 va_f49 va_sM in let va_f47 = va_lemma_merge_total va_b47 va_s47 va_fc48 va_s48 va_f48 va_sM in let va_f46 = va_lemma_merge_total va_b46 va_s46 va_fc47 va_s47 va_f47 va_sM in let va_f45 = va_lemma_merge_total va_b45 va_s45 va_fc46 va_s46 va_f46 va_sM in let va_f44 = va_lemma_merge_total va_b44 va_s44 va_fc45 va_s45 va_f45 va_sM in let va_f43 = va_lemma_merge_total va_b43 va_s43 va_fc44 va_s44 va_f44 va_sM in let va_f42 = va_lemma_merge_total va_b42 va_s42 va_fc43 va_s43 va_f43 va_sM in let va_f41 = va_lemma_merge_total va_b41 va_s41 va_fc42 va_s42 va_f42 va_sM in let va_f40 = va_lemma_merge_total va_b40 va_s40 va_fc41 va_s41 va_f41 va_sM in let va_f39 = va_lemma_merge_total va_b39 va_s39 va_fc40 va_s40 va_f40 va_sM in let va_f38 = va_lemma_merge_total va_b38 va_s38 va_fc39 va_s39 va_f39 va_sM in let va_f37 = va_lemma_merge_total va_b37 va_s37 va_fc38 va_s38 va_f38 va_sM in let va_f36 = va_lemma_merge_total va_b36 va_s36 va_fc37 va_s37 va_f37 va_sM in let va_f35 = va_lemma_merge_total va_b35 va_s35 va_fc36 va_s36 va_f36 va_sM in let va_f34 = va_lemma_merge_total va_b34 va_s34 va_fc35 va_s35 va_f35 va_sM in let va_f33 = va_lemma_merge_total va_b33 va_s33 va_fc34 va_s34 va_f34 va_sM in let va_f32 = va_lemma_merge_total va_b32 va_s32 va_fc33 va_s33 va_f33 va_sM in let va_f31 = va_lemma_merge_total va_b31 va_s31 va_fc32 va_s32 va_f32 va_sM in let va_f30 = va_lemma_merge_total va_b30 va_s30 va_fc31 va_s31 va_f31 va_sM in let va_f29 = va_lemma_merge_total va_b29 va_s29 va_fc30 va_s30 va_f30 va_sM in let va_f28 = va_lemma_merge_total va_b28 va_s28 va_fc29 va_s29 va_f29 va_sM in let va_f27 = va_lemma_merge_total va_b27 va_s27 va_fc28 va_s28 va_f28 va_sM in let va_f26 = va_lemma_merge_total va_b26 va_s26 va_fc27 va_s27 va_f27 va_sM in let va_f25 = va_lemma_merge_total va_b25 va_s25 va_fc26 va_s26 va_f26 va_sM in let va_f24 = va_lemma_merge_total va_b24 va_s24 va_fc25 va_s25 va_f25 va_sM in let va_f23 = va_lemma_merge_total va_b23 va_s23 va_fc24 va_s24 va_f24 va_sM in let va_f22 = va_lemma_merge_total va_b22 va_s22 va_fc23 va_s23 va_f23 va_sM in let va_f21 = va_lemma_merge_total va_b21 va_s21 va_fc22 va_s22 va_f22 va_sM in let va_f20 = va_lemma_merge_total va_b20 va_s20 va_fc21 va_s21 va_f21 va_sM in let va_f19 = va_lemma_merge_total va_b19 va_s19 va_fc20 va_s20 va_f20 va_sM in let va_f18 = va_lemma_merge_total va_b18 va_s18 va_fc19 va_s19 va_f19 va_sM in let va_f17 = va_lemma_merge_total va_b17 va_s17 va_fc18 va_s18 va_f18 va_sM in let va_f16 = va_lemma_merge_total va_b16 va_s16 va_fc17 va_s17 va_f17 va_sM in let va_f15 = va_lemma_merge_total va_b15 va_s15 va_fc16 va_s16 va_f16 va_sM in let va_f14 = va_lemma_merge_total va_b14 va_s14 va_fc15 va_s15 va_f15 va_sM in let va_f13 = va_lemma_merge_total va_b13 va_s13 va_fc14 va_s14 va_f14 va_sM in let va_f12 = va_lemma_merge_total va_b12 va_s12 va_fc13 va_s13 va_f13 va_sM in let va_fM = va_lemma_merge_total va_b1 va_s0 va_fc12 va_s12 va_f12 va_sM in (va_sM, va_fM)
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.jump_sum
val jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc))
val jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc))
let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr)
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 64, "end_line": 580, "start_col": 0, "start_line": 570 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> v: LowParse.Low.Base.jumper p -> p32: LowParse.Low.Base.leaf_reader p -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> pc32: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.jumper (FStar.Pervasives.dsnd (pc x))) -> destr: LowParse.Spec.Enum.dep_maybe_enum_destr_t (LowParse.Spec.Sum.sum_enum t) (LowParse.Low.Sum.jump_sum_aux_payload_t t pc) -> LowParse.Low.Base.jumper (LowParse.Spec.Sum.parse_sum t p pc)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Low.Base.jumper", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Sum.sum_type_of_tag", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Enum.dep_maybe_enum_destr_t", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Low.Sum.jump_sum_aux_payload_t", "LowParse.Low.Sum.jump_sum_aux", "LowParse.Low.Sum.jump_sum_aux_payload", "LowParse.Spec.Sum.parse_sum_kind", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.parse_sum" ]
[]
false
false
false
false
false
let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) =
jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr)
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.validate_sum_aux_payload_if
val validate_sum_aux_payload_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k))
val validate_sum_aux_payload_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k))
let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 37, "end_line": 124, "start_col": 0, "start_line": 119 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Enum.maybe_enum_key (LowParse.Spec.Sum.sum_enum t) -> LowParse.Spec.Enum.if_combinator (LowParse.Low.Sum.validate_sum_aux_payload_t t pc k) (LowParse.Low.Sum.validate_sum_aux_payload_eq t pc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Low.Sum.validate_sum_aux_payload_if'", "LowParse.Spec.Enum.if_combinator", "LowParse.Low.Sum.validate_sum_aux_payload_t", "LowParse.Low.Sum.validate_sum_aux_payload_eq" ]
[]
false
false
false
false
false
let validate_sum_aux_payload_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) =
validate_sum_aux_payload_if' t pc k
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.read_sum_cases_t_eq
val read_sum_cases_t_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y: read_sum_cases_t t pc k) : GTot Type0
val read_sum_cases_t_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y: read_sum_cases_t t pc k) : GTot Type0
let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 611, "start_col": 0, "start_line": 605 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Sum.sum_key t -> x: LowParse.Low.Sum.read_sum_cases_t t pc k -> y: LowParse.Low.Sum.read_sum_cases_t t pc k -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Sum.read_sum_cases_t", "Prims.l_True" ]
[]
false
false
false
false
true
let read_sum_cases_t_eq (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y: read_sum_cases_t t pc k) : GTot Type0 =
True
false
Steel.HigherReference.fst
Steel.HigherReference.ghost_pts_to_perm
val ghost_pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ghost_ref a) : SteelGhost unit u (ghost_pts_to r p v) (fun _ -> ghost_pts_to r p v) (fun _ -> True) (fun _ _ _ -> p `lesser_equal_perm` full_perm)
val ghost_pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ghost_ref a) : SteelGhost unit u (ghost_pts_to r p v) (fun _ -> ghost_pts_to r p v) (fun _ -> True) (fun _ _ _ -> p `lesser_equal_perm` full_perm)
let ghost_pts_to_perm #a #_ #p #v r = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (ghost_pts_to r p v) (RP.pts_to r v_old `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (RP.pts_to r v_old `star` pure (perm_ok p)) (ghost_pts_to r p v) (fun _ -> ())
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 19, "end_line": 457, "start_col": 0, "start_line": 446 }
(* Copyright 2020 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 Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in calc (equiv) { p `star` q; (equiv) { star_commutative p q } q `star` p; (equiv) { equiv_extensional_on_star q r p } r `star` p; (equiv) { star_commutative p r } p `star` r; } let cas_action_helper (p q r s:slprop) (m:mem) : Lemma (requires interp Mem.(p `star` q `star` r `star` s) m) (ensures interp Mem.(p `star` q `star` s) m) = let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { p `star` q `star` r `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } (p `star` q `star` s) `star` r; }; assert (interp ((p `star` q `star` s) `star` r) m); affine_star (p `star` q `star` s) r m let cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:Ghost.erased t) (v_old:t) (v_new:t) (fr:slprop) : MstTot (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (cas_provides r v v_new) fr (fun _ -> True) (fun _ _ _ -> True) = let m0 : full_mem = NMSTTotal.get () in let fv = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let fv' = Some (v_new, full_perm) in assert (interp Mem.(pts_to_sl r full_perm v `star` fr `star` locks_invariant uses m0) m0); assert (interp Mem.(pts_to r fv `star` pure (perm_ok full_perm) `star` fr `star` locks_invariant uses m0) m0); cas_action_helper (Mem.pts_to r fv) (Mem.pure (perm_ok full_perm)) fr (locks_invariant uses m0) m0; assert (interp Mem.((pts_to r fv `star` pure (perm_ok full_perm)) `star` locks_invariant uses m0) m0); let fv_actual = Mem.frame (Mem.pure (perm_ok full_perm)) (sel_action uses r fv) fr in assert (compatible pcm_frac fv fv_actual); let Some (v', p) = fv_actual in assert (v == Ghost.hide v'); assert (p == full_perm); let b = if eq v' v_old then (Mem.frame (Mem.pure (perm_ok full_perm)) (upd_action uses r fv fv') fr; true) else false in b (*** GHOST REFERENCES ***) let ghost_ref a = erased (ref a) [@@__reduce__] let ghost_pts_to_sl #a (r:ghost_ref a) (p:perm) (x:a) = pts_to_sl (reveal r) p x let reveal_ghost_ref _ = () let reveal_ghost_pts_to_sl _ _ _ = () #push-options "--z3rlimit 20 --warn_error -271" let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m)) (ensures (x == y)) [SMTPat ()] = Mem.pts_to_join (Ghost.reveal r) (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in assert (forall x y m. interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m ==> x == y); assert (is_witness_invariant (ghost_pts_to_sl r p)) #pop-options let ghost_alloc_aux (#a:Type) (#u:_) (x:a) : SteelGhostT (ref a) u emp (fun r -> pts_to r full_perm (Ghost.hide x)) = let v : fractional a = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); rewrite_slprop emp (to_vprop Mem.emp) (fun _ -> reveal_emp()); let r : ref a = as_atomic_action_ghost (Steel.Memory.alloc_action u v) in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m); r let ghost_alloc x = let r = ghost_alloc_aux (reveal x) in hide r let ghost_free #a #u #v r = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); as_atomic_action_ghost (free_action u r v_old); drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let ghost_share_gen r p1 p2 = share_gen (reveal r) p1 p2 let ghost_share r = share (reveal r) let ghost_gather r = gather (reveal r) let ghost_pts_to_injective_eq #_ #_ #p0 #p1 r v0 v1 = higher_ref_pts_to_injective_eq #_ #_ #p0 #p1 #v0 #v1 (reveal r)
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "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: Steel.HigherReference.ghost_ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "Steel.HigherReference.ghost_ref", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Effect.Common.star", "Steel.PCMReference.pts_to", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac", "FStar.Ghost.reveal", "Steel.HigherReference.ref", "Steel.Effect.Common.pure", "Steel.HigherReference.perm_ok", "Steel.HigherReference.ghost_pts_to", "Steel.Memory.mem", "Prims.unit", "Steel.Effect.Atomic.intro_pure", "Steel.Effect.Atomic.elim_pure", "FStar.Ghost.erased", "FStar.Ghost.hide", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
true
false
false
false
let ghost_pts_to_perm #a #_ #p #v r =
let v_old:erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (ghost_pts_to r p v) ((RP.pts_to r v_old) `star` (pure (perm_ok p))) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop ((RP.pts_to r v_old) `star` (pure (perm_ok p))) (ghost_pts_to r p v) (fun _ -> ())
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.validate_sum_cases_t_if
val validate_sum_cases_t_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k))
val validate_sum_cases_t_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k))
let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 28, "end_line": 54, "start_col": 0, "start_line": 46 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Sum.sum_key t -> LowParse.Spec.Enum.if_combinator (LowParse.Low.Sum.validate_sum_cases_t t pc k) (LowParse.Low.Sum.validate_sum_cases_t_eq t pc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "Prims.bool", "LowParse.Spec.Combinators.cond_true", "LowParse.Low.Sum.validate_sum_cases_t", "LowParse.Spec.Combinators.cond_false", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t", "LowParse.Spec.Enum.if_combinator", "LowParse.Low.Sum.validate_sum_cases_t_eq" ]
[]
false
false
false
false
false
let validate_sum_cases_t_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) =
fun cond (sv_true: (cond_true cond -> Tot (validate_sum_cases_t t pc k))) (sv_false: (cond_false cond -> Tot (validate_sum_cases_t t pc k))) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.validate_sum_cases_aux
val validate_sum_cases_aux (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k))
val validate_sum_cases_aux (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k))
let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) ()
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 27, "start_col": 0, "start_line": 12 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> vc: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.validator (FStar.Pervasives.dsnd (pc x))) -> k: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.validator (LowParse.Spec.Sum.parse_sum_cases t pc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Base.validator", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Low.Combinators.validate_synth", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Base.weaken", "LowParse.Low.Combinators.validate_weaken", "LowParse.Spec.Sum.synth_sum_case", "Prims.unit", "LowParse.Spec.Sum.synth_sum_case_injective", "LowParse.Spec.Sum.parse_sum_cases" ]
[]
false
false
false
false
false
let validate_sum_cases_aux (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) =
[@@ inline_let ]let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) ()) (synth_sum_case t k) ()
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.validate_sum_aux_payload'
val validate_sum_aux_payload' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k)
val validate_sum_aux_payload' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k)
let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 34, "end_line": 179, "start_col": 0, "start_line": 166 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> pc32: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.validator (FStar.Pervasives.dsnd (pc x))) -> k: LowParse.Spec.Enum.maybe_enum_key (LowParse.Spec.Sum.sum_enum t) -> LowParse.Low.Sum.validate_sum_aux_payload_t t pc k
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Base.validator", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t", "LowParse.Spec.Enum.enum_key", "Prims.unit", "LowParse.Spec.Sum.synth_sum_case_injective", "LowParse.Low.ErrorCode.validator_error_generic", "LowParse.Low.Sum.validate_sum_aux_payload_t" ]
[]
false
false
false
false
false
let validate_sum_aux_payload' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) =
fun #rrel #rel input pos -> match k with | Known k -> [@@ inline_let ]let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> validator_error_generic
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.validate_sum_cases
val validate_sum_cases (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k))
val validate_sum_cases (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k))
let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 70, "start_col": 0, "start_line": 57 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> vc: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.validator (FStar.Pervasives.dsnd (pc x))) -> destr: LowParse.Spec.Enum.dep_enum_destr (LowParse.Spec.Sum.sum_enum t) (LowParse.Low.Sum.validate_sum_cases_t t pc) -> k: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.validator (LowParse.Spec.Sum.parse_sum_cases t pc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Base.validator", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Enum.dep_enum_destr", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Low.Sum.validate_sum_cases_t", "LowParse.Low.Sum.validate_sum_cases_t_eq", "LowParse.Low.Sum.validate_sum_cases_t_if", "LowParse.Spec.Enum.enum_key", "Prims.unit", "LowParse.Low.Sum.validate_sum_cases_aux", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Sum.parse_sum_cases" ]
[]
false
false
false
false
false
let validate_sum_cases (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) =
destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.validate_sum_aux_payload
val validate_sum_aux_payload (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))
val validate_sum_aux_payload (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))
let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 153, "end_line": 189, "start_col": 0, "start_line": 182 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> pc32: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.validator (FStar.Pervasives.dsnd (pc x))) -> destr: LowParse.Spec.Enum.dep_maybe_enum_destr_t (LowParse.Spec.Sum.sum_enum t) (LowParse.Low.Sum.validate_sum_aux_payload_t t pc) -> k: LowParse.Spec.Sum.sum_repr_type t -> LowParse.Low.Sum.validate_sum_aux_payload_t t pc (LowParse.Spec.Enum.maybe_enum_key_of_repr (LowParse.Spec.Sum.sum_enum t) k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Base.validator", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Enum.dep_maybe_enum_destr_t", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Low.Sum.validate_sum_aux_payload_t", "LowParse.Low.Sum.validate_sum_aux_payload_eq", "LowParse.Low.Sum.validate_sum_aux_payload_if", "LowParse.Spec.Enum.maybe_enum_key", "Prims.unit", "LowParse.Low.Sum.validate_sum_aux_payload'", "LowParse.Spec.Enum.maybe_enum_key_of_repr" ]
[]
false
false
false
false
false
let validate_sum_aux_payload (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) =
destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.serialize32_sum_cases_t_eq
val serialize32_sum_cases_t_eq (t: sum) (#pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: (x: sum_key t -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0
val serialize32_sum_cases_t_eq (t: sum) (#pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: (x: sum_key t -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0
let serialize32_sum_cases_t_eq (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 = True
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 682, "start_col": 0, "start_line": 675 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos) inline_for_extraction let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k #push-options "--z3rlimit 32" inline_for_extraction let read_sum (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (p32: leaf_reader (parse_enum_key p (sum_enum t))) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) : Tot (leaf_reader (parse_sum t p pc)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_sum t p pc) h input pos; parse_sum_eq' t p pc (bytes_of_slice_from h input pos); valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_enum_key j (sum_enum t) input pos in valid_facts (parse_sum_cases' t pc k) h input pos' ; read_sum_cases t pc pc32 destr k input pos' #pop-options inline_for_extraction let serialize32_sum_cases_t (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot Type = serializer32 (serialize_sum_cases t pc sc k)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> sc: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (pc x))) -> k: LowParse.Spec.Sum.sum_key t -> x: LowParse.Low.Sum.serialize32_sum_cases_t t sc k -> y: LowParse.Low.Sum.serialize32_sum_cases_t t sc k -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Base.serializer", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Low.Sum.serialize32_sum_cases_t", "Prims.l_True" ]
[]
false
false
false
false
true
let serialize32_sum_cases_t_eq (t: sum) (#pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: (x: sum_key t -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 =
True
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.eliminate_strong_all_used_not_by
val eliminate_strong_all_used_not_by (#kt #vt: _) (r: repr_t kt vt) (k: kt) (i: nat{i < r.sz}) : Lemma (requires strong_all_used_not_by r (canonical_index k r) r.sz k) (ensures Used? (r @@ i) /\ Used?.k (r @@ i) <> k)
val eliminate_strong_all_used_not_by (#kt #vt: _) (r: repr_t kt vt) (k: kt) (i: nat{i < r.sz}) : Lemma (requires strong_all_used_not_by r (canonical_index k r) r.sz k) (ensures Used? (r @@ i) /\ Used?.k (r @@ i) <> k)
let eliminate_strong_all_used_not_by #kt #vt (r:repr_t kt vt) (k:kt) (i:nat{i < r.sz}) : Lemma (requires strong_all_used_not_by r (canonical_index k r) r.sz k) (ensures Used? (r @@ i) /\ Used?.k (r @@ i) <> k) = let j = canonical_index k r in if (j < i) then ( assert (i == (j + (i-j)) % r.sz); assert (Used? (r @@ i)) ) else ( let k = ((r.sz - j) + i) in assert (i == (j + k) % r.sz); if (k < r.sz) then ( assert (Used? (r @@ i)) ) else ( assert (i == (j + 0) % r.sz); assert (Used? (r @@ ((j + 0) % r.sz))) ) )
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 764, "start_col": 0, "start_line": 744 }
(* Copyright 2023 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 Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key noeq type repr_t (k:eqtype) (v:Type) = { sz:pos; seq:Seq.lseq (cell k v) sz; hashf: k -> nat } let canonical_index (#kt:eqtype) #vt (key:kt) (repr:repr_t kt vt) : nat = repr.hashf key % repr.sz let (@@) #kt #vt (r:repr_t kt vt) (i:nat{ i < r.sz }) = Seq.index r.seq i let (++) #k #v (htf : spec_t k v) (key, value) : spec_t k v = fun k' -> if key = k' then Some value else htf k' let (--) #k #v (htf : spec_t k v) key : spec_t k v = fun k' -> if key = k' then None else htf k' // starting at idx, walk until you find kv pair (k,v) at index idx' // return Some (idx',v) else None if took sz steps and did not find let rec walk_get_idx #kt #vt (repr : repr_t kt vt) (idx:nat) (k:kt) (off:nat{off<=repr.sz}) : Tot (o:(option (vt & nat)) {match o with | Some (v,i) -> i<repr.sz /\ repr @@ i == Used k v | None -> true}) (decreases repr.sz - off) = if off = repr.sz then None else let idx' = (idx + off) % repr.sz in match repr @@ idx' with | Clean -> None | Used k' v -> if k = k' then Some (v,idx') else walk_get_idx repr idx k (off+1) | Zombie -> walk_get_idx repr idx k (off + 1) let rec walk_get_idx_upd #kt #vt (repr1 repr2:repr_t kt vt) (idx:nat) (k:kt) (off:nat{off <= repr1.sz}) (idx':nat { idx' < repr1.sz /\ Used? (repr1 @@ idx') }) (v:vt) : Lemma (requires (let Used k' v' = repr1 @@ idx' in repr2 == { repr1 with seq = Seq.upd repr1.seq idx' (Used k' v) })) (ensures (let Used k' v' = repr1 @@ idx' in let o1 = walk_get_idx repr1 idx k off in let o2 = walk_get_idx repr2 idx k off in match o1, o2 with | None, None -> True | Some (_, i1), Some (v2, i2) -> i1 == i2 /\ Seq.index repr2.seq i2 == Used k v2 | _ -> False)) (decreases repr1.sz - off) = if off = repr1.sz then () else let idx'' = (idx + off) % repr1.sz in match repr1 @@ idx'' with | Clean -> () | Used k' v' -> if k' = k then () else walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v | Zombie -> walk_get_idx_upd repr1 repr2 idx k (off+1) idx' v // perform a walk from idx but do not return idx' where k was found let walk #kt #vt (repr : repr_t kt vt) (idx:nat) (k : kt) (off:nat{off <= repr.sz}) : option vt = match walk_get_idx repr idx k off with | Some (v,_) -> Some v | _ -> None // perform a walk starting at the cacnonical index of k let lookup_repr #kt #vt (repr : repr_t kt vt) (k : kt) : option vt = let idx = canonical_index k repr in walk repr idx k 0 // perform a walk starting at the canonical index of k // but do not return idx' where k was found let lookup_repr_index #kt #vt (repr : repr_t kt vt) (k : kt) : option (vt & nat) = let idx = canonical_index k repr in walk_get_idx repr idx k 0 type spec_submap_repr #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_spec spec k) ==> lookup_repr repr k == lookup_spec spec k type repr_submap_spec #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall k. Some? (lookup_repr repr k) ==> lookup_repr repr k == lookup_spec spec k type unique_keys #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = forall i k v. repr @@ i == Used k v ==> lookup_repr_index repr k == Some (v, i) // FIXME: missing a bunch more interesting properties type pht_models #kt #vt (spec : spec_t kt vt) (repr : repr_t kt vt) : Type0 = spec_submap_repr spec repr /\ repr_submap_spec spec repr /\ unique_keys spec repr (* This is the main hash table type *) noeq type pht_t (kt:eqtype) (vt:Type) = { // spec is the pure, very high-level view of the hash table // as a partial map from keys to values. We mark it erased // so it does not show up in extraction. Another possibility // is to have a keyt -> GTot (option vt) function. Is that better // somehow? Does it also get erased? (I think so, but double check) spec : Ghost.erased (spec_t kt vt); repr : repr_t kt vt; inv : squash (pht_models spec repr /\ US.fits repr.sz); } let upd_ #kt #vt (repr : repr_t kt vt) idx k v : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx (Used k v) } let del_ #kt #vt (repr : repr_t kt vt) idx : repr_t kt vt = { repr with seq=Seq.upd repr.seq idx Zombie } let repr_related #kt #vt (r1 r2:repr_t kt vt) = r1.hashf == r2.hashf /\ r1.sz == r2.sz let repr_t_sz kt vt sz = r:repr_t kt vt { r.sz == sz} let lemma_clean_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ None? (lookup_repr repr1 k) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Clean /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases repr1.sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr1 @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_used_upd_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) idx k (k':_{k =!= k'}) (v v' : vt) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < repr1.sz /\ i <> idx ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ idx == Used k v' /\ repr2 @@ idx == Used k v /\ repr2 == upd_ repr1 idx k v /\ spec2 == spec1 ++ (k,v)) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = repr1.sz then () else if (idx' + off) % sz = idx then match repr1 @@ idx with | Used k'' _ -> if k' = k'' then () else aux (off+1) else begin match repr1 @@ ((idx' + off) % repr1.sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_del_lookup_walk #kt #vt #sz (spec1 spec2 : spec_t kt vt) (repr1 repr2 : repr_t_sz kt vt sz) upos k v (k':_{k =!= k'}) : Lemma (requires repr_related repr1 repr2 /\ (forall i. i < sz /\ i <> upos ==> repr1 @@ i == repr2 @@ i) /\ pht_models spec1 repr1 /\ repr1 @@ upos == Used k v /\ repr2 @@ upos == Zombie /\ spec2 == spec1 -- k) (ensures lookup_repr repr1 k' == lookup_repr repr2 k') = let idx' = canonical_index k' repr1 in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr1 idx' k' off == lookup_repr repr1 k' /\ walk repr2 idx' k' off == lookup_repr repr2 k') (ensures walk repr1 idx' k' off == walk repr2 idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = upos then aux (off+1) else begin match repr1 @@ (idx' + off) % sz with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let lemma_zombie_upd_lookup_walk #kt #vt #sz (spec spec' : spec_t kt vt) (repr repr' : repr_t_sz kt vt sz) idx k v (k':_{k =!= k'}) : Lemma (requires repr_related repr repr' /\ (forall i. i < sz /\ i <> idx ==> repr @@ i == repr' @@ i) /\ pht_models spec repr /\ repr' == upd_ repr idx k v /\ repr @@ idx == Zombie /\ spec' == spec ++ (k,v)) (ensures lookup_repr repr k' == lookup_repr repr' k') = let idx' = canonical_index k' repr in let rec aux (off:nat{off <= sz}) : Lemma (requires walk repr idx' k' off == lookup_repr repr k' /\ walk repr' idx' k' off == lookup_repr repr' k') (ensures walk repr idx' k' off == walk repr' idx' k' off) (decreases sz - off) = if off = sz then () else if (idx' + off) % sz = idx then aux (off+1) else begin match repr @@ ((idx' + off) % sz) with | Clean -> () | Used k'' v'' -> if k' = k'' then () else aux (off+1) | Zombie -> aux (off+1) end in aux 0 let strong_used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = (Used? (repr @@ i) /\ Used?.k (repr @@ i) <> k) let used_not_by #kt #kv (repr : repr_t kt kv) (k : kt) (i : nat{i < repr.sz}): prop = strong_used_not_by repr k i \/ Zombie? (repr @@ i) let all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). used_not_by repr k ((idx+i) % repr.sz) let strong_all_used_not_by #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (len : nat) (k : kt) : prop = forall (i:nat{i < len}). strong_used_not_by repr k ((idx+i) % repr.sz) let aunb_extend #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ used_not_by repr k ((idx+off) % repr.sz)) (ensures all_used_not_by repr idx (off+1) k) = () let aunb_shrink #kt #kv (repr : repr_t kt kv) (idx : (n:nat{n < repr.sz})) (off : nat) (k : kt) : Lemma (requires all_used_not_by repr idx off k /\ off > 0) (ensures all_used_not_by repr ((idx+1) % repr.sz) (off-1) k) = let sz = repr.sz in let sidx = (idx+1) % sz in let open FStar.Math.Lemmas in let aux (i:nat{i < off-1}) : Lemma (used_not_by repr k ((sidx+i)%sz)) = assert (used_not_by repr k ((idx+(i+1)) % repr.sz)); calc (==) { (sidx + i) % sz; == {} (((idx + 1) % sz) + i) % sz; == { lemma_mod_twice (idx+1) sz; assert (sidx % sz = (idx+1) % sz); modulo_add sz i sidx (idx+1) } (idx + 1 + i) % sz; }; assert (used_not_by repr k ((sidx+i) % sz)); () in Classical.forall_intro #(i:nat{i < off-1}) aux; () #push-options "--z3rlimit 20" let lemma_walk_from_canonical_all_used #kt #kv (repr : repr_t kt kv) (off : nat{off < repr.sz}) k v : Lemma (requires all_used_not_by repr (canonical_index k repr) off k /\ repr @@ ((canonical_index k repr + off) % repr.sz) == Used k v) (ensures lookup_repr repr k == Some v) = let sz = repr.sz in let cidx = canonical_index k repr in let rec aux (off':nat{off' <= off}) (_ : squash (all_used_not_by repr ((cidx+off')%sz) (off-off') k)) : Lemma (ensures walk repr cidx k off' == Some v) (decreases off - off') = if off' = off then () else begin Math.Lemmas.modulo_distributivity (cidx+off') 1 sz; assert (sz >= 2); // Note: we can only be here if off>0, which means sz>1 Math.Lemmas.modulo_lemma 1 sz; assert (1 % sz == 1); assert (((cidx + off') % sz + 1) % sz == (cidx+off'+1) % sz); aunb_shrink repr ((cidx+off')%sz) (off-off') k; aux (off'+1) () end in Math.Lemmas.modulo_lemma cidx sz; assert (cidx % sz == cidx); // hint for z3 aux 0 (); assert (lookup_repr repr k == walk repr cidx k 0); assert (lookup_repr repr k == Some v); () #pop-options let lemma_clean_upd #kt #vt spec (repr : repr_t kt vt) (off:nat{off < repr.sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % repr.sz == Clean /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % repr.sz) k v)) = let sz = repr.sz in let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k = k' then lemma_walk_from_canonical_all_used repr' off k v else lemma_clean_upd_lookup_walk #_ #_ #repr.sz spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_used_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k (v v' : vt) : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off)%sz == Used k v' /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off)%sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in let aux3 (i':nat{i'<sz}) (k':kt) (v'':vt) : Lemma (requires (repr' @@ i' == Used k' v'')) (ensures (lookup_repr_index repr' k' == Some (v'', i'))) = if k' = k then begin assert (lookup_repr_index repr k == Some (v',idx)); // this assert is necessary lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_used_upd_lookup_walk spec spec' repr repr' idx k k' v v' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_zombie_upd #kt #vt #sz spec (repr : repr_t_sz kt vt sz) (off:nat{off < sz}) k v : Lemma (requires pht_models spec repr /\ None? (lookup_repr repr k) /\ repr @@ (canonical_index k repr + off) % sz == Zombie /\ all_used_not_by repr (canonical_index k repr) off k) (ensures pht_models (spec ++ (k,v)) (upd_ repr ((canonical_index k repr + off) % sz) k v)) = let spec' = spec ++ (k,v) in let idx = (canonical_index k repr + off) % sz in let repr' = upd_ repr idx k v in let aux (i:nat{i < off}) : Lemma (used_not_by repr' k ((canonical_index k repr + i) % sz)) = calc (==>) { (canonical_index k repr + i) % sz == idx; ==> {} (canonical_index k repr + i) % sz == (canonical_index k repr + off) % sz; ==> { Math.Lemmas.lemma_mod_plus_injective sz (canonical_index k repr) i off } i == off; } in Classical.forall_intro aux; assert (all_used_not_by repr' (canonical_index k repr) off k); let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin lemma_walk_from_canonical_all_used repr' off k v; () end else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then lemma_walk_from_canonical_all_used repr' off k v else lemma_zombie_upd_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let lemma_del #kt #vt #sz spec (repr : repr_t_sz kt vt sz) idx k v : Lemma (requires pht_models spec repr /\ Some? (lookup_repr repr k) /\ repr @@ idx == Used k v) (ensures pht_models (spec -- k) (del_ repr idx)) = let spec' = spec -- k in let repr' = del_ repr idx in let aux1 (k':kt) : Lemma (requires (Some? (lookup_spec spec' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then () else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux2 (k':kt) : Lemma (requires (Some? (lookup_repr repr' k'))) (ensures (lookup_repr repr' k' == lookup_spec spec' k')) = if k' = k then begin let Some (v', i') = lookup_repr_index repr' k' in assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in let aux3 (i':nat{i'<sz}) (k':kt) (v':vt) : Lemma (requires (repr' @@ i' == Used k' v')) (ensures (lookup_repr_index repr' k' == Some (v', i'))) = if k' = k then begin assert (i' <> idx); assert (lookup_repr_index repr k == Some (v', i')); assert (lookup_repr_index repr k == Some (v, idx)); () end else lemma_del_lookup_walk spec spec' repr repr' idx k v k' in Classical.forall_intro (Classical.move_requires aux1); Classical.forall_intro (Classical.move_requires aux2); Classical.forall_intro_3 (Classical.move_requires_3 aux3) let not_full #kt #vt (r:repr_t kt vt) : Type0 = exists i. ~(Used? (r @@ i )) #set-options "--split_queries always" let rec insert_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr /\ not_full repr}) (k : kt) (v : vt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (strong_all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then ( // Impossible! table was not full let aux (i:nat{i < sz}) : Lemma (Used? (repr @@ i)) = assert (all_used_not_by repr cidx sz k); let off = (i - cidx) % sz in calc (==) { (cidx + off) % sz; == {} (cidx + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_lemma cidx sz } (cidx % sz + ((i - cidx) % sz)) % sz; == { Math.Lemmas.modulo_distributivity cidx (i-cidx) sz } i % sz; == { Math.Lemmas.modulo_lemma i sz } i; }; assert (Used? (repr @@ i)); () in Classical.forall_intro aux; unreachable () ) else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_used_upd spec repr off k v v'; upd_ repr idx k v end else begin assert (all_used_not_by repr cidx (off+1) k); insert_repr_walk #kt #vt #sz #spec repr k v (off+1) cidx () () end | Clean -> (**)lemma_clean_upd spec repr off k v; upd_ repr idx k v | Zombie -> match lookup_repr_index repr k with | Some (v_old,i) -> ( (**)lemma_del spec repr i k v_old; // Don't need these asserts let cidx = canonical_index k repr in assert (all_used_not_by repr cidx off k); // GM: Removing this assert, not needed now it seems //assert (if idx >= cidx then i > idx || i <= cidx else i > idx /\ i <= cidx); assert (all_used_not_by (del_ repr i) cidx off k); (**)lemma_zombie_upd #_ #_ #sz (spec -- k) (del_ repr i) off k v; upd_ (del_ repr i) idx k v ) | None -> ( (**)lemma_zombie_upd spec repr off k v; upd_ repr idx k v ) let insert_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (v : vt) : Pure (r':repr_t_sz kt vt sz{ pht_models (spec ++ (k,v)) r' /\ repr_related repr r' }) (requires not_full repr) (ensures fun _ -> True) = let cidx = canonical_index k repr in let res = insert_repr_walk #kt #vt #sz #spec repr k v 0 cidx () () in res let rec delete_repr_walk #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) (off:nat{off <= sz}) (cidx:nat{cidx = canonical_index k repr}) (_ : squash (all_used_not_by repr cidx off k)) (_ : squash (walk repr cidx k off == lookup_repr repr k)) : Tot (repr':repr_t_sz kt vt sz{ pht_models (spec -- k) repr' /\ repr_related repr repr' }) (decreases sz - off) = if off = sz then repr // If we reach this, the element was not in the table else let idx = (cidx+off) % sz in match repr @@ idx with | Used k' v' -> if k = k' then begin (**)lemma_del spec repr idx k v'; del_ repr idx end else begin assert (all_used_not_by repr cidx (off+1) k); delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () end | Clean -> repr | Zombie -> delete_repr_walk #kt #vt #sz #spec repr k (off+1) cidx () () let delete_repr #kt #vt #sz (#spec : erased (spec_t kt vt)) (repr : repr_t_sz kt vt sz{pht_models spec repr}) (k : kt) : r':repr_t_sz kt vt sz{ pht_models (spec -- k) r' /\ repr_related repr r' } = let cidx = canonical_index k repr in let res = delete_repr_walk #kt #vt #sz #spec repr k 0 cidx () () in res // TODO: This states we can only insert on a non-full table, // but that's only if the key we want to insert is not already present, // so it's stronger than it should be. This is anyway perhaps not important // for this pure implementation, as the Pulse implementation could always // keep one cell free and trivially satisfy this invariant. let insert #kt #vt (ht : pht_t kt vt{not_full ht.repr}) (k : kt) (v : vt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec ++ (k,v)) } = { ht with spec = Ghost.hide (ht.spec ++ (k,v)); repr = insert_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k v; inv = () } let delete #kt #vt (ht : pht_t kt vt) (k : kt) : ht':(pht_t kt vt){ht'.spec == Ghost.hide (ht.spec -- k) } = { ht with spec = Ghost.hide (ht.spec -- k); repr = delete_repr #_ #_ #ht.repr.sz #ht.spec ht.repr k; inv = () } let lookup #kt #vt (ht : pht_t kt vt) (k : kt) : o:(option vt){o == lookup_spec ht.spec k} = lookup_repr ht.repr k let lookup_index #kt #vt (ht : pht_t kt vt) (k : kt) : option (vt & nat) = lookup_repr_index ht.repr k // let lookup_index_us #kt #vt (ht : pht_t kt vt) (k : kt) // : option (vt & US.t) // = let o = lookup_repr_index ht.repr k in // match o with // | Some (v,i) -> Some (v, US.uint_to_t i) // | None -> None let lookup_index_us #kt #vt (ht : pht_t kt vt) (k : kt) : option US.t = let o = lookup_repr_index ht.repr k in match o with | Some (_, i) -> Some (US.uint_to_t i) | None -> None let upd_pht (#kt:eqtype) (#vt:Type) (pht:pht_t kt vt) idx (k:kt) (v:vt) (_:squash (lookup_index_us pht k == Some idx)) : pht_t kt vt = let spec' = Ghost.hide (pht.spec ++ (k, v)) in let repr' = upd_ pht.repr (US.v idx) k v in let Used k v' = pht.repr @@ US.v idx in let cidx = canonical_index #kt #vt k pht.repr in walk_get_idx_upd pht.repr repr' cidx k 0 (US.v idx) v; assert (lookup_repr_index repr' k == Some (v, US.v idx)); introduce forall (k':kt { k' =!= k }). lookup_repr repr' k' == lookup_repr pht.repr k' with lemma_used_upd_lookup_walk #_ #_ #pht.repr.sz pht.spec spec' pht.repr repr' (US.v idx) k k' v v'; { pht with spec = spec'; repr = repr'; inv = () }
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "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": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Pulse.Lib.HashTable.Spec.repr_t kt vt -> k: kt -> i: Prims.nat{i < Mkrepr_t?.sz r} -> FStar.Pervasives.Lemma (requires Pulse.Lib.HashTable.Spec.strong_all_used_not_by r (Pulse.Lib.HashTable.Spec.canonical_index k r) (Mkrepr_t?.sz r) k) (ensures Used? (r @@ i) /\ Used?.k (r @@ i) <> k)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.repr_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Pulse.Lib.HashTable.Spec.__proj__Mkrepr_t__item__sz", "Prims._assert", "Pulse.Lib.HashTable.Spec.uu___is_Used", "Pulse.Lib.HashTable.Spec.op_At_At", "Prims.unit", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Prims.op_Addition", "Prims.op_Subtraction", "Prims.bool", "Pulse.Lib.HashTable.Spec.canonical_index", "Pulse.Lib.HashTable.Spec.strong_all_used_not_by", "Prims.squash", "Prims.l_and", "Prims.op_disEquality", "Pulse.Lib.HashTable.Spec.__proj__Used__item__k", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let eliminate_strong_all_used_not_by #kt #vt (r: repr_t kt vt) (k: kt) (i: nat{i < r.sz}) : Lemma (requires strong_all_used_not_by r (canonical_index k r) r.sz k) (ensures Used? (r @@ i) /\ Used?.k (r @@ i) <> k) =
let j = canonical_index k r in if (j < i) then (assert (i == (j + (i - j)) % r.sz); assert (Used? (r @@ i))) else (let k = ((r.sz - j) + i) in assert (i == (j + k) % r.sz); if (k < r.sz) then (assert (Used? (r @@ i))) else (assert (i == (j + 0) % r.sz); assert (Used? (r @@ ((j + 0) % r.sz)))))
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.validate_sum_aux_payload_if'
val validate_sum_aux_payload_if' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k)
val validate_sum_aux_payload_if' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k)
let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 59, "end_line": 116, "start_col": 0, "start_line": 103 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Enum.maybe_enum_key (LowParse.Spec.Sum.sum_enum t) -> cond: Prims.bool -> ift: (_: LowParse.Spec.Combinators.cond_true cond -> LowParse.Low.Sum.validate_sum_aux_payload_t t pc k) -> iff: (_: LowParse.Spec.Combinators.cond_false cond -> LowParse.Low.Sum.validate_sum_aux_payload_t t pc k) -> LowParse.Low.Sum.validate_sum_aux_payload_t t pc k
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "Prims.bool", "LowParse.Spec.Combinators.cond_true", "LowParse.Low.Sum.validate_sum_aux_payload_t", "LowParse.Spec.Combinators.cond_false", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t" ]
[]
false
false
false
false
false
let validate_sum_aux_payload_if' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) =
fun #rrel #rel input pos -> if cond then (ift () <: validate_sum_aux_payload_t t pc k) input pos else (iff () <: validate_sum_aux_payload_t t pc k) input pos
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.jump_sum_cases
val jump_sum_cases (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k))
val jump_sum_cases (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k))
let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 333, "start_col": 0, "start_line": 320 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> vc: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.jumper (FStar.Pervasives.dsnd (pc x))) -> destr: LowParse.Spec.Enum.dep_enum_destr (LowParse.Spec.Sum.sum_enum t) (LowParse.Low.Sum.jump_sum_cases_t t pc) -> k: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.jumper (LowParse.Spec.Sum.parse_sum_cases t pc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Base.jumper", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Enum.dep_enum_destr", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Low.Sum.jump_sum_cases_t", "LowParse.Low.Sum.jump_sum_cases_t_eq", "LowParse.Low.Sum.jump_sum_cases_t_if", "LowParse.Spec.Enum.enum_key", "Prims.unit", "LowParse.Low.Sum.jump_sum_cases_aux", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Sum.parse_sum_cases" ]
[]
false
false
false
false
false
let jump_sum_cases (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) =
destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.clens_sum_tag
val clens_sum_tag (s: sum) : Tot (clens (sum_type s) (sum_key s))
val clens_sum_tag (s: sum) : Tot (clens (sum_type s) (sum_key s))
let clens_sum_tag (s: sum) : Tot (clens (sum_type s) (sum_key s)) = { clens_cond = (fun _ -> True); clens_get = sum_tag_of_data s; }
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 760, "start_col": 0, "start_line": 754 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos) inline_for_extraction let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k #push-options "--z3rlimit 32" inline_for_extraction let read_sum (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (p32: leaf_reader (parse_enum_key p (sum_enum t))) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) : Tot (leaf_reader (parse_sum t p pc)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_sum t p pc) h input pos; parse_sum_eq' t p pc (bytes_of_slice_from h input pos); valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_enum_key j (sum_enum t) input pos in valid_facts (parse_sum_cases' t pc k) h input pos' ; read_sum_cases t pc pc32 destr k input pos' #pop-options inline_for_extraction let serialize32_sum_cases_t (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot Type = serializer32 (serialize_sum_cases t pc sc k) let serialize32_sum_cases_t_eq (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 = True inline_for_extraction let serialize32_sum_cases_t_if (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_sum_cases_t t sc k))) (sv_false: (cond_false cond -> Tot (serialize32_sum_cases_t t sc k))) x #rrel #rel b pos -> if cond then (sv_true () x b pos) else (sv_false () x b pos) inline_for_extraction let serialize32_sum_cases_aux (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = fun x #rrel #rel b pos -> [@inline_let] let _ = Classical.forall_intro (parse_sum_cases_eq' t pc k); synth_sum_case_injective t k; synth_sum_case_inverse t k in serialize32_synth (sc32 k) (synth_sum_case t k) (synth_sum_case_recip t k) (fun x -> synth_sum_case_recip t k x) () x b pos inline_for_extraction let serialize32_sum_cases (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = destr _ (serialize32_sum_cases_t_if t sc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (serialize32_sum_cases_aux t sc sc32) k inline_for_extraction let serialize32_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p {kt.parser_kind_subkind == Some ParserStrong}) (s32: serializer32 (serialize_enum_key _ s (sum_enum t))) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) : Tot (serializer32 (serialize_sum t s sc)) = fun x #rrel #rel b pos -> serialize_sum_eq t s sc x; let tg = sum_tag_of_data t x in serialize32_nondep_then_aux s32 (serialize32_sum_cases t sc sc32 destr tg) tg x b pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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.Sum.sum -> LowParse.Low.Base.Spec.clens (LowParse.Spec.Sum.sum_type s) (LowParse.Spec.Sum.sum_key s)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Low.Base.Spec.Mkclens", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.sum_key", "Prims.l_True", "LowParse.Spec.Sum.sum_tag_of_data", "LowParse.Low.Base.Spec.clens" ]
[]
false
false
false
false
false
let clens_sum_tag (s: sum) : Tot (clens (sum_type s) (sum_key s)) =
{ clens_cond = (fun _ -> True); clens_get = sum_tag_of_data s }
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.gaccessor_sum_tag
val gaccessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (gaccessor (parse_sum t p pc) (parse_enum_key p (sum_enum t)) (clens_sum_tag t))
val gaccessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (gaccessor (parse_sum t p pc) (parse_enum_key p (sum_enum t)) (clens_sum_tag t))
let gaccessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (gaccessor (parse_sum t p pc) (parse_enum_key p (sum_enum t)) (clens_sum_tag t)) = gaccessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc)
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 26, "end_line": 771, "start_col": 0, "start_line": 762 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos) inline_for_extraction let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k #push-options "--z3rlimit 32" inline_for_extraction let read_sum (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (p32: leaf_reader (parse_enum_key p (sum_enum t))) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) : Tot (leaf_reader (parse_sum t p pc)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_sum t p pc) h input pos; parse_sum_eq' t p pc (bytes_of_slice_from h input pos); valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_enum_key j (sum_enum t) input pos in valid_facts (parse_sum_cases' t pc k) h input pos' ; read_sum_cases t pc pc32 destr k input pos' #pop-options inline_for_extraction let serialize32_sum_cases_t (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot Type = serializer32 (serialize_sum_cases t pc sc k) let serialize32_sum_cases_t_eq (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 = True inline_for_extraction let serialize32_sum_cases_t_if (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_sum_cases_t t sc k))) (sv_false: (cond_false cond -> Tot (serialize32_sum_cases_t t sc k))) x #rrel #rel b pos -> if cond then (sv_true () x b pos) else (sv_false () x b pos) inline_for_extraction let serialize32_sum_cases_aux (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = fun x #rrel #rel b pos -> [@inline_let] let _ = Classical.forall_intro (parse_sum_cases_eq' t pc k); synth_sum_case_injective t k; synth_sum_case_inverse t k in serialize32_synth (sc32 k) (synth_sum_case t k) (synth_sum_case_recip t k) (fun x -> synth_sum_case_recip t k x) () x b pos inline_for_extraction let serialize32_sum_cases (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = destr _ (serialize32_sum_cases_t_if t sc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (serialize32_sum_cases_aux t sc sc32) k inline_for_extraction let serialize32_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p {kt.parser_kind_subkind == Some ParserStrong}) (s32: serializer32 (serialize_enum_key _ s (sum_enum t))) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) : Tot (serializer32 (serialize_sum t s sc)) = fun x #rrel #rel b pos -> serialize_sum_eq t s sc x; let tg = sum_tag_of_data t x in serialize32_nondep_then_aux s32 (serialize32_sum_cases t sc sc32 destr tg) tg x b pos let clens_sum_tag (s: sum) : Tot (clens (sum_type s) (sum_key s)) = { clens_cond = (fun _ -> True); clens_get = sum_tag_of_data s; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.sum_repr_type t) -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Sum.parse_sum t p pc) (LowParse.Spec.Enum.parse_enum_key p (LowParse.Spec.Sum.sum_enum t)) (LowParse.Low.Sum.clens_sum_tag t)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Combinators.gaccessor_tagged_union_tag", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.sum_tag_of_data", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Sum.parse_sum_cases", "LowParse.Low.Base.Spec.gaccessor", "LowParse.Spec.Sum.parse_sum_kind", "LowParse.Spec.Sum.parse_sum", "LowParse.Low.Sum.clens_sum_tag" ]
[]
false
false
false
false
false
let gaccessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (gaccessor (parse_sum t p pc) (parse_enum_key p (sum_enum t)) (clens_sum_tag t)) =
gaccessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc)
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.jump_sum_cases_t_if
val jump_sum_cases_t_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k))
val jump_sum_cases_t_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k))
let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 28, "end_line": 317, "start_col": 0, "start_line": 309 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Sum.sum_key t -> LowParse.Spec.Enum.if_combinator (LowParse.Low.Sum.jump_sum_cases_t t pc k) (LowParse.Low.Sum.jump_sum_cases_t_eq t pc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "Prims.bool", "LowParse.Spec.Combinators.cond_true", "LowParse.Low.Sum.jump_sum_cases_t", "LowParse.Spec.Combinators.cond_false", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Spec.Enum.if_combinator", "LowParse.Low.Sum.jump_sum_cases_t_eq" ]
[]
false
false
false
false
false
let jump_sum_cases_t_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) =
fun cond (sv_true: (cond_true cond -> Tot (jump_sum_cases_t t pc k))) (sv_false: (cond_false cond -> Tot (jump_sum_cases_t t pc k))) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.accessor_sum_tag
val accessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (accessor (gaccessor_sum_tag t p pc))
val accessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (accessor (gaccessor_sum_tag t p pc))
let accessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (accessor (gaccessor_sum_tag t p pc)) = accessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc)
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 26, "end_line": 783, "start_col": 0, "start_line": 774 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos) inline_for_extraction let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k #push-options "--z3rlimit 32" inline_for_extraction let read_sum (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (p32: leaf_reader (parse_enum_key p (sum_enum t))) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) : Tot (leaf_reader (parse_sum t p pc)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_sum t p pc) h input pos; parse_sum_eq' t p pc (bytes_of_slice_from h input pos); valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_enum_key j (sum_enum t) input pos in valid_facts (parse_sum_cases' t pc k) h input pos' ; read_sum_cases t pc pc32 destr k input pos' #pop-options inline_for_extraction let serialize32_sum_cases_t (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot Type = serializer32 (serialize_sum_cases t pc sc k) let serialize32_sum_cases_t_eq (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 = True inline_for_extraction let serialize32_sum_cases_t_if (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_sum_cases_t t sc k))) (sv_false: (cond_false cond -> Tot (serialize32_sum_cases_t t sc k))) x #rrel #rel b pos -> if cond then (sv_true () x b pos) else (sv_false () x b pos) inline_for_extraction let serialize32_sum_cases_aux (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = fun x #rrel #rel b pos -> [@inline_let] let _ = Classical.forall_intro (parse_sum_cases_eq' t pc k); synth_sum_case_injective t k; synth_sum_case_inverse t k in serialize32_synth (sc32 k) (synth_sum_case t k) (synth_sum_case_recip t k) (fun x -> synth_sum_case_recip t k x) () x b pos inline_for_extraction let serialize32_sum_cases (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = destr _ (serialize32_sum_cases_t_if t sc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (serialize32_sum_cases_aux t sc sc32) k inline_for_extraction let serialize32_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p {kt.parser_kind_subkind == Some ParserStrong}) (s32: serializer32 (serialize_enum_key _ s (sum_enum t))) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) : Tot (serializer32 (serialize_sum t s sc)) = fun x #rrel #rel b pos -> serialize_sum_eq t s sc x; let tg = sum_tag_of_data t x in serialize32_nondep_then_aux s32 (serialize32_sum_cases t sc sc32 destr tg) tg x b pos let clens_sum_tag (s: sum) : Tot (clens (sum_type s) (sum_key s)) = { clens_cond = (fun _ -> True); clens_get = sum_tag_of_data s; } let gaccessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (gaccessor (parse_sum t p pc) (parse_enum_key p (sum_enum t)) (clens_sum_tag t)) = gaccessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.sum_repr_type t) -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> LowParse.Low.Base.accessor (LowParse.Low.Sum.gaccessor_sum_tag t p pc)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Combinators.accessor_tagged_union_tag", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.sum_tag_of_data", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Sum.parse_sum_cases", "LowParse.Low.Base.accessor", "LowParse.Spec.Sum.parse_sum_kind", "LowParse.Spec.Sum.parse_sum", "LowParse.Low.Sum.clens_sum_tag", "LowParse.Low.Sum.gaccessor_sum_tag" ]
[]
false
false
false
false
false
let accessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (accessor (gaccessor_sum_tag t p pc)) =
accessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc)
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.jump_sum_aux_payload_if'
val jump_sum_aux_payload_if' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k)
val jump_sum_aux_payload_if' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k)
let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 55, "end_line": 379, "start_col": 0, "start_line": 366 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Enum.maybe_enum_key (LowParse.Spec.Sum.sum_enum t) -> cond: Prims.bool -> ift: (_: LowParse.Spec.Combinators.cond_true cond -> LowParse.Low.Sum.jump_sum_aux_payload_t t pc k ) -> iff: (_: LowParse.Spec.Combinators.cond_false cond -> LowParse.Low.Sum.jump_sum_aux_payload_t t pc k) -> LowParse.Low.Sum.jump_sum_aux_payload_t t pc k
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "Prims.bool", "LowParse.Spec.Combinators.cond_true", "LowParse.Low.Sum.jump_sum_aux_payload_t", "LowParse.Spec.Combinators.cond_false", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t" ]
[]
false
false
false
false
false
let jump_sum_aux_payload_if' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) =
fun #rrel #rel input pos -> if cond then (ift () <: jump_sum_aux_payload_t t pc k) input pos else (iff () <: jump_sum_aux_payload_t t pc k) input pos
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.read_sum_cases'
val read_sum_cases' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k))
val read_sum_cases' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k))
let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) ()
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 14, "end_line": 595, "start_col": 0, "start_line": 583 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> pc32: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.leaf_reader (FStar.Pervasives.dsnd (pc x))) -> k: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.leaf_reader (LowParse.Spec.Sum.parse_sum_cases' t pc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Base.leaf_reader", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Low.Combinators.read_synth'", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Sum.synth_sum_case", "Prims.unit", "LowParse.Spec.Sum.synth_sum_case_injective", "FStar.Pervasives.dfst", "LowParse.Spec.Sum.parse_sum_cases'" ]
[]
false
false
false
false
false
let read_sum_cases' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) =
[@@ inline_let ]let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) ()
false
Steel.HigherReference.fst
Steel.HigherReference.atomic_write
val atomic_write (#opened:_) (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelAtomicT unit opened (pts_to r full_perm v) (fun _ -> pts_to r full_perm x)
val atomic_write (#opened:_) (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelAtomicT unit opened (pts_to r full_perm v) (fun _ -> pts_to r full_perm x)
let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m)
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 84, "end_line": 210, "start_col": 0, "start_line": 200 }
(* Copyright 2020 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 Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m)
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "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: Steel.HigherReference.ref a -> x: a -> Steel.Effect.Atomic.SteelAtomicT Prims.unit
Steel.Effect.Atomic.SteelAtomicT
[]
[]
[ "Steel.Memory.inames", "FStar.Ghost.erased", "Steel.HigherReference.ref", "Steel.Effect.Atomic.rewrite_slprop", "Steel.PCMReference.pts_to", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac", "Steel.HigherReference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.Memory.mem", "Steel.Memory.pure_star_interp", "Steel.Effect.Common.hp_of", "Steel.HigherReference.pts_to_raw", "FStar.Ghost.hide", "Steel.HigherReference.perm_ok", "Prims.unit", "Steel.Memory.emp_unit", "Steel.PCMReference.atomic_write", "Steel.Effect.Atomic.elim_pure", "FStar.Ghost.reveal", "Steel.Effect.Common.star", "Steel.Effect.Common.pure", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "Steel.FractionalPermission.perm", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
true
false
false
false
let atomic_write #opened #a #v r x =
let v_old:erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new:fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) ((RP.pts_to r v_old) `star` (pure (perm_ok full_perm))) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m)
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.jump_sum_aux_payload_if
val jump_sum_aux_payload_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k))
val jump_sum_aux_payload_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k))
let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 33, "end_line": 387, "start_col": 0, "start_line": 382 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Enum.maybe_enum_key (LowParse.Spec.Sum.sum_enum t) -> LowParse.Spec.Enum.if_combinator (LowParse.Low.Sum.jump_sum_aux_payload_t t pc k) (LowParse.Low.Sum.jump_sum_aux_payload_eq t pc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Low.Sum.jump_sum_aux_payload_if'", "LowParse.Spec.Enum.if_combinator", "LowParse.Low.Sum.jump_sum_aux_payload_t", "LowParse.Low.Sum.jump_sum_aux_payload_eq" ]
[]
false
false
false
false
false
let jump_sum_aux_payload_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) =
jump_sum_aux_payload_if' t pc k
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.accessor_clens_sum_payload
val accessor_clens_sum_payload (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_payload t p pc k))
val accessor_clens_sum_payload (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_payload t p pc k))
let accessor_clens_sum_payload (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_payload t p pc k)) = fun #rrel #rel -> accessor_clens_sum_payload' t j pc k #rrel #rel
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 67, "end_line": 915, "start_col": 0, "start_line": 907 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos) inline_for_extraction let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k #push-options "--z3rlimit 32" inline_for_extraction let read_sum (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (p32: leaf_reader (parse_enum_key p (sum_enum t))) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) : Tot (leaf_reader (parse_sum t p pc)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_sum t p pc) h input pos; parse_sum_eq' t p pc (bytes_of_slice_from h input pos); valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_enum_key j (sum_enum t) input pos in valid_facts (parse_sum_cases' t pc k) h input pos' ; read_sum_cases t pc pc32 destr k input pos' #pop-options inline_for_extraction let serialize32_sum_cases_t (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot Type = serializer32 (serialize_sum_cases t pc sc k) let serialize32_sum_cases_t_eq (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 = True inline_for_extraction let serialize32_sum_cases_t_if (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_sum_cases_t t sc k))) (sv_false: (cond_false cond -> Tot (serialize32_sum_cases_t t sc k))) x #rrel #rel b pos -> if cond then (sv_true () x b pos) else (sv_false () x b pos) inline_for_extraction let serialize32_sum_cases_aux (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = fun x #rrel #rel b pos -> [@inline_let] let _ = Classical.forall_intro (parse_sum_cases_eq' t pc k); synth_sum_case_injective t k; synth_sum_case_inverse t k in serialize32_synth (sc32 k) (synth_sum_case t k) (synth_sum_case_recip t k) (fun x -> synth_sum_case_recip t k x) () x b pos inline_for_extraction let serialize32_sum_cases (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = destr _ (serialize32_sum_cases_t_if t sc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (serialize32_sum_cases_aux t sc sc32) k inline_for_extraction let serialize32_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p {kt.parser_kind_subkind == Some ParserStrong}) (s32: serializer32 (serialize_enum_key _ s (sum_enum t))) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) : Tot (serializer32 (serialize_sum t s sc)) = fun x #rrel #rel b pos -> serialize_sum_eq t s sc x; let tg = sum_tag_of_data t x in serialize32_nondep_then_aux s32 (serialize32_sum_cases t sc sc32 destr tg) tg x b pos let clens_sum_tag (s: sum) : Tot (clens (sum_type s) (sum_key s)) = { clens_cond = (fun _ -> True); clens_get = sum_tag_of_data s; } let gaccessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (gaccessor (parse_sum t p pc) (parse_enum_key p (sum_enum t)) (clens_sum_tag t)) = gaccessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc) inline_for_extraction let accessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (accessor (gaccessor_sum_tag t p pc)) = accessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc) let clens_sum_payload (s: sum) (k: sum_key s) : Tot (clens (sum_type s) (sum_type_of_tag s k)) = { clens_cond = (fun (x: sum_type s) -> sum_tag_of_data s x == k); clens_get = (fun (x: sum_type s) -> synth_sum_case_recip s k x <: Ghost (sum_type_of_tag s k) (requires (sum_tag_of_data s x == k)) (ensures (fun _ -> True))); } #push-options "--z3rlimit 32" let gaccessor_clens_sum_payload' (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor' (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k)) = fun (input: bytes) -> parse_sum_eq'' t p pc input; let res = match parse p input with | Some (_, consumed) -> synth_sum_case_inverse t k; synth_sum_case_injective t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) (); (consumed) | _ -> 0 // dummy in (res <: (res: _ { gaccessor_post' (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) input res } )) #push-options "--z3rlimit 64" let gaccessor_clens_sum_payload_injective (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (sl sl' : bytes) : Lemma (requires ( gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl' /\ injective_precond (parse_sum t p pc) sl sl' )) (ensures (gaccessor_clens_sum_payload' t p pc k sl == gaccessor_clens_sum_payload' t p pc k sl')) = parse_sum_eq'' t p pc sl; parse_sum_eq'' t p pc sl' ; parse_injective (parse_sum t p pc) sl sl' ; parse_injective p sl sl' #pop-options let gaccessor_clens_sum_payload_no_lookahead (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (sl sl' : bytes) : Lemma (requires ( (parse_sum_kind kt t pc).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl' /\ no_lookahead_on_precond (parse_sum t p pc) sl sl' )) (ensures (gaccessor_clens_sum_payload' t p pc k sl == gaccessor_clens_sum_payload' t p pc k sl')) = parse_sum_eq'' t p pc sl; parse_sum_eq'' t p pc sl' ; parse_strong_prefix (parse_sum t p pc) sl sl' ; parse_injective p sl sl' let gaccessor_clens_sum_payload (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k)) = Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_clens_sum_payload_injective t p pc k x)); Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_clens_sum_payload_no_lookahead t p pc k x)); gaccessor_prop_equiv (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) (gaccessor_clens_sum_payload' t p pc k); gaccessor_clens_sum_payload' t p pc k inline_for_extraction let accessor_clens_sum_payload' (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_sum t p pc) h input pos /\ (clens_sum_payload t k).clens_cond (contents (parse_sum t p pc) h input pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h (gaccessor_clens_sum_payload t p pc k) input pos )) = let h = HST.get () in [@inline_let] let _ = let pos' = get_valid_pos (parse_sum t p pc) h input pos in let large = bytes_of_slice_from h input pos in slice_access_eq h (gaccessor_clens_sum_payload t p pc k) input pos; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq'' t p pc large; valid_facts p h input pos in j input pos #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> j: LowParse.Low.Base.jumper p -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.accessor (LowParse.Low.Sum.gaccessor_clens_sum_payload t p pc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Low.Base.jumper", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Low.Sum.accessor_clens_sum_payload'", "LowParse.Slice.slice", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.Sum.parse_sum_kind", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.parse_sum", "LowParse.Low.Base.Spec.__proj__Mkclens__item__clens_cond", "LowParse.Low.Sum.clens_sum_payload", "LowParse.Low.Base.Spec.contents", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.eq2", "LowParse.Low.Base.Spec.slice_access", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Low.Sum.gaccessor_clens_sum_payload", "LowParse.Low.Base.accessor" ]
[]
false
false
false
false
false
let accessor_clens_sum_payload (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_payload t p pc k)) =
fun #rrel #rel -> accessor_clens_sum_payload' t j pc k #rrel #rel
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.parse_sum_eq3
val parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k': sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures (let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False))
val parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k': sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures (let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False))
let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 29, "end_line": 408, "start_col": 0, "start_line": 389 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.sum_repr_type t) -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> input: LowParse.Bytes.bytes -> k': LowParse.Spec.Sum.sum_repr_type t -> consumed_k: LowParse.Spec.Base.consumed_length input -> FStar.Pervasives.Lemma (requires Some? (LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_sum t p pc) input) /\ LowParse.Spec.Base.parse p input == FStar.Pervasives.Native.Some (k', consumed_k)) (ensures (let input_k = FStar.Seq.Base.slice input consumed_k (FStar.Seq.Base.length input) in let k = LowParse.Spec.Enum.maybe_enum_key_of_repr (LowParse.Spec.Sum.sum_enum t) k' in (match k with | LowParse.Spec.Enum.Known #_ #_ #_ k -> Some? (LowParse.Spec.Base.parse (FStar.Pervasives.dsnd (pc k)) input_k) | _ -> Prims.l_False) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Bytes.bytes", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Sum.parse_sum_eq''", "Prims.unit", "Prims.l_and", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_sum", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.squash", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "FStar.Pervasives.dsnd", "LowParse.Spec.Enum.maybe_enum_key", "Prims.l_False", "LowParse.Spec.Enum.maybe_enum_key_of_repr", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k': sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures (let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False)) =
parse_sum_eq'' t p pc input
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.read_sum_tag
val read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos)))
val read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos)))
let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 48, "end_line": 524, "start_col": 0, "start_line": 504 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> p32: LowParse.Low.Base.leaf_reader p -> destr: LowParse.Spec.Enum.dep_maybe_enum_destr_t (LowParse.Spec.Sum.sum_enum t) (LowParse.Low.Enum.read_enum_key_t (LowParse.Spec.Sum.sum_enum t)) -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack (LowParse.Spec.Sum.sum_key t)
FStar.HyperStack.ST.Stack
[]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.Enum.dep_maybe_enum_destr_t", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Low.Enum.read_enum_key_t", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Enum.read_enum_key", "LowParse.Spec.Enum.enum_key", "Prims.unit", "LowParse.Low.Sum.valid_sum_elim_tag", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.Sum.parse_sum_kind", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.parse_sum", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.eq2", "LowParse.Spec.Sum.sum_tag_of_data", "LowParse.Low.Base.Spec.contents" ]
[]
false
true
false
false
false
let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos))) =
let h = HST.get () in [@@ inline_let ]let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.read_sum_cases
val read_sum_cases (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k))
val read_sum_cases (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k))
let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 638, "start_col": 0, "start_line": 625 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> pc32: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.leaf_reader (FStar.Pervasives.dsnd (pc x))) -> destr: LowParse.Spec.Enum.dep_enum_destr (LowParse.Spec.Sum.sum_enum t) (LowParse.Low.Sum.read_sum_cases_t t pc) -> k: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.leaf_reader (LowParse.Spec.Sum.parse_sum_cases' t pc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Base.leaf_reader", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Enum.dep_enum_destr", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Low.Sum.read_sum_cases_t", "LowParse.Low.Sum.read_sum_cases_t_eq", "LowParse.Low.Sum.read_sum_cases_t_if", "LowParse.Spec.Enum.enum_key", "Prims.unit", "LowParse.Low.Sum.read_sum_cases'", "FStar.Pervasives.dfst", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Sum.parse_sum_cases'" ]
[]
false
false
false
false
false
let read_sum_cases (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) =
destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.jump_sum_cases_aux
val jump_sum_cases_aux (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k))
val jump_sum_cases_aux (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k))
let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) ()
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 290, "start_col": 0, "start_line": 275 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> vc: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.jumper (FStar.Pervasives.dsnd (pc x))) -> k: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.jumper (LowParse.Spec.Sum.parse_sum_cases t pc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Base.jumper", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Low.Combinators.jump_synth", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Base.weaken", "LowParse.Low.Combinators.jump_weaken", "LowParse.Spec.Sum.synth_sum_case", "Prims.unit", "LowParse.Spec.Sum.synth_sum_case_injective", "LowParse.Spec.Sum.parse_sum_cases" ]
[]
false
false
false
false
false
let jump_sum_cases_aux (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) =
[@@ inline_let ]let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) ()) (synth_sum_case t k) ()
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.clens_sum_cases_payload
val clens_sum_cases_payload (s: sum) (k: sum_key s) : Tot (clens (sum_cases s k) (sum_type_of_tag s k))
val clens_sum_cases_payload (s: sum) (k: sum_key s) : Tot (clens (sum_cases s k) (sum_type_of_tag s k))
let clens_sum_cases_payload (s: sum) (k: sum_key s) : Tot (clens (sum_cases s k) (sum_type_of_tag s k)) = { clens_cond = (fun (x: sum_cases s k) -> True); clens_get = (fun (x: sum_cases s k) -> synth_sum_case_recip s k x <: Ghost (sum_type_of_tag s k) (requires (True)) (ensures (fun _ -> True))); }
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 924, "start_col": 0, "start_line": 917 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos) inline_for_extraction let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k #push-options "--z3rlimit 32" inline_for_extraction let read_sum (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (p32: leaf_reader (parse_enum_key p (sum_enum t))) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) : Tot (leaf_reader (parse_sum t p pc)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_sum t p pc) h input pos; parse_sum_eq' t p pc (bytes_of_slice_from h input pos); valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_enum_key j (sum_enum t) input pos in valid_facts (parse_sum_cases' t pc k) h input pos' ; read_sum_cases t pc pc32 destr k input pos' #pop-options inline_for_extraction let serialize32_sum_cases_t (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot Type = serializer32 (serialize_sum_cases t pc sc k) let serialize32_sum_cases_t_eq (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 = True inline_for_extraction let serialize32_sum_cases_t_if (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_sum_cases_t t sc k))) (sv_false: (cond_false cond -> Tot (serialize32_sum_cases_t t sc k))) x #rrel #rel b pos -> if cond then (sv_true () x b pos) else (sv_false () x b pos) inline_for_extraction let serialize32_sum_cases_aux (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = fun x #rrel #rel b pos -> [@inline_let] let _ = Classical.forall_intro (parse_sum_cases_eq' t pc k); synth_sum_case_injective t k; synth_sum_case_inverse t k in serialize32_synth (sc32 k) (synth_sum_case t k) (synth_sum_case_recip t k) (fun x -> synth_sum_case_recip t k x) () x b pos inline_for_extraction let serialize32_sum_cases (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = destr _ (serialize32_sum_cases_t_if t sc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (serialize32_sum_cases_aux t sc sc32) k inline_for_extraction let serialize32_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p {kt.parser_kind_subkind == Some ParserStrong}) (s32: serializer32 (serialize_enum_key _ s (sum_enum t))) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) : Tot (serializer32 (serialize_sum t s sc)) = fun x #rrel #rel b pos -> serialize_sum_eq t s sc x; let tg = sum_tag_of_data t x in serialize32_nondep_then_aux s32 (serialize32_sum_cases t sc sc32 destr tg) tg x b pos let clens_sum_tag (s: sum) : Tot (clens (sum_type s) (sum_key s)) = { clens_cond = (fun _ -> True); clens_get = sum_tag_of_data s; } let gaccessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (gaccessor (parse_sum t p pc) (parse_enum_key p (sum_enum t)) (clens_sum_tag t)) = gaccessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc) inline_for_extraction let accessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (accessor (gaccessor_sum_tag t p pc)) = accessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc) let clens_sum_payload (s: sum) (k: sum_key s) : Tot (clens (sum_type s) (sum_type_of_tag s k)) = { clens_cond = (fun (x: sum_type s) -> sum_tag_of_data s x == k); clens_get = (fun (x: sum_type s) -> synth_sum_case_recip s k x <: Ghost (sum_type_of_tag s k) (requires (sum_tag_of_data s x == k)) (ensures (fun _ -> True))); } #push-options "--z3rlimit 32" let gaccessor_clens_sum_payload' (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor' (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k)) = fun (input: bytes) -> parse_sum_eq'' t p pc input; let res = match parse p input with | Some (_, consumed) -> synth_sum_case_inverse t k; synth_sum_case_injective t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) (); (consumed) | _ -> 0 // dummy in (res <: (res: _ { gaccessor_post' (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) input res } )) #push-options "--z3rlimit 64" let gaccessor_clens_sum_payload_injective (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (sl sl' : bytes) : Lemma (requires ( gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl' /\ injective_precond (parse_sum t p pc) sl sl' )) (ensures (gaccessor_clens_sum_payload' t p pc k sl == gaccessor_clens_sum_payload' t p pc k sl')) = parse_sum_eq'' t p pc sl; parse_sum_eq'' t p pc sl' ; parse_injective (parse_sum t p pc) sl sl' ; parse_injective p sl sl' #pop-options let gaccessor_clens_sum_payload_no_lookahead (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (sl sl' : bytes) : Lemma (requires ( (parse_sum_kind kt t pc).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl' /\ no_lookahead_on_precond (parse_sum t p pc) sl sl' )) (ensures (gaccessor_clens_sum_payload' t p pc k sl == gaccessor_clens_sum_payload' t p pc k sl')) = parse_sum_eq'' t p pc sl; parse_sum_eq'' t p pc sl' ; parse_strong_prefix (parse_sum t p pc) sl sl' ; parse_injective p sl sl' let gaccessor_clens_sum_payload (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k)) = Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_clens_sum_payload_injective t p pc k x)); Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_clens_sum_payload_no_lookahead t p pc k x)); gaccessor_prop_equiv (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) (gaccessor_clens_sum_payload' t p pc k); gaccessor_clens_sum_payload' t p pc k inline_for_extraction let accessor_clens_sum_payload' (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_sum t p pc) h input pos /\ (clens_sum_payload t k).clens_cond (contents (parse_sum t p pc) h input pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h (gaccessor_clens_sum_payload t p pc k) input pos )) = let h = HST.get () in [@inline_let] let _ = let pos' = get_valid_pos (parse_sum t p pc) h input pos in let large = bytes_of_slice_from h input pos in slice_access_eq h (gaccessor_clens_sum_payload t p pc k) input pos; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq'' t p pc large; valid_facts p h input pos in j input pos #pop-options inline_for_extraction let accessor_clens_sum_payload (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_payload t p pc k)) = fun #rrel #rel -> accessor_clens_sum_payload' t j pc k #rrel #rel
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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.Sum.sum -> k: LowParse.Spec.Sum.sum_key s -> LowParse.Low.Base.Spec.clens (LowParse.Spec.Sum.sum_cases s k) (LowParse.Spec.Sum.sum_type_of_tag s k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "LowParse.Low.Base.Spec.Mkclens", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Sum.sum_type_of_tag", "Prims.l_True", "LowParse.Spec.Sum.synth_sum_case_recip", "LowParse.Low.Base.Spec.clens" ]
[]
false
false
false
false
false
let clens_sum_cases_payload (s: sum) (k: sum_key s) : Tot (clens (sum_cases s k) (sum_type_of_tag s k)) =
{ clens_cond = (fun (x: sum_cases s k) -> True); clens_get = (fun (x: sum_cases s k) -> synth_sum_case_recip s k x <: Ghost (sum_type_of_tag s k) (requires (True)) (ensures (fun _ -> True))) }
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.jump_sum_aux_payload
val jump_sum_aux_payload (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))
val jump_sum_aux_payload (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))
let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 141, "end_line": 567, "start_col": 0, "start_line": 560 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> pc32: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.jumper (FStar.Pervasives.dsnd (pc x))) -> destr: LowParse.Spec.Enum.dep_maybe_enum_destr_t (LowParse.Spec.Sum.sum_enum t) (LowParse.Low.Sum.jump_sum_aux_payload_t t pc) -> k: LowParse.Spec.Sum.sum_repr_type t -> LowParse.Low.Sum.jump_sum_aux_payload_t t pc (LowParse.Spec.Enum.maybe_enum_key_of_repr (LowParse.Spec.Sum.sum_enum t) k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Base.jumper", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Enum.dep_maybe_enum_destr_t", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Low.Sum.jump_sum_aux_payload_t", "LowParse.Low.Sum.jump_sum_aux_payload_eq", "LowParse.Low.Sum.jump_sum_aux_payload_if", "LowParse.Spec.Enum.maybe_enum_key", "Prims.unit", "LowParse.Low.Sum.jump_sum_aux_payload'", "LowParse.Spec.Enum.maybe_enum_key_of_repr" ]
[]
false
false
false
false
false
let jump_sum_aux_payload (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) =
destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.jump_sum_aux_payload'
val jump_sum_aux_payload' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k)
val jump_sum_aux_payload' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k)
let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 14, "end_line": 557, "start_col": 0, "start_line": 545 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> pc32: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.jumper (FStar.Pervasives.dsnd (pc x))) -> k: LowParse.Spec.Enum.maybe_enum_key (LowParse.Spec.Sum.sum_enum t) -> LowParse.Low.Sum.jump_sum_aux_payload_t t pc k
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Base.jumper", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Spec.Enum.enum_key", "Prims.unit", "LowParse.Spec.Sum.synth_sum_case_injective", "FStar.UInt32.__uint_to_t", "LowParse.Low.Sum.jump_sum_aux_payload_t" ]
[]
false
false
false
false
false
let jump_sum_aux_payload' (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: (x: sum_key t -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) =
fun #rrel #rel input pos -> match k with | Known k -> [@@ inline_let ]let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.jump_sum_aux
val jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: (k: sum_repr_type t -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)))) : Tot (jumper (parse_sum t p pc))
val jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: (k: sum_repr_type t -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)))) : Tot (jumper (parse_sum t p pc))
let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 34, "end_line": 542, "start_col": 0, "start_line": 527 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> v: LowParse.Low.Base.jumper p -> p32: LowParse.Low.Base.leaf_reader p -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> v_payload: (k: LowParse.Spec.Sum.sum_repr_type t -> LowParse.Low.Sum.jump_sum_aux_payload_t t pc (LowParse.Spec.Enum.maybe_enum_key_of_repr (LowParse.Spec.Sum.sum_enum t) k)) -> LowParse.Low.Base.jumper (LowParse.Spec.Sum.parse_sum t p pc)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Low.Base.jumper", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Low.Sum.jump_sum_aux_payload_t", "LowParse.Spec.Enum.maybe_enum_key_of_repr", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "Prims.unit", "LowParse.Low.Sum.valid_sum_elim", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Spec.Sum.parse_sum_kind", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.parse_sum" ]
[]
false
false
false
false
false
let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: (k: sum_repr_type t -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)))) : Tot (jumper (parse_sum t p pc)) =
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.parse_sum_eq4
val parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k': sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ (let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ (let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload) | _ -> False))) (ensures (let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload))
val parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k': sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ (let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ (let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload) | _ -> False))) (ensures (let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload))
let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 29, "end_line": 436, "start_col": 0, "start_line": 410 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.sum_repr_type t) -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> input: LowParse.Bytes.bytes -> k': LowParse.Spec.Sum.sum_repr_type t -> consumed_k: LowParse.Spec.Base.consumed_length input -> consumed_payload: Prims.nat -> FStar.Pervasives.Lemma (requires Some? (LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_sum t p pc) input) /\ LowParse.Spec.Base.parse p input == FStar.Pervasives.Native.Some (k', consumed_k) /\ (let input_k = FStar.Seq.Base.slice input consumed_k (FStar.Seq.Base.length input) in let k = LowParse.Spec.Enum.maybe_enum_key_of_repr (LowParse.Spec.Sum.sum_enum t) k' in (match k with | LowParse.Spec.Enum.Known #_ #_ #_ k -> Some? (LowParse.Spec.Base.parse (FStar.Pervasives.dsnd (pc k)) input_k) /\ (let _ = LowParse.Spec.Base.parse (FStar.Pervasives.dsnd (pc k)) input_k in (let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ _ consumed_payload') = _ in consumed_payload' == consumed_payload) <: Prims.logical) | _ -> Prims.l_False) <: Prims.logical)) (ensures (let _ = LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_sum t p pc) input in (let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ _ consumed) = _ in consumed == consumed_k + consumed_payload) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Bytes.bytes", "LowParse.Spec.Base.consumed_length", "Prims.nat", "LowParse.Spec.Sum.parse_sum_eq''", "Prims.unit", "Prims.l_and", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_sum", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "FStar.Pervasives.dsnd", "Prims.logical", "LowParse.Spec.Enum.maybe_enum_key", "Prims.l_False", "LowParse.Spec.Enum.maybe_enum_key_of_repr", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "Prims.squash", "Prims.int", "Prims.op_Addition", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k': sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ (let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ (let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload) | _ -> False))) (ensures (let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload)) =
parse_sum_eq'' t p pc input
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.validate_dsum_cases_eq
val validate_dsum_cases_eq (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (v1 v2: validate_dsum_cases_t s f g x) : GTot Type0
val validate_dsum_cases_eq (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (v1 v2: validate_dsum_cases_t s f g x) : GTot Type0
let validate_dsum_cases_eq (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (v1 v2 : validate_dsum_cases_t s f g x) : GTot Type0 = True
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 974, "start_col": 0, "start_line": 966 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos) inline_for_extraction let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k #push-options "--z3rlimit 32" inline_for_extraction let read_sum (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (p32: leaf_reader (parse_enum_key p (sum_enum t))) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) : Tot (leaf_reader (parse_sum t p pc)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_sum t p pc) h input pos; parse_sum_eq' t p pc (bytes_of_slice_from h input pos); valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_enum_key j (sum_enum t) input pos in valid_facts (parse_sum_cases' t pc k) h input pos' ; read_sum_cases t pc pc32 destr k input pos' #pop-options inline_for_extraction let serialize32_sum_cases_t (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot Type = serializer32 (serialize_sum_cases t pc sc k) let serialize32_sum_cases_t_eq (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 = True inline_for_extraction let serialize32_sum_cases_t_if (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_sum_cases_t t sc k))) (sv_false: (cond_false cond -> Tot (serialize32_sum_cases_t t sc k))) x #rrel #rel b pos -> if cond then (sv_true () x b pos) else (sv_false () x b pos) inline_for_extraction let serialize32_sum_cases_aux (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = fun x #rrel #rel b pos -> [@inline_let] let _ = Classical.forall_intro (parse_sum_cases_eq' t pc k); synth_sum_case_injective t k; synth_sum_case_inverse t k in serialize32_synth (sc32 k) (synth_sum_case t k) (synth_sum_case_recip t k) (fun x -> synth_sum_case_recip t k x) () x b pos inline_for_extraction let serialize32_sum_cases (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = destr _ (serialize32_sum_cases_t_if t sc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (serialize32_sum_cases_aux t sc sc32) k inline_for_extraction let serialize32_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p {kt.parser_kind_subkind == Some ParserStrong}) (s32: serializer32 (serialize_enum_key _ s (sum_enum t))) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (destr: dep_enum_destr (sum_enum t) (serialize32_sum_cases_t t sc)) : Tot (serializer32 (serialize_sum t s sc)) = fun x #rrel #rel b pos -> serialize_sum_eq t s sc x; let tg = sum_tag_of_data t x in serialize32_nondep_then_aux s32 (serialize32_sum_cases t sc sc32 destr tg) tg x b pos let clens_sum_tag (s: sum) : Tot (clens (sum_type s) (sum_key s)) = { clens_cond = (fun _ -> True); clens_get = sum_tag_of_data s; } let gaccessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (gaccessor (parse_sum t p pc) (parse_enum_key p (sum_enum t)) (clens_sum_tag t)) = gaccessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc) inline_for_extraction let accessor_sum_tag (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot (accessor (gaccessor_sum_tag t p pc)) = accessor_tagged_union_tag (parse_enum_key p (sum_enum t)) (sum_tag_of_data t) (parse_sum_cases t pc) let clens_sum_payload (s: sum) (k: sum_key s) : Tot (clens (sum_type s) (sum_type_of_tag s k)) = { clens_cond = (fun (x: sum_type s) -> sum_tag_of_data s x == k); clens_get = (fun (x: sum_type s) -> synth_sum_case_recip s k x <: Ghost (sum_type_of_tag s k) (requires (sum_tag_of_data s x == k)) (ensures (fun _ -> True))); } #push-options "--z3rlimit 32" let gaccessor_clens_sum_payload' (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor' (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k)) = fun (input: bytes) -> parse_sum_eq'' t p pc input; let res = match parse p input with | Some (_, consumed) -> synth_sum_case_inverse t k; synth_sum_case_injective t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) (); (consumed) | _ -> 0 // dummy in (res <: (res: _ { gaccessor_post' (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) input res } )) #push-options "--z3rlimit 64" let gaccessor_clens_sum_payload_injective (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (sl sl' : bytes) : Lemma (requires ( gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl' /\ injective_precond (parse_sum t p pc) sl sl' )) (ensures (gaccessor_clens_sum_payload' t p pc k sl == gaccessor_clens_sum_payload' t p pc k sl')) = parse_sum_eq'' t p pc sl; parse_sum_eq'' t p pc sl' ; parse_injective (parse_sum t p pc) sl sl' ; parse_injective p sl sl' #pop-options let gaccessor_clens_sum_payload_no_lookahead (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (sl sl' : bytes) : Lemma (requires ( (parse_sum_kind kt t pc).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl /\ gaccessor_pre (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) sl' /\ no_lookahead_on_precond (parse_sum t p pc) sl sl' )) (ensures (gaccessor_clens_sum_payload' t p pc k sl == gaccessor_clens_sum_payload' t p pc k sl')) = parse_sum_eq'' t p pc sl; parse_sum_eq'' t p pc sl' ; parse_strong_prefix (parse_sum t p pc) sl sl' ; parse_injective p sl sl' let gaccessor_clens_sum_payload (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k)) = Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_clens_sum_payload_injective t p pc k x)); Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_clens_sum_payload_no_lookahead t p pc k x)); gaccessor_prop_equiv (parse_sum t p pc) (dsnd (pc k)) (clens_sum_payload t k) (gaccessor_clens_sum_payload' t p pc k); gaccessor_clens_sum_payload' t p pc k inline_for_extraction let accessor_clens_sum_payload' (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_sum t p pc) h input pos /\ (clens_sum_payload t k).clens_cond (contents (parse_sum t p pc) h input pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h (gaccessor_clens_sum_payload t p pc k) input pos )) = let h = HST.get () in [@inline_let] let _ = let pos' = get_valid_pos (parse_sum t p pc) h input pos in let large = bytes_of_slice_from h input pos in slice_access_eq h (gaccessor_clens_sum_payload t p pc k) input pos; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq'' t p pc large; valid_facts p h input pos in j input pos #pop-options inline_for_extraction let accessor_clens_sum_payload (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_payload t p pc k)) = fun #rrel #rel -> accessor_clens_sum_payload' t j pc k #rrel #rel let clens_sum_cases_payload (s: sum) (k: sum_key s) : Tot (clens (sum_cases s k) (sum_type_of_tag s k)) = { clens_cond = (fun (x: sum_cases s k) -> True); clens_get = (fun (x: sum_cases s k) -> synth_sum_case_recip s k x <: Ghost (sum_type_of_tag s k) (requires (True)) (ensures (fun _ -> True))); } let gaccessor_clens_sum_cases_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (gaccessor (parse_sum_cases' t pc k) (dsnd (pc k)) (clens_sum_cases_payload t k)) = synth_sum_case_injective t k; synth_sum_case_inverse t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) (); gaccessor_ext (gaccessor_synth (dsnd (pc k)) (synth_sum_case t k) (synth_sum_case_recip t k) ()) (clens_sum_cases_payload t k) () inline_for_extraction let accessor_clens_sum_cases_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (accessor (gaccessor_clens_sum_cases_payload t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k; synth_sum_case_inverse t k; synth_injective_synth_inverse_synth_inverse_recip (synth_sum_case t k) (synth_sum_case_recip t k) () in accessor_ext (accessor_synth (dsnd (pc k)) (synth_sum_case t k) (synth_sum_case_recip t k) ()) (clens_sum_cases_payload t k) () inline_for_extraction let validate_dsum_cases_t (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) : Tot Type = validator (parse_dsum_cases' s f g x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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.Sum.dsum -> f: (x: LowParse.Spec.Sum.dsum_known_key s -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag s x))) -> g: LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_unknown_tag s) -> x: LowParse.Spec.Sum.dsum_key s -> v1: LowParse.Low.Sum.validate_dsum_cases_t s f g x -> v2: LowParse.Low.Sum.validate_dsum_cases_t s f g x -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Spec.Sum.dsum", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_type_of_known_tag", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Spec.Sum.dsum_key", "LowParse.Low.Sum.validate_dsum_cases_t", "Prims.l_True" ]
[]
false
false
false
false
true
let validate_dsum_cases_eq (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (x: dsum_key s) (v1 v2: validate_dsum_cases_t s f g x) : GTot Type0 =
True
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.read_sum_cases_t_if
val read_sum_cases_t_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k))
val read_sum_cases_t_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k))
let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos)
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 30, "end_line": 622, "start_col": 0, "start_line": 614 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> k: LowParse.Spec.Sum.sum_key t -> LowParse.Spec.Enum.if_combinator (LowParse.Low.Sum.read_sum_cases_t t pc k) (LowParse.Low.Sum.read_sum_cases_t_eq t pc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "Prims.bool", "LowParse.Spec.Combinators.cond_true", "LowParse.Low.Sum.read_sum_cases_t", "LowParse.Spec.Combinators.cond_false", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Enum.if_combinator", "LowParse.Low.Sum.read_sum_cases_t_eq" ]
[]
false
false
false
false
false
let read_sum_cases_t_if (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) =
fun cond (sv_true: (cond_true cond -> Tot (read_sum_cases_t t pc k))) (sv_false: (cond_false cond -> Tot (read_sum_cases_t t pc k))) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos)
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.serialize32_sum_cases_t_if
val serialize32_sum_cases_t_if (t: sum) (#pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: (x: sum_key t -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k))
val serialize32_sum_cases_t_if (t: sum) (#pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: (x: sum_key t -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k))
let serialize32_sum_cases_t_if (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_sum_cases_t t sc k))) (sv_false: (cond_false cond -> Tot (serialize32_sum_cases_t t sc k))) x #rrel #rel b pos -> if cond then (sv_true () x b pos) else (sv_false () x b pos)
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 28, "end_line": 694, "start_col": 0, "start_line": 685 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos) inline_for_extraction let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k #push-options "--z3rlimit 32" inline_for_extraction let read_sum (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (p32: leaf_reader (parse_enum_key p (sum_enum t))) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) : Tot (leaf_reader (parse_sum t p pc)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_sum t p pc) h input pos; parse_sum_eq' t p pc (bytes_of_slice_from h input pos); valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_enum_key j (sum_enum t) input pos in valid_facts (parse_sum_cases' t pc k) h input pos' ; read_sum_cases t pc pc32 destr k input pos' #pop-options inline_for_extraction let serialize32_sum_cases_t (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot Type = serializer32 (serialize_sum_cases t pc sc k) let serialize32_sum_cases_t_eq (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 = True
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> sc: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (pc x))) -> k: LowParse.Spec.Sum.sum_key t -> LowParse.Spec.Enum.if_combinator (LowParse.Low.Sum.serialize32_sum_cases_t t sc k) (LowParse.Low.Sum.serialize32_sum_cases_t_eq t sc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Base.serializer", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "Prims.bool", "LowParse.Spec.Combinators.cond_true", "LowParse.Low.Sum.serialize32_sum_cases_t", "LowParse.Spec.Combinators.cond_false", "LowParse.Spec.Sum.sum_cases", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "LowParse.Spec.Enum.if_combinator", "LowParse.Low.Sum.serialize32_sum_cases_t_eq" ]
[]
false
false
false
false
false
let serialize32_sum_cases_t_if (t: sum) (#pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: (x: sum_key t -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k)) =
fun cond (sv_true: (cond_true cond -> Tot (serialize32_sum_cases_t t sc k))) (sv_false: (cond_false cond -> Tot (serialize32_sum_cases_t t sc k))) x #rrel #rel b pos -> if cond then (sv_true () x b pos) else (sv_false () x b pos)
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.finalize_sum_case
val finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ (let pos_payload = pos `U32.add` (U32.uint_to_t len_tag) in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` (U32.uint_to_t len_tag) in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload)))
val finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ (let pos_payload = pos `U32.add` (U32.uint_to_t len_tag) in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` (U32.uint_to_t len_tag) in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload)))
let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in ()
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 4, "end_line": 272, "start_col": 0, "start_line": 242 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> s: LowParse.Spec.Base.serializer p -> w: LowParse.Low.Base.leaf_writer_strong s -> pc: (x: LowParse.Spec.Sum.sum_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag t x))) -> destr: LowParse.Spec.Enum.enum_repr_of_key'_t (LowParse.Spec.Sum.sum_enum t) -> k: LowParse.Spec.Sum.sum_key t -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Base.serializer", "LowParse.Low.Base.leaf_writer_strong", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Enum.enum_repr_of_key'_t", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "Prims.unit", "LowParse.Low.Sum.valid_sum_intro", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Enum.write_enum_key", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Addition", "FStar.UInt32.v", "LowParse.Low.Base.Spec.valid", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Low.Base.writable", "LowParse.Slice.buffer_srel_of_srel", "LowParse.Slice.__proj__Mkslice__item__base", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "Prims.nat", "LowParse.Low.Base.Spec.serialized_length", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Enum.serialize_enum_key", "LowStar.Monotonic.Buffer.modifies", "LowParse.Slice.loc_slice_from_to", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.Sum.parse_sum_kind", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.parse_sum", "LowParse.Spec.Sum.synth_sum_case", "LowParse.Low.Base.Spec.contents", "LowParse.Low.Base.Spec.get_valid_pos" ]
[]
false
true
false
false
false
let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ (let pos_payload = pos `U32.add` (U32.uint_to_t len_tag) in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` (U32.uint_to_t len_tag) in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload))) =
let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@@ inline_let ]let _ = valid_sum_intro h t p pc input pos in ()
false
Steel.HigherReference.fst
Steel.HigherReference.alloc
val alloc (#a:Type) (x:a) : Steel (ref a) emp (fun r -> pts_to r full_perm x) (requires fun _ -> True) (ensures fun _ r _ -> not (is_null r))
val alloc (#a:Type) (x:a) : Steel (ref a) emp (fun r -> pts_to r full_perm x) (requires fun _ -> True) (ensures fun _ r _ -> not (is_null r))
let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 11, "end_line": 144, "start_col": 0, "start_line": 132 }
(* Copyright 2020 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 Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ())
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "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: a -> Steel.Effect.Steel (Steel.HigherReference.ref a)
Steel.Effect.Steel
[]
[]
[ "Steel.Effect.Atomic.return", "Steel.HigherReference.ref", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.HigherReference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.Effect.Common.vprop", "Prims.unit", "Steel.Effect.Atomic.extract_info_raw", "Prims.l_not", "Prims.b2t", "Steel.HigherReference.is_null", "Steel.Memory.mem", "Steel.HigherReference.pts_to_not_null", "Steel.Effect.Atomic.rewrite_slprop", "Steel.PCMReference.pts_to", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac", "Steel.Memory.pure_star_interp", "Steel.Effect.Common.hp_of", "Steel.HigherReference.pts_to_raw", "Steel.HigherReference.perm_ok", "Steel.Memory.emp_unit", "Steel.Memory.ref", "Steel.PCMReference.alloc", "Prims._assert", "FStar.PCM.compatible", "FStar.PCM.composable", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.tuple2", "Steel.FractionalPermission.perm", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
true
false
false
false
let alloc #a x =
let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m); extract_info_raw (pts_to r full_perm x) (~(is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r
false
LowParse.Low.Sum.fst
LowParse.Low.Sum.serialize32_sum_cases_aux
val serialize32_sum_cases_aux (t: sum) (#pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: (x: sum_key t -> Tot (serializer (dsnd (pc x))))) (sc32: (x: sum_key t -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k))
val serialize32_sum_cases_aux (t: sum) (#pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: (x: sum_key t -> Tot (serializer (dsnd (pc x))))) (sc32: (x: sum_key t -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k))
let serialize32_sum_cases_aux (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (sc32: ((x: sum_key t) -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) = fun x #rrel #rel b pos -> [@inline_let] let _ = Classical.forall_intro (parse_sum_cases_eq' t pc k); synth_sum_case_injective t k; synth_sum_case_inverse t k in serialize32_synth (sc32 k) (synth_sum_case t k) (synth_sum_case_recip t k) (fun x -> synth_sum_case_recip t k x) () x b pos
{ "file_name": "src/lowparse/LowParse.Low.Sum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 7, "end_line": 718, "start_col": 0, "start_line": 697 }
module LowParse.Low.Sum include LowParse.Low.Enum include LowParse.Spec.Sum module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in validate_synth (validate_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let validate_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = validator (parse_sum_cases t pc k) let validate_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : validate_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let validate_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (validate_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (validate_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (validate_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let validate_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (validate_sum_cases_t t pc)) (k: sum_key t) : Tot (validator (parse_sum_cases t pc k)) = destr _ (validate_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_cases_aux t pc vc) k inline_for_extraction let validate_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h input /\ U64.v pos <= U32.v input.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> is_error res | Known k' -> if is_success res then valid_pos (dsnd (pc k')) h input (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid (dsnd (pc k')) h input (uint64_to_uint32 pos))) ))) let validate_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k -> validate_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let validate_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (validate_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (validate_sum_aux_payload_t t pc k))) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: validate_sum_aux_payload_t t pc k) input pos end else (iff () <: validate_sum_aux_payload_t t pc k) input pos inline_for_extraction let validate_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (validate_sum_aux_payload_eq t pc k)) = validate_sum_aux_payload_if' t pc k #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --using_facts_from '* -FStar.Int.Cast -LowParse.BitFields'" // --query_stats --smtencoding.elim_box true --smtencoding.l_arith_repr native --z3refresh" inline_for_extraction let validate_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (validator (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = parse_sum_eq'' t p pc (bytes_of_slice_from h input (uint64_to_uint32 pos)) in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input (uint64_to_uint32 pos) in [@inline_let] let _ = valid_facts p h input (uint64_to_uint32 pos) in let len_after_tag = v input pos in if is_error len_after_tag then len_after_tag else begin let h1 = HST.get () in let k' = p32 input (uint64_to_uint32 pos) in [@inline_let] let _ = match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input (uint64_to_uint32 len_after_tag) | _ -> () in v_payload k' input len_after_tag end #pop-options inline_for_extraction let validate_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (validate_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos // validate_synth (pc32 k) (synth_sum_case t k) () input pos | _ -> validator_error_generic inline_for_extraction let validate_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (validate_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (validate_sum_aux_payload_eq t pc) (validate_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (validate_sum_aux_payload' t pc pc32) k inline_for_extraction let validate_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: validator p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (validator (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (validate_sum_aux_payload_t t pc)) : Tot (validator (parse_sum t p pc)) = validate_sum_aux t v p32 pc (validate_sum_aux_payload t pc pc32 destr) module HS = FStar.HyperStack #push-options "--z3rlimit 256 --z3cliopt smt.arith.nl=false --initial_ifuel 8 --max_ifuel 8 --initial_fuel 2 --max_fuel 2" #restart-solver let valid_sum_intro (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_enum_key p (sum_enum t)) h input pos /\ ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in valid (dsnd (pc k)) h input (get_valid_pos (parse_enum_key p (sum_enum t)) h input pos) ))) (ensures ( let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_content_pos (parse_sum t p pc) h input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = contents (parse_enum_key p (sum_enum t)) h input pos in let pos_payload = get_valid_pos (parse_enum_key p (sum_enum t)) h input pos in valid_facts (dsnd (pc k)) h input pos_payload; valid_facts (parse_sum t p pc) h input pos; parse_sum_eq t p pc (bytes_of_slice_from h input pos) #pop-options inline_for_extraction let finalize_sum_case (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (s: serializer p) (w: leaf_writer_strong s) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (destr: enum_repr_of_key'_t (sum_enum t)) (k: sum_key t) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack unit (requires (fun h -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in U32.v pos + len_tag < 4294967296 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t len_tag in valid (dsnd (pc k)) h input pos_payload /\ writable input.base (U32.v pos) (U32.v pos_payload) h ))) (ensures (fun h _ h' -> let len_tag = serialized_length (serialize_enum_key _ s (sum_enum t)) k in let pos_payload = pos `U32.add` U32.uint_to_t len_tag in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ valid_content_pos (parse_sum t p pc) h' input pos (synth_sum_case t k (contents (dsnd (pc k)) h input pos_payload)) (get_valid_pos (dsnd (pc k)) h input pos_payload) )) = let pos1 = write_enum_key w (sum_enum t) destr k input pos in let h = HST.get () in [@inline_let] let _ = valid_sum_intro h t p pc input pos in () inline_for_extraction let jump_sum_cases_aux (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in jump_synth (jump_weaken (weaken_parse_cases_kind t pc) (vc k) () ) (synth_sum_case t k) () inline_for_extraction let jump_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = jumper (parse_sum_cases t pc k) let jump_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : jump_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let jump_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (jump_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (jump_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (jump_sum_cases_t t pc k)) #rrel #rel input pos -> if cond then sv_true () input pos else sv_false () input pos inline_for_extraction let jump_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (vc: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (jump_sum_cases_t t pc)) (k: sum_key t) : Tot (jumper (parse_sum_cases t pc k)) = destr _ (jump_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_cases_aux t pc vc) k inline_for_extraction let jump_sum_aux_payload_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot Type = (#rrel: _) -> (#rel: _) -> (input: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h input /\ U32.v pos <= U32.v input.len /\ ( match k with | Unknown _ -> False | Known k' -> valid (dsnd (pc k')) h input pos ))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( match k with | Unknown _ -> False | Known k' -> valid_pos (dsnd (pc k')) h input pos res ))) let jump_sum_aux_payload_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k -> jump_sum_aux_payload_t t pc k -> GTot Type0) = fun _ _ -> True inline_for_extraction let jump_sum_aux_payload_if' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) (cond: bool) (ift: ((cond_true cond) -> Tot (jump_sum_aux_payload_t t pc k))) (iff: ((cond_false cond) -> Tot (jump_sum_aux_payload_t t pc k))) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> if cond then begin (ift () <: jump_sum_aux_payload_t t pc k) input pos end else (iff () <: jump_sum_aux_payload_t t pc k) input pos inline_for_extraction let jump_sum_aux_payload_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: maybe_enum_key (sum_enum t)) : Tot (if_combinator _ (jump_sum_aux_payload_eq t pc k)) = jump_sum_aux_payload_if' t pc k let parse_sum_eq3 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k))) (ensures ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) | _ -> False end )) = parse_sum_eq'' t p pc input let parse_sum_eq4 (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (input: bytes) (k' : sum_repr_type t) (consumed_k: consumed_length input) (consumed_payload: nat) : Lemma (requires (Some? (parse (parse_sum t p pc) input) /\ parse p input == Some (k', consumed_k) /\ ( let input_k = Seq.slice input consumed_k (Seq.length input) in let k = maybe_enum_key_of_repr (sum_enum t) k' in begin match k with | Known k -> Some? (parse (dsnd (pc k)) input_k) /\ ( let Some (_, consumed_payload') = parse (dsnd (pc k)) input_k in consumed_payload' == consumed_payload ) | _ -> False end ))) (ensures ( let Some (_, consumed) = parse (parse_sum t p pc) input in consumed == consumed_k + consumed_payload )) = parse_sum_eq'' t p pc input #push-options "--z3rlimit 16" let valid_sum_elim (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid p h input pos /\ ( let pos_payload = get_valid_pos p h input pos in let k' = maybe_enum_key_of_repr (sum_enum t) (contents p h input pos) in match k' with | Known k -> k == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) /\ valid (dsnd (pc k)) h input pos_payload /\ valid_pos (parse_sum t p pc) h input pos (get_valid_pos (dsnd (pc k)) h input pos_payload) | _ -> False ))) = let sinput = bytes_of_slice_from h input pos in let _ = parse_sum_eq'' t p pc sinput in [@inline_let] let _ = valid_facts (parse_sum t p pc) h input pos in let Some (k', consumed_k) = parse p sinput in let pos_after_tag = U32.uint_to_t (U32.v pos + consumed_k) in [@inline_let] let _ = valid_facts p h input pos in assert (valid_content_pos p h input pos k' pos_after_tag); match maybe_enum_key_of_repr (sum_enum t) k' with | Known k -> valid_facts (dsnd (pc k)) h input pos_after_tag | _ -> () #pop-options let valid_sum_elim_tag (h: HS.mem) (t: sum) (#kt: parser_kind) (p: parser kt (sum_repr_type t)) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_sum t p pc) h input pos )) (ensures ( valid (parse_enum_key p (sum_enum t)) h input pos /\ contents (parse_enum_key p (sum_enum t)) h input pos == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let _ = parse_sum_eq' t p pc (bytes_of_slice_from h input pos) in let _ = valid_facts (parse_sum t p pc) h input pos in let _ = valid_facts (parse_enum_key p (sum_enum t)) h input pos in () inline_for_extraction let read_sum_tag (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (p32: leaf_reader p) (destr: dep_maybe_enum_destr_t (sum_enum t) (read_enum_key_t (sum_enum t))) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack (sum_key t) (requires (fun h -> valid (parse_sum t p pc) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == sum_tag_of_data t (contents (parse_sum t p pc) h input pos) )) = let h = HST.get () in [@inline_let] let _ = valid_sum_elim_tag h t p pc input pos in read_enum_key p32 (sum_enum t) destr input pos inline_for_extraction let jump_sum_aux (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (v_payload: ((k: sum_repr_type t)) -> Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k))) : Tot (jumper (parse_sum t p pc)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_sum_elim h t p pc input pos in let pos_after_tag = v input pos in let k' = p32 input pos in v_payload k' input pos_after_tag inline_for_extraction let jump_sum_aux_payload' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (k: maybe_enum_key (sum_enum t)) : Tot (jump_sum_aux_payload_t t pc k) = fun #rrel #rel input pos -> match k with | Known k -> [@inline_let] let _ = synth_sum_case_injective t k in pc32 k input pos | _ -> 0ul // dummy, but we MUST NOT remove this branch, otherwise extraction fails inline_for_extraction let jump_sum_aux_payload (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) (k: sum_repr_type t) : Tot (jump_sum_aux_payload_t t pc (maybe_enum_key_of_repr (sum_enum t) k)) = destr (jump_sum_aux_payload_eq t pc) (jump_sum_aux_payload_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (jump_sum_aux_payload' t pc pc32) k inline_for_extraction let jump_sum (t: sum) (#kt: parser_kind) (#p: parser kt (sum_repr_type t)) (v: jumper p) (p32: leaf_reader p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (jumper (dsnd (pc x))))) (destr: dep_maybe_enum_destr_t (sum_enum t) (jump_sum_aux_payload_t t pc)) : Tot (jumper (parse_sum t p pc)) = jump_sum_aux t v p32 pc (jump_sum_aux_payload t pc pc32 destr) inline_for_extraction let read_sum_cases' (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = [@inline_let] let _ = synth_sum_case_injective t k in read_synth' (dsnd (pc k)) (synth_sum_case t k) (pc32 k) () inline_for_extraction let read_sum_cases_t (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot Type = leaf_reader (parse_sum_cases' t pc k) let read_sum_cases_t_eq (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) (x y : read_sum_cases_t t pc k) : GTot Type0 = True inline_for_extraction let read_sum_cases_t_if (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (k: sum_key t) : Tot (if_combinator _ (read_sum_cases_t_eq t pc k)) = fun cond (sv_true: cond_true cond -> Tot (read_sum_cases_t t pc k)) (sv_false: cond_false cond -> Tot (read_sum_cases_t t pc k)) #_ #_ input pos -> if cond then (sv_true () input pos) else (sv_false () input pos) inline_for_extraction let read_sum_cases (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) (k: sum_key t) : Tot (leaf_reader (parse_sum_cases' t pc k)) = destr _ (read_sum_cases_t_if t pc) (fun _ _ -> ()) (fun _ _ _ _ -> ()) (read_sum_cases' t pc pc32) k #push-options "--z3rlimit 32" inline_for_extraction let read_sum (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (p32: leaf_reader (parse_enum_key p (sum_enum t))) (j: jumper p) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (pc32: ((x: sum_key t) -> Tot (leaf_reader (dsnd (pc x))))) (destr: dep_enum_destr (sum_enum t) (read_sum_cases_t t pc)) : Tot (leaf_reader (parse_sum t p pc)) = fun #_ #_ input pos -> let h = HST.get () in valid_facts (parse_sum t p pc) h input pos; parse_sum_eq' t p pc (bytes_of_slice_from h input pos); valid_facts (parse_enum_key p (sum_enum t)) h input pos; let k = p32 input pos in let pos' = jump_enum_key j (sum_enum t) input pos in valid_facts (parse_sum_cases' t pc k) h input pos' ; read_sum_cases t pc pc32 destr k input pos' #pop-options inline_for_extraction let serialize32_sum_cases_t (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot Type = serializer32 (serialize_sum_cases t pc sc k) let serialize32_sum_cases_t_eq (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) (x y: serialize32_sum_cases_t t sc k) : GTot Type0 = True inline_for_extraction let serialize32_sum_cases_t_if (t: sum) (#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x))))) (k: sum_key t) : Tot (if_combinator _ (serialize32_sum_cases_t_eq t sc k)) = fun cond (sv_true: (cond_true cond -> Tot (serialize32_sum_cases_t t sc k))) (sv_false: (cond_false cond -> Tot (serialize32_sum_cases_t t sc k))) x #rrel #rel b pos -> if cond then (sv_true () x b pos) else (sv_false () x b pos)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Sum.fst.checked", "LowParse.Low.Enum.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Sum.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Sum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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
t: LowParse.Spec.Sum.sum -> sc: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (pc x))) -> sc32: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.serializer32 (sc x)) -> k: LowParse.Spec.Sum.sum_key t -> LowParse.Low.Base.serializer32 (LowParse.Spec.Sum.serialize_sum_cases t pc sc k)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Base.serializer", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Low.Base.serializer32", "LowParse.Spec.Sum.sum_cases", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "LowParse.Low.Combinators.serialize32_synth", "LowParse.Spec.Sum.synth_sum_case", "LowParse.Spec.Sum.synth_sum_case_recip", "Prims.eq2", "Prims.unit", "LowParse.Spec.Sum.synth_sum_case_inverse", "LowParse.Spec.Sum.synth_sum_case_injective", "FStar.Classical.forall_intro", "LowParse.Bytes.bytes", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_sum_cases", "LowParse.Spec.Sum.parse_sum_cases'", "LowParse.Spec.Sum.parse_sum_cases_eq'", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Sum.serialize_sum_cases" ]
[]
false
false
false
false
false
let serialize32_sum_cases_aux (t: sum) (#pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) (sc: (x: sum_key t -> Tot (serializer (dsnd (pc x))))) (sc32: (x: sum_key t -> Tot (serializer32 (sc x)))) (k: sum_key t) : Tot (serializer32 (serialize_sum_cases t pc sc k)) =
fun x #rrel #rel b pos -> [@@ inline_let ]let _ = Classical.forall_intro (parse_sum_cases_eq' t pc k); synth_sum_case_injective t k; synth_sum_case_inverse t k in serialize32_synth (sc32 k) (synth_sum_case t k) (synth_sum_case_recip t k) (fun x -> synth_sum_case_recip t k x) () x b pos
false